⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xdelta3-test.h

📁 This program is free software you can redistribute it and/or modify it under the terms of the GNU G
💻 H
📖 第 1 页 / 共 5 页
字号:
  if ((ret = do_cmd (stream, buf))) { return ret; }  if ((ret = compare_files (stream, TEST_COPY_FILE, TEST_RECON2_FILE))) { return ret; }  /* Encode with decompression disabled */  sprintf (buf, "%s -feqD -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_TARGET_FILE, TEST_DELTA_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  /* Decode the delta file with recompression enabled, it doesn't matter, should get the   * compressed file out. */  sprintf (buf, "%s -fdq -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_DELTA_FILE, TEST_RECON_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  if ((ret = compare_files (stream, TEST_TARGET_FILE, TEST_RECON_FILE))) { return ret; }  /* Try again with recompression disabled, it doesn't make a difference. */  sprintf (buf, "%s -fqRd -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_DELTA_FILE, TEST_RECON_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  if ((ret = compare_files (stream, TEST_TARGET_FILE, TEST_RECON_FILE))) { return ret; }  test_cleanup();  return 0;}#endif/****************************************************************************************** FORCE, STDOUT ******************************************************************************************//* This tests that output will not overwrite an existing file unless -f was specified. * The test is for encoding (the same code handles it for decoding). */static inttest_force_behavior (xd3_stream *stream, int ignore){  int ret;  char buf[TESTBUFSIZE];  /* Create empty target file */  test_setup ();  sprintf (buf, "cp /dev/null %s", TEST_TARGET_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  /* Encode to delta file */  sprintf (buf, "%s -e %s %s", program_name, TEST_TARGET_FILE, TEST_DELTA_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  /* Encode again, should fail. */  sprintf (buf, "%s -e %s %s ", program_name, TEST_TARGET_FILE, TEST_DELTA_FILE);  if ((ret = do_fail (stream, buf))) { return ret; }  /* Force it, should succeed. */  sprintf (buf, "%s -f -e %s %s", program_name, TEST_TARGET_FILE, TEST_DELTA_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  test_cleanup();  return 0;}/* This checks the proper operation of the -c flag.  When specified the default output * becomes stdout, otherwise the input must be provided (encode) or it may be defaulted * (decode w/ app header). */static inttest_stdout_behavior (xd3_stream *stream, int ignore){  int ret;  char buf[TESTBUFSIZE];  test_setup();  sprintf (buf, "cp /dev/null %s", TEST_TARGET_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  /* Without -c, encode writes to delta file */  sprintf (buf, "%s -e %s %s", program_name, TEST_TARGET_FILE, TEST_DELTA_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  /* With -c, encode writes to stdout */  sprintf (buf, "%s -e -c %s > %s", program_name, TEST_TARGET_FILE, TEST_DELTA_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  /* Without -c, decode writes to target file name, but it fails because the file exists. */  sprintf (buf, "%s -d %s ", program_name, TEST_DELTA_FILE);  if ((ret = do_fail (stream, buf))) { return ret; }  /* With -c, decode writes to stdout */  sprintf (buf, "%s -d -c %s > /dev/null", program_name, TEST_DELTA_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  test_cleanup();  return 0;}/* This tests that the no-output flag (-J) works. */static inttest_no_output (xd3_stream *stream, int ignore){  int ret;  char buf[TESTBUFSIZE];    test_setup ();  sprintf (buf, "touch %s && chmod 0000 %s", TEST_NOPERM_FILE, TEST_NOPERM_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  if ((ret = test_make_inputs (stream, NULL, NULL))) { return ret; }  /* Try no_output encode w/out unwritable output file */  sprintf (buf, "%s -e %s %s", program_name, TEST_TARGET_FILE, TEST_NOPERM_FILE);  if ((ret = do_fail (stream, buf))) { return ret; }  sprintf (buf, "%s -J -e %s %s", program_name, TEST_TARGET_FILE, TEST_NOPERM_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  /* Now really write the delta to test decode no-output */  sprintf (buf, "%s -e %s %s", program_name, TEST_TARGET_FILE, TEST_DELTA_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  sprintf (buf, "%s -d %s %s", program_name, TEST_DELTA_FILE, TEST_NOPERM_FILE);  if ((ret = do_fail (stream, buf))) { return ret; }  sprintf (buf, "%s -J -d %s %s", program_name, TEST_DELTA_FILE, TEST_NOPERM_FILE);  if ((ret = do_cmd (stream, buf))) { return ret; }  test_cleanup ();  return 0;}/****************************************************************************************** Source identical optimization ******************************************************************************************//* Computing a delta should be fastest when the two inputs are identical, this checks it. * The library is called to compute a delta between a 10000 byte file, 1000 byte winsize, * 500 byte source blocksize.  The same buffer is used for both source and target. */static inttest_identical_behavior (xd3_stream *stream, int ignore){#define IDB_TGTSZ 10000#define IDB_BLKSZ 500#define IDB_WINSZ 1000#define IDB_DELSZ 1000#define IDB_WINCNT (IDB_TGTSZ / IDB_WINSZ)  int ret, i;  uint8_t buf[IDB_TGTSZ];  uint8_t del[IDB_DELSZ];  uint8_t rec[IDB_TGTSZ];  xd3_source source;  int    encwin = 0;  usize_t delpos = 0, recsize;  xd3_config config;  for (i = 0; i < IDB_TGTSZ; i += 1) { buf[i] = rand (); }   stream->winsize = IDB_WINSZ;  source.size     = IDB_TGTSZ;  source.blksize  = IDB_BLKSZ;  source.name     = "";  source.curblk   = NULL;  source.curblkno = -1;  if ((ret = xd3_set_source (stream, & source))) { goto fail; }  /* Compute an delta between identical source and targets. */  for (;;)    {      ret = xd3_encode_input (stream);      if (ret == XD3_INPUT)	{	  if (encwin == IDB_WINCNT-1) { break; }	  xd3_avail_input (stream, buf + (IDB_WINSZ * encwin), IDB_WINSZ);	  encwin += 1;	  continue;	}      if (ret == XD3_GETSRCBLK)	{	  source.curblkno = source.getblkno;	  source.onblk    = IDB_BLKSZ;	  source.curblk   = buf + source.getblkno * IDB_BLKSZ;	  continue;	}      if (ret == XD3_WINSTART) { continue; }      if (ret == XD3_WINFINISH) { continue; }      if (ret != XD3_OUTPUT) { goto fail; }      CHECK(delpos + stream->avail_out <= IDB_DELSZ);      memcpy (del + delpos, stream->next_out, stream->avail_out);      delpos += stream->avail_out;      xd3_consume_output (stream);    }  /* Reset. */  source.blksize  = IDB_TGTSZ;  source.onblk    = IDB_TGTSZ;  source.curblk   = buf;  source.curblkno = 0;  if ((ret = xd3_close_stream (stream))) { goto fail; }  xd3_free_stream (stream);  xd3_init_config (& config, 0);  if ((ret = xd3_config_stream (stream, & config))) { goto fail; }  if ((ret = xd3_set_source (stream, & source))) { goto fail; }  /* Decode. */  if ((ret = xd3_decode_stream (stream, del, delpos, rec, & recsize, IDB_TGTSZ))) { goto fail; }  /* Check result size and data. */  if (recsize != IDB_TGTSZ) { stream->msg = "wrong size reconstruction"; goto fail; }  if (memcmp (rec, buf, IDB_TGTSZ) != 0) { stream->msg = "wrong data reconstruction"; goto fail; }  /* Check that there was one copy per window. */  IF_DEBUG (if (stream->n_scpy != IDB_WINCNT ||		stream->n_add != 0 ||		stream->n_run != 0) { stream->msg = "wrong copy count"; goto fail; });  /* Check that no checksums were computed because the initial match was presumed. */  IF_DEBUG (if (stream->large_ckcnt != 0) { stream->msg = "wrong checksum behavior"; goto fail; });  ret = 0; fail:  return ret;}/****************************************************************************************** String matching test ******************************************************************************************//* Check particular matching behaviors by calling xd3_string_match_soft directly with * specific arguments. */typedef struct _string_match_test string_match_test;typedef enum{  SM_NONE    = 0,  SM_LAZY    = (1 << 1),} string_match_flags;struct _string_match_test{  const char *input;  int         flags;  const char *result;};static const string_match_test match_tests[] ={  /* nothing */  { "1234567890", SM_NONE, "" },  /* basic run, copy */  { "11111111112323232323", SM_NONE, "R0/10 C12/8@10" },  /* no run smaller than MIN_RUN=8 */  { "1111111",  SM_NONE, "C1/6@0" },  { "11111111", SM_NONE, "R0/8" },  /* simple promotion: the third copy address depends on promotion */  { "ABCDEF_ABCDEF^ABCDEF", SM_NONE,    "C7/6@0 C14/6@7" },  /* { "ABCDEF_ABCDEF^ABCDEF", SM_PROMOTE, "C7/6@0 C14/6@0" }, forgotten */  /* simple lazy: there is a better copy starting with "23 X" than "123 " */  { "123 23 XYZ 123 XYZ", SM_NONE, "C11/4@0" },  { "123 23 XYZ 123 XYZ", SM_LAZY, "C11/4@0 C12/6@4" },  /* trylazy: no lazy matches unless there are at least two characters beyond the first   * match */  { "2123_121212",   SM_LAZY, "C7/4@5" },  { "2123_1212123",  SM_LAZY, "C7/4@5" },  { "2123_1212123_", SM_LAZY, "C7/4@5 C8/5@0" },  /* trylazy: no lazy matches if the copy is >= MAXLAZY=10 */  { "2123_121212123_",   SM_LAZY, "C7/6@5 C10/5@0" },  { "2123_12121212123_", SM_LAZY, "C7/8@5 C12/5@0" },  { "2123_1212121212123_", SM_LAZY, "C7/10@5" },  /* lazy run: check a run overlapped by a longer copy */  { "11111112 111111112 1", SM_LAZY, "C1/6@0 R9/8 C10/10@0" },  /* lazy match: match_length,run_l >= min_match tests, shouldn't get any copies within   * the run, no run within the copy */  { "^________^________  ", SM_LAZY, "R1/8 C9/9@0" },  /* chain depth: it only goes back 10. this checks that the 10th match hits and the 11th   * misses. */  { "1234 1234_1234-1234=1234+1234[1234]1234{1234}1234<1234 ", SM_NONE,    "C5/4@0 C10/4@5 C15/4@10 C20/4@15 C25/4@20 C30/4@25 C35/4@30 C40/4@35 C45/4@40 C50/5@0" },  { "1234 1234_1234-1234=1234+1234[1234]1234{1234}1234<1234>1234 ", SM_NONE,    "C5/4@0 C10/4@5 C15/4@10 C20/4@15 C25/4@20 C30/4@25 C35/4@30 C40/4@35 C45/4@40 C50/4@45 C55/4@50" },  /* ssmatch test */  { "ABCDE___ABCDE*** BCDE***", SM_NONE, "C8/5@0 C17/4@1" },  /*{ "ABCDE___ABCDE*** BCDE***", SM_SSMATCH, "C8/5@0 C17/7@9" }, forgotten */};static inttest_string_matching (xd3_stream *stream, int ignore){  int i, ret;  xd3_config config;  char rbuf[TESTBUFSIZE];  for (i = 0; i < SIZEOF_ARRAY (match_tests); i += 1)    {      const string_match_test *test = & match_tests[i];      char *rptr = rbuf;      usize_t len = strlen (test->input);      xd3_free_stream (stream);      xd3_init_config (& config, 0);      config.smatch_cfg   = XD3_SMATCH_SOFT;      config.smatcher_soft.large_look   = 4;      config.smatcher_soft.large_step   = 4;      config.smatcher_soft.small_look   = 4;      config.smatcher_soft.small_chain  = 10;      config.smatcher_soft.small_lchain = 10;      config.smatcher_soft.max_lazy     = (test->flags & SM_LAZY) ? 10 : 0;      config.smatcher_soft.long_enough  = 10;      if ((ret = xd3_config_stream (stream, & config))) { return ret; }      if ((ret = xd3_encode_init (stream))) { return ret; }      xd3_avail_input (stream, (uint8_t*)test->input, len);      if ((ret = stream->smatcher.string_match (stream))) { return ret; }      *rptr = 0;      while (! xd3_rlist_empty (& stream->iopt_used))	{	  xd3_rinst *inst = xd3_rlist_pop_front (& stream->iopt_used);	  switch (inst->type)	    {	    case XD3_RUN: *rptr++ = 'R'; break;	    case XD3_CPY: *rptr++ = 'C'; break;	    default: CHECK(0);	    }	  sprintf (rptr, "%d/%d", inst->pos, inst->size);	  rptr += strlen (rptr);	  if (inst->type == XD3_CPY)	    {	      *rptr++ = '@';	      sprintf (rptr, "%"Q"d", inst->addr);	      rptr += strlen (rptr);	    }	  *rptr++ = ' ';	  xd3_rlist_push_back (& stream->iopt_free, inst);	}      if (rptr != rbuf)	{	  rptr -= 1; *rptr = 0;	}      if (strcmp (rbuf, test->result) != 0)	{	  DP(RINT "test %u: expected %s: got %s", i, test->result, rbuf);	  stream->msg = "wrong result";	  return XD3_INTERNAL;	}    }  return 0;}/* * This is a test for many overlapping instructions. It must be a lazy * matcher. */static inttest_iopt_flush_instructions (xd3_stream *stream, int ignore){  int ret, i, tpos = 0;  usize_t delta_size, recon_size;  xd3_config config;  uint8_t target[TESTBUFSIZE];  uint8_t delta[TESTBUFSIZE];  uint8_t recon[TESTBUFSIZE];  xd3_free_stream (stream);  xd3_init_config (& config, 0);  config.smatch_cfg    = XD3_SMATCH_SOFT;  config.smatcher_soft.large_look    = 16;  config.smatcher_soft.large_step    = 16;  config.smatcher_soft.small_look    = 4;  config.smatcher_soft.small_chain   = 128;  config.smatcher_soft.small_lchain  = 16;  config.smatcher_soft.max_lazy      = 8;  config.smatcher_soft.long_enough   = 128;  if ((ret = xd3_config_stream (stream, & config))) { return ret; }  for (i = 1; i < 250; i++)    {      target[tpos++] = i;      target[tpos++] = i+1;      target[tpos++] = i+2;      target[tpos++] = i+3;      target[tpos++] = 0;    }  for (i = 1; i < 253; i++)    {      target[tpos++] = i;    }  if ((ret = xd3_encode_stream (stream, target, tpos,				    delta, & delta_size, sizeof (delta))))    {      return ret;    }  xd3_free_stream(stream);  if ((ret = xd3_config_stream (stream, & config))) { return ret; }  if ((ret = xd3_decode_stream (stream, delta, delta_size,				recon, & recon_size, sizeof (recon))))    {      return ret;    }  CHECK(tpos == recon_size);  CHECK(memcmp(target, r

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -