unittest.cc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * libtest
  4. *
  5. * Copyright (C) 2011 Data Differential, http://datadifferential.com/
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 3 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <config.h>
  22. #include <libtest/test.hpp>
  23. #if defined(LIBTEST_WITH_LIBMEMCACHED_SUPPORT) && LIBTEST_WITH_LIBMEMCACHED_SUPPORT
  24. #include <libmemcached-1.0/memcached.h>
  25. #endif
  26. #if defined(LIBTEST_WITH_LIBGEARMAN_SUPPORT) && LIBTEST_WITH_LIBGEARMAN_SUPPORT
  27. #include <libgearman/gearman.h>
  28. #endif
  29. #include <cstdlib>
  30. #include <unistd.h>
  31. using namespace libtest;
  32. static test_return_t LIBTOOL_COMMAND_test(void *)
  33. {
  34. test_true(getenv("LIBTOOL_COMMAND"));
  35. return TEST_SUCCESS;
  36. }
  37. static test_return_t VALGRIND_COMMAND_test(void *)
  38. {
  39. test_true(getenv("VALGRIND_COMMAND"));
  40. return TEST_SUCCESS;
  41. }
  42. static test_return_t HELGRIND_COMMAND_test(void *)
  43. {
  44. test_true(getenv("HELGRIND_COMMAND"));
  45. return TEST_SUCCESS;
  46. }
  47. static test_return_t GDB_COMMAND_test(void *)
  48. {
  49. test_true(getenv("GDB_COMMAND"));
  50. return TEST_SUCCESS;
  51. }
  52. static test_return_t test_success_equals_one_test(void *)
  53. {
  54. test_skip(HAVE_LIBMEMCACHED, 1);
  55. #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
  56. test_zero(MEMCACHED_SUCCESS);
  57. #endif
  58. return TEST_SUCCESS;
  59. }
  60. static test_return_t test_success_test(void *)
  61. {
  62. return TEST_SUCCESS;
  63. }
  64. static test_return_t test_failure_test(void *)
  65. {
  66. return TEST_SKIPPED; // Only run this when debugging
  67. test_compare(1, 2);
  68. return TEST_SUCCESS;
  69. }
  70. static test_return_t local_test(void *)
  71. {
  72. if (getenv("LIBTEST_LOCAL"))
  73. {
  74. test_true(test_is_local());
  75. }
  76. else
  77. {
  78. test_false(test_is_local());
  79. }
  80. return TEST_SUCCESS;
  81. }
  82. static test_return_t local_not_test(void *)
  83. {
  84. return TEST_SKIPPED;
  85. std::string temp;
  86. const char *ptr;
  87. if ((ptr= getenv("LIBTEST_LOCAL")) == NULL)
  88. {
  89. temp.append(ptr);
  90. }
  91. // unsetenv() will cause issues with valgrind
  92. _compare(__FILE__, __LINE__, __func__, 0, unsetenv("LIBTEST_LOCAL"), true);
  93. test_compare(0, unsetenv("LIBTEST_LOCAL"));
  94. test_false(test_is_local());
  95. test_compare(0, setenv("LIBTEST_LOCAL", "1", 1));
  96. test_true(test_is_local());
  97. if (temp.empty())
  98. {
  99. test_compare(0, unsetenv("LIBTEST_LOCAL"));
  100. }
  101. else
  102. {
  103. char *old_string= strdup(temp.c_str());
  104. test_compare(0, setenv("LIBTEST_LOCAL", old_string, 1));
  105. }
  106. return TEST_SUCCESS;
  107. }
  108. static test_return_t var_exists_test(void *)
  109. {
  110. test_compare(0, access("var", R_OK | W_OK | X_OK));
  111. return TEST_SUCCESS;
  112. }
  113. static test_return_t var_tmp_exists_test(void *)
  114. {
  115. test_compare(0, access("var/tmp", R_OK | W_OK | X_OK));
  116. return TEST_SUCCESS;
  117. }
  118. static test_return_t var_run_exists_test(void *)
  119. {
  120. test_compare(0, access("var/run", R_OK | W_OK | X_OK));
  121. return TEST_SUCCESS;
  122. }
  123. static test_return_t var_log_exists_test(void *)
  124. {
  125. test_compare(0, access("var/log", R_OK | W_OK | X_OK));
  126. return TEST_SUCCESS;
  127. }
  128. static test_return_t var_tmp_test(void *)
  129. {
  130. FILE *file= fopen("var/tmp/junk", "w+");
  131. char buffer[1024];
  132. const char *dir= getcwd(buffer, sizeof(buffer));
  133. test_true_got(file, dir);
  134. fclose(file);
  135. return TEST_SUCCESS;
  136. }
  137. static test_return_t var_run_test(void *)
  138. {
  139. FILE *file= fopen("var/run/junk", "w+");
  140. test_true(file);
  141. fclose(file);
  142. return TEST_SUCCESS;
  143. }
  144. static test_return_t var_log_test(void *)
  145. {
  146. FILE *file= fopen("var/log/junk", "w+");
  147. test_true(file);
  148. fclose(file);
  149. return TEST_SUCCESS;
  150. }
  151. static test_return_t var_tmp_rm_test(void *)
  152. {
  153. test_true(unlink("var/tmp/junk") == 0);
  154. return TEST_SUCCESS;
  155. }
  156. static test_return_t var_run_rm_test(void *)
  157. {
  158. test_true(unlink("var/run/junk") == 0);
  159. return TEST_SUCCESS;
  160. }
  161. static test_return_t var_log_rm_test(void *)
  162. {
  163. test_true(unlink("var/log/junk") == 0);
  164. return TEST_SUCCESS;
  165. }
  166. static test_return_t _compare_test_return_t_test(void *)
  167. {
  168. test_compare(TEST_SUCCESS, TEST_SUCCESS);
  169. return TEST_SUCCESS;
  170. }
  171. static test_return_t _compare_memcached_return_t_test(void *)
  172. {
  173. test_skip(HAVE_LIBMEMCACHED, true);
  174. #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
  175. test_compare(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
  176. #endif
  177. return TEST_SUCCESS;
  178. }
  179. static test_return_t _compare_gearman_return_t_test(void *)
  180. {
  181. test_skip(HAVE_LIBGEARMAN, true);
  182. #if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
  183. test_compare(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
  184. #endif
  185. return TEST_SUCCESS;
  186. }
  187. static test_return_t gearmand_cycle_test(void *object)
  188. {
  189. server_startup_st *servers= (server_startup_st*)object;
  190. test_true(servers and servers->validate());
  191. #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
  192. test_true(has_gearmand_binary());
  193. #endif
  194. test_skip(true, has_gearmand_binary());
  195. test_true(server_startup(*servers, "gearmand", get_free_port(), 0, NULL));
  196. return TEST_SUCCESS;
  197. }
  198. static test_return_t memcached_light_cycle_TEST(void *object)
  199. {
  200. server_startup_st *servers= (server_startup_st*)object;
  201. test_true(servers);
  202. test_skip(true, bool(HAVE_MEMCACHED_LIGHT_BINARY));
  203. test_true(server_startup(*servers, "memcached-light", get_free_port(), 0, NULL));
  204. return TEST_SUCCESS;
  205. }
  206. static test_return_t skip_shim(bool a, bool b)
  207. {
  208. test_skip(a, b);
  209. return TEST_SUCCESS;
  210. }
  211. static test_return_t test_skip_true_TEST(void *object)
  212. {
  213. test_compare(true, true);
  214. test_compare(false, false);
  215. test_compare(TEST_SUCCESS, skip_shim(true, true));
  216. test_compare(TEST_SUCCESS, skip_shim(false, false));
  217. return TEST_SUCCESS;
  218. }
  219. static test_return_t test_skip_false_TEST(void *object)
  220. {
  221. test_compare(TEST_SKIPPED, skip_shim(true, false));
  222. test_compare(TEST_SKIPPED, skip_shim(false, true));
  223. return TEST_SUCCESS;
  224. }
  225. static test_return_t memcached_cycle_test(void *object)
  226. {
  227. server_startup_st *servers= (server_startup_st*)object;
  228. test_true(servers);
  229. if (MEMCACHED_BINARY and HAVE_LIBMEMCACHED)
  230. {
  231. test_true(has_memcached_binary());
  232. test_true(server_startup(*servers, "memcached", get_free_port(), 0, NULL));
  233. return TEST_SUCCESS;
  234. }
  235. return TEST_SKIPPED;
  236. }
  237. static test_return_t memcached_socket_cycle_test(void *object)
  238. {
  239. server_startup_st *servers= (server_startup_st*)object;
  240. test_true(servers);
  241. if (MEMCACHED_BINARY)
  242. {
  243. if (HAVE_LIBMEMCACHED)
  244. {
  245. test_true(has_memcached_binary());
  246. test_true(servers->start_socket_server("memcached", get_free_port(), 0, NULL));
  247. return TEST_SUCCESS;
  248. }
  249. }
  250. return TEST_SKIPPED;
  251. }
  252. static test_return_t memcached_sasl_test(void *object)
  253. {
  254. server_startup_st *servers= (server_startup_st*)object;
  255. test_true(servers);
  256. test_skip(false, bool(getenv("TESTS_ENVIRONMENT")));
  257. if (MEMCACHED_SASL_BINARY)
  258. {
  259. if (HAVE_LIBMEMCACHED)
  260. {
  261. test_true(has_memcached_sasl_binary());
  262. test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL));
  263. return TEST_SUCCESS;
  264. }
  265. }
  266. return TEST_SKIPPED;
  267. }
  268. static test_return_t application_true_BINARY(void *)
  269. {
  270. Application true_app("true");
  271. test_compare(Application::SUCCESS, true_app.run());
  272. test_compare(Application::SUCCESS, true_app.wait());
  273. return TEST_SUCCESS;
  274. }
  275. static test_return_t application_gdb_true_BINARY2(void *)
  276. {
  277. test_skip(0, access("/usr/bin/gdb", X_OK ));
  278. Application true_app("true");
  279. true_app.use_gdb();
  280. test_compare(Application::SUCCESS, true_app.run());
  281. test_compare(Application::SUCCESS, true_app.wait());
  282. return TEST_SUCCESS;
  283. }
  284. static test_return_t application_gdb_true_BINARY(void *)
  285. {
  286. test_skip(0, access("/usr/bin/gdb", X_OK ));
  287. Application true_app("true");
  288. true_app.use_gdb();
  289. const char *args[]= { "--fubar", 0 };
  290. test_compare(Application::SUCCESS, true_app.run(args));
  291. test_compare(Application::SUCCESS, true_app.wait());
  292. return TEST_SUCCESS;
  293. }
  294. static test_return_t application_true_fubar_BINARY(void *)
  295. {
  296. Application true_app("true");
  297. const char *args[]= { "--fubar", 0 };
  298. test_compare(Application::SUCCESS, true_app.run(args));
  299. test_compare(Application::SUCCESS, true_app.wait());
  300. test_compare(0, true_app.stdout_result().size());
  301. return TEST_SUCCESS;
  302. }
  303. static test_return_t application_doesnotexist_BINARY(void *)
  304. {
  305. test_skip_valgrind();
  306. Application true_app("doesnotexist");
  307. const char *args[]= { "--fubar", 0 };
  308. #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
  309. test_compare(Application::INVALID, true_app.run(args));
  310. test_compare(Application::FAILURE, true_app.wait());
  311. #else
  312. test_compare(Application::SUCCESS, true_app.run(args));
  313. test_compare(Application::INVALID, true_app.wait());
  314. #endif
  315. test_compare(0, true_app.stdout_result().size());
  316. return TEST_SUCCESS;
  317. }
  318. static test_return_t application_true_fubar_eq_doh_BINARY(void *)
  319. {
  320. Application true_app("true");
  321. const char *args[]= { "--fubar=doh", 0 };
  322. test_compare(Application::SUCCESS, true_app.run(args));
  323. test_compare(Application::SUCCESS, true_app.wait());
  324. test_compare(0, true_app.stdout_result().size());
  325. return TEST_SUCCESS;
  326. }
  327. static test_return_t application_true_fubar_eq_doh_option_BINARY(void *)
  328. {
  329. Application true_app("true");
  330. true_app.add_option("--fubar=", "doh");
  331. test_compare(Application::SUCCESS, true_app.run());
  332. test_compare(Application::SUCCESS, true_app.wait());
  333. test_compare(0, true_app.stdout_result().size());
  334. return TEST_SUCCESS;
  335. }
  336. static test_return_t GET_TEST(void *)
  337. {
  338. libtest::http::GET get("http://foo.example.com/");
  339. test_compare(false, get.execute());
  340. return TEST_SUCCESS;
  341. }
  342. static test_return_t POST_TEST(void *)
  343. {
  344. libtest::vchar_t body;
  345. libtest::http::POST post("http://foo.example.com/", body);
  346. test_compare(false, post.execute());
  347. return TEST_SUCCESS;
  348. }
  349. static test_return_t TRACE_TEST(void *)
  350. {
  351. libtest::vchar_t body;
  352. libtest::http::TRACE trace("http://foo.example.com/", body);
  353. test_compare(false, trace.execute());
  354. return TEST_SUCCESS;
  355. }
  356. static test_return_t vchar_t_TEST(void *)
  357. {
  358. libtest::vchar_t response;
  359. libtest::make_vector(response, test_literal_param("fubar\n"));
  360. test_compare(response, response);
  361. return TEST_SUCCESS;
  362. }
  363. static test_return_t application_echo_fubar_BINARY(void *)
  364. {
  365. Application true_app("echo");
  366. const char *args[]= { "fubar", 0 };
  367. test_compare(Application::SUCCESS, true_app.run(args));
  368. test_compare(Application::SUCCESS, true_app.wait());
  369. libtest::vchar_t response;
  370. make_vector(response, test_literal_param("fubar\n"));
  371. test_compare(response, true_app.stdout_result());
  372. return TEST_SUCCESS;
  373. }
  374. static test_return_t application_echo_fubar_BINARY2(void *)
  375. {
  376. Application true_app("echo");
  377. true_app.add_option("fubar");
  378. test_compare(Application::SUCCESS, true_app.run());
  379. test_compare(Application::SUCCESS, true_app.wait());
  380. libtest::vchar_t response;
  381. make_vector(response, test_literal_param("fubar\n"));
  382. test_compare(response, true_app.stdout_result());
  383. return TEST_SUCCESS;
  384. }
  385. static test_return_t true_BINARY(void *)
  386. {
  387. const char *args[]= { 0 };
  388. test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
  389. return TEST_SUCCESS;
  390. }
  391. static test_return_t true_fubar_BINARY(void *)
  392. {
  393. const char *args[]= { "--fubar", 0 };
  394. test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
  395. return TEST_SUCCESS;
  396. }
  397. static test_return_t echo_fubar_BINARY(void *)
  398. {
  399. const char *args[]= { "fubar", 0 };
  400. test_compare(EXIT_SUCCESS, exec_cmdline("echo", args));
  401. return TEST_SUCCESS;
  402. }
  403. static test_return_t wait_BINARY(void *)
  404. {
  405. const char *args[]= { "--quiet", 0 };
  406. test_compare(EXIT_FAILURE, exec_cmdline("libtest/wait", args, true));
  407. return TEST_SUCCESS;
  408. }
  409. static test_return_t wait_help_BINARY(void *)
  410. {
  411. const char *args[]= { "--quiet", "--help", 0 };
  412. test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
  413. return TEST_SUCCESS;
  414. }
  415. static test_return_t wait_version_BINARY(void *)
  416. {
  417. const char *args[]= { "--quiet", "--version", 0 };
  418. test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
  419. return TEST_SUCCESS;
  420. }
  421. static test_return_t wait_services_BINARY(void *)
  422. {
  423. test_skip(0, access("/etc/services", R_OK ));
  424. const char *args[]= { "--quiet", "/etc/services", 0 };
  425. test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
  426. return TEST_SUCCESS;
  427. }
  428. static test_return_t wait_services_BINARY2(void *)
  429. {
  430. test_skip(0, access("/etc/services", R_OK ));
  431. const char *args[]= { "/etc/services", 0 };
  432. test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
  433. return TEST_SUCCESS;
  434. }
  435. static test_return_t wait_services_appliction_TEST(void *)
  436. {
  437. test_skip(0, access("/usr/bin/gdb", X_OK ));
  438. test_skip(0, access("/etc/services", R_OK ));
  439. libtest::Application wait_app("libtest/wait", true);
  440. wait_app.use_gdb();
  441. const char *args[]= { "/etc/services", 0 };
  442. test_compare(Application::SUCCESS, wait_app.run(args));
  443. test_compare(Application::SUCCESS, wait_app.wait());
  444. return TEST_SUCCESS;
  445. }
  446. static test_return_t gdb_wait_services_appliction_TEST(void *)
  447. {
  448. #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
  449. test_skip(0, TARGET_OS_OSX);
  450. #endif
  451. test_skip(0, access("/usr/bin/gdb", X_OK ));
  452. test_skip(0, access("/etc/services", R_OK ));
  453. libtest::Application wait_app("libtest/wait", true);
  454. wait_app.use_gdb();
  455. const char *args[]= { "/etc/services", 0 };
  456. test_compare(Application::SUCCESS, wait_app.run(args));
  457. test_compare(Application::SUCCESS, wait_app.wait());
  458. return TEST_SUCCESS;
  459. }
  460. static test_return_t gdb_abort_services_appliction_TEST(void *)
  461. {
  462. test_skip(0, access("/usr/bin/gdb", X_OK ));
  463. #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
  464. test_skip(0, TARGET_OS_OSX);
  465. #endif
  466. libtest::Application abort_app("libtest/abort", true);
  467. abort_app.use_gdb();
  468. test_compare(Application::SUCCESS, abort_app.run());
  469. test_compare(Application::SUCCESS, abort_app.wait());
  470. std::string gdb_filename= abort_app.gdb_filename();
  471. const char *args[]= { "SIGABRT", gdb_filename.c_str(), 0 };
  472. test_compare(EXIT_SUCCESS, exec_cmdline("grep", args));
  473. // Sanity test
  474. args[0]= "THIS_WILL_NOT_BE_FOUND";
  475. test_compare(EXIT_FAILURE, exec_cmdline("grep", args));
  476. return TEST_SUCCESS;
  477. }
  478. static test_return_t get_free_port_TEST(void *)
  479. {
  480. in_port_t ret_port;
  481. test_true_hint((ret_port= get_free_port()), ret_port);
  482. test_true(get_free_port() != default_port());
  483. test_true(get_free_port() != get_free_port());
  484. return TEST_SUCCESS;
  485. }
  486. static uint32_t fatal_calls= 0;
  487. static test_return_t fatal_TEST(void *)
  488. {
  489. test_compare(fatal_calls++, fatal::disabled_counter());
  490. throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Testing va_args based fatal(): %d", 10);
  491. return TEST_SUCCESS;
  492. }
  493. static test_return_t number_of_cpus_TEST(void *)
  494. {
  495. test_true(number_of_cpus() >= 1);
  496. return TEST_SUCCESS;
  497. }
  498. static test_return_t create_tmpfile_TEST(void *)
  499. {
  500. std::string tmp= create_tmpfile(__func__);
  501. Application touch_app("touch");
  502. const char *args[]= { tmp.c_str(), 0 };
  503. test_compare(Application::SUCCESS, touch_app.run(args));
  504. test_compare(Application::SUCCESS, touch_app.wait());
  505. test_compare_hint(0, access(tmp.c_str(), R_OK), strerror(errno));
  506. test_compare_hint(0, unlink(tmp.c_str()), strerror(errno));
  507. return TEST_SUCCESS;
  508. }
  509. static test_return_t fatal_message_TEST(void *)
  510. {
  511. test_compare(fatal_calls++, fatal::disabled_counter());
  512. throw fatal_message("Fatal test");
  513. return TEST_SUCCESS;
  514. }
  515. static test_return_t default_port_TEST(void *)
  516. {
  517. in_port_t ret_port= default_port();
  518. test_compare(ret_port, libtest::default_port());
  519. test_compare(ret_port, libtest::default_port());
  520. return TEST_SUCCESS;
  521. }
  522. static test_return_t check_for_gearman(void *)
  523. {
  524. test_skip(true, HAVE_LIBGEARMAN);
  525. test_skip(true, has_gearmand_binary());
  526. return TEST_SUCCESS;
  527. }
  528. test_st gearmand_tests[] ={
  529. #if 0
  530. {"pause", 0, pause_test },
  531. #endif
  532. {"gearmand startup-shutdown", 0, gearmand_cycle_test },
  533. {"_compare(gearman_return_t)", 0, _compare_gearman_return_t_test },
  534. {0, 0, 0}
  535. };
  536. static test_return_t check_for_libmemcached(void *)
  537. {
  538. test_skip(true, HAVE_LIBMEMCACHED);
  539. test_skip(true, has_memcached_binary());
  540. return TEST_SUCCESS;
  541. }
  542. test_st memcached_tests[] ={
  543. {"memcached startup-shutdown", 0, memcached_cycle_test },
  544. {"memcached-light startup-shutdown", 0, memcached_light_cycle_TEST },
  545. {"memcached(socket file) startup-shutdown", 0, memcached_socket_cycle_test },
  546. {"memcached_sasl() startup-shutdown", 0, memcached_sasl_test },
  547. {"_compare(memcached_return_t)", 0, _compare_memcached_return_t_test },
  548. {0, 0, 0}
  549. };
  550. test_st test_skip_TESTS[] ={
  551. {"true, true", 0, test_skip_true_TEST },
  552. {"true, false", 0, test_skip_false_TEST },
  553. {0, 0, 0}
  554. };
  555. test_st environment_tests[] ={
  556. {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test },
  557. {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test },
  558. {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test },
  559. {"GDB_COMMAND", 0, GDB_COMMAND_test },
  560. {0, 0, 0}
  561. };
  562. test_st tests_log[] ={
  563. {"TEST_SUCCESS", false, test_success_test },
  564. {"TEST_FAILURE", false, test_failure_test },
  565. {"TEST_SUCCESS == 0", false, test_success_equals_one_test },
  566. {0, 0, 0}
  567. };
  568. test_st local_log[] ={
  569. {"test_is_local()", 0, local_test },
  570. {"test_is_local(NOT)", 0, local_not_test },
  571. {0, 0, 0}
  572. };
  573. test_st directories_tests[] ={
  574. {"var exists", 0, var_exists_test },
  575. {"var/tmp exists", 0, var_tmp_exists_test },
  576. {"var/run exists", 0, var_run_exists_test },
  577. {"var/log exists", 0, var_log_exists_test },
  578. {"var/tmp", 0, var_tmp_test },
  579. {"var/run", 0, var_run_test },
  580. {"var/log", 0, var_log_test },
  581. {"var/tmp rm", 0, var_tmp_rm_test },
  582. {"var/run rm", 0, var_run_rm_test },
  583. {"var/log rm", 0, var_log_rm_test },
  584. {0, 0, 0}
  585. };
  586. test_st comparison_tests[] ={
  587. {"_compare(test_return_t)", 0, _compare_test_return_t_test },
  588. {0, 0, 0}
  589. };
  590. test_st cmdline_tests[] ={
  591. {"true", 0, true_BINARY },
  592. {"true --fubar", 0, true_fubar_BINARY },
  593. {"echo fubar", 0, echo_fubar_BINARY },
  594. {"wait --quiet", 0, wait_BINARY },
  595. {"wait --quiet --help", 0, wait_help_BINARY },
  596. {"wait --quiet --version", 0, wait_version_BINARY },
  597. {"wait --quiet /etc/services", 0, wait_services_BINARY },
  598. {"wait /etc/services", 0, wait_services_BINARY2 },
  599. {"wait /etc/services", 0, wait_services_appliction_TEST },
  600. {"gdb wait /etc/services", 0, gdb_wait_services_appliction_TEST },
  601. {"gdb abort", 0, gdb_abort_services_appliction_TEST },
  602. {0, 0, 0}
  603. };
  604. test_st get_free_port_TESTS[] ={
  605. {"get_free_port()", 0, get_free_port_TEST },
  606. {"default_port()", 0, default_port_TEST },
  607. {0, 0, 0}
  608. };
  609. test_st fatal_message_TESTS[] ={
  610. {"libtest::fatal", 0, fatal_TEST },
  611. {"fatal_message()", 0, fatal_message_TEST },
  612. {0, 0, 0}
  613. };
  614. test_st number_of_cpus_TESTS[] ={
  615. {"libtest::number_of_cpus()", 0, number_of_cpus_TEST },
  616. {0, 0, 0}
  617. };
  618. test_st create_tmpfile_TESTS[] ={
  619. {"libtest::create_tmpfile()", 0, create_tmpfile_TEST },
  620. {0, 0, 0}
  621. };
  622. test_st application_tests[] ={
  623. {"vchar_t", 0, vchar_t_TEST },
  624. {"true", 0, application_true_BINARY },
  625. {"gbd true --fubar", 0, application_gdb_true_BINARY },
  626. {"gbd true", 0, application_gdb_true_BINARY2 },
  627. {"true --fubar", 0, application_true_fubar_BINARY },
  628. {"doesnotexist --fubar", 0, application_doesnotexist_BINARY },
  629. {"true --fubar=doh", 0, application_true_fubar_eq_doh_BINARY },
  630. {"true --fubar=doh add_option()", 0, application_true_fubar_eq_doh_option_BINARY },
  631. {"echo fubar", 0, application_echo_fubar_BINARY },
  632. {"echo fubar (as option)", 0, application_echo_fubar_BINARY2 },
  633. {0, 0, 0}
  634. };
  635. static test_return_t check_for_curl(void *)
  636. {
  637. test_skip(true, HAVE_LIBCURL);
  638. return TEST_SUCCESS;
  639. }
  640. static test_return_t disable_fatal_exception(void *)
  641. {
  642. fatal::disable();
  643. return TEST_SUCCESS;
  644. }
  645. static test_return_t enable_fatal_exception(void *)
  646. {
  647. fatal::disable();
  648. return TEST_SUCCESS;
  649. }
  650. test_st http_tests[] ={
  651. {"GET", 0, GET_TEST },
  652. {"POST", 0, POST_TEST },
  653. {"TRACE", 0, TRACE_TEST },
  654. {0, 0, 0}
  655. };
  656. collection_st collection[] ={
  657. {"environment", 0, 0, environment_tests},
  658. {"return values", 0, 0, tests_log},
  659. {"test_skip()", 0, 0, test_skip_TESTS },
  660. {"local", 0, 0, local_log},
  661. {"directories", 0, 0, directories_tests},
  662. {"comparison", 0, 0, comparison_tests},
  663. {"gearmand", check_for_gearman, 0, gearmand_tests},
  664. {"memcached", check_for_libmemcached, 0, memcached_tests},
  665. {"cmdline", 0, 0, cmdline_tests},
  666. {"application", 0, 0, application_tests},
  667. {"http", check_for_curl, 0, http_tests},
  668. {"get_free_port()", 0, 0, get_free_port_TESTS },
  669. {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS },
  670. {"number_of_cpus()", 0, 0, number_of_cpus_TESTS },
  671. {"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
  672. {0, 0, 0, 0}
  673. };
  674. static void *world_create(server_startup_st& servers, test_return_t&)
  675. {
  676. return &servers;
  677. }
  678. void get_world(Framework *world)
  679. {
  680. world->collections= collection;
  681. world->_create= world_create;
  682. }