0f82a560a701f31e177cedb1850c2e5d9d5a5489
[m6w6/libmemcached] / libtest / unittest.cc
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
22
23 #include <config.h>
24
25 #include <libtest/test.hpp>
26
27 #if defined(LIBTEST_WITH_LIBMEMCACHED_SUPPORT) && LIBTEST_WITH_LIBMEMCACHED_SUPPORT
28 #include <libmemcached-1.0/memcached.h>
29 #endif
30
31 #if defined(LIBTEST_WITH_LIBGEARMAN_SUPPORT) && LIBTEST_WITH_LIBGEARMAN_SUPPORT
32 #include <libgearman/gearman.h>
33 #endif
34
35 #include <cstdlib>
36 #include <unistd.h>
37
38 using namespace libtest;
39
40 static test_return_t LIBTOOL_COMMAND_test(void *)
41 {
42 test_true(getenv("LIBTOOL_COMMAND"));
43 return TEST_SUCCESS;
44 }
45
46 static test_return_t VALGRIND_COMMAND_test(void *)
47 {
48 test_true(getenv("VALGRIND_COMMAND"));
49 return TEST_SUCCESS;
50 }
51
52 static test_return_t HELGRIND_COMMAND_test(void *)
53 {
54 test_true(getenv("HELGRIND_COMMAND"));
55 return TEST_SUCCESS;
56 }
57
58 static test_return_t GDB_COMMAND_test(void *)
59 {
60 test_true(getenv("GDB_COMMAND"));
61 return TEST_SUCCESS;
62 }
63
64 static test_return_t test_success_equals_one_test(void *)
65 {
66 test_skip(HAVE_LIBMEMCACHED, 1);
67 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
68 test_zero(MEMCACHED_SUCCESS);
69 #endif
70 return TEST_SUCCESS;
71 }
72
73 static test_return_t test_success_test(void *)
74 {
75 return TEST_SUCCESS;
76 }
77
78 static test_return_t test_failure_test(void *)
79 {
80 return TEST_SKIPPED; // Only run this when debugging
81
82 test_compare(1, 2);
83 return TEST_SUCCESS;
84 }
85
86 static test_return_t local_test(void *)
87 {
88 if (getenv("LIBTEST_LOCAL"))
89 {
90 test_true(test_is_local());
91 }
92 else
93 {
94 test_false(test_is_local());
95 }
96
97 return TEST_SUCCESS;
98 }
99
100 static test_return_t local_not_test(void *)
101 {
102 return TEST_SKIPPED;
103
104 std::string temp;
105
106 const char *ptr;
107 if ((ptr= getenv("LIBTEST_LOCAL")) == NULL)
108 {
109 temp.append(ptr);
110 }
111
112 // unsetenv() will cause issues with valgrind
113 _compare(__FILE__, __LINE__, __func__, 0, unsetenv("LIBTEST_LOCAL"), true);
114 test_compare(0, unsetenv("LIBTEST_LOCAL"));
115 test_false(test_is_local());
116
117 test_compare(0, setenv("LIBTEST_LOCAL", "1", 1));
118 test_true(test_is_local());
119
120 if (temp.empty())
121 {
122 test_compare(0, unsetenv("LIBTEST_LOCAL"));
123 }
124 else
125 {
126 char *old_string= strdup(temp.c_str());
127 test_compare(0, setenv("LIBTEST_LOCAL", old_string, 1));
128 }
129
130 return TEST_SUCCESS;
131 }
132
133 static test_return_t var_exists_test(void *)
134 {
135 test_compare(0, access("var", R_OK | W_OK | X_OK));
136 return TEST_SUCCESS;
137 }
138
139 static test_return_t var_tmp_exists_test(void *)
140 {
141 test_compare(0, access("var/tmp", R_OK | W_OK | X_OK));
142 return TEST_SUCCESS;
143 }
144
145 static test_return_t var_run_exists_test(void *)
146 {
147 test_compare(0, access("var/run", R_OK | W_OK | X_OK));
148 return TEST_SUCCESS;
149 }
150
151 static test_return_t var_log_exists_test(void *)
152 {
153 test_compare(0, access("var/log", R_OK | W_OK | X_OK));
154 return TEST_SUCCESS;
155 }
156
157 static test_return_t var_tmp_test(void *)
158 {
159 FILE *file= fopen("var/tmp/junk", "w+");
160 char buffer[1024];
161 const char *dir= getcwd(buffer, sizeof(buffer));
162 test_true_got(file, dir);
163 fclose(file);
164 return TEST_SUCCESS;
165 }
166
167 static test_return_t var_run_test(void *)
168 {
169 FILE *file= fopen("var/run/junk", "w+");
170 test_true(file);
171 fclose(file);
172 return TEST_SUCCESS;
173 }
174
175 static test_return_t var_log_test(void *)
176 {
177 FILE *file= fopen("var/log/junk", "w+");
178 test_true(file);
179 fclose(file);
180 return TEST_SUCCESS;
181 }
182
183 static test_return_t var_tmp_rm_test(void *)
184 {
185 test_true(unlink("var/tmp/junk") == 0);
186 return TEST_SUCCESS;
187 }
188
189 static test_return_t var_run_rm_test(void *)
190 {
191 test_true(unlink("var/run/junk") == 0);
192 return TEST_SUCCESS;
193 }
194
195 static test_return_t var_log_rm_test(void *)
196 {
197 test_true(unlink("var/log/junk") == 0);
198 return TEST_SUCCESS;
199 }
200
201 static test_return_t _compare_test_return_t_test(void *)
202 {
203 test_compare(TEST_SUCCESS, TEST_SUCCESS);
204
205 return TEST_SUCCESS;
206 }
207
208 static test_return_t _compare_memcached_return_t_test(void *)
209 {
210 test_skip(HAVE_LIBMEMCACHED, true);
211 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
212 test_compare(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
213 #endif
214
215 return TEST_SUCCESS;
216 }
217
218 static test_return_t _compare_gearman_return_t_test(void *)
219 {
220 test_skip(HAVE_LIBGEARMAN, true);
221 #if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
222 test_compare(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
223 #endif
224
225 return TEST_SUCCESS;
226 }
227
228 static test_return_t gearmand_cycle_test(void *object)
229 {
230 server_startup_st *servers= (server_startup_st*)object;
231 test_true(servers and servers->validate());
232
233 #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
234 test_true(has_gearmand_binary());
235 #endif
236
237 test_skip(true, has_gearmand_binary());
238
239 Error << " " << has_gearmand_binary();
240
241 test_true(server_startup(*servers, "gearmand", get_free_port(), 0, NULL));
242
243 return TEST_SUCCESS;
244 }
245
246 static test_return_t memcached_light_cycle_TEST(void *object)
247 {
248 server_startup_st *servers= (server_startup_st*)object;
249 test_true(servers);
250
251 test_skip(true, bool(HAVE_MEMCACHED_LIGHT_BINARY));
252
253 test_true(server_startup(*servers, "memcached-light", get_free_port(), 0, NULL));
254
255 return TEST_SUCCESS;
256 }
257
258 static test_return_t skip_shim(bool a, bool b)
259 {
260 test_skip(a, b);
261 return TEST_SUCCESS;
262 }
263
264 static test_return_t test_skip_true_TEST(void *object)
265 {
266 test_compare(true, true);
267 test_compare(false, false);
268 test_compare(TEST_SUCCESS, skip_shim(true, true));
269 test_compare(TEST_SUCCESS, skip_shim(false, false));
270
271 return TEST_SUCCESS;
272 }
273
274 static test_return_t test_skip_false_TEST(void *object)
275 {
276 test_compare(TEST_SKIPPED, skip_shim(true, false));
277 test_compare(TEST_SKIPPED, skip_shim(false, true));
278 return TEST_SUCCESS;
279 }
280
281 static test_return_t memcached_cycle_test(void *object)
282 {
283 server_startup_st *servers= (server_startup_st*)object;
284 test_true(servers);
285
286 if (MEMCACHED_BINARY and HAVE_LIBMEMCACHED)
287 {
288 test_true(has_memcached_binary());
289 test_true(server_startup(*servers, "memcached", get_free_port(), 0, NULL));
290
291 return TEST_SUCCESS;
292 }
293
294 return TEST_SKIPPED;
295 }
296
297 static test_return_t memcached_socket_cycle_test(void *object)
298 {
299 server_startup_st *servers= (server_startup_st*)object;
300 test_true(servers);
301
302 if (MEMCACHED_BINARY)
303 {
304 if (HAVE_LIBMEMCACHED)
305 {
306 test_true(has_memcached_binary());
307 test_true(servers->start_socket_server("memcached", get_free_port(), 0, NULL));
308
309 return TEST_SUCCESS;
310 }
311 }
312
313 return TEST_SKIPPED;
314 }
315
316 static test_return_t memcached_sasl_test(void *object)
317 {
318 server_startup_st *servers= (server_startup_st*)object;
319 test_true(servers);
320
321 test_skip(false, bool(getenv("TESTS_ENVIRONMENT")));
322
323 if (MEMCACHED_SASL_BINARY)
324 {
325 if (HAVE_LIBMEMCACHED)
326 {
327 test_true(has_memcached_sasl_binary());
328 test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL));
329
330 return TEST_SUCCESS;
331 }
332 }
333
334 return TEST_SKIPPED;
335 }
336
337 static test_return_t application_true_BINARY(void *)
338 {
339 Application true_app("true");
340
341 test_compare(Application::SUCCESS, true_app.run());
342 test_compare(Application::SUCCESS, true_app.wait());
343
344 return TEST_SUCCESS;
345 }
346
347 static test_return_t application_gdb_true_BINARY2(void *)
348 {
349 test_skip(0, access("/usr/bin/gdb", X_OK ));
350 Application true_app("true");
351 true_app.use_gdb();
352
353 test_compare(Application::SUCCESS, true_app.run());
354 test_compare(Application::SUCCESS, true_app.wait());
355
356 return TEST_SUCCESS;
357 }
358
359 static test_return_t application_gdb_true_BINARY(void *)
360 {
361 test_skip(0, access("/usr/bin/gdb", X_OK ));
362 Application true_app("true");
363 true_app.use_gdb();
364
365 const char *args[]= { "--fubar", 0 };
366 test_compare(Application::SUCCESS, true_app.run(args));
367 test_compare(Application::SUCCESS, true_app.wait());
368
369 return TEST_SUCCESS;
370 }
371
372 static test_return_t application_true_fubar_BINARY(void *)
373 {
374 Application true_app("true");
375
376 const char *args[]= { "--fubar", 0 };
377 test_compare(Application::SUCCESS, true_app.run(args));
378 test_compare(Application::SUCCESS, true_app.wait());
379 test_compare(0, true_app.stdout_result().size());
380
381 return TEST_SUCCESS;
382 }
383
384 static test_return_t application_doesnotexist_BINARY(void *)
385 {
386 test_skip_valgrind();
387
388 Application true_app("doesnotexist");
389
390 const char *args[]= { "--fubar", 0 };
391 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
392 test_compare(Application::INVALID, true_app.run(args));
393 test_compare(Application::FAILURE, true_app.wait());
394 #else
395 test_compare(Application::SUCCESS, true_app.run(args));
396 test_compare(Application::INVALID, true_app.wait());
397 #endif
398
399 test_compare(0, true_app.stdout_result().size());
400
401 return TEST_SUCCESS;
402 }
403
404 static test_return_t application_true_fubar_eq_doh_BINARY(void *)
405 {
406 Application true_app("true");
407
408 const char *args[]= { "--fubar=doh", 0 };
409 test_compare(Application::SUCCESS, true_app.run(args));
410 test_compare(Application::SUCCESS, true_app.wait());
411 test_compare(0, true_app.stdout_result().size());
412
413 return TEST_SUCCESS;
414 }
415
416 static test_return_t application_true_fubar_eq_doh_option_BINARY(void *)
417 {
418 Application true_app("true");
419
420 true_app.add_option("--fubar=", "doh");
421
422 test_compare(Application::SUCCESS, true_app.run());
423 test_compare(Application::SUCCESS, true_app.wait());
424 test_compare(0, true_app.stdout_result().size());
425
426 return TEST_SUCCESS;
427 }
428
429
430 static test_return_t GET_TEST(void *)
431 {
432 libtest::http::GET get("http://foo.example.com/");
433
434 test_compare(false, get.execute());
435
436 return TEST_SUCCESS;
437 }
438
439 static test_return_t POST_TEST(void *)
440 {
441 libtest::vchar_t body;
442 libtest::http::POST post("http://foo.example.com/", body);
443
444 test_compare(false, post.execute());
445
446 return TEST_SUCCESS;
447 }
448
449 static test_return_t TRACE_TEST(void *)
450 {
451 libtest::vchar_t body;
452 libtest::http::TRACE trace("http://foo.example.com/", body);
453
454 test_compare(false, trace.execute());
455
456 return TEST_SUCCESS;
457 }
458
459
460 static test_return_t vchar_t_TEST(void *)
461 {
462 libtest::vchar_t response;
463 libtest::make_vector(response, test_literal_param("fubar\n"));
464 test_compare(response, response);
465
466 return TEST_SUCCESS;
467 }
468
469 static test_return_t application_echo_fubar_BINARY(void *)
470 {
471 Application true_app("echo");
472
473 const char *args[]= { "fubar", 0 };
474 test_compare(Application::SUCCESS, true_app.run(args));
475 test_compare(Application::SUCCESS, true_app.wait());
476
477 libtest::vchar_t response;
478 make_vector(response, test_literal_param("fubar\n"));
479 test_compare(response, true_app.stdout_result());
480
481 return TEST_SUCCESS;
482 }
483
484 static test_return_t application_echo_fubar_BINARY2(void *)
485 {
486 Application true_app("echo");
487
488 true_app.add_option("fubar");
489
490 test_compare(Application::SUCCESS, true_app.run());
491 test_compare(Application::SUCCESS, true_app.wait());
492 libtest::vchar_t response;
493 make_vector(response, test_literal_param("fubar\n"));
494 test_compare(response, true_app.stdout_result());
495
496 return TEST_SUCCESS;
497 }
498
499 static test_return_t true_BINARY(void *)
500 {
501 const char *args[]= { 0 };
502 test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
503
504 return TEST_SUCCESS;
505 }
506
507 static test_return_t true_fubar_BINARY(void *)
508 {
509 const char *args[]= { "--fubar", 0 };
510 test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
511
512 return TEST_SUCCESS;
513 }
514
515 static test_return_t echo_fubar_BINARY(void *)
516 {
517 const char *args[]= { "fubar", 0 };
518 test_compare(EXIT_SUCCESS, exec_cmdline("echo", args));
519
520 return TEST_SUCCESS;
521 }
522
523 static test_return_t wait_BINARY(void *)
524 {
525 const char *args[]= { "--quiet", 0 };
526
527 test_compare(EXIT_FAILURE, exec_cmdline("libtest/wait", args, true));
528
529 return TEST_SUCCESS;
530 }
531
532 static test_return_t wait_help_BINARY(void *)
533 {
534 const char *args[]= { "--quiet", "--help", 0 };
535
536 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
537
538 return TEST_SUCCESS;
539 }
540
541 static test_return_t wait_version_BINARY(void *)
542 {
543 const char *args[]= { "--quiet", "--version", 0 };
544
545 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
546
547 return TEST_SUCCESS;
548 }
549
550 static test_return_t wait_services_BINARY(void *)
551 {
552 test_skip(0, access("/etc/services", R_OK ));
553
554 const char *args[]= { "--quiet", "/etc/services", 0 };
555
556 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
557
558 return TEST_SUCCESS;
559 }
560
561 static test_return_t wait_services_BINARY2(void *)
562 {
563 test_skip(0, access("/etc/services", R_OK ));
564
565 const char *args[]= { "/etc/services", 0 };
566
567 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
568
569 return TEST_SUCCESS;
570 }
571
572 static test_return_t wait_services_appliction_TEST(void *)
573 {
574 test_skip(0, access("/usr/bin/gdb", X_OK ));
575 test_skip(0, access("/etc/services", R_OK ));
576
577 libtest::Application wait_app("libtest/wait", true);
578 wait_app.use_gdb();
579
580 const char *args[]= { "/etc/services", 0 };
581 test_compare(Application::SUCCESS, wait_app.run(args));
582 test_compare(Application::SUCCESS, wait_app.wait());
583
584 return TEST_SUCCESS;
585 }
586
587 static test_return_t gdb_wait_services_appliction_TEST(void *)
588 {
589 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
590 test_skip(0, TARGET_OS_OSX);
591 #endif
592
593 test_skip(0, access("/usr/bin/gdb", X_OK ));
594 test_skip(0, access("/etc/services", R_OK ));
595
596 libtest::Application wait_app("libtest/wait", true);
597 wait_app.use_gdb();
598
599 const char *args[]= { "/etc/services", 0 };
600 test_compare(Application::SUCCESS, wait_app.run(args));
601 test_compare(Application::SUCCESS, wait_app.wait());
602
603 return TEST_SUCCESS;
604 }
605
606 static test_return_t gdb_abort_services_appliction_TEST(void *)
607 {
608 test_skip(0, access("/usr/bin/gdb", X_OK ));
609
610 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
611 test_skip(0, TARGET_OS_OSX);
612 #endif
613
614 libtest::Application abort_app("libtest/abort", true);
615 abort_app.use_gdb();
616
617 test_compare(Application::SUCCESS, abort_app.run());
618 test_compare(Application::SUCCESS, abort_app.wait());
619
620 std::string gdb_filename= abort_app.gdb_filename();
621 const char *args[]= { "SIGABRT", gdb_filename.c_str(), 0 };
622 test_compare(EXIT_SUCCESS, exec_cmdline("grep", args));
623
624 // Sanity test
625 args[0]= "THIS_WILL_NOT_BE_FOUND";
626 test_compare(EXIT_FAILURE, exec_cmdline("grep", args));
627
628 return TEST_SUCCESS;
629 }
630
631 static test_return_t get_free_port_TEST(void *)
632 {
633 in_port_t ret_port;
634 test_true_hint((ret_port= get_free_port()), ret_port);
635 test_true(get_free_port() != default_port());
636 test_true(get_free_port() != get_free_port());
637
638 return TEST_SUCCESS;
639 }
640
641 static uint32_t fatal_calls= 0;
642
643 static test_return_t fatal_TEST(void *)
644 {
645 test_compare(fatal_calls++, fatal::disabled_counter());
646 throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Testing va_args based fatal(): %d", 10);
647
648 return TEST_SUCCESS;
649 }
650
651 static test_return_t number_of_cpus_TEST(void *)
652 {
653 test_true(number_of_cpus() >= 1);
654
655 return TEST_SUCCESS;
656 }
657
658 static test_return_t create_tmpfile_TEST(void *)
659 {
660 std::string tmp= create_tmpfile(__func__);
661
662 Application touch_app("touch");
663 const char *args[]= { tmp.c_str(), 0 };
664 test_compare(Application::SUCCESS, touch_app.run(args));
665 test_compare(Application::SUCCESS, touch_app.wait());
666
667 test_compare_hint(0, access(tmp.c_str(), R_OK), strerror(errno));
668 test_compare_hint(0, unlink(tmp.c_str()), strerror(errno));
669
670 return TEST_SUCCESS;
671 }
672
673 static test_return_t fatal_message_TEST(void *)
674 {
675 test_compare(fatal_calls++, fatal::disabled_counter());
676 throw fatal_message("Fatal test");
677
678 return TEST_SUCCESS;
679 }
680
681 static test_return_t default_port_TEST(void *)
682 {
683 in_port_t ret_port= default_port();
684 test_compare(ret_port, libtest::default_port());
685 test_compare(ret_port, libtest::default_port());
686
687 return TEST_SUCCESS;
688 }
689
690 static test_return_t check_for_gearman(void *)
691 {
692 test_skip(true, HAVE_LIBGEARMAN);
693 test_skip(true, has_gearmand_binary());
694 return TEST_SUCCESS;
695 }
696
697
698 test_st gearmand_tests[] ={
699 #if 0
700 {"pause", 0, pause_test },
701 #endif
702 {"gearmand startup-shutdown", 0, gearmand_cycle_test },
703 {"_compare(gearman_return_t)", 0, _compare_gearman_return_t_test },
704 {0, 0, 0}
705 };
706
707 static test_return_t check_for_libmemcached(void *)
708 {
709 test_skip(true, HAVE_LIBMEMCACHED);
710 test_skip(true, has_memcached_binary());
711 return TEST_SUCCESS;
712 }
713
714 test_st memcached_tests[] ={
715 {"memcached startup-shutdown", 0, memcached_cycle_test },
716 {"memcached-light startup-shutdown", 0, memcached_light_cycle_TEST },
717 {"memcached(socket file) startup-shutdown", 0, memcached_socket_cycle_test },
718 {"memcached_sasl() startup-shutdown", 0, memcached_sasl_test },
719 {"_compare(memcached_return_t)", 0, _compare_memcached_return_t_test },
720 {0, 0, 0}
721 };
722
723 test_st test_skip_TESTS[] ={
724 {"true, true", 0, test_skip_true_TEST },
725 {"true, false", 0, test_skip_false_TEST },
726 {0, 0, 0}
727 };
728
729 test_st environment_tests[] ={
730 {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test },
731 {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test },
732 {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test },
733 {"GDB_COMMAND", 0, GDB_COMMAND_test },
734 {0, 0, 0}
735 };
736
737 test_st tests_log[] ={
738 {"TEST_SUCCESS", false, test_success_test },
739 {"TEST_FAILURE", false, test_failure_test },
740 {"TEST_SUCCESS == 0", false, test_success_equals_one_test },
741 {0, 0, 0}
742 };
743
744 test_st local_log[] ={
745 {"test_is_local()", 0, local_test },
746 {"test_is_local(NOT)", 0, local_not_test },
747 {0, 0, 0}
748 };
749
750 test_st directories_tests[] ={
751 {"var exists", 0, var_exists_test },
752 {"var/tmp exists", 0, var_tmp_exists_test },
753 {"var/run exists", 0, var_run_exists_test },
754 {"var/log exists", 0, var_log_exists_test },
755 {"var/tmp", 0, var_tmp_test },
756 {"var/run", 0, var_run_test },
757 {"var/log", 0, var_log_test },
758 {"var/tmp rm", 0, var_tmp_rm_test },
759 {"var/run rm", 0, var_run_rm_test },
760 {"var/log rm", 0, var_log_rm_test },
761 {0, 0, 0}
762 };
763
764 test_st comparison_tests[] ={
765 {"_compare(test_return_t)", 0, _compare_test_return_t_test },
766 {0, 0, 0}
767 };
768
769 test_st cmdline_tests[] ={
770 {"true", 0, true_BINARY },
771 {"true --fubar", 0, true_fubar_BINARY },
772 {"echo fubar", 0, echo_fubar_BINARY },
773 {"wait --quiet", 0, wait_BINARY },
774 {"wait --quiet --help", 0, wait_help_BINARY },
775 {"wait --quiet --version", 0, wait_version_BINARY },
776 {"wait --quiet /etc/services", 0, wait_services_BINARY },
777 {"wait /etc/services", 0, wait_services_BINARY2 },
778 {"wait /etc/services", 0, wait_services_appliction_TEST },
779 {"gdb wait /etc/services", 0, gdb_wait_services_appliction_TEST },
780 {"gdb abort", 0, gdb_abort_services_appliction_TEST },
781 {0, 0, 0}
782 };
783
784 test_st get_free_port_TESTS[] ={
785 {"get_free_port()", 0, get_free_port_TEST },
786 {"default_port()", 0, default_port_TEST },
787 {0, 0, 0}
788 };
789
790 test_st fatal_message_TESTS[] ={
791 {"libtest::fatal", 0, fatal_TEST },
792 {"fatal_message()", 0, fatal_message_TEST },
793 {0, 0, 0}
794 };
795
796 test_st number_of_cpus_TESTS[] ={
797 {"libtest::number_of_cpus()", 0, number_of_cpus_TEST },
798 {0, 0, 0}
799 };
800
801 test_st create_tmpfile_TESTS[] ={
802 {"libtest::create_tmpfile()", 0, create_tmpfile_TEST },
803 {0, 0, 0}
804 };
805
806 test_st application_tests[] ={
807 {"vchar_t", 0, vchar_t_TEST },
808 {"true", 0, application_true_BINARY },
809 {"gbd true --fubar", 0, application_gdb_true_BINARY },
810 {"gbd true", 0, application_gdb_true_BINARY2 },
811 {"true --fubar", 0, application_true_fubar_BINARY },
812 {"doesnotexist --fubar", 0, application_doesnotexist_BINARY },
813 {"true --fubar=doh", 0, application_true_fubar_eq_doh_BINARY },
814 {"true --fubar=doh add_option()", 0, application_true_fubar_eq_doh_option_BINARY },
815 {"echo fubar", 0, application_echo_fubar_BINARY },
816 {"echo fubar (as option)", 0, application_echo_fubar_BINARY2 },
817 {0, 0, 0}
818 };
819
820 static test_return_t check_for_curl(void *)
821 {
822 test_skip(true, HAVE_LIBCURL);
823 return TEST_SUCCESS;
824 }
825
826 static test_return_t disable_fatal_exception(void *)
827 {
828 fatal::disable();
829 return TEST_SUCCESS;
830 }
831
832 static test_return_t enable_fatal_exception(void *)
833 {
834 fatal::disable();
835 return TEST_SUCCESS;
836 }
837
838 test_st http_tests[] ={
839 {"GET", 0, GET_TEST },
840 {"POST", 0, POST_TEST },
841 {"TRACE", 0, TRACE_TEST },
842 {0, 0, 0}
843 };
844
845 collection_st collection[] ={
846 {"environment", 0, 0, environment_tests},
847 {"return values", 0, 0, tests_log},
848 {"test_skip()", 0, 0, test_skip_TESTS },
849 {"local", 0, 0, local_log},
850 {"directories", 0, 0, directories_tests},
851 {"comparison", 0, 0, comparison_tests},
852 {"gearmand", check_for_gearman, 0, gearmand_tests},
853 {"memcached", check_for_libmemcached, 0, memcached_tests},
854 {"cmdline", 0, 0, cmdline_tests},
855 {"application", 0, 0, application_tests},
856 {"http", check_for_curl, 0, http_tests},
857 {"get_free_port()", 0, 0, get_free_port_TESTS },
858 {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS },
859 {"number_of_cpus()", 0, 0, number_of_cpus_TESTS },
860 {"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
861 {0, 0, 0, 0}
862 };
863
864 static void *world_create(server_startup_st& servers, test_return_t&)
865 {
866 return &servers;
867 }
868
869 void get_world(Framework *world)
870 {
871 world->collections= collection;
872 world->_create= world_create;
873 }