test_consdiff.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. /* Copyright (c) 2014, Daniel Martí
  2. * Copyright (c) 2014, The Tor Project, Inc. */
  3. /* See LICENSE for licensing information */
  4. #define CONSDIFF_PRIVATE
  5. #include "or.h"
  6. #include "test.h"
  7. #include "consdiff.h"
  8. #include "routerparse.h"
  9. #include "log_test_helpers.h"
  10. static void
  11. test_consdiff_smartlist_slice(void *arg)
  12. {
  13. smartlist_t *sl = smartlist_new();
  14. smartlist_slice_t *sls;
  15. /* Create a regular smartlist. */
  16. (void)arg;
  17. smartlist_add(sl, (void*)1);
  18. smartlist_add(sl, (void*)2);
  19. smartlist_add(sl, (void*)3);
  20. smartlist_add(sl, (void*)4);
  21. smartlist_add(sl, (void*)5);
  22. /* See if the slice was done correctly. */
  23. sls = smartlist_slice(sl, 2, 5);
  24. tt_ptr_op(sl, OP_EQ, sls->list);
  25. tt_ptr_op((void*)3, OP_EQ, smartlist_get(sls->list, sls->offset));
  26. tt_ptr_op((void*)5, OP_EQ,
  27. smartlist_get(sls->list, sls->offset + (sls->len-1)));
  28. tor_free(sls);
  29. /* See that using -1 as the end does get to the last element. */
  30. sls = smartlist_slice(sl, 2, -1);
  31. tt_ptr_op(sl, OP_EQ, sls->list);
  32. tt_ptr_op((void*)3, OP_EQ, smartlist_get(sls->list, sls->offset));
  33. tt_ptr_op((void*)5, OP_EQ,
  34. smartlist_get(sls->list, sls->offset + (sls->len-1)));
  35. done:
  36. tor_free(sls);
  37. smartlist_free(sl);
  38. }
  39. static void
  40. test_consdiff_smartlist_slice_string_pos(void *arg)
  41. {
  42. smartlist_t *sl = smartlist_new();
  43. smartlist_slice_t *sls;
  44. /* Create a regular smartlist. */
  45. (void)arg;
  46. smartlist_split_string(sl, "a:d:c:a:b", ":", 0, 0);
  47. /* See that smartlist_slice_string_pos respects the bounds of the slice. */
  48. sls = smartlist_slice(sl, 2, 5);
  49. tt_int_op(3, OP_EQ, smartlist_slice_string_pos(sls, "a"));
  50. tt_int_op(-1, OP_EQ, smartlist_slice_string_pos(sls, "d"));
  51. done:
  52. tor_free(sls);
  53. if (sl) SMARTLIST_FOREACH(sl, char*, line, tor_free(line));
  54. smartlist_free(sl);
  55. }
  56. static void
  57. test_consdiff_lcs_lengths(void *arg)
  58. {
  59. smartlist_t *sl1 = smartlist_new();
  60. smartlist_t *sl2 = smartlist_new();
  61. smartlist_slice_t *sls1, *sls2;
  62. int *lengths1, *lengths2;
  63. /* Expected lcs lengths in regular and reverse order. */
  64. int e_lengths1[] = { 0, 1, 2, 3, 3, 4 };
  65. int e_lengths2[] = { 0, 1, 1, 2, 3, 4 };
  66. (void)arg;
  67. smartlist_split_string(sl1, "a:b:c:d:e", ":", 0, 0);
  68. smartlist_split_string(sl2, "a:c:d:i:e", ":", 0, 0);
  69. sls1 = smartlist_slice(sl1, 0, -1);
  70. sls2 = smartlist_slice(sl2, 0, -1);
  71. lengths1 = lcs_lengths(sls1, sls2, 1);
  72. lengths2 = lcs_lengths(sls1, sls2, -1);
  73. tt_mem_op(e_lengths1, OP_EQ, lengths1, sizeof(int) * 6);
  74. tt_mem_op(e_lengths2, OP_EQ, lengths2, sizeof(int) * 6);
  75. done:
  76. tor_free(lengths1);
  77. tor_free(lengths2);
  78. tor_free(sls1);
  79. tor_free(sls2);
  80. if (sl1) SMARTLIST_FOREACH(sl1, char*, line, tor_free(line));
  81. if (sl2) SMARTLIST_FOREACH(sl2, char*, line, tor_free(line));
  82. smartlist_free(sl1);
  83. smartlist_free(sl2);
  84. }
  85. static void
  86. test_consdiff_trim_slices(void *arg)
  87. {
  88. smartlist_t *sl1 = smartlist_new();
  89. smartlist_t *sl2 = smartlist_new();
  90. smartlist_t *sl3 = smartlist_new();
  91. smartlist_t *sl4 = smartlist_new();
  92. smartlist_slice_t *sls1, *sls2, *sls3, *sls4;
  93. (void)arg;
  94. smartlist_split_string(sl1, "a:b:b:b:d", ":", 0, 0);
  95. smartlist_split_string(sl2, "a:c:c:c:d", ":", 0, 0);
  96. smartlist_split_string(sl3, "a:b:b:b:a", ":", 0, 0);
  97. smartlist_split_string(sl4, "c:b:b:b:c", ":", 0, 0);
  98. sls1 = smartlist_slice(sl1, 0, -1);
  99. sls2 = smartlist_slice(sl2, 0, -1);
  100. sls3 = smartlist_slice(sl3, 0, -1);
  101. sls4 = smartlist_slice(sl4, 0, -1);
  102. /* They should be trimmed by one line at each end. */
  103. tt_int_op(5, OP_EQ, sls1->len);
  104. tt_int_op(5, OP_EQ, sls2->len);
  105. trim_slices(sls1, sls2);
  106. tt_int_op(3, OP_EQ, sls1->len);
  107. tt_int_op(3, OP_EQ, sls2->len);
  108. /* They should not be trimmed at all. */
  109. tt_int_op(5, OP_EQ, sls3->len);
  110. tt_int_op(5, OP_EQ, sls4->len);
  111. trim_slices(sls3, sls4);
  112. tt_int_op(5, OP_EQ, sls3->len);
  113. tt_int_op(5, OP_EQ, sls4->len);
  114. done:
  115. tor_free(sls1);
  116. tor_free(sls2);
  117. tor_free(sls3);
  118. tor_free(sls4);
  119. if (sl1) SMARTLIST_FOREACH(sl1, char*, line, tor_free(line));
  120. if (sl2) SMARTLIST_FOREACH(sl2, char*, line, tor_free(line));
  121. if (sl3) SMARTLIST_FOREACH(sl3, char*, line, tor_free(line));
  122. if (sl4) SMARTLIST_FOREACH(sl4, char*, line, tor_free(line));
  123. smartlist_free(sl1);
  124. smartlist_free(sl2);
  125. smartlist_free(sl3);
  126. smartlist_free(sl4);
  127. }
  128. static void
  129. test_consdiff_set_changed(void *arg)
  130. {
  131. smartlist_t *sl1 = smartlist_new();
  132. smartlist_t *sl2 = smartlist_new();
  133. bitarray_t *changed1 = bitarray_init_zero(4);
  134. bitarray_t *changed2 = bitarray_init_zero(4);
  135. smartlist_slice_t *sls1, *sls2;
  136. (void)arg;
  137. smartlist_split_string(sl1, "a:b:a:a", ":", 0, 0);
  138. smartlist_split_string(sl2, "a:a:a:a", ":", 0, 0);
  139. /* Length of sls1 is 0. */
  140. sls1 = smartlist_slice(sl1, 0, 0);
  141. sls2 = smartlist_slice(sl2, 1, 3);
  142. set_changed(changed1, changed2, sls1, sls2);
  143. /* The former is not changed, the latter changes all of its elements. */
  144. tt_assert(!bitarray_is_set(changed1, 0));
  145. tt_assert(!bitarray_is_set(changed1, 1));
  146. tt_assert(!bitarray_is_set(changed1, 2));
  147. tt_assert(!bitarray_is_set(changed1, 3));
  148. tt_assert(!bitarray_is_set(changed2, 0));
  149. tt_assert(bitarray_is_set(changed2, 1));
  150. tt_assert(bitarray_is_set(changed2, 2));
  151. tt_assert(!bitarray_is_set(changed2, 3));
  152. bitarray_clear(changed2, 1);
  153. bitarray_clear(changed2, 2);
  154. /* Length of sls1 is 1 and its element is in sls2. */
  155. tor_free(sls1);
  156. sls1 = smartlist_slice(sl1, 0, 1);
  157. set_changed(changed1, changed2, sls1, sls2);
  158. /* The latter changes all elements but the (first) common one. */
  159. tt_assert(!bitarray_is_set(changed1, 0));
  160. tt_assert(!bitarray_is_set(changed1, 1));
  161. tt_assert(!bitarray_is_set(changed1, 2));
  162. tt_assert(!bitarray_is_set(changed1, 3));
  163. tt_assert(!bitarray_is_set(changed2, 0));
  164. tt_assert(!bitarray_is_set(changed2, 1));
  165. tt_assert(bitarray_is_set(changed2, 2));
  166. tt_assert(!bitarray_is_set(changed2, 3));
  167. bitarray_clear(changed2, 2);
  168. /* Length of sls1 is 1 and its element is not in sls2. */
  169. tor_free(sls1);
  170. sls1 = smartlist_slice(sl1, 1, 2);
  171. set_changed(changed1, changed2, sls1, sls2);
  172. /* The former changes its element, the latter changes all elements. */
  173. tt_assert(!bitarray_is_set(changed1, 0));
  174. tt_assert(bitarray_is_set(changed1, 1));
  175. tt_assert(!bitarray_is_set(changed1, 2));
  176. tt_assert(!bitarray_is_set(changed1, 3));
  177. tt_assert(!bitarray_is_set(changed2, 0));
  178. tt_assert(bitarray_is_set(changed2, 1));
  179. tt_assert(bitarray_is_set(changed2, 2));
  180. tt_assert(!bitarray_is_set(changed2, 3));
  181. done:
  182. bitarray_free(changed1);
  183. bitarray_free(changed2);
  184. if (sl1) SMARTLIST_FOREACH(sl1, char*, line, tor_free(line));
  185. if (sl2) SMARTLIST_FOREACH(sl2, char*, line, tor_free(line));
  186. smartlist_free(sl1);
  187. smartlist_free(sl2);
  188. tor_free(sls1);
  189. tor_free(sls2);
  190. }
  191. static void
  192. test_consdiff_calc_changes(void *arg)
  193. {
  194. smartlist_t *sl1 = smartlist_new();
  195. smartlist_t *sl2 = smartlist_new();
  196. smartlist_slice_t *sls1, *sls2;
  197. bitarray_t *changed1 = bitarray_init_zero(4);
  198. bitarray_t *changed2 = bitarray_init_zero(4);
  199. (void)arg;
  200. smartlist_split_string(sl1, "a:a:a:a", ":", 0, 0);
  201. smartlist_split_string(sl2, "a:a:a:a", ":", 0, 0);
  202. sls1 = smartlist_slice(sl1, 0, -1);
  203. sls2 = smartlist_slice(sl2, 0, -1);
  204. calc_changes(sls1, sls2, changed1, changed2);
  205. /* Nothing should be set to changed. */
  206. tt_assert(!bitarray_is_set(changed1, 0));
  207. tt_assert(!bitarray_is_set(changed1, 1));
  208. tt_assert(!bitarray_is_set(changed1, 2));
  209. tt_assert(!bitarray_is_set(changed1, 3));
  210. tt_assert(!bitarray_is_set(changed2, 0));
  211. tt_assert(!bitarray_is_set(changed2, 1));
  212. tt_assert(!bitarray_is_set(changed2, 2));
  213. tt_assert(!bitarray_is_set(changed2, 3));
  214. SMARTLIST_FOREACH(sl2, char*, line, tor_free(line));
  215. smartlist_clear(sl2);
  216. smartlist_split_string(sl2, "a:b:a:b", ":", 0, 0);
  217. tor_free(sls1);
  218. tor_free(sls2);
  219. sls1 = smartlist_slice(sl1, 0, -1);
  220. sls2 = smartlist_slice(sl2, 0, -1);
  221. calc_changes(sls1, sls2, changed1, changed2);
  222. /* Two elements are changed. */
  223. tt_assert(!bitarray_is_set(changed1, 0));
  224. tt_assert(bitarray_is_set(changed1, 1));
  225. tt_assert(bitarray_is_set(changed1, 2));
  226. tt_assert(!bitarray_is_set(changed1, 3));
  227. bitarray_clear(changed1, 1);
  228. bitarray_clear(changed1, 2);
  229. tt_assert(!bitarray_is_set(changed2, 0));
  230. tt_assert(bitarray_is_set(changed2, 1));
  231. tt_assert(!bitarray_is_set(changed2, 2));
  232. tt_assert(bitarray_is_set(changed2, 3));
  233. bitarray_clear(changed1, 1);
  234. bitarray_clear(changed1, 3);
  235. SMARTLIST_FOREACH(sl2, char*, line, tor_free(line));
  236. smartlist_clear(sl2);
  237. smartlist_split_string(sl2, "b:b:b:b", ":", 0, 0);
  238. tor_free(sls1);
  239. tor_free(sls2);
  240. sls1 = smartlist_slice(sl1, 0, -1);
  241. sls2 = smartlist_slice(sl2, 0, -1);
  242. calc_changes(sls1, sls2, changed1, changed2);
  243. /* All elements are changed. */
  244. tt_assert(bitarray_is_set(changed1, 0));
  245. tt_assert(bitarray_is_set(changed1, 1));
  246. tt_assert(bitarray_is_set(changed1, 2));
  247. tt_assert(bitarray_is_set(changed1, 3));
  248. tt_assert(bitarray_is_set(changed2, 0));
  249. tt_assert(bitarray_is_set(changed2, 1));
  250. tt_assert(bitarray_is_set(changed2, 2));
  251. tt_assert(bitarray_is_set(changed2, 3));
  252. done:
  253. bitarray_free(changed1);
  254. bitarray_free(changed2);
  255. if (sl1) SMARTLIST_FOREACH(sl1, char*, line, tor_free(line));
  256. if (sl2) SMARTLIST_FOREACH(sl2, char*, line, tor_free(line));
  257. smartlist_free(sl1);
  258. smartlist_free(sl2);
  259. tor_free(sls1);
  260. tor_free(sls2);
  261. }
  262. static void
  263. test_consdiff_get_id_hash(void *arg)
  264. {
  265. const char *line, *e_hash;
  266. /* No hash. */
  267. (void)arg;
  268. tt_ptr_op(NULL, OP_EQ, get_id_hash("r name"));
  269. /* The hash contains characters that are not base64. */
  270. tt_ptr_op(NULL, OP_EQ, get_id_hash( "r name _hash_isnt_base64 etc"));
  271. line = "r name hash+valid+base64 etc";
  272. e_hash = line+7;
  273. tt_ptr_op(e_hash, OP_EQ, get_id_hash(line));
  274. done:
  275. ;
  276. }
  277. static void
  278. test_consdiff_is_valid_router_entry(void *arg)
  279. {
  280. /* Doesn't start with "r ". */
  281. (void)arg;
  282. tt_int_op(0, OP_EQ, is_valid_router_entry("foo"));
  283. /* These are already tested with get_id_hash, but make sure it's run
  284. * properly. */
  285. tt_int_op(0, OP_EQ, is_valid_router_entry("r name"));
  286. tt_int_op(0, OP_EQ, is_valid_router_entry("r name _hash_isnt_base64 etc"));
  287. tt_int_op(1, OP_EQ, is_valid_router_entry("r name hash+valid+base64 etc"));
  288. done:
  289. ;
  290. }
  291. static void
  292. test_consdiff_next_router(void *arg)
  293. {
  294. smartlist_t *sl = smartlist_new();
  295. (void)arg;
  296. smartlist_add(sl, (char*)"foo");
  297. smartlist_add(sl,
  298. (char*)"r name hash+longer+than+27+chars+and+valid+base64 etc");
  299. smartlist_add(sl, (char*)"foo");
  300. smartlist_add(sl, (char*)"foo");
  301. smartlist_add(sl,
  302. (char*)"r name hash+longer+than+27+chars+and+valid+base64 etc");
  303. smartlist_add(sl, (char*)"foo");
  304. /* Not currently on a router entry line, finding the next one. */
  305. tt_int_op(1, OP_EQ, next_router(sl, 0));
  306. tt_int_op(4, OP_EQ, next_router(sl, 2));
  307. /* Already at the beginning of a router entry line, ignore it. */
  308. tt_int_op(4, OP_EQ, next_router(sl, 1));
  309. /* There are no more router entries, so return the line after the last. */
  310. tt_int_op(6, OP_EQ, next_router(sl, 4));
  311. tt_int_op(6, OP_EQ, next_router(sl, 5));
  312. done:
  313. smartlist_free(sl);
  314. }
  315. static void
  316. test_consdiff_base64cmp(void *arg)
  317. {
  318. /* NULL arguments. */
  319. (void)arg;
  320. tt_int_op(0, OP_EQ, base64cmp(NULL, NULL));
  321. tt_int_op(-1, OP_EQ, base64cmp(NULL, "foo"));
  322. tt_int_op(1, OP_EQ, base64cmp("bar", NULL));
  323. /* Nil base64 values. */
  324. tt_int_op(0, OP_EQ, base64cmp("", ""));
  325. tt_int_op(0, OP_EQ, base64cmp("_", "&"));
  326. /* Exact same valid strings. */
  327. tt_int_op(0, OP_EQ, base64cmp("abcABC/+", "abcABC/+"));
  328. /* Both end with an invalid base64 char other than '\0'. */
  329. tt_int_op(0, OP_EQ, base64cmp("abcABC/+ ", "abcABC/+ "));
  330. /* Only one ends with an invalid base64 char other than '\0'. */
  331. tt_int_op(0, OP_EQ, base64cmp("abcABC/+ ", "abcABC/+"));
  332. /* Comparisons that would return differently with strcmp(). */
  333. tt_int_op(-1, OP_EQ, strcmp("/foo", "Afoo"));
  334. tt_int_op(1, OP_EQ, base64cmp("/foo", "Afoo"));
  335. tt_int_op(1, OP_EQ, strcmp("Afoo", "0foo"));
  336. tt_int_op(-1, OP_EQ, base64cmp("Afoo", "0foo"));
  337. /* Comparisons that would return the same as with strcmp(). */
  338. tt_int_op(1, OP_EQ, strcmp("afoo", "Afoo"));
  339. tt_int_op(1, OP_EQ, base64cmp("afoo", "Afoo"));
  340. /* Different lengths */
  341. tt_int_op(-1, OP_EQ, base64cmp("afoo", "afooo"));
  342. tt_int_op(1, OP_EQ, base64cmp("afooo", "afoo"));
  343. done:
  344. ;
  345. }
  346. static void
  347. test_consdiff_gen_ed_diff(void *arg)
  348. {
  349. smartlist_t *cons1=NULL, *cons2=NULL, *diff=NULL;
  350. int i;
  351. int free_cons_entries = 0;/* 1 if the cons1 and cons2 contents are
  352. * heap-allocated */
  353. setup_capture_of_logs(LOG_WARN);
  354. (void)arg;
  355. cons1 = smartlist_new();
  356. cons2 = smartlist_new();
  357. /* Identity hashes are not sorted properly, return NULL. */
  358. smartlist_add(cons1, (char*)"r name bbbbbbbbbbbbbbbbbbbbbbbbbbb etc");
  359. smartlist_add(cons1, (char*)"foo");
  360. smartlist_add(cons1, (char*)"r name aaaaaaaaaaaaaaaaaaaaaaaaaaa etc");
  361. smartlist_add(cons1, (char*)"bar");
  362. smartlist_add(cons2, (char*)"r name aaaaaaaaaaaaaaaaaaaaaaaaaaa etc");
  363. smartlist_add(cons2, (char*)"foo");
  364. smartlist_add(cons2, (char*)"r name ccccccccccccccccccccccccccc etc");
  365. smartlist_add(cons2, (char*)"bar");
  366. diff = gen_ed_diff(cons1, cons2);
  367. tt_ptr_op(NULL, OP_EQ, diff);
  368. expect_single_log_msg_containing("Refusing to generate consensus diff "
  369. "because the base consensus doesn't have its router entries sorted "
  370. "properly.");
  371. /* Same, but now with the second consensus. */
  372. mock_clean_saved_logs();
  373. diff = gen_ed_diff(cons2, cons1);
  374. tt_ptr_op(NULL, OP_EQ, diff);
  375. expect_single_log_msg_containing("Refusing to generate consensus diff "
  376. "because the target consensus doesn't have its router entries sorted "
  377. "properly.");
  378. /* Identity hashes are repeated, return NULL. */
  379. smartlist_clear(cons1);
  380. smartlist_add(cons1, (char*)"r name bbbbbbbbbbbbbbbbbbbbbbbbbbb etc");
  381. smartlist_add(cons1, (char*)"foo");
  382. smartlist_add(cons1, (char*)"r name bbbbbbbbbbbbbbbbbbbbbbbbbbb etc");
  383. smartlist_add(cons1, (char*)"bar");
  384. mock_clean_saved_logs();
  385. diff = gen_ed_diff(cons1, cons2);
  386. tt_ptr_op(NULL, OP_EQ, diff);
  387. expect_single_log_msg_containing("Refusing to generate consensus diff "
  388. "because the base consensus doesn't have its router entries sorted "
  389. "properly.");
  390. /* We have to add a line that is just a dot, return NULL. */
  391. smartlist_clear(cons1);
  392. smartlist_clear(cons2);
  393. smartlist_add(cons1, (char*)"foo1");
  394. smartlist_add(cons1, (char*)"foo2");
  395. smartlist_add(cons2, (char*)"foo1");
  396. smartlist_add(cons2, (char*)".");
  397. smartlist_add(cons2, (char*)"foo2");
  398. mock_clean_saved_logs();
  399. diff = gen_ed_diff(cons1, cons2);
  400. tt_ptr_op(NULL, OP_EQ, diff);
  401. expect_single_log_msg_containing("Cannot generate consensus diff "
  402. "because one of the lines to be added is \".\".");
  403. #define MAX_LINE_COUNT (10000)
  404. /* Too many lines to be fed to the quadratic-time function. */
  405. smartlist_clear(cons1);
  406. smartlist_clear(cons2);
  407. for (i=0; i < MAX_LINE_COUNT; ++i) smartlist_add(cons1, (char*)"a");
  408. for (i=0; i < MAX_LINE_COUNT; ++i) smartlist_add(cons1, (char*)"b");
  409. mock_clean_saved_logs();
  410. diff = gen_ed_diff(cons1, cons2);
  411. tt_ptr_op(NULL, OP_EQ, diff);
  412. expect_single_log_msg_containing("Refusing to generate consensus diff "
  413. "because we found too few common router ids.");
  414. /* We have dot lines, but they don't interfere with the script format. */
  415. smartlist_clear(cons1);
  416. smartlist_clear(cons2);
  417. smartlist_add(cons1, (char*)"foo1");
  418. smartlist_add(cons1, (char*)".");
  419. smartlist_add(cons1, (char*)".");
  420. smartlist_add(cons1, (char*)"foo2");
  421. smartlist_add(cons2, (char*)"foo1");
  422. smartlist_add(cons2, (char*)".");
  423. smartlist_add(cons2, (char*)"foo2");
  424. diff = gen_ed_diff(cons1, cons2);
  425. tt_ptr_op(NULL, OP_NE, diff);
  426. SMARTLIST_FOREACH(diff, char*, line, tor_free(line));
  427. smartlist_free(diff);
  428. /* Empty diff tests. */
  429. smartlist_clear(cons1);
  430. smartlist_clear(cons2);
  431. diff = gen_ed_diff(cons1, cons2);
  432. tt_ptr_op(NULL, OP_NE, diff);
  433. tt_int_op(0, OP_EQ, smartlist_len(diff));
  434. smartlist_free(diff);
  435. smartlist_add(cons1, (char*)"foo");
  436. smartlist_add(cons1, (char*)"bar");
  437. smartlist_add(cons2, (char*)"foo");
  438. smartlist_add(cons2, (char*)"bar");
  439. diff = gen_ed_diff(cons1, cons2);
  440. tt_ptr_op(NULL, OP_NE, diff);
  441. tt_int_op(0, OP_EQ, smartlist_len(diff));
  442. smartlist_free(diff);
  443. /* Everything is deleted. */
  444. smartlist_clear(cons2);
  445. diff = gen_ed_diff(cons1, cons2);
  446. tt_ptr_op(NULL, OP_NE, diff);
  447. tt_int_op(1, OP_EQ, smartlist_len(diff));
  448. tt_str_op("1,2d", OP_EQ, smartlist_get(diff, 0));
  449. SMARTLIST_FOREACH(diff, char*, line, tor_free(line));
  450. smartlist_free(diff);
  451. /* Everything is added. */
  452. diff = gen_ed_diff(cons2, cons1);
  453. tt_ptr_op(NULL, OP_NE, diff);
  454. tt_int_op(4, OP_EQ, smartlist_len(diff));
  455. tt_str_op("0a", OP_EQ, smartlist_get(diff, 0));
  456. tt_str_op("foo", OP_EQ, smartlist_get(diff, 1));
  457. tt_str_op("bar", OP_EQ, smartlist_get(diff, 2));
  458. tt_str_op(".", OP_EQ, smartlist_get(diff, 3));
  459. SMARTLIST_FOREACH(diff, char*, line, tor_free(line));
  460. smartlist_free(diff);
  461. /* Everything is changed. */
  462. smartlist_add(cons2, (char*)"foo2");
  463. smartlist_add(cons2, (char*)"bar2");
  464. diff = gen_ed_diff(cons1, cons2);
  465. tt_ptr_op(NULL, OP_NE, diff);
  466. tt_int_op(4, OP_EQ, smartlist_len(diff));
  467. tt_str_op("1,2c", OP_EQ, smartlist_get(diff, 0));
  468. tt_str_op("foo2", OP_EQ, smartlist_get(diff, 1));
  469. tt_str_op("bar2", OP_EQ, smartlist_get(diff, 2));
  470. tt_str_op(".", OP_EQ, smartlist_get(diff, 3));
  471. SMARTLIST_FOREACH(diff, char*, line, tor_free(line));
  472. smartlist_free(diff);
  473. /* Test 'a', 'c' and 'd' together. See that it is done in reverse order. */
  474. smartlist_clear(cons1);
  475. smartlist_clear(cons2);
  476. smartlist_split_string(cons1, "A:B:C:D:E", ":", 0, 0);
  477. smartlist_split_string(cons2, "A:C:O:E:U", ":", 0, 0);
  478. free_cons_entries = 1;
  479. diff = gen_ed_diff(cons1, cons2);
  480. tt_ptr_op(NULL, OP_NE, diff);
  481. tt_int_op(7, OP_EQ, smartlist_len(diff));
  482. tt_str_op("5a", OP_EQ, smartlist_get(diff, 0));
  483. tt_str_op("U", OP_EQ, smartlist_get(diff, 1));
  484. tt_str_op(".", OP_EQ, smartlist_get(diff, 2));
  485. tt_str_op("4c", OP_EQ, smartlist_get(diff, 3));
  486. tt_str_op("O", OP_EQ, smartlist_get(diff, 4));
  487. tt_str_op(".", OP_EQ, smartlist_get(diff, 5));
  488. tt_str_op("2d", OP_EQ, smartlist_get(diff, 6));
  489. /* TODO: small real use-cases, i.e. consensuses. */
  490. done:
  491. teardown_capture_of_logs();
  492. if (free_cons_entries) {
  493. if (cons1) SMARTLIST_FOREACH(cons1, char*, line, tor_free(line));
  494. if (cons2) SMARTLIST_FOREACH(cons2, char*, line, tor_free(line));
  495. }
  496. smartlist_free(cons1);
  497. smartlist_free(cons2);
  498. if (diff) SMARTLIST_FOREACH(diff, char*, line, tor_free(line));
  499. smartlist_free(diff);
  500. }
  501. static void
  502. test_consdiff_apply_ed_diff(void *arg)
  503. {
  504. smartlist_t *cons1=NULL, *cons2=NULL, *diff=NULL;
  505. (void)arg;
  506. cons1 = smartlist_new();
  507. diff = smartlist_new();
  508. smartlist_split_string(cons1, "A:B:C:D:E", ":", 0, 0);
  509. /* Command without range. */
  510. smartlist_add(diff, (char*)"a");
  511. cons2 = apply_ed_diff(cons1, diff);
  512. tt_ptr_op(NULL, OP_EQ, cons2);
  513. smartlist_clear(diff);
  514. /* Range without command. */
  515. smartlist_add(diff, (char*)"1");
  516. cons2 = apply_ed_diff(cons1, diff);
  517. tt_ptr_op(NULL, OP_EQ, cons2);
  518. smartlist_clear(diff);
  519. /* Range without end. */
  520. smartlist_add(diff, (char*)"1,");
  521. cons2 = apply_ed_diff(cons1, diff);
  522. tt_ptr_op(NULL, OP_EQ, cons2);
  523. smartlist_clear(diff);
  524. /* Incoherent ranges. */
  525. smartlist_add(diff, (char*)"1,1");
  526. cons2 = apply_ed_diff(cons1, diff);
  527. tt_ptr_op(NULL, OP_EQ, cons2);
  528. smartlist_clear(diff);
  529. smartlist_add(diff, (char*)"3,2");
  530. cons2 = apply_ed_diff(cons1, diff);
  531. tt_ptr_op(NULL, OP_EQ, cons2);
  532. smartlist_clear(diff);
  533. /* Script is not in reverse order. */
  534. smartlist_add(diff, (char*)"1d");
  535. smartlist_add(diff, (char*)"3d");
  536. cons2 = apply_ed_diff(cons1, diff);
  537. tt_ptr_op(NULL, OP_EQ, cons2);
  538. smartlist_clear(diff);
  539. /* Script contains unrecognised commands longer than one char. */
  540. smartlist_add(diff, (char*)"1foo");
  541. cons2 = apply_ed_diff(cons1, diff);
  542. tt_ptr_op(NULL, OP_EQ, cons2);
  543. smartlist_clear(diff);
  544. /* Script contains unrecognised commands. */
  545. smartlist_add(diff, (char*)"1e");
  546. cons2 = apply_ed_diff(cons1, diff);
  547. tt_ptr_op(NULL, OP_EQ, cons2);
  548. smartlist_clear(diff);
  549. /* Command that should be followed by at least one line and a ".", but
  550. * isn't. */
  551. smartlist_add(diff, (char*)"0a");
  552. cons2 = apply_ed_diff(cons1, diff);
  553. tt_ptr_op(NULL, OP_EQ, cons2);
  554. /* Now it is followed by a ".", but it inserts zero lines. */
  555. smartlist_add(diff, (char*)".");
  556. cons2 = apply_ed_diff(cons1, diff);
  557. tt_ptr_op(NULL, OP_EQ, cons2);
  558. smartlist_clear(diff);
  559. /* Test appending text, 'a'. */
  560. smartlist_split_string(diff, "3a:U:O:.:0a:V:.", ":", 0, 0);
  561. cons2 = apply_ed_diff(cons1, diff);
  562. tt_ptr_op(NULL, OP_NE, cons2);
  563. tt_int_op(8, OP_EQ, smartlist_len(cons2));
  564. tt_str_op("V", OP_EQ, smartlist_get(cons2, 0));
  565. tt_str_op("A", OP_EQ, smartlist_get(cons2, 1));
  566. tt_str_op("B", OP_EQ, smartlist_get(cons2, 2));
  567. tt_str_op("C", OP_EQ, smartlist_get(cons2, 3));
  568. tt_str_op("U", OP_EQ, smartlist_get(cons2, 4));
  569. tt_str_op("O", OP_EQ, smartlist_get(cons2, 5));
  570. tt_str_op("D", OP_EQ, smartlist_get(cons2, 6));
  571. tt_str_op("E", OP_EQ, smartlist_get(cons2, 7));
  572. SMARTLIST_FOREACH(diff, char*, line, tor_free(line));
  573. smartlist_clear(diff);
  574. SMARTLIST_FOREACH(cons2, char*, line, tor_free(line));
  575. smartlist_free(cons2);
  576. /* Test deleting text, 'd'. */
  577. smartlist_split_string(diff, "4d:1,2d", ":", 0, 0);
  578. cons2 = apply_ed_diff(cons1, diff);
  579. tt_ptr_op(NULL, OP_NE, cons2);
  580. tt_int_op(2, OP_EQ, smartlist_len(cons2));
  581. tt_str_op("C", OP_EQ, smartlist_get(cons2, 0));
  582. tt_str_op("E", OP_EQ, smartlist_get(cons2, 1));
  583. SMARTLIST_FOREACH(diff, char*, line, tor_free(line));
  584. smartlist_clear(diff);
  585. SMARTLIST_FOREACH(cons2, char*, line, tor_free(line));
  586. smartlist_free(cons2);
  587. /* Test changing text, 'c'. */
  588. smartlist_split_string(diff, "4c:T:X:.:1, 2c:M:.", ":", 0, 0);
  589. cons2 = apply_ed_diff(cons1, diff);
  590. tt_ptr_op(NULL, OP_NE, cons2);
  591. tt_int_op(5, OP_EQ, smartlist_len(cons2));
  592. tt_str_op("M", OP_EQ, smartlist_get(cons2, 0));
  593. tt_str_op("C", OP_EQ, smartlist_get(cons2, 1));
  594. tt_str_op("T", OP_EQ, smartlist_get(cons2, 2));
  595. tt_str_op("X", OP_EQ, smartlist_get(cons2, 3));
  596. tt_str_op("E", OP_EQ, smartlist_get(cons2, 4));
  597. SMARTLIST_FOREACH(diff, char*, line, tor_free(line));
  598. smartlist_clear(diff);
  599. SMARTLIST_FOREACH(cons2, char*, line, tor_free(line));
  600. smartlist_free(cons2);
  601. /* Test 'a', 'd' and 'c' together. */
  602. smartlist_split_string(diff, "4c:T:X:.:2d:0a:M:.", ":", 0, 0);
  603. cons2 = apply_ed_diff(cons1, diff);
  604. tt_ptr_op(NULL, OP_NE, cons2);
  605. tt_int_op(6, OP_EQ, smartlist_len(cons2));
  606. tt_str_op("M", OP_EQ, smartlist_get(cons2, 0));
  607. tt_str_op("A", OP_EQ, smartlist_get(cons2, 1));
  608. tt_str_op("C", OP_EQ, smartlist_get(cons2, 2));
  609. tt_str_op("T", OP_EQ, smartlist_get(cons2, 3));
  610. tt_str_op("X", OP_EQ, smartlist_get(cons2, 4));
  611. tt_str_op("E", OP_EQ, smartlist_get(cons2, 5));
  612. done:
  613. if (cons1) SMARTLIST_FOREACH(cons1, char*, line, tor_free(line));
  614. if (cons2) SMARTLIST_FOREACH(cons2, char*, line, tor_free(line));
  615. smartlist_free(cons1);
  616. smartlist_free(cons2);
  617. if (diff) SMARTLIST_FOREACH(diff, char*, line, tor_free(line));
  618. smartlist_free(diff);
  619. }
  620. static void
  621. test_consdiff_gen_diff(void *arg)
  622. {
  623. char *cons1_str=NULL, *cons2_str=NULL;
  624. smartlist_t *cons1=NULL, *cons2=NULL, *diff=NULL;
  625. common_digests_t digests1, digests2;
  626. (void)arg;
  627. cons1 = smartlist_new();
  628. cons2 = smartlist_new();
  629. /* Identity hashes are not sorted properly, return NULL.
  630. * Already tested in gen_ed_diff, but see that a NULL ed diff also makes
  631. * gen_diff return NULL. */
  632. cons1_str = tor_strdup(
  633. "header\nnetwork-status-version foo\n"
  634. "r name bbbbbbbbbbbbbbbbb etc\nfoo\n"
  635. "r name aaaaaaaaaaaaaaaaa etc\nbar\n"
  636. "directory-signature foo bar\nbar\n"
  637. );
  638. cons2_str = tor_strdup(
  639. "header\nnetwork-status-version foo\n"
  640. "r name aaaaaaaaaaaaaaaaa etc\nfoo\n"
  641. "r name ccccccccccccccccc etc\nbar\n"
  642. "directory-signature foo bar\nbar\n"
  643. );
  644. tt_int_op(0, OP_EQ,
  645. router_get_networkstatus_v3_hashes(cons1_str, &digests1));
  646. tt_int_op(0, OP_EQ,
  647. router_get_networkstatus_v3_hashes(cons2_str, &digests2));
  648. tor_split_lines(cons1, cons1_str, (int)strlen(cons1_str));
  649. tor_split_lines(cons2, cons2_str, (int)strlen(cons2_str));
  650. diff = consdiff_gen_diff(cons1, cons2, &digests1, &digests2);
  651. tt_ptr_op(NULL, OP_EQ, diff);
  652. /* Check that the headers are done properly. */
  653. tor_free(cons1_str);
  654. cons1_str = tor_strdup(
  655. "header\nnetwork-status-version foo\n"
  656. "r name ccccccccccccccccc etc\nfoo\n"
  657. "r name eeeeeeeeeeeeeeeee etc\nbar\n"
  658. "directory-signature foo bar\nbar\n"
  659. );
  660. tt_int_op(0, OP_EQ,
  661. router_get_networkstatus_v3_hashes(cons1_str, &digests1));
  662. smartlist_clear(cons1);
  663. tor_split_lines(cons1, cons1_str, (int)strlen(cons1_str));
  664. diff = consdiff_gen_diff(cons1, cons2, &digests1, &digests2);
  665. tt_ptr_op(NULL, OP_NE, diff);
  666. tt_int_op(7, OP_EQ, smartlist_len(diff));
  667. tt_str_op("network-status-diff-version 1", OP_EQ, smartlist_get(diff, 0));
  668. tt_str_op("hash "
  669. "C2199B6827514F39ED9B3F2E2E73735C6C5468FD636240BB454C526220DE702A "
  670. "B193E5FBFE5C009AEDE56F9218E6421A1AE5C19F43E091786A73F43F60409B60",
  671. OP_EQ, smartlist_get(diff, 1));
  672. tt_str_op("4,5d", OP_EQ, smartlist_get(diff, 2));
  673. tt_str_op("2a", OP_EQ, smartlist_get(diff, 3));
  674. tt_str_op("r name aaaaaaaaaaaaaaaaa etc", OP_EQ, smartlist_get(diff, 4));
  675. tt_str_op("foo", OP_EQ, smartlist_get(diff, 5));
  676. tt_str_op(".", OP_EQ, smartlist_get(diff, 6));
  677. /* TODO: small real use-cases, i.e. consensuses. */
  678. done:
  679. tor_free(cons1_str);
  680. tor_free(cons2_str);
  681. smartlist_free(cons1);
  682. smartlist_free(cons2);
  683. if (diff) SMARTLIST_FOREACH(diff, char*, line, tor_free(line));
  684. smartlist_free(diff);
  685. }
  686. static void
  687. test_consdiff_apply_diff(void *arg)
  688. {
  689. smartlist_t *cons1=NULL, *diff=NULL;
  690. char *cons1_str=NULL, *cons2 = NULL;
  691. common_digests_t digests1;
  692. (void)arg;
  693. cons1 = smartlist_new();
  694. diff = smartlist_new();
  695. cons1_str = tor_strdup(
  696. "header\nnetwork-status-version foo\n"
  697. "r name ccccccccccccccccc etc\nfoo\n"
  698. "r name eeeeeeeeeeeeeeeee etc\nbar\n"
  699. "directory-signature foo bar\nbar\n"
  700. );
  701. tt_int_op(0, OP_EQ,
  702. router_get_networkstatus_v3_hashes(cons1_str, &digests1));
  703. tor_split_lines(cons1, cons1_str, (int)strlen(cons1_str));
  704. /* diff doesn't have enough lines. */
  705. cons2 = consdiff_apply_diff(cons1, diff, &digests1);
  706. tt_ptr_op(NULL, OP_EQ, cons2);
  707. /* first line doesn't match format-version string. */
  708. smartlist_add(diff, (char*)"foo-bar");
  709. smartlist_add(diff, (char*)"header-line");
  710. cons2 = consdiff_apply_diff(cons1, diff, &digests1);
  711. tt_ptr_op(NULL, OP_EQ, cons2);
  712. /* The first word of the second header line is not "hash". */
  713. smartlist_clear(diff);
  714. smartlist_add(diff, (char*)"network-status-diff-version 1");
  715. smartlist_add(diff, (char*)"word a b");
  716. cons2 = consdiff_apply_diff(cons1, diff, &digests1);
  717. tt_ptr_op(NULL, OP_EQ, cons2);
  718. /* Wrong number of words after "hash". */
  719. smartlist_clear(diff);
  720. smartlist_add(diff, (char*)"network-status-diff-version 1");
  721. smartlist_add(diff, (char*)"hash a b c");
  722. cons2 = consdiff_apply_diff(cons1, diff, &digests1);
  723. tt_ptr_op(NULL, OP_EQ, cons2);
  724. /* base16 sha256 digests do not have the expected length. */
  725. smartlist_clear(diff);
  726. smartlist_add(diff, (char*)"network-status-diff-version 1");
  727. smartlist_add(diff, (char*)"hash aaa bbb");
  728. cons2 = consdiff_apply_diff(cons1, diff, &digests1);
  729. tt_ptr_op(NULL, OP_EQ, cons2);
  730. /* base16 sha256 digests contain non-base16 characters. */
  731. smartlist_clear(diff);
  732. smartlist_add(diff, (char*)"network-status-diff-version 1");
  733. smartlist_add(diff, (char*)"hash"
  734. " ????????????????????????????????????????????????????????????????"
  735. " ----------------------------------------------------------------");
  736. cons2 = consdiff_apply_diff(cons1, diff, &digests1);
  737. tt_ptr_op(NULL, OP_EQ, cons2);
  738. /* Invalid ed diff.
  739. * As tested in apply_ed_diff, but check that apply_diff does return NULL if
  740. * the ed diff can't be applied. */
  741. smartlist_clear(diff);
  742. smartlist_add(diff, (char*)"network-status-diff-version 1");
  743. smartlist_add(diff, (char*)"hash"
  744. /* sha256 of cons1. */
  745. " C2199B6827514F39ED9B3F2E2E73735C6C5468FD636240BB454C526220DE702A"
  746. /* sha256 of cons2. */
  747. " 635D34593020C08E5ECD865F9986E29D50028EFA62843766A8197AD228A7F6AA");
  748. smartlist_add(diff, (char*)"foobar");
  749. cons2 = consdiff_apply_diff(cons1, diff, &digests1);
  750. tt_ptr_op(NULL, OP_EQ, cons2);
  751. /* Base consensus doesn't match its digest as found in the diff. */
  752. smartlist_clear(diff);
  753. smartlist_add(diff, (char*)"network-status-diff-version 1");
  754. smartlist_add(diff, (char*)"hash"
  755. /* bogus sha256. */
  756. " 3333333333333333333333333333333333333333333333333333333333333333"
  757. /* sha256 of cons2. */
  758. " 635D34593020C08E5ECD865F9986E29D50028EFA62843766A8197AD228A7F6AA");
  759. cons2 = consdiff_apply_diff(cons1, diff, &digests1);
  760. tt_ptr_op(NULL, OP_EQ, cons2);
  761. /* Resulting consensus doesn't match its digest as found in the diff. */
  762. smartlist_clear(diff);
  763. smartlist_add(diff, (char*)"network-status-diff-version 1");
  764. smartlist_add(diff, (char*)"hash"
  765. /* sha256 of cons1. */
  766. " C2199B6827514F39ED9B3F2E2E73735C6C5468FD636240BB454C526220DE702A"
  767. /* bogus sha256. */
  768. " 3333333333333333333333333333333333333333333333333333333333333333");
  769. cons2 = consdiff_apply_diff(cons1, diff, &digests1);
  770. tt_ptr_op(NULL, OP_EQ, cons2);
  771. /* Very simple test, only to see that nothing errors. */
  772. smartlist_clear(diff);
  773. smartlist_add(diff, (char*)"network-status-diff-version 1");
  774. smartlist_add(diff, (char*)"hash"
  775. /* sha256 of cons1. */
  776. " C2199B6827514F39ED9B3F2E2E73735C6C5468FD636240BB454C526220DE702A"
  777. /* sha256 of cons2. */
  778. " 635D34593020C08E5ECD865F9986E29D50028EFA62843766A8197AD228A7F6AA");
  779. smartlist_add(diff, (char*)"4c");
  780. smartlist_add(diff, (char*)"sample");
  781. smartlist_add(diff, (char*)".");
  782. cons2 = consdiff_apply_diff(cons1, diff, &digests1);
  783. tt_ptr_op(NULL, OP_NE, cons2);
  784. tt_str_op(
  785. "header\nnetwork-status-version foo\n"
  786. "r name ccccccccccccccccc etc\nsample\n"
  787. "r name eeeeeeeeeeeeeeeee etc\nbar\n"
  788. "directory-signature foo bar\nbar\n", OP_EQ,
  789. cons2);
  790. tor_free(cons2);
  791. /* Check that lowercase letters in base16-encoded digests work too. */
  792. smartlist_clear(diff);
  793. smartlist_add(diff, (char*)"network-status-diff-version 1");
  794. smartlist_add(diff, (char*)"hash"
  795. /* sha256 of cons1. */
  796. " c2199b6827514f39ed9b3f2e2e73735c6c5468fd636240bb454c526220de702a"
  797. /* sha256 of cons2. */
  798. " 635d34593020c08e5ecd865f9986e29d50028efa62843766a8197ad228a7f6aa");
  799. smartlist_add(diff, (char*)"4c");
  800. smartlist_add(diff, (char*)"sample");
  801. smartlist_add(diff, (char*)".");
  802. cons2 = consdiff_apply_diff(cons1, diff, &digests1);
  803. tt_ptr_op(NULL, OP_NE, cons2);
  804. tt_str_op(
  805. "header\nnetwork-status-version foo\n"
  806. "r name ccccccccccccccccc etc\nsample\n"
  807. "r name eeeeeeeeeeeeeeeee etc\nbar\n"
  808. "directory-signature foo bar\nbar\n", OP_EQ,
  809. cons2);
  810. tor_free(cons2);
  811. smartlist_clear(diff);
  812. done:
  813. tor_free(cons1_str);
  814. smartlist_free(cons1);
  815. smartlist_free(diff);
  816. }
  817. #define CONSDIFF_LEGACY(name) \
  818. { #name, test_consdiff_ ## name , 0, NULL, NULL }
  819. struct testcase_t consdiff_tests[] = {
  820. CONSDIFF_LEGACY(smartlist_slice),
  821. CONSDIFF_LEGACY(smartlist_slice_string_pos),
  822. CONSDIFF_LEGACY(lcs_lengths),
  823. CONSDIFF_LEGACY(trim_slices),
  824. CONSDIFF_LEGACY(set_changed),
  825. CONSDIFF_LEGACY(calc_changes),
  826. CONSDIFF_LEGACY(get_id_hash),
  827. CONSDIFF_LEGACY(is_valid_router_entry),
  828. CONSDIFF_LEGACY(next_router),
  829. CONSDIFF_LEGACY(base64cmp),
  830. CONSDIFF_LEGACY(gen_ed_diff),
  831. CONSDIFF_LEGACY(apply_ed_diff),
  832. CONSDIFF_LEGACY(gen_diff),
  833. CONSDIFF_LEGACY(apply_diff),
  834. END_OF_TESTCASES
  835. };