Update framework.
[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_drizzle_exists_test(void *)
158 {
159 test_compare(0, access("var/drizzle", R_OK | W_OK | X_OK));
160 return TEST_SUCCESS;
161 }
162
163 static test_return_t var_tmp_test(void *)
164 {
165 FILE *file= fopen("var/tmp/junk", "w+");
166 char buffer[1024];
167 const char *dir= getcwd(buffer, sizeof(buffer));
168 test_true_got(file, dir);
169 fclose(file);
170 return TEST_SUCCESS;
171 }
172
173 static test_return_t var_run_test(void *)
174 {
175 FILE *file= fopen("var/run/junk", "w+");
176 test_true(file);
177 fclose(file);
178 return TEST_SUCCESS;
179 }
180
181 static test_return_t var_log_test(void *)
182 {
183 FILE *file= fopen("var/log/junk", "w+");
184 test_true(file);
185 fclose(file);
186 return TEST_SUCCESS;
187 }
188
189 static test_return_t var_drizzle_test(void *)
190 {
191 FILE *file= fopen("var/drizzle/junk", "w+");
192 test_true(file);
193 fclose(file);
194 return TEST_SUCCESS;
195 }
196
197 static test_return_t var_tmp_rm_test(void *)
198 {
199 test_true(unlink("var/tmp/junk") == 0);
200 return TEST_SUCCESS;
201 }
202
203 static test_return_t var_run_rm_test(void *)
204 {
205 test_true(unlink("var/run/junk") == 0);
206 return TEST_SUCCESS;
207 }
208
209 static test_return_t var_log_rm_test(void *)
210 {
211 test_true(unlink("var/log/junk") == 0);
212 return TEST_SUCCESS;
213 }
214
215 static test_return_t var_drizzle_rm_test(void *)
216 {
217 test_true(unlink("var/drizzle/junk") == 0);
218 return TEST_SUCCESS;
219 }
220
221 static test_return_t _compare_test_return_t_test(void *)
222 {
223 test_compare(TEST_SUCCESS, TEST_SUCCESS);
224
225 return TEST_SUCCESS;
226 }
227
228 static test_return_t _compare_memcached_return_t_test(void *)
229 {
230 test_skip(HAVE_LIBMEMCACHED, true);
231 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
232 test_compare(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
233 #endif
234
235 return TEST_SUCCESS;
236 }
237
238 static test_return_t _compare_gearman_return_t_test(void *)
239 {
240 test_skip(HAVE_LIBGEARMAN, true);
241 #if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
242 test_compare(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
243 #endif
244
245 return TEST_SUCCESS;
246 }
247
248 static test_return_t drizzled_cycle_test(void *object)
249 {
250 server_startup_st *servers= (server_startup_st*)object;
251 test_true(servers and servers->validate());
252
253 #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
254 test_true(has_drizzled_binary());
255 #endif
256
257 test_skip(true, has_drizzled_binary());
258
259 test_true(server_startup(*servers, "drizzled", get_free_port(), 0, NULL));
260
261 return TEST_SUCCESS;
262 }
263
264 static test_return_t gearmand_cycle_test(void *object)
265 {
266 server_startup_st *servers= (server_startup_st*)object;
267 test_true(servers and servers->validate());
268
269 #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
270 test_true(has_gearmand_binary());
271 #endif
272
273 test_skip(true, has_gearmand_binary());
274
275 test_true(server_startup(*servers, "gearmand", get_free_port(), 0, NULL));
276
277 return TEST_SUCCESS;
278 }
279
280 static test_return_t memcached_light_cycle_TEST(void *object)
281 {
282 server_startup_st *servers= (server_startup_st*)object;
283 test_true(servers);
284
285 test_skip(true, bool(HAVE_MEMCACHED_LIGHT_BINARY));
286
287 test_true(server_startup(*servers, "memcached-light", get_free_port(), 0, NULL));
288
289 return TEST_SUCCESS;
290 }
291
292 static test_return_t skip_shim(bool a, bool b)
293 {
294 test_skip(a, b);
295 return TEST_SUCCESS;
296 }
297
298 static test_return_t test_skip_true_TEST(void *object)
299 {
300 test_compare(true, true);
301 test_compare(false, false);
302 test_compare(TEST_SUCCESS, skip_shim(true, true));
303 test_compare(TEST_SUCCESS, skip_shim(false, false));
304
305 return TEST_SUCCESS;
306 }
307
308 static test_return_t test_skip_false_TEST(void *object)
309 {
310 test_compare(TEST_SKIPPED, skip_shim(true, false));
311 test_compare(TEST_SKIPPED, skip_shim(false, true));
312 return TEST_SUCCESS;
313 }
314
315 static test_return_t memcached_cycle_test(void *object)
316 {
317 server_startup_st *servers= (server_startup_st*)object;
318 test_true(servers);
319
320 if (MEMCACHED_BINARY and HAVE_LIBMEMCACHED)
321 {
322 test_true(has_memcached_binary());
323 test_true(server_startup(*servers, "memcached", get_free_port(), 0, NULL));
324
325 return TEST_SUCCESS;
326 }
327
328 return TEST_SKIPPED;
329 }
330
331 static test_return_t memcached_socket_cycle_test(void *object)
332 {
333 server_startup_st *servers= (server_startup_st*)object;
334 test_true(servers);
335
336 if (MEMCACHED_BINARY)
337 {
338 if (HAVE_LIBMEMCACHED)
339 {
340 test_true(has_memcached_binary());
341 test_true(servers->start_socket_server("memcached", get_free_port(), 0, NULL));
342
343 return TEST_SUCCESS;
344 }
345 }
346
347 return TEST_SKIPPED;
348 }
349
350 static test_return_t memcached_sasl_test(void *object)
351 {
352 server_startup_st *servers= (server_startup_st*)object;
353 test_true(servers);
354
355 test_skip(false, bool(getenv("TESTS_ENVIRONMENT")));
356
357 if (MEMCACHED_SASL_BINARY)
358 {
359 if (HAVE_LIBMEMCACHED)
360 {
361 test_true(has_memcached_sasl_binary());
362 test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL));
363
364 return TEST_SUCCESS;
365 }
366 }
367
368 return TEST_SKIPPED;
369 }
370
371 static test_return_t application_true_BINARY(void *)
372 {
373 Application true_app("true");
374
375 test_compare(Application::SUCCESS, true_app.run());
376 test_compare(Application::SUCCESS, true_app.wait());
377
378 return TEST_SUCCESS;
379 }
380
381 static test_return_t application_gdb_true_BINARY2(void *)
382 {
383 test_skip(0, access("/usr/bin/gdb", X_OK ));
384 Application true_app("true");
385 true_app.use_gdb();
386
387 test_compare(Application::SUCCESS, true_app.run());
388 test_compare(Application::SUCCESS, true_app.wait());
389
390 return TEST_SUCCESS;
391 }
392
393 static test_return_t application_gdb_true_BINARY(void *)
394 {
395 test_skip(0, access("/usr/bin/gdb", X_OK ));
396 Application true_app("true");
397 true_app.use_gdb();
398
399 const char *args[]= { "--fubar", 0 };
400 test_compare(Application::SUCCESS, true_app.run(args));
401 test_compare(Application::SUCCESS, true_app.wait());
402
403 return TEST_SUCCESS;
404 }
405
406 static test_return_t application_true_fubar_BINARY(void *)
407 {
408 Application true_app("true");
409
410 const char *args[]= { "--fubar", 0 };
411 test_compare(Application::SUCCESS, true_app.run(args));
412 test_compare(Application::SUCCESS, true_app.wait());
413 test_compare(0, true_app.stdout_result().size());
414
415 return TEST_SUCCESS;
416 }
417
418 static test_return_t application_doesnotexist_BINARY(void *)
419 {
420
421 test_skip_valgrind();
422 Application true_app("doesnotexist");
423 true_app.will_fail();
424
425 const char *args[]= { "--fubar", 0 };
426 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
427 test_compare(Application::INVALID, true_app.run(args));
428 #else
429 test_compare(Application::SUCCESS, true_app.run(args));
430 test_compare(Application::INVALID, true_app.wait(false));
431 #endif
432
433 test_compare(0, true_app.stdout_result().size());
434
435 return TEST_SUCCESS;
436 }
437
438 static test_return_t application_true_fubar_eq_doh_BINARY(void *)
439 {
440 Application true_app("true");
441
442 const char *args[]= { "--fubar=doh", 0 };
443 test_compare(Application::SUCCESS, true_app.run(args));
444 test_compare(Application::SUCCESS, true_app.wait());
445 test_compare(0, true_app.stdout_result().size());
446
447 return TEST_SUCCESS;
448 }
449
450 static test_return_t application_true_fubar_eq_doh_option_BINARY(void *)
451 {
452 Application true_app("true");
453
454 true_app.add_option("--fubar=", "doh");
455
456 test_compare(Application::SUCCESS, true_app.run());
457 test_compare(Application::SUCCESS, true_app.wait());
458 test_compare(0, true_app.stdout_result().size());
459
460 return TEST_SUCCESS;
461 }
462
463
464 static test_return_t GET_TEST(void *)
465 {
466 libtest::http::GET get("http://foo.example.com/");
467
468 test_compare(false, get.execute());
469
470 return TEST_SUCCESS;
471 }
472
473 static test_return_t POST_TEST(void *)
474 {
475 libtest::vchar_t body;
476 libtest::http::POST post("http://foo.example.com/", body);
477
478 test_compare(false, post.execute());
479
480 return TEST_SUCCESS;
481 }
482
483 static test_return_t TRACE_TEST(void *)
484 {
485 libtest::vchar_t body;
486 libtest::http::TRACE trace("http://foo.example.com/", body);
487
488 test_compare(false, trace.execute());
489
490 return TEST_SUCCESS;
491 }
492
493
494 static test_return_t vchar_t_TEST(void *)
495 {
496 libtest::vchar_t response;
497 libtest::make_vector(response, test_literal_param("fubar\n"));
498 test_compare(response, response);
499
500 return TEST_SUCCESS;
501 }
502
503 static test_return_t vchar_t_compare_neg_TEST(void *)
504 {
505 libtest::vchar_t response;
506 libtest::vchar_t response2;
507 libtest::make_vector(response, test_literal_param("fubar\n"));
508 libtest::make_vector(response2, test_literal_param(__func__));
509 test_true(response != response2);
510
511 return TEST_SUCCESS;
512 }
513
514 static test_return_t application_echo_fubar_BINARY(void *)
515 {
516 Application true_app("echo");
517
518 const char *args[]= { "fubar", 0 };
519 test_compare(Application::SUCCESS, true_app.run(args));
520 test_compare(Application::SUCCESS, true_app.wait());
521
522 while (true_app.slurp() == false) {} ;
523
524 libtest::vchar_t response;
525 make_vector(response, test_literal_param("fubar\n"));
526 test_compare(response, true_app.stdout_result());
527
528 return TEST_SUCCESS;
529 }
530
531 static test_return_t application_echo_fubar_BINARY2(void *)
532 {
533 Application true_app("echo");
534
535 true_app.add_option("fubar");
536
537 test_compare(Application::SUCCESS, true_app.run());
538 test_compare(Application::SUCCESS, true_app.wait(false));
539
540 libtest::vchar_t response;
541 make_vector(response, test_literal_param("fubar\n"));
542 test_compare(response, true_app.stdout_result());
543
544 return TEST_SUCCESS;
545 }
546
547 static test_return_t true_BINARY(void *)
548 {
549 const char *args[]= { 0 };
550 test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
551
552 return TEST_SUCCESS;
553 }
554
555 static test_return_t true_fubar_BINARY(void *)
556 {
557 const char *args[]= { "--fubar", 0 };
558 test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
559
560 return TEST_SUCCESS;
561 }
562
563 static test_return_t echo_fubar_BINARY(void *)
564 {
565 const char *args[]= { "fubar", 0 };
566 test_compare(EXIT_SUCCESS, exec_cmdline("echo", args));
567
568 return TEST_SUCCESS;
569 }
570
571 static test_return_t wait_BINARY(void *)
572 {
573 const char *args[]= { "--quiet", 0 };
574
575 test_compare(EXIT_FAILURE, exec_cmdline("libtest/wait", args, true));
576
577 return TEST_SUCCESS;
578 }
579
580 static test_return_t wait_help_BINARY(void *)
581 {
582 const char *args[]= { "--quiet", "--help", 0 };
583
584 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
585
586 return TEST_SUCCESS;
587 }
588
589 static test_return_t wait_version_BINARY(void *)
590 {
591 const char *args[]= { "--quiet", "--version", 0 };
592
593 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
594
595 return TEST_SUCCESS;
596 }
597
598 static test_return_t wait_services_BINARY(void *)
599 {
600 test_skip(0, access("/etc/services", R_OK ));
601
602 const char *args[]= { "--quiet", "/etc/services", 0 };
603
604 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
605
606 return TEST_SUCCESS;
607 }
608
609 static test_return_t wait_services_BINARY2(void *)
610 {
611 test_skip(0, access("/etc/services", R_OK ));
612
613 const char *args[]= { "/etc/services", 0 };
614
615 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
616
617 return TEST_SUCCESS;
618 }
619
620 static test_return_t wait_services_appliction_TEST(void *)
621 {
622 test_skip(0, access("/usr/bin/gdb", X_OK ));
623 test_skip(0, access("/etc/services", R_OK ));
624
625 libtest::Application wait_app("libtest/wait", true);
626 wait_app.use_gdb();
627
628 const char *args[]= { "/etc/services", 0 };
629 test_compare(Application::SUCCESS, wait_app.run(args));
630 test_compare(Application::SUCCESS, wait_app.wait());
631
632 return TEST_SUCCESS;
633 }
634
635 static test_return_t gdb_wait_services_appliction_TEST(void *)
636 {
637 test_skip(true, false);
638 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
639 test_skip(0, TARGET_OS_OSX);
640 #endif
641
642 test_skip(0, access("/usr/bin/gdb", X_OK ));
643 test_skip(0, access("/etc/services", R_OK ));
644
645 libtest::Application wait_app("libtest/wait", true);
646 wait_app.use_gdb();
647
648 const char *args[]= { "/etc/services", 0 };
649 test_compare(Application::SUCCESS, wait_app.run(args));
650 test_compare(Application::SUCCESS, wait_app.wait());
651
652 return TEST_SUCCESS;
653 }
654
655 static test_return_t gdb_abort_services_appliction_TEST(void *)
656 {
657 test_skip(true, false);
658 test_skip(0, access("/usr/bin/gdb", X_OK ));
659
660 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
661 test_skip(0, TARGET_OS_OSX);
662 #endif
663
664 libtest::Application abort_app("libtest/abort", true);
665 abort_app.use_gdb();
666
667 test_compare(Application::SUCCESS, abort_app.run());
668 test_compare(Application::SUCCESS, abort_app.wait());
669
670 std::string gdb_filename= abort_app.gdb_filename();
671 test_skip(0, access(gdb_filename.c_str(), R_OK ));
672 const char *args[]= { "SIGABRT", gdb_filename.c_str(), 0 };
673 test_compare(EXIT_SUCCESS, exec_cmdline("grep", args));
674
675 // Sanity test
676 args[0]= "THIS_WILL_NOT_BE_FOUND";
677 test_compare(EXIT_FAILURE, exec_cmdline("grep", args));
678
679 return TEST_SUCCESS;
680 }
681
682 static test_return_t get_free_port_TEST(void *)
683 {
684 in_port_t ret_port;
685 test_true_hint((ret_port= get_free_port()), ret_port);
686 test_true(get_free_port() != default_port());
687 test_true(get_free_port() != get_free_port());
688
689 return TEST_SUCCESS;
690 }
691
692 static uint32_t fatal_calls= 0;
693
694 static test_return_t fatal_TEST(void *)
695 {
696 test_compare(fatal_calls++, fatal::disabled_counter());
697 throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Testing va_args based fatal(): %d", 10);
698
699 return TEST_SUCCESS;
700 }
701
702 static test_return_t number_of_cpus_TEST(void *)
703 {
704 test_true(number_of_cpus() >= 1);
705
706 return TEST_SUCCESS;
707 }
708
709 static test_return_t create_tmpfile_TEST(void *)
710 {
711 std::string tmp= create_tmpfile(__func__);
712 test_compare(-1, access(tmp.c_str(), R_OK));
713 test_compare(-1, access(tmp.c_str(), F_OK));
714
715 Application touch_app("touch");
716 const char *args[]= { tmp.c_str(), 0 };
717 test_compare(Application::SUCCESS, touch_app.run(args));
718 test_compare(Application::SUCCESS, touch_app.wait(false));
719
720 test_compare_hint(0, access(tmp.c_str(), R_OK), strerror(errno));
721 test_compare_hint(0, unlink(tmp.c_str()), strerror(errno));
722
723 return TEST_SUCCESS;
724 }
725
726 static test_return_t fatal_message_TEST(void *)
727 {
728 test_compare(fatal_calls++, fatal::disabled_counter());
729 fatal_message("Fatal test");
730
731 return TEST_SUCCESS;
732 }
733
734 static test_return_t default_port_TEST(void *)
735 {
736 in_port_t ret_port= default_port();
737 test_compare(ret_port, libtest::default_port());
738 test_compare(ret_port, libtest::default_port());
739
740 return TEST_SUCCESS;
741 }
742
743 static test_return_t check_for_gearman(void *)
744 {
745 test_skip(true, HAVE_LIBGEARMAN);
746 test_skip(true, has_gearmand_binary());
747 return TEST_SUCCESS;
748 }
749
750 static test_return_t check_for_drizzle(void *)
751 {
752 test_skip(true, HAVE_LIBDRIZZLE);
753 test_skip(true, has_drizzled_binary());
754 return TEST_SUCCESS;
755 }
756
757
758 test_st drizzled_tests[] ={
759 {"drizzled startup-shutdown", 0, drizzled_cycle_test },
760 {0, 0, 0}
761 };
762
763 test_st gearmand_tests[] ={
764 #if 0
765 {"pause", 0, pause_test },
766 #endif
767 {"gearmand startup-shutdown", 0, gearmand_cycle_test },
768 {"_compare(gearman_return_t)", 0, _compare_gearman_return_t_test },
769 {0, 0, 0}
770 };
771
772 static test_return_t check_for_libmemcached(void *)
773 {
774 test_skip(true, HAVE_LIBMEMCACHED);
775 test_skip(true, has_memcached_binary());
776 return TEST_SUCCESS;
777 }
778
779 test_st memcached_tests[] ={
780 {"memcached startup-shutdown", 0, memcached_cycle_test },
781 {"memcached-light startup-shutdown", 0, memcached_light_cycle_TEST },
782 {"memcached(socket file) startup-shutdown", 0, memcached_socket_cycle_test },
783 {"memcached_sasl() startup-shutdown", 0, memcached_sasl_test },
784 {"_compare(memcached_return_t)", 0, _compare_memcached_return_t_test },
785 {0, 0, 0}
786 };
787
788 test_st test_skip_TESTS[] ={
789 {"true, true", 0, test_skip_true_TEST },
790 {"true, false", 0, test_skip_false_TEST },
791 {0, 0, 0}
792 };
793
794 test_st environment_tests[] ={
795 {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test },
796 {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test },
797 {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test },
798 {"GDB_COMMAND", 0, GDB_COMMAND_test },
799 {0, 0, 0}
800 };
801
802 test_st tests_log[] ={
803 {"TEST_SUCCESS", false, test_success_test },
804 {"TEST_FAILURE", false, test_failure_test },
805 {"TEST_SUCCESS == 0", false, test_success_equals_one_test },
806 {0, 0, 0}
807 };
808
809 test_st local_log[] ={
810 {"test_is_local()", 0, local_test },
811 {"test_is_local(NOT)", 0, local_not_test },
812 {0, 0, 0}
813 };
814
815 test_st directories_tests[] ={
816 {"var exists", 0, var_exists_test },
817 {"var/tmp exists", 0, var_tmp_exists_test },
818 {"var/run exists", 0, var_run_exists_test },
819 {"var/log exists", 0, var_log_exists_test },
820 {"var/drizzle exists", 0, var_drizzle_exists_test },
821 {"var/tmp", 0, var_tmp_test },
822 {"var/run", 0, var_run_test },
823 {"var/log", 0, var_log_test },
824 {"var/drizzle", 0, var_drizzle_test },
825 {"var/tmp rm", 0, var_tmp_rm_test },
826 {"var/run rm", 0, var_run_rm_test },
827 {"var/log rm", 0, var_log_rm_test },
828 {"var/drizzle rm", 0, var_drizzle_rm_test },
829 {0, 0, 0}
830 };
831
832 test_st comparison_tests[] ={
833 {"_compare(test_return_t)", 0, _compare_test_return_t_test },
834 {0, 0, 0}
835 };
836
837 test_st cmdline_tests[] ={
838 {"true", 0, true_BINARY },
839 {"true --fubar", 0, true_fubar_BINARY },
840 {"echo fubar", 0, echo_fubar_BINARY },
841 {"wait --quiet", 0, wait_BINARY },
842 {"wait --quiet --help", 0, wait_help_BINARY },
843 {"wait --quiet --version", 0, wait_version_BINARY },
844 {"wait --quiet /etc/services", 0, wait_services_BINARY },
845 {"wait /etc/services", 0, wait_services_BINARY2 },
846 {"wait /etc/services", 0, wait_services_appliction_TEST },
847 {"gdb wait /etc/services", 0, gdb_wait_services_appliction_TEST },
848 {"gdb abort", 0, gdb_abort_services_appliction_TEST },
849 {0, 0, 0}
850 };
851
852 test_st get_free_port_TESTS[] ={
853 {"get_free_port()", 0, get_free_port_TEST },
854 {"default_port()", 0, default_port_TEST },
855 {0, 0, 0}
856 };
857
858 test_st fatal_message_TESTS[] ={
859 {"libtest::fatal", 0, fatal_TEST },
860 {"fatal_message()", 0, fatal_message_TEST },
861 {0, 0, 0}
862 };
863
864 test_st number_of_cpus_TESTS[] ={
865 {"libtest::number_of_cpus()", 0, number_of_cpus_TEST },
866 {0, 0, 0}
867 };
868
869 test_st create_tmpfile_TESTS[] ={
870 {"libtest::create_tmpfile()", 0, create_tmpfile_TEST },
871 {0, 0, 0}
872 };
873
874 test_st application_tests[] ={
875 {"vchar_t", 0, vchar_t_TEST },
876 {"vchar_t compare()", 0, vchar_t_compare_neg_TEST },
877 {"true", 0, application_true_BINARY },
878 {"gbd true --fubar", 0, application_gdb_true_BINARY },
879 {"gbd true", 0, application_gdb_true_BINARY2 },
880 {"true --fubar", 0, application_true_fubar_BINARY },
881 {"doesnotexist --fubar", 0, application_doesnotexist_BINARY },
882 {"true --fubar=doh", 0, application_true_fubar_eq_doh_BINARY },
883 {"true --fubar=doh add_option()", 0, application_true_fubar_eq_doh_option_BINARY },
884 {"echo fubar", 0, application_echo_fubar_BINARY },
885 {"echo fubar (as option)", 0, application_echo_fubar_BINARY2 },
886 {0, 0, 0}
887 };
888
889 static test_return_t check_for_curl(void *)
890 {
891 test_skip(true, HAVE_LIBCURL);
892 return TEST_SUCCESS;
893 }
894
895 static test_return_t disable_fatal_exception(void *)
896 {
897 fatal::disable();
898 return TEST_SUCCESS;
899 }
900
901 static test_return_t enable_fatal_exception(void *)
902 {
903 fatal::disable();
904 return TEST_SUCCESS;
905 }
906
907 test_st http_tests[] ={
908 {"GET", 0, GET_TEST },
909 {"POST", 0, POST_TEST },
910 {"TRACE", 0, TRACE_TEST },
911 {0, 0, 0}
912 };
913
914 collection_st collection[] ={
915 {"environment", 0, 0, environment_tests},
916 {"return values", 0, 0, tests_log},
917 {"test_skip()", 0, 0, test_skip_TESTS },
918 {"local", 0, 0, local_log},
919 {"directories", 0, 0, directories_tests},
920 {"comparison", 0, 0, comparison_tests},
921 {"gearmand", check_for_gearman, 0, gearmand_tests},
922 {"memcached", check_for_libmemcached, 0, memcached_tests},
923 {"drizzled", check_for_drizzle, 0, drizzled_tests},
924 {"cmdline", 0, 0, cmdline_tests},
925 {"application", 0, 0, application_tests},
926 {"http", check_for_curl, 0, http_tests},
927 {"http", check_for_curl, 0, http_tests},
928 {"get_free_port()", 0, 0, get_free_port_TESTS },
929 {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS },
930 {"number_of_cpus()", 0, 0, number_of_cpus_TESTS },
931 {"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
932 {0, 0, 0, 0}
933 };
934
935 static void *world_create(server_startup_st& servers, test_return_t&)
936 {
937 return &servers;
938 }
939
940 void get_world(Framework *world)
941 {
942 world->collections= collection;
943 world->_create= world_create;
944 }