test_consdiff.c 32 KB

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