test_util.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. /* Copyright (c) 2001-2004, Roger Dingledine.
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2010, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #include "orconfig.h"
  6. #define CONTROL_PRIVATE
  7. #define MEMPOOL_PRIVATE
  8. #include "or.h"
  9. #include "config.h"
  10. #include "control.h"
  11. #include "test.h"
  12. #include "mempool.h"
  13. #include "memarea.h"
  14. static void
  15. test_util_time(void)
  16. {
  17. struct timeval start, end;
  18. struct tm a_time;
  19. char timestr[RFC1123_TIME_LEN+1];
  20. time_t t_res;
  21. int i;
  22. start.tv_sec = 5;
  23. start.tv_usec = 5000;
  24. end.tv_sec = 5;
  25. end.tv_usec = 5000;
  26. test_eq(0L, tv_udiff(&start, &end));
  27. end.tv_usec = 7000;
  28. test_eq(2000L, tv_udiff(&start, &end));
  29. end.tv_sec = 6;
  30. test_eq(1002000L, tv_udiff(&start, &end));
  31. end.tv_usec = 0;
  32. test_eq(995000L, tv_udiff(&start, &end));
  33. end.tv_sec = 4;
  34. test_eq(-1005000L, tv_udiff(&start, &end));
  35. end.tv_usec = 999990;
  36. start.tv_sec = 1;
  37. start.tv_usec = 500;
  38. /* The test values here are confirmed to be correct on a platform
  39. * with a working timegm. */
  40. a_time.tm_year = 2003-1900;
  41. a_time.tm_mon = 7;
  42. a_time.tm_mday = 30;
  43. a_time.tm_hour = 6;
  44. a_time.tm_min = 14;
  45. a_time.tm_sec = 55;
  46. test_eq((time_t) 1062224095UL, tor_timegm(&a_time));
  47. a_time.tm_year = 2004-1900; /* Try a leap year, after feb. */
  48. test_eq((time_t) 1093846495UL, tor_timegm(&a_time));
  49. a_time.tm_mon = 1; /* Try a leap year, in feb. */
  50. a_time.tm_mday = 10;
  51. test_eq((time_t) 1076393695UL, tor_timegm(&a_time));
  52. format_rfc1123_time(timestr, 0);
  53. test_streq("Thu, 01 Jan 1970 00:00:00 GMT", timestr);
  54. format_rfc1123_time(timestr, (time_t)1091580502UL);
  55. test_streq("Wed, 04 Aug 2004 00:48:22 GMT", timestr);
  56. t_res = 0;
  57. i = parse_rfc1123_time(timestr, &t_res);
  58. test_eq(i,0);
  59. test_eq(t_res, (time_t)1091580502UL);
  60. test_eq(-1, parse_rfc1123_time("Wed, zz Aug 2004 99-99x99 GMT", &t_res));
  61. tor_gettimeofday(&start);
  62. /* now make sure time works. */
  63. tor_gettimeofday(&end);
  64. /* We might've timewarped a little. */
  65. tt_int_op(tv_udiff(&start, &end), >=, -5000);
  66. done:
  67. ;
  68. }
  69. static void
  70. test_util_config_line(void)
  71. {
  72. char buf[1024];
  73. char *k=NULL, *v=NULL;
  74. const char *str;
  75. /* Test parse_config_line_from_str */
  76. strlcpy(buf, "k v\n" " key value with spaces \n" "keykey val\n"
  77. "k2\n"
  78. "k3 \n" "\n" " \n" "#comment\n"
  79. "k4#a\n" "k5#abc\n" "k6 val #with comment\n"
  80. "kseven \"a quoted 'string\"\n"
  81. "k8 \"a \\x71uoted\\n\\\"str\\\\ing\\t\\001\\01\\1\\\"\"\n"
  82. , sizeof(buf));
  83. str = buf;
  84. str = parse_config_line_from_str(str, &k, &v);
  85. test_streq(k, "k");
  86. test_streq(v, "v");
  87. tor_free(k); tor_free(v);
  88. test_assert(!strcmpstart(str, "key value with"));
  89. str = parse_config_line_from_str(str, &k, &v);
  90. test_streq(k, "key");
  91. test_streq(v, "value with spaces");
  92. tor_free(k); tor_free(v);
  93. test_assert(!strcmpstart(str, "keykey"));
  94. str = parse_config_line_from_str(str, &k, &v);
  95. test_streq(k, "keykey");
  96. test_streq(v, "val");
  97. tor_free(k); tor_free(v);
  98. test_assert(!strcmpstart(str, "k2\n"));
  99. str = parse_config_line_from_str(str, &k, &v);
  100. test_streq(k, "k2");
  101. test_streq(v, "");
  102. tor_free(k); tor_free(v);
  103. test_assert(!strcmpstart(str, "k3 \n"));
  104. str = parse_config_line_from_str(str, &k, &v);
  105. test_streq(k, "k3");
  106. test_streq(v, "");
  107. tor_free(k); tor_free(v);
  108. test_assert(!strcmpstart(str, "#comment"));
  109. str = parse_config_line_from_str(str, &k, &v);
  110. test_streq(k, "k4");
  111. test_streq(v, "");
  112. tor_free(k); tor_free(v);
  113. test_assert(!strcmpstart(str, "k5#abc"));
  114. str = parse_config_line_from_str(str, &k, &v);
  115. test_streq(k, "k5");
  116. test_streq(v, "");
  117. tor_free(k); tor_free(v);
  118. test_assert(!strcmpstart(str, "k6"));
  119. str = parse_config_line_from_str(str, &k, &v);
  120. test_streq(k, "k6");
  121. test_streq(v, "val");
  122. tor_free(k); tor_free(v);
  123. test_assert(!strcmpstart(str, "kseven"));
  124. str = parse_config_line_from_str(str, &k, &v);
  125. test_streq(k, "kseven");
  126. test_streq(v, "a quoted \'string");
  127. tor_free(k); tor_free(v);
  128. test_assert(!strcmpstart(str, "k8 "));
  129. str = parse_config_line_from_str(str, &k, &v);
  130. test_streq(k, "k8");
  131. test_streq(v, "a quoted\n\"str\\ing\t\x01\x01\x01\"");
  132. tor_free(k); tor_free(v);
  133. test_streq(str, "");
  134. done:
  135. tor_free(k);
  136. tor_free(v);
  137. }
  138. /** Test basic string functionality. */
  139. static void
  140. test_util_strmisc(void)
  141. {
  142. char buf[1024];
  143. int i;
  144. char *cp;
  145. /* Tests for corner cases of strl operations */
  146. test_eq(5, strlcpy(buf, "Hello", 0));
  147. strlcpy(buf, "Hello", sizeof(buf));
  148. test_eq(10, strlcat(buf, "Hello", 5));
  149. /* Test tor_strstrip() */
  150. strlcpy(buf, "Testing 1 2 3", sizeof(buf));
  151. tor_strstrip(buf, ",!");
  152. test_streq(buf, "Testing 1 2 3");
  153. strlcpy(buf, "!Testing 1 2 3?", sizeof(buf));
  154. tor_strstrip(buf, "!? ");
  155. test_streq(buf, "Testing123");
  156. /* Test tor_parse_long. */
  157. test_eq(10L, tor_parse_long("10",10,0,100,NULL,NULL));
  158. test_eq(0L, tor_parse_long("10",10,50,100,NULL,NULL));
  159. test_eq(-50L, tor_parse_long("-50",10,-100,100,NULL,NULL));
  160. /* Test tor_parse_ulong */
  161. test_eq(10UL, tor_parse_ulong("10",10,0,100,NULL,NULL));
  162. test_eq(0UL, tor_parse_ulong("10",10,50,100,NULL,NULL));
  163. /* Test tor_parse_uint64. */
  164. test_assert(U64_LITERAL(10) == tor_parse_uint64("10 x",10,0,100, &i, &cp));
  165. test_assert(i == 1);
  166. test_streq(cp, " x");
  167. test_assert(U64_LITERAL(12345678901) ==
  168. tor_parse_uint64("12345678901",10,0,UINT64_MAX, &i, &cp));
  169. test_assert(i == 1);
  170. test_streq(cp, "");
  171. test_assert(U64_LITERAL(0) ==
  172. tor_parse_uint64("12345678901",10,500,INT32_MAX, &i, &cp));
  173. test_assert(i == 0);
  174. {
  175. /* Test tor_parse_double. */
  176. double d = tor_parse_double("10", 0, UINT64_MAX,&i,NULL);
  177. test_assert(i == 1);
  178. test_assert(DBL_TO_U64(d) == 10);
  179. d = tor_parse_double("0", 0, UINT64_MAX,&i,NULL);
  180. test_assert(i == 1);
  181. test_assert(DBL_TO_U64(d) == 0);
  182. d = tor_parse_double(" ", 0, UINT64_MAX,&i,NULL);
  183. test_assert(i == 0);
  184. d = tor_parse_double(".0a", 0, UINT64_MAX,&i,NULL);
  185. test_assert(i == 0);
  186. d = tor_parse_double(".0a", 0, UINT64_MAX,&i,&cp);
  187. test_assert(i == 1);
  188. d = tor_parse_double("-.0", 0, UINT64_MAX,&i,NULL);
  189. test_assert(i == 1);
  190. }
  191. /* Test failing snprintf cases */
  192. test_eq(-1, tor_snprintf(buf, 0, "Foo"));
  193. test_eq(-1, tor_snprintf(buf, 2, "Foo"));
  194. /* Test printf with uint64 */
  195. tor_snprintf(buf, sizeof(buf), "x!"U64_FORMAT"!x",
  196. U64_PRINTF_ARG(U64_LITERAL(12345678901)));
  197. test_streq(buf, "x!12345678901!x");
  198. /* Test for strcmpstart and strcmpend. */
  199. test_assert(strcmpstart("abcdef", "abcdef")==0);
  200. test_assert(strcmpstart("abcdef", "abc")==0);
  201. test_assert(strcmpstart("abcdef", "abd")<0);
  202. test_assert(strcmpstart("abcdef", "abb")>0);
  203. test_assert(strcmpstart("ab", "abb")<0);
  204. test_assert(strcmpend("abcdef", "abcdef")==0);
  205. test_assert(strcmpend("abcdef", "def")==0);
  206. test_assert(strcmpend("abcdef", "deg")<0);
  207. test_assert(strcmpend("abcdef", "dee")>0);
  208. test_assert(strcmpend("ab", "abb")<0);
  209. test_assert(strcasecmpend("AbcDEF", "abcdef")==0);
  210. test_assert(strcasecmpend("abcdef", "dEF")==0);
  211. test_assert(strcasecmpend("abcDEf", "deg")<0);
  212. test_assert(strcasecmpend("abcdef", "DEE")>0);
  213. test_assert(strcasecmpend("ab", "abB")<0);
  214. /* Test mem_is_zero */
  215. memset(buf,0,128);
  216. buf[128] = 'x';
  217. test_assert(tor_digest_is_zero(buf));
  218. test_assert(tor_mem_is_zero(buf, 10));
  219. test_assert(tor_mem_is_zero(buf, 20));
  220. test_assert(tor_mem_is_zero(buf, 128));
  221. test_assert(!tor_mem_is_zero(buf, 129));
  222. buf[60] = (char)255;
  223. test_assert(!tor_mem_is_zero(buf, 128));
  224. buf[0] = (char)1;
  225. test_assert(!tor_mem_is_zero(buf, 10));
  226. /* Test 'escaped' */
  227. test_streq("\"\"", escaped(""));
  228. test_streq("\"abcd\"", escaped("abcd"));
  229. test_streq("\"\\\\\\n\\r\\t\\\"\\'\"", escaped("\\\n\r\t\"\'"));
  230. test_streq("\"z\\001abc\\277d\"", escaped("z\001abc\277d"));
  231. test_assert(NULL == escaped(NULL));
  232. /* Test strndup and memdup */
  233. {
  234. const char *s = "abcdefghijklmnopqrstuvwxyz";
  235. cp = tor_strndup(s, 30);
  236. test_streq(cp, s); /* same string, */
  237. test_neq(cp, s); /* but different pointers. */
  238. tor_free(cp);
  239. cp = tor_strndup(s, 5);
  240. test_streq(cp, "abcde");
  241. tor_free(cp);
  242. s = "a\0b\0c\0d\0e\0";
  243. cp = tor_memdup(s,10);
  244. test_memeq(cp, s, 10); /* same ram, */
  245. test_neq(cp, s); /* but different pointers. */
  246. tor_free(cp);
  247. }
  248. /* Test str-foo functions */
  249. cp = tor_strdup("abcdef");
  250. test_assert(tor_strisnonupper(cp));
  251. cp[3] = 'D';
  252. test_assert(!tor_strisnonupper(cp));
  253. tor_strupper(cp);
  254. test_streq(cp, "ABCDEF");
  255. test_assert(tor_strisprint(cp));
  256. cp[3] = 3;
  257. test_assert(!tor_strisprint(cp));
  258. tor_free(cp);
  259. /* Test eat_whitespace. */
  260. {
  261. const char *s = " \n a";
  262. test_eq_ptr(eat_whitespace(s), s+4);
  263. s = "abcd";
  264. test_eq_ptr(eat_whitespace(s), s);
  265. s = "#xyz\nab";
  266. test_eq_ptr(eat_whitespace(s), s+5);
  267. }
  268. /* Test memmem and memstr */
  269. {
  270. const char *haystack = "abcde";
  271. tor_assert(!tor_memmem(haystack, 5, "ef", 2));
  272. test_eq_ptr(tor_memmem(haystack, 5, "cd", 2), haystack + 2);
  273. test_eq_ptr(tor_memmem(haystack, 5, "cde", 3), haystack + 2);
  274. haystack = "ababcad";
  275. test_eq_ptr(tor_memmem(haystack, 7, "abc", 3), haystack + 2);
  276. test_eq_ptr(tor_memstr(haystack, 7, "abc"), haystack + 2);
  277. test_assert(!tor_memstr(haystack, 7, "fe"));
  278. test_assert(!tor_memstr(haystack, 7, "longerthantheoriginal"));
  279. }
  280. /* Test wrap_string */
  281. {
  282. smartlist_t *sl = smartlist_create();
  283. wrap_string(sl, "This is a test of string wrapping functionality: woot.",
  284. 10, "", "");
  285. cp = smartlist_join_strings(sl, "", 0, NULL);
  286. test_streq(cp,
  287. "This is a\ntest of\nstring\nwrapping\nfunctional\nity: woot.\n");
  288. tor_free(cp);
  289. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  290. smartlist_clear(sl);
  291. wrap_string(sl, "This is a test of string wrapping functionality: woot.",
  292. 16, "### ", "# ");
  293. cp = smartlist_join_strings(sl, "", 0, NULL);
  294. test_streq(cp,
  295. "### This is a\n# test of string\n# wrapping\n# functionality:\n"
  296. "# woot.\n");
  297. tor_free(cp);
  298. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  299. smartlist_free(sl);
  300. }
  301. done:
  302. ;
  303. }
  304. static void
  305. test_util_pow2(void)
  306. {
  307. /* Test tor_log2(). */
  308. test_eq(tor_log2(64), 6);
  309. test_eq(tor_log2(65), 6);
  310. test_eq(tor_log2(63), 5);
  311. test_eq(tor_log2(1), 0);
  312. test_eq(tor_log2(2), 1);
  313. test_eq(tor_log2(3), 1);
  314. test_eq(tor_log2(4), 2);
  315. test_eq(tor_log2(5), 2);
  316. test_eq(tor_log2(U64_LITERAL(40000000000000000)), 55);
  317. test_eq(tor_log2(UINT64_MAX), 63);
  318. /* Test round_to_power_of_2 */
  319. test_eq(round_to_power_of_2(120), 128);
  320. test_eq(round_to_power_of_2(128), 128);
  321. test_eq(round_to_power_of_2(130), 128);
  322. test_eq(round_to_power_of_2(U64_LITERAL(40000000000000000)),
  323. U64_LITERAL(1)<<55);
  324. test_eq(round_to_power_of_2(0), 2);
  325. done:
  326. ;
  327. }
  328. /** mutex for thread test to stop the threads hitting data at the same time. */
  329. static tor_mutex_t *_thread_test_mutex = NULL;
  330. /** mutexes for the thread test to make sure that the threads have to
  331. * interleave somewhat. */
  332. static tor_mutex_t *_thread_test_start1 = NULL,
  333. *_thread_test_start2 = NULL;
  334. /** Shared strmap for the thread test. */
  335. static strmap_t *_thread_test_strmap = NULL;
  336. /** The name of thread1 for the thread test */
  337. static char *_thread1_name = NULL;
  338. /** The name of thread2 for the thread test */
  339. static char *_thread2_name = NULL;
  340. static void _thread_test_func(void* _s) ATTR_NORETURN;
  341. /** How many iterations have the threads in the unit test run? */
  342. static int t1_count = 0, t2_count = 0;
  343. /** Helper function for threading unit tests: This function runs in a
  344. * subthread. It grabs its own mutex (start1 or start2) to make sure that it
  345. * should start, then it repeatedly alters _test_thread_strmap protected by
  346. * _thread_test_mutex. */
  347. static void
  348. _thread_test_func(void* _s)
  349. {
  350. char *s = _s;
  351. int i, *count;
  352. tor_mutex_t *m;
  353. char buf[64];
  354. char **cp;
  355. if (!strcmp(s, "thread 1")) {
  356. m = _thread_test_start1;
  357. cp = &_thread1_name;
  358. count = &t1_count;
  359. } else {
  360. m = _thread_test_start2;
  361. cp = &_thread2_name;
  362. count = &t2_count;
  363. }
  364. tor_snprintf(buf, sizeof(buf), "%lu", tor_get_thread_id());
  365. *cp = tor_strdup(buf);
  366. tor_mutex_acquire(m);
  367. for (i=0; i<10000; ++i) {
  368. tor_mutex_acquire(_thread_test_mutex);
  369. strmap_set(_thread_test_strmap, "last to run", *cp);
  370. ++*count;
  371. tor_mutex_release(_thread_test_mutex);
  372. }
  373. tor_mutex_acquire(_thread_test_mutex);
  374. strmap_set(_thread_test_strmap, s, *cp);
  375. tor_mutex_release(_thread_test_mutex);
  376. tor_mutex_release(m);
  377. spawn_exit();
  378. }
  379. /** Run unit tests for threading logic. */
  380. static void
  381. test_util_threads(void)
  382. {
  383. char *s1 = NULL, *s2 = NULL;
  384. int done = 0, timedout = 0;
  385. time_t started;
  386. #ifndef MS_WINDOWS
  387. struct timeval tv;
  388. tv.tv_sec=0;
  389. tv.tv_usec=10;
  390. #endif
  391. #ifndef TOR_IS_MULTITHREADED
  392. /* Skip this test if we aren't threading. We should be threading most
  393. * everywhere by now. */
  394. if (1)
  395. return;
  396. #endif
  397. _thread_test_mutex = tor_mutex_new();
  398. _thread_test_start1 = tor_mutex_new();
  399. _thread_test_start2 = tor_mutex_new();
  400. _thread_test_strmap = strmap_new();
  401. s1 = tor_strdup("thread 1");
  402. s2 = tor_strdup("thread 2");
  403. tor_mutex_acquire(_thread_test_start1);
  404. tor_mutex_acquire(_thread_test_start2);
  405. spawn_func(_thread_test_func, s1);
  406. spawn_func(_thread_test_func, s2);
  407. tor_mutex_release(_thread_test_start2);
  408. tor_mutex_release(_thread_test_start1);
  409. started = time(NULL);
  410. while (!done) {
  411. tor_mutex_acquire(_thread_test_mutex);
  412. strmap_assert_ok(_thread_test_strmap);
  413. if (strmap_get(_thread_test_strmap, "thread 1") &&
  414. strmap_get(_thread_test_strmap, "thread 2")) {
  415. done = 1;
  416. } else if (time(NULL) > started + 25) {
  417. timedout = done = 1;
  418. }
  419. tor_mutex_release(_thread_test_mutex);
  420. #ifndef MS_WINDOWS
  421. /* Prevent the main thread from starving the worker threads. */
  422. select(0, NULL, NULL, NULL, &tv);
  423. #endif
  424. }
  425. tor_mutex_acquire(_thread_test_start1);
  426. tor_mutex_release(_thread_test_start1);
  427. tor_mutex_acquire(_thread_test_start2);
  428. tor_mutex_release(_thread_test_start2);
  429. tor_mutex_free(_thread_test_mutex);
  430. if (timedout) {
  431. printf("\nTimed out: %d %d", t1_count, t2_count);
  432. test_assert(strmap_get(_thread_test_strmap, "thread 1"));
  433. test_assert(strmap_get(_thread_test_strmap, "thread 2"));
  434. test_assert(!timedout);
  435. }
  436. /* different thread IDs. */
  437. test_assert(strcmp(strmap_get(_thread_test_strmap, "thread 1"),
  438. strmap_get(_thread_test_strmap, "thread 2")));
  439. test_assert(!strcmp(strmap_get(_thread_test_strmap, "thread 1"),
  440. strmap_get(_thread_test_strmap, "last to run")) ||
  441. !strcmp(strmap_get(_thread_test_strmap, "thread 2"),
  442. strmap_get(_thread_test_strmap, "last to run")));
  443. done:
  444. tor_free(s1);
  445. tor_free(s2);
  446. tor_free(_thread1_name);
  447. tor_free(_thread2_name);
  448. if (_thread_test_strmap)
  449. strmap_free(_thread_test_strmap, NULL);
  450. if (_thread_test_start1)
  451. tor_mutex_free(_thread_test_start1);
  452. if (_thread_test_start2)
  453. tor_mutex_free(_thread_test_start2);
  454. }
  455. /** Run unit tests for compression functions */
  456. static void
  457. test_util_gzip(void)
  458. {
  459. char *buf1=NULL, *buf2=NULL, *buf3=NULL, *cp1, *cp2;
  460. const char *ccp2;
  461. size_t len1, len2;
  462. tor_zlib_state_t *state = NULL;
  463. buf1 = tor_strdup("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAZ");
  464. test_assert(detect_compression_method(buf1, strlen(buf1)) == UNKNOWN_METHOD);
  465. if (is_gzip_supported()) {
  466. test_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
  467. GZIP_METHOD));
  468. test_assert(buf2);
  469. test_assert(!memcmp(buf2, "\037\213", 2)); /* Gzip magic. */
  470. test_assert(detect_compression_method(buf2, len1) == GZIP_METHOD);
  471. test_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1,
  472. GZIP_METHOD, 1, LOG_INFO));
  473. test_assert(buf3);
  474. test_streq(buf1,buf3);
  475. tor_free(buf2);
  476. tor_free(buf3);
  477. }
  478. test_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
  479. ZLIB_METHOD));
  480. test_assert(buf2);
  481. test_assert(!memcmp(buf2, "\x78\xDA", 2)); /* deflate magic. */
  482. test_assert(detect_compression_method(buf2, len1) == ZLIB_METHOD);
  483. test_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1,
  484. ZLIB_METHOD, 1, LOG_INFO));
  485. test_assert(buf3);
  486. test_streq(buf1,buf3);
  487. /* Check whether we can uncompress concatenated, compressed strings. */
  488. tor_free(buf3);
  489. buf2 = tor_realloc(buf2, len1*2);
  490. memcpy(buf2+len1, buf2, len1);
  491. test_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1*2,
  492. ZLIB_METHOD, 1, LOG_INFO));
  493. test_eq(len2, (strlen(buf1)+1)*2);
  494. test_memeq(buf3,
  495. "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAZ\0"
  496. "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAZ\0",
  497. (strlen(buf1)+1)*2);
  498. tor_free(buf1);
  499. tor_free(buf2);
  500. tor_free(buf3);
  501. /* Check whether we can uncompress partial strings. */
  502. buf1 =
  503. tor_strdup("String with low redundancy that won't be compressed much.");
  504. test_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
  505. ZLIB_METHOD));
  506. tor_assert(len1>16);
  507. /* when we allow an incomplete string, we should succeed.*/
  508. tor_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
  509. ZLIB_METHOD, 0, LOG_INFO));
  510. buf3[len2]='\0';
  511. tor_assert(len2 > 5);
  512. tor_assert(!strcmpstart(buf1, buf3));
  513. /* when we demand a complete string, this must fail. */
  514. tor_free(buf3);
  515. tor_assert(tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
  516. ZLIB_METHOD, 1, LOG_INFO));
  517. tor_assert(!buf3);
  518. /* Now, try streaming compression. */
  519. tor_free(buf1);
  520. tor_free(buf2);
  521. tor_free(buf3);
  522. state = tor_zlib_new(1, ZLIB_METHOD);
  523. tor_assert(state);
  524. cp1 = buf1 = tor_malloc(1024);
  525. len1 = 1024;
  526. ccp2 = "ABCDEFGHIJABCDEFGHIJ";
  527. len2 = 21;
  528. test_assert(tor_zlib_process(state, &cp1, &len1, &ccp2, &len2, 0)
  529. == TOR_ZLIB_OK);
  530. test_eq(len2, 0); /* Make sure we compressed it all. */
  531. test_assert(cp1 > buf1);
  532. len2 = 0;
  533. cp2 = cp1;
  534. test_assert(tor_zlib_process(state, &cp1, &len1, &ccp2, &len2, 1)
  535. == TOR_ZLIB_DONE);
  536. test_eq(len2, 0);
  537. test_assert(cp1 > cp2); /* Make sure we really added something. */
  538. tor_assert(!tor_gzip_uncompress(&buf3, &len2, buf1, 1024-len1,
  539. ZLIB_METHOD, 1, LOG_WARN));
  540. test_streq(buf3, "ABCDEFGHIJABCDEFGHIJ"); /*Make sure it compressed right.*/
  541. done:
  542. if (state)
  543. tor_zlib_free(state);
  544. tor_free(buf2);
  545. tor_free(buf3);
  546. tor_free(buf1);
  547. }
  548. /** Run unit tests for mmap() wrapper functionality. */
  549. static void
  550. test_util_mmap(void)
  551. {
  552. char *fname1 = tor_strdup(get_fname("mapped_1"));
  553. char *fname2 = tor_strdup(get_fname("mapped_2"));
  554. char *fname3 = tor_strdup(get_fname("mapped_3"));
  555. const size_t buflen = 17000;
  556. char *buf = tor_malloc(17000);
  557. tor_mmap_t *mapping = NULL;
  558. crypto_rand(buf, buflen);
  559. mapping = tor_mmap_file(fname1);
  560. test_assert(! mapping);
  561. write_str_to_file(fname1, "Short file.", 1);
  562. write_bytes_to_file(fname2, buf, buflen, 1);
  563. write_bytes_to_file(fname3, buf, 16384, 1);
  564. mapping = tor_mmap_file(fname1);
  565. test_assert(mapping);
  566. test_eq(mapping->size, strlen("Short file."));
  567. test_streq(mapping->data, "Short file.");
  568. #ifdef MS_WINDOWS
  569. tor_munmap_file(mapping);
  570. mapping = NULL;
  571. test_assert(unlink(fname1) == 0);
  572. #else
  573. /* make sure we can unlink. */
  574. test_assert(unlink(fname1) == 0);
  575. test_streq(mapping->data, "Short file.");
  576. tor_munmap_file(mapping);
  577. mapping = NULL;
  578. #endif
  579. /* Now a zero-length file. */
  580. write_str_to_file(fname1, "", 1);
  581. mapping = tor_mmap_file(fname1);
  582. test_eq(mapping, NULL);
  583. test_eq(ERANGE, errno);
  584. unlink(fname1);
  585. /* Make sure that we fail to map a no-longer-existent file. */
  586. mapping = tor_mmap_file(fname1);
  587. test_assert(mapping == NULL);
  588. /* Now try a big file that stretches across a few pages and isn't aligned */
  589. mapping = tor_mmap_file(fname2);
  590. test_assert(mapping);
  591. test_eq(mapping->size, buflen);
  592. test_memeq(mapping->data, buf, buflen);
  593. tor_munmap_file(mapping);
  594. mapping = NULL;
  595. /* Now try a big aligned file. */
  596. mapping = tor_mmap_file(fname3);
  597. test_assert(mapping);
  598. test_eq(mapping->size, 16384);
  599. test_memeq(mapping->data, buf, 16384);
  600. tor_munmap_file(mapping);
  601. mapping = NULL;
  602. done:
  603. unlink(fname1);
  604. unlink(fname2);
  605. unlink(fname3);
  606. tor_free(fname1);
  607. tor_free(fname2);
  608. tor_free(fname3);
  609. tor_free(buf);
  610. if (mapping)
  611. tor_munmap_file(mapping);
  612. }
  613. /** Run unit tests for escaping/unescaping data for use by controllers. */
  614. static void
  615. test_util_control_formats(void)
  616. {
  617. char *out = NULL;
  618. const char *inp =
  619. "..This is a test\r\nof the emergency \nbroadcast\r\n..system.\r\nZ.\r\n";
  620. size_t sz;
  621. sz = read_escaped_data(inp, strlen(inp), &out);
  622. test_streq(out,
  623. ".This is a test\nof the emergency \nbroadcast\n.system.\nZ.\n");
  624. test_eq(sz, strlen(out));
  625. done:
  626. tor_free(out);
  627. }
  628. static void
  629. test_util_sscanf(void)
  630. {
  631. unsigned u1, u2, u3;
  632. char s1[10], s2[10], s3[10], ch;
  633. int r;
  634. r = tor_sscanf("hello world", "hello world"); /* String match: success */
  635. test_eq(r, 0);
  636. r = tor_sscanf("hello world 3", "hello worlb %u", &u1); /* String fail */
  637. test_eq(r, 0);
  638. r = tor_sscanf("12345", "%u", &u1); /* Simple number */
  639. test_eq(r, 1);
  640. test_eq(u1, 12345u);
  641. r = tor_sscanf("", "%u", &u1); /* absent number */
  642. test_eq(r, 0);
  643. r = tor_sscanf("A", "%u", &u1); /* bogus number */
  644. test_eq(r, 0);
  645. r = tor_sscanf("4294967295", "%u", &u1); /* UINT32_MAX should work. */
  646. test_eq(r, 1);
  647. test_eq(u1, 4294967295u);
  648. r = tor_sscanf("4294967296", "%u", &u1); /* Always say -1 at 32 bits. */
  649. test_eq(r, 0);
  650. r = tor_sscanf("123456", "%2u%u", &u1, &u2); /* Width */
  651. test_eq(r, 2);
  652. test_eq(u1, 12u);
  653. test_eq(u2, 3456u);
  654. r = tor_sscanf("!12:3:456", "!%2u:%2u:%3u", &u1, &u2, &u3); /* separators */
  655. test_eq(r, 3);
  656. test_eq(u1, 12u);
  657. test_eq(u2, 3u);
  658. test_eq(u3, 456u);
  659. r = tor_sscanf("12:3:045", "%2u:%2u:%3u", &u1, &u2, &u3); /* 0s */
  660. test_eq(r, 3);
  661. test_eq(u1, 12u);
  662. test_eq(u2, 3u);
  663. test_eq(u3, 45u);
  664. /* %u does not match space.*/
  665. r = tor_sscanf("12:3: 45", "%2u:%2u:%3u", &u1, &u2, &u3);
  666. test_eq(r, 2);
  667. /* %u does not match negative numbers. */
  668. r = tor_sscanf("12:3:-4", "%2u:%2u:%3u", &u1, &u2, &u3);
  669. test_eq(r, 2);
  670. /* Arbitrary amounts of 0-padding are okay */
  671. r = tor_sscanf("12:03:000000000000000099", "%2u:%2u:%u", &u1, &u2, &u3);
  672. test_eq(r, 3);
  673. test_eq(u1, 12u);
  674. test_eq(u2, 3u);
  675. test_eq(u3, 99u);
  676. r = tor_sscanf("99% fresh", "%3u%% fresh", &u1); /* percents are scannable.*/
  677. test_eq(r, 1);
  678. test_eq(u1, 99);
  679. r = tor_sscanf("hello", "%s", s1); /* %s needs a number. */
  680. test_eq(r, -1);
  681. r = tor_sscanf("hello", "%3s%7s", s1, s2); /* %s matches characters. */
  682. test_eq(r, 2);
  683. test_streq(s1, "hel");
  684. test_streq(s2, "lo");
  685. r = tor_sscanf("WD40", "%2s%u", s3, &u1); /* %s%u */
  686. test_eq(r, 2);
  687. test_streq(s3, "WD");
  688. test_eq(u1, 40);
  689. r = tor_sscanf("76trombones", "%6u%9s", &u1, s1); /* %u%s */
  690. test_eq(r, 2);
  691. test_eq(u1, 76);
  692. test_streq(s1, "trombones");
  693. r = tor_sscanf("hello world", "%9s %9s", s1, s2); /* %s doesn't eat space. */
  694. test_eq(r, 2);
  695. test_streq(s1, "hello");
  696. test_streq(s2, "world");
  697. r = tor_sscanf("hi", "%9s%9s%3s", s1, s2, s3); /* %s can be empty. */
  698. test_eq(r, 3);
  699. test_streq(s1, "hi");
  700. test_streq(s2, "");
  701. test_streq(s3, "");
  702. r = tor_sscanf("1.2.3", "%u.%u.%u%c", &u1, &u2, &u3, &ch);
  703. test_eq(r, 3);
  704. r = tor_sscanf("1.2.3 foobar", "%u.%u.%u%c", &u1, &u2, &u3, &ch);
  705. test_eq(r, 4);
  706. done:
  707. ;
  708. }
  709. /** Run unittests for memory pool allocator */
  710. static void
  711. test_util_mempool(void)
  712. {
  713. mp_pool_t *pool = NULL;
  714. smartlist_t *allocated = NULL;
  715. int i;
  716. pool = mp_pool_new(1, 100);
  717. test_assert(pool);
  718. test_assert(pool->new_chunk_capacity >= 100);
  719. test_assert(pool->item_alloc_size >= sizeof(void*)+1);
  720. mp_pool_destroy(pool);
  721. pool = NULL;
  722. pool = mp_pool_new(241, 2500);
  723. test_assert(pool);
  724. test_assert(pool->new_chunk_capacity >= 10);
  725. test_assert(pool->item_alloc_size >= sizeof(void*)+241);
  726. test_eq(pool->item_alloc_size & 0x03, 0);
  727. test_assert(pool->new_chunk_capacity < 60);
  728. allocated = smartlist_create();
  729. for (i = 0; i < 20000; ++i) {
  730. if (smartlist_len(allocated) < 20 || crypto_rand_int(2)) {
  731. void *m = mp_pool_get(pool);
  732. memset(m, 0x09, 241);
  733. smartlist_add(allocated, m);
  734. //printf("%d: %p\n", i, m);
  735. //mp_pool_assert_ok(pool);
  736. } else {
  737. int idx = crypto_rand_int(smartlist_len(allocated));
  738. void *m = smartlist_get(allocated, idx);
  739. //printf("%d: free %p\n", i, m);
  740. smartlist_del(allocated, idx);
  741. mp_pool_release(m);
  742. //mp_pool_assert_ok(pool);
  743. }
  744. if (crypto_rand_int(777)==0)
  745. mp_pool_clean(pool, 1, 1);
  746. if (i % 777)
  747. mp_pool_assert_ok(pool);
  748. }
  749. done:
  750. if (allocated) {
  751. SMARTLIST_FOREACH(allocated, void *, m, mp_pool_release(m));
  752. mp_pool_assert_ok(pool);
  753. mp_pool_clean(pool, 0, 0);
  754. mp_pool_assert_ok(pool);
  755. smartlist_free(allocated);
  756. }
  757. if (pool)
  758. mp_pool_destroy(pool);
  759. }
  760. /** Run unittests for memory area allocator */
  761. static void
  762. test_util_memarea(void)
  763. {
  764. memarea_t *area = memarea_new();
  765. char *p1, *p2, *p3, *p1_orig;
  766. void *malloced_ptr = NULL;
  767. int i;
  768. test_assert(area);
  769. p1_orig = p1 = memarea_alloc(area,64);
  770. p2 = memarea_alloc_zero(area,52);
  771. p3 = memarea_alloc(area,11);
  772. test_assert(memarea_owns_ptr(area, p1));
  773. test_assert(memarea_owns_ptr(area, p2));
  774. test_assert(memarea_owns_ptr(area, p3));
  775. /* Make sure we left enough space. */
  776. test_assert(p1+64 <= p2);
  777. test_assert(p2+52 <= p3);
  778. /* Make sure we aligned. */
  779. test_eq(((uintptr_t)p1) % sizeof(void*), 0);
  780. test_eq(((uintptr_t)p2) % sizeof(void*), 0);
  781. test_eq(((uintptr_t)p3) % sizeof(void*), 0);
  782. test_assert(!memarea_owns_ptr(area, p3+8192));
  783. test_assert(!memarea_owns_ptr(area, p3+30));
  784. test_assert(tor_mem_is_zero(p2, 52));
  785. /* Make sure we don't overalign. */
  786. p1 = memarea_alloc(area, 1);
  787. p2 = memarea_alloc(area, 1);
  788. test_eq(p1+sizeof(void*), p2);
  789. {
  790. malloced_ptr = tor_malloc(64);
  791. test_assert(!memarea_owns_ptr(area, malloced_ptr));
  792. tor_free(malloced_ptr);
  793. }
  794. /* memarea_memdup */
  795. {
  796. malloced_ptr = tor_malloc(64);
  797. crypto_rand((char*)malloced_ptr, 64);
  798. p1 = memarea_memdup(area, malloced_ptr, 64);
  799. test_assert(p1 != malloced_ptr);
  800. test_memeq(p1, malloced_ptr, 64);
  801. tor_free(malloced_ptr);
  802. }
  803. /* memarea_strdup. */
  804. p1 = memarea_strdup(area,"");
  805. p2 = memarea_strdup(area, "abcd");
  806. test_assert(p1);
  807. test_assert(p2);
  808. test_streq(p1, "");
  809. test_streq(p2, "abcd");
  810. /* memarea_strndup. */
  811. {
  812. const char *s = "Ad ogni porta batte la morte e grida: il nome!";
  813. /* (From Turandot, act 3.) */
  814. size_t len = strlen(s);
  815. p1 = memarea_strndup(area, s, 1000);
  816. p2 = memarea_strndup(area, s, 10);
  817. test_streq(p1, s);
  818. test_assert(p2 >= p1 + len + 1);
  819. test_memeq(s, p2, 10);
  820. test_eq(p2[10], '\0');
  821. p3 = memarea_strndup(area, s, len);
  822. test_streq(p3, s);
  823. p3 = memarea_strndup(area, s, len-1);
  824. test_memeq(s, p3, len-1);
  825. test_eq(p3[len-1], '\0');
  826. }
  827. memarea_clear(area);
  828. p1 = memarea_alloc(area, 1);
  829. test_eq(p1, p1_orig);
  830. memarea_clear(area);
  831. /* Check for running over an area's size. */
  832. for (i = 0; i < 512; ++i) {
  833. p1 = memarea_alloc(area, crypto_rand_int(5)+1);
  834. test_assert(memarea_owns_ptr(area, p1));
  835. }
  836. memarea_assert_ok(area);
  837. /* Make sure we can allocate a too-big object. */
  838. p1 = memarea_alloc_zero(area, 9000);
  839. p2 = memarea_alloc_zero(area, 16);
  840. test_assert(memarea_owns_ptr(area, p1));
  841. test_assert(memarea_owns_ptr(area, p2));
  842. done:
  843. memarea_drop_all(area);
  844. tor_free(malloced_ptr);
  845. }
  846. /** Run unit tests for utility functions to get file names relative to
  847. * the data directory. */
  848. static void
  849. test_util_datadir(void)
  850. {
  851. char buf[1024];
  852. char *f = NULL;
  853. char *temp_dir = NULL;
  854. temp_dir = get_datadir_fname(NULL);
  855. f = get_datadir_fname("state");
  856. tor_snprintf(buf, sizeof(buf), "%s"PATH_SEPARATOR"state", temp_dir);
  857. test_streq(f, buf);
  858. tor_free(f);
  859. f = get_datadir_fname2("cache", "thingy");
  860. tor_snprintf(buf, sizeof(buf),
  861. "%s"PATH_SEPARATOR"cache"PATH_SEPARATOR"thingy", temp_dir);
  862. test_streq(f, buf);
  863. tor_free(f);
  864. f = get_datadir_fname2_suffix("cache", "thingy", ".foo");
  865. tor_snprintf(buf, sizeof(buf),
  866. "%s"PATH_SEPARATOR"cache"PATH_SEPARATOR"thingy.foo", temp_dir);
  867. test_streq(f, buf);
  868. tor_free(f);
  869. f = get_datadir_fname_suffix("cache", ".foo");
  870. tor_snprintf(buf, sizeof(buf), "%s"PATH_SEPARATOR"cache.foo",
  871. temp_dir);
  872. test_streq(f, buf);
  873. done:
  874. tor_free(f);
  875. tor_free(temp_dir);
  876. }
  877. static void
  878. test_util_strtok(void)
  879. {
  880. char buf[128];
  881. char buf2[128];
  882. char *cp1, *cp2;
  883. strlcpy(buf, "Graved on the dark in gestures of descent", sizeof(buf));
  884. strlcpy(buf2, "they.seemed;their!own;most.perfect;monument", sizeof(buf2));
  885. /* -- "Year's End", Richard Wilbur */
  886. test_streq("Graved", tor_strtok_r_impl(buf, " ", &cp1));
  887. test_streq("they", tor_strtok_r_impl(buf2, ".!..;!", &cp2));
  888. #define S1() tor_strtok_r_impl(NULL, " ", &cp1)
  889. #define S2() tor_strtok_r_impl(NULL, ".!..;!", &cp2)
  890. test_streq("on", S1());
  891. test_streq("the", S1());
  892. test_streq("dark", S1());
  893. test_streq("seemed", S2());
  894. test_streq("their", S2());
  895. test_streq("own", S2());
  896. test_streq("in", S1());
  897. test_streq("gestures", S1());
  898. test_streq("of", S1());
  899. test_streq("most", S2());
  900. test_streq("perfect", S2());
  901. test_streq("descent", S1());
  902. test_streq("monument", S2());
  903. test_assert(NULL == S1());
  904. test_assert(NULL == S2());
  905. done:
  906. ;
  907. }
  908. static void
  909. test_util_find_str_at_start_of_line(void *ptr)
  910. {
  911. const char *long_string =
  912. "hello world. hello world. hello hello. howdy.\n"
  913. "hello hello world\n";
  914. (void)ptr;
  915. /* not-found case. */
  916. tt_assert(! find_str_at_start_of_line(long_string, "fred"));
  917. /* not-found case where haystack doesn't end with \n */
  918. tt_assert(! find_str_at_start_of_line("foobar\nbaz", "fred"));
  919. /* start-of-string case */
  920. tt_assert(long_string ==
  921. find_str_at_start_of_line(long_string, "hello world."));
  922. /* start-of-line case */
  923. tt_assert(strchr(long_string,'\n')+1 ==
  924. find_str_at_start_of_line(long_string, "hello hello"));
  925. done:
  926. ;
  927. }
  928. static void
  929. test_util_asprintf(void *ptr)
  930. {
  931. #define LOREMIPSUM \
  932. "Lorem ipsum dolor sit amet, consectetur adipisicing elit"
  933. char *cp=NULL, *cp2=NULL;
  934. int r;
  935. (void)ptr;
  936. /* empty string. */
  937. r = tor_asprintf(&cp, "%s", "");
  938. tt_assert(cp);
  939. tt_int_op(r, ==, strlen(cp));
  940. tt_str_op(cp, ==, "");
  941. /* Short string with some printing in it. */
  942. r = tor_asprintf(&cp2, "First=%d, Second=%d", 101, 202);
  943. tt_assert(cp2);
  944. tt_int_op(r, ==, strlen(cp2));
  945. tt_str_op(cp2, ==, "First=101, Second=202");
  946. tt_assert(cp != cp2);
  947. tor_free(cp);
  948. tor_free(cp2);
  949. /* Glass-box test: a string exactly 128 characters long. */
  950. r = tor_asprintf(&cp, "Lorem1: %sLorem2: %s", LOREMIPSUM, LOREMIPSUM);
  951. tt_assert(cp);
  952. tt_int_op(r, ==, 128);
  953. tt_assert(cp[128] == '\0');
  954. tt_str_op(cp, ==,
  955. "Lorem1: "LOREMIPSUM"Lorem2: "LOREMIPSUM);
  956. tor_free(cp);
  957. /* String longer than 128 characters */
  958. r = tor_asprintf(&cp, "1: %s 2: %s 3: %s",
  959. LOREMIPSUM, LOREMIPSUM, LOREMIPSUM);
  960. tt_assert(cp);
  961. tt_int_op(r, ==, strlen(cp));
  962. tt_str_op(cp, ==, "1: "LOREMIPSUM" 2: "LOREMIPSUM" 3: "LOREMIPSUM);
  963. done:
  964. tor_free(cp);
  965. tor_free(cp2);
  966. }
  967. #define UTIL_LEGACY(name) \
  968. { #name, legacy_test_helper, 0, &legacy_setup, test_util_ ## name }
  969. #define UTIL_TEST(name, flags) \
  970. { #name, test_util_ ## name, flags, NULL, NULL }
  971. struct testcase_t util_tests[] = {
  972. UTIL_LEGACY(time),
  973. UTIL_LEGACY(config_line),
  974. UTIL_LEGACY(strmisc),
  975. UTIL_LEGACY(pow2),
  976. UTIL_LEGACY(gzip),
  977. UTIL_LEGACY(datadir),
  978. UTIL_LEGACY(mempool),
  979. UTIL_LEGACY(memarea),
  980. UTIL_LEGACY(control_formats),
  981. UTIL_LEGACY(mmap),
  982. UTIL_LEGACY(threads),
  983. UTIL_LEGACY(sscanf),
  984. UTIL_LEGACY(strtok),
  985. UTIL_TEST(find_str_at_start_of_line, 0),
  986. UTIL_TEST(asprintf, 0),
  987. END_OF_TESTCASES
  988. };