Update all config.h usage.
[m6w6/libmemcached] / libtest / unittest.cc
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Data Differential YATL (i.e. libtest) library
4 *
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37 #include "mem_config.h"
38
39 #include <libtest/test.hpp>
40
41 #if defined(LIBTEST_WITH_LIBMEMCACHED_SUPPORT) && LIBTEST_WITH_LIBMEMCACHED_SUPPORT
42 #include <libmemcached-1.0/memcached.h>
43 #endif
44
45 #if defined(LIBTEST_WITH_LIBGEARMAN_SUPPORT) && LIBTEST_WITH_LIBGEARMAN_SUPPORT
46 #include <libgearman/gearman.h>
47 #endif
48
49 #include <cstdlib>
50 #include <unistd.h>
51
52 using namespace libtest;
53
54 static std::string testing_service;
55
56 // Used to track setups where we see if failure is happening
57 static uint32_t fatal_calls= 0;
58
59 static test_return_t LIBTOOL_COMMAND_test(void *)
60 {
61 test_true(getenv("LIBTOOL_COMMAND"));
62 return TEST_SUCCESS;
63 }
64
65 static test_return_t VALGRIND_COMMAND_test(void *)
66 {
67 test_true(getenv("VALGRIND_COMMAND"));
68 return TEST_SUCCESS;
69 }
70
71 static test_return_t HELGRIND_COMMAND_test(void *)
72 {
73 test_true(getenv("HELGRIND_COMMAND"));
74 return TEST_SUCCESS;
75 }
76
77 static test_return_t GDB_COMMAND_test(void *)
78 {
79 test_true(getenv("GDB_COMMAND"));
80 return TEST_SUCCESS;
81 }
82
83 static test_return_t test_success_equals_one_test(void *)
84 {
85 test_skip(HAVE_LIBMEMCACHED, 1);
86 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
87 test_zero(MEMCACHED_SUCCESS);
88 #endif
89 return TEST_SUCCESS;
90 }
91
92 static test_return_t test_success_test(void *)
93 {
94 return TEST_SUCCESS;
95 }
96
97 static test_return_t test_failure_test(void *)
98 {
99 return TEST_SKIPPED; // Only run this when debugging
100
101 test_compare(1, 2);
102 return TEST_SUCCESS;
103 }
104
105 static test_return_t local_test(void *)
106 {
107 if (getenv("LIBTEST_LOCAL"))
108 {
109 test_true(test_is_local());
110 }
111 else
112 {
113 test_false(test_is_local());
114 }
115
116 return TEST_SUCCESS;
117 }
118
119 static test_return_t local_not_test(void *)
120 {
121 return TEST_SKIPPED;
122
123 std::string temp;
124
125 const char *ptr;
126 if ((ptr= getenv("LIBTEST_LOCAL")) == NULL)
127 {
128 temp.append(ptr);
129 }
130
131 // unsetenv() will cause issues with valgrind
132 _compare(__FILE__, __LINE__, __func__, 0, unsetenv("LIBTEST_LOCAL"), true);
133 test_compare(0, unsetenv("LIBTEST_LOCAL"));
134 test_false(test_is_local());
135
136 test_compare(0, setenv("LIBTEST_LOCAL", "1", 1));
137 test_true(test_is_local());
138
139 if (temp.empty())
140 {
141 test_compare(0, unsetenv("LIBTEST_LOCAL"));
142 }
143 else
144 {
145 char *old_string= strdup(temp.c_str());
146 test_compare(0, setenv("LIBTEST_LOCAL", old_string, 1));
147 }
148
149 return TEST_SUCCESS;
150 }
151
152 static test_return_t var_exists_test(void *)
153 {
154 test_compare(0, access("var", R_OK | W_OK | X_OK));
155 return TEST_SUCCESS;
156 }
157
158 static test_return_t var_tmp_exists_test(void *)
159 {
160 test_compare(0, access("var/tmp", R_OK | W_OK | X_OK));
161 return TEST_SUCCESS;
162 }
163
164 static test_return_t var_run_exists_test(void *)
165 {
166 test_compare(0, access("var/run", R_OK | W_OK | X_OK));
167 return TEST_SUCCESS;
168 }
169
170 static test_return_t var_log_exists_test(void *)
171 {
172 test_compare(0, access("var/log", R_OK | W_OK | X_OK));
173 return TEST_SUCCESS;
174 }
175
176 static test_return_t var_drizzle_exists_test(void *)
177 {
178 test_compare(0, access("var/drizzle", R_OK | W_OK | X_OK));
179 return TEST_SUCCESS;
180 }
181
182 static test_return_t var_tmp_test(void *)
183 {
184 FILE *file= fopen("var/tmp/junk", "w+");
185 test_true(file);
186 fclose(file);
187 return TEST_SUCCESS;
188 }
189
190 static test_return_t var_run_test(void *)
191 {
192 FILE *file= fopen("var/run/junk", "w+");
193 test_true(file);
194 fclose(file);
195 return TEST_SUCCESS;
196 }
197
198 static test_return_t var_log_test(void *)
199 {
200 FILE *file= fopen("var/log/junk", "w+");
201 test_true(file);
202 fclose(file);
203 return TEST_SUCCESS;
204 }
205
206 static test_return_t var_drizzle_test(void *)
207 {
208 FILE *file= fopen("var/drizzle/junk", "w+");
209 test_true(file);
210 fclose(file);
211 return TEST_SUCCESS;
212 }
213
214 static test_return_t var_tmp_rm_test(void *)
215 {
216 test_true(unlink("var/tmp/junk") == 0);
217 return TEST_SUCCESS;
218 }
219
220 static test_return_t var_run_rm_test(void *)
221 {
222 test_true(unlink("var/run/junk") == 0);
223 return TEST_SUCCESS;
224 }
225
226 static test_return_t var_log_rm_test(void *)
227 {
228 test_true(unlink("var/log/junk") == 0);
229 return TEST_SUCCESS;
230 }
231
232 static test_return_t var_drizzle_rm_test(void *)
233 {
234 test_true(unlink("var/drizzle/junk") == 0);
235 return TEST_SUCCESS;
236 }
237
238 static test_return_t _compare_test_return_t_test(void *)
239 {
240 test_compare(TEST_SUCCESS, TEST_SUCCESS);
241
242 return TEST_SUCCESS;
243 }
244
245 static test_return_t _compare_memcached_return_t_test(void *)
246 {
247 test_skip(HAVE_LIBMEMCACHED, true);
248 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
249 test_compare(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
250 #endif
251
252 return TEST_SUCCESS;
253 }
254
255 static test_return_t _compare_gearman_return_t_test(void *)
256 {
257 test_skip(HAVE_LIBGEARMAN, true);
258 #if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
259 test_compare(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
260 #endif
261
262 return TEST_SUCCESS;
263 }
264
265 static test_return_t drizzled_cycle_test(void *object)
266 {
267 server_startup_st *servers= (server_startup_st*)object;
268 test_true(servers and servers->validate());
269
270 #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
271 test_true(has_drizzled());
272 #endif
273
274 test_skip(true, has_drizzled());
275
276 test_skip(true, server_startup(*servers, "drizzled", get_free_port(), 0, NULL, false));
277
278 return TEST_SUCCESS;
279 }
280
281 static test_return_t gearmand_cycle_test(void *object)
282 {
283 server_startup_st *servers= (server_startup_st*)object;
284 test_true(servers and servers->validate());
285
286 test_skip(true, has_gearmand());
287 test_skip(true, server_startup(*servers, "gearmand", get_free_port(), 0, NULL, false));
288 servers->clear();
289
290 return TEST_SUCCESS;
291 }
292
293 #if 0
294 static test_return_t memcached_light_cycle_TEST(void *object)
295 {
296 server_startup_st *servers= (server_startup_st*)object;
297 test_true(servers);
298
299 test_skip(true, bool(HAVE_MEMCACHED_LIGHT_BINARY));
300
301 test_true(server_startup(*servers, "memcached-light", get_free_port(), 0, NULL, false));
302
303 return TEST_SUCCESS;
304 }
305 #endif
306
307 static test_return_t skip_shim(bool a, bool b)
308 {
309 test_skip(a, b);
310 return TEST_SUCCESS;
311 }
312
313 static test_return_t test_skip_true_TEST(void*)
314 {
315 test_compare(true, true);
316 test_compare(false, false);
317 test_compare(TEST_SUCCESS, skip_shim(true, true));
318 test_compare(TEST_SUCCESS, skip_shim(false, false));
319
320 return TEST_SUCCESS;
321 }
322
323 static test_return_t test_skip_false_TEST(void*)
324 {
325 test_compare(TEST_SKIPPED, skip_shim(true, false));
326 test_compare(TEST_SKIPPED, skip_shim(false, true));
327 return TEST_SUCCESS;
328 }
329
330 static test_return_t server_startup_fail_TEST(void *object)
331 {
332 server_startup_st *servers= (server_startup_st*)object;
333 test_true(servers);
334
335 fatal::disable();
336 test_compare(servers->start_server(testing_service, LIBTEST_FAIL_PORT, 0, NULL, false), true);
337 fatal::enable();
338
339 return TEST_SUCCESS;
340 }
341
342 static test_return_t server_startup_TEST(void *object)
343 {
344 server_startup_st *servers= (server_startup_st*)object;
345 test_true(servers);
346
347 test_compare(servers->start_server(testing_service, get_free_port(), 0, NULL, false), true);
348
349 test_true(servers->last());
350 pid_t last_pid= servers->last()->pid();
351
352 test_compare(servers->last()->pid(), last_pid);
353 test_true(last_pid > 1);
354 test_compare(kill(last_pid, 0), 0);
355
356 test_true(servers->shutdown());
357 #if 0
358 test_compare(servers->last()->pid(), -1);
359 test_compare(kill(last_pid, 0), -1);
360 #endif
361
362 return TEST_SUCCESS;
363 }
364
365 static test_return_t socket_server_startup_TEST(void *object)
366 {
367 server_startup_st *servers= (server_startup_st*)object;
368 test_true(servers);
369
370 test_true(servers->start_socket_server(testing_service, get_free_port(), 0, NULL, false));
371
372 return TEST_SUCCESS;
373 }
374
375 #if 0
376 static test_return_t memcached_sasl_test(void *object)
377 {
378 server_startup_st *servers= (server_startup_st*)object;
379 test_true(servers);
380
381 test_skip(false, bool(getenv("TESTS_ENVIRONMENT")));
382
383 if (MEMCACHED_SASL_BINARY)
384 {
385 if (HAVE_LIBMEMCACHED)
386 {
387 test_true(has_memcached_sasl());
388 test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL, false));
389
390 return TEST_SUCCESS;
391 }
392 }
393
394 return TEST_SKIPPED;
395 }
396 #endif
397
398 static test_return_t application_true_BINARY(void *)
399 {
400 test_skip(0, access("/usr/bin/true", X_OK ));
401 Application true_app("/usr/bin/true");
402
403 test_compare(Application::SUCCESS, true_app.run());
404 test_compare(Application::SUCCESS, true_app.join());
405
406 return TEST_SUCCESS;
407 }
408
409 static test_return_t application_gdb_true_BINARY2(void *)
410 {
411 test_skip(0, access("/usr/bin/gdb", X_OK ));
412 Application true_app("/usr/bin/true");
413 true_app.use_gdb();
414
415 test_compare(Application::SUCCESS, true_app.run());
416 test_compare(Application::SUCCESS, true_app.join());
417
418 return TEST_SUCCESS;
419 }
420
421 static test_return_t application_gdb_true_BINARY(void *)
422 {
423 test_skip(0, access("/usr/bin/gdb", X_OK ));
424 Application true_app("/usr/bin/true");
425 true_app.use_gdb();
426
427 const char *args[]= { "--fubar", 0 };
428 test_compare(Application::SUCCESS, true_app.run(args));
429 test_compare(Application::SUCCESS, true_app.join());
430
431 return TEST_SUCCESS;
432 }
433
434 static test_return_t application_true_fubar_BINARY(void *)
435 {
436 test_skip(0, access("/usr/bin/true", X_OK ));
437 Application true_app("/usr/bin/true");
438
439 const char *args[]= { "--fubar", 0 };
440 test_compare(Application::SUCCESS, true_app.run(args));
441 test_compare(Application::SUCCESS, true_app.join());
442 test_zero(true_app.stdout_result().size());
443
444 return TEST_SUCCESS;
445 }
446
447 static test_return_t application_doesnotexist_BINARY(void *)
448 {
449
450 test_skip_valgrind();
451 Application true_app("doesnotexist");
452 true_app.will_fail();
453
454 const char *args[]= { "--fubar", 0 };
455 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
456 test_compare(Application::INVALID_POSIX_SPAWN, true_app.run(args));
457 #else
458 test_compare(Application::SUCCESS, true_app.run(args));
459 test_compare(Application::INVALID_POSIX_SPAWN, true_app.join());
460 #endif
461
462 test_zero(true_app.stdout_result().size());
463
464 return TEST_SUCCESS;
465 }
466
467 static test_return_t GET_TEST(void *)
468 {
469 libtest::http::GET get("http://foo.example.com/");
470
471 test_compare(false, get.execute());
472
473 return TEST_SUCCESS;
474 }
475
476 static test_return_t POST_TEST(void *)
477 {
478 libtest::vchar_t body;
479 libtest::http::POST post("http://foo.example.com/", body);
480
481 test_compare(false, post.execute());
482
483 return TEST_SUCCESS;
484 }
485
486 static test_return_t TRACE_TEST(void *)
487 {
488 libtest::vchar_t body;
489 libtest::http::TRACE trace("http://foo.example.com/", body);
490
491 test_compare(false, trace.execute());
492
493 return TEST_SUCCESS;
494 }
495
496
497 static test_return_t vchar_t_TEST(void *)
498 {
499 libtest::vchar_t response;
500 libtest::make_vector(response, test_literal_param("fubar\n"));
501 test_compare(response, response);
502
503 return TEST_SUCCESS;
504 }
505
506 static test_return_t vchar_t_compare_neg_TEST(void *)
507 {
508 libtest::vchar_t response;
509 libtest::vchar_t response2;
510 libtest::make_vector(response, test_literal_param("fubar\n"));
511 libtest::make_vector(response2, test_literal_param(__func__));
512 test_true(response != response2);
513
514 return TEST_SUCCESS;
515 }
516
517 static test_return_t application_echo_fubar_BINARY(void *)
518 {
519 if (0)
520 {
521 test_skip(0, access("/bin/echo", X_OK ));
522 Application true_app("/bin/echo");
523
524 const char *args[]= { "fubar", 0 };
525 test_compare(Application::SUCCESS, true_app.run(args));
526
527 while (true_app.slurp() == false) {} ;
528
529 libtest::vchar_t response;
530 make_vector(response, test_literal_param("fubar\n"));
531 test_compare(response, true_app.stdout_result());
532 }
533
534 return TEST_SUCCESS;
535 }
536
537 static test_return_t application_echo_fubar_BINARY2(void *)
538 {
539 if (0)
540 {
541 test_skip(0, access("/bin/echo", X_OK ));
542 Application true_app("/bin/echo");
543
544 true_app.add_option("fubar");
545
546 test_compare(Application::SUCCESS, true_app.run());
547 test_compare(Application::SUCCESS, true_app.join());
548
549 libtest::vchar_t response;
550 make_vector(response, test_literal_param("fubar\n"));
551 test_compare(response, true_app.stdout_result());
552 }
553
554 return TEST_SUCCESS;
555 }
556
557 static test_return_t echo_fubar_BINARY(void *)
558 {
559 const char *args[]= { "fubar", 0 };
560 test_compare(EXIT_SUCCESS, exec_cmdline("/bin/echo", args));
561
562 return TEST_SUCCESS;
563 }
564
565 static test_return_t core_count_BINARY(void *)
566 {
567 const char *args[]= { 0 };
568
569 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/core-count", args, true));
570
571 return TEST_SUCCESS;
572 }
573
574 static test_return_t wait_BINARY(void *)
575 {
576 const char *args[]= { "--quiet", 0 };
577
578 test_compare(EXIT_FAILURE, exec_cmdline("libtest/wait", args, true));
579
580 return TEST_SUCCESS;
581 }
582
583 static test_return_t wait_help_BINARY(void *)
584 {
585 const char *args[]= { "--quiet", "--help", 0 };
586
587 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
588
589 return TEST_SUCCESS;
590 }
591
592 static test_return_t wait_version_BINARY(void *)
593 {
594 const char *args[]= { "--quiet", "--version", 0 };
595
596 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
597
598 return TEST_SUCCESS;
599 }
600
601 static test_return_t wait_services_BINARY(void *)
602 {
603 test_skip(0, access("/etc/services", R_OK ));
604
605 const char *args[]= { "--quiet", "/etc/services", 0 };
606
607 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
608
609 return TEST_SUCCESS;
610 }
611
612 static test_return_t wait_services_BINARY2(void *)
613 {
614 test_skip(0, access("/etc/services", R_OK ));
615
616 const char *args[]= { "/etc/services", 0 };
617
618 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
619
620 return TEST_SUCCESS;
621 }
622
623 static test_return_t wait_services_appliction_TEST(void *)
624 {
625 test_skip(0, access("/usr/bin/gdb", X_OK ));
626 test_skip(0, access("/etc/services", R_OK ));
627
628 libtest::Application wait_app("libtest/wait", true);
629 wait_app.use_gdb();
630
631 const char *args[]= { "/etc/services", 0 };
632 test_compare(Application::SUCCESS, wait_app.run(args));
633 test_compare(Application::SUCCESS, wait_app.join());
634
635 return TEST_SUCCESS;
636 }
637
638 static test_return_t gdb_wait_services_appliction_TEST(void *)
639 {
640 test_skip(true, false);
641 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
642 test_skip(0, TARGET_OS_OSX);
643 #endif
644
645 test_skip(0, access("/usr/bin/gdb", X_OK ));
646 test_skip(0, access("/etc/services", R_OK ));
647
648 libtest::Application wait_app("libtest/wait", true);
649 wait_app.use_gdb();
650
651 const char *args[]= { "/etc/services", 0 };
652 test_compare(Application::SUCCESS, wait_app.run(args));
653 test_compare(Application::SUCCESS, wait_app.join());
654
655 return TEST_SUCCESS;
656 }
657
658 static test_return_t gdb_abort_services_appliction_TEST(void *)
659 {
660 test_skip(true, false);
661 test_skip(0, access("/usr/bin/gdb", X_OK ));
662
663 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
664 test_skip(0, TARGET_OS_OSX);
665 #endif
666
667 libtest::Application abort_app("libtest/abort", true);
668 abort_app.use_gdb();
669
670 test_compare(Application::SUCCESS, abort_app.run());
671 test_compare(Application::SUCCESS, abort_app.join());
672
673 std::string gdb_filename= abort_app.gdb_filename();
674 test_skip(0, access(gdb_filename.c_str(), R_OK ));
675 const char *args[]= { "SIGABRT", gdb_filename.c_str(), 0 };
676 test_compare(EXIT_SUCCESS, exec_cmdline("grep", args));
677
678 // Sanity test
679 args[0]= "THIS_WILL_NOT_BE_FOUND";
680 test_compare(EXIT_FAILURE, exec_cmdline("grep", args));
681
682 return TEST_SUCCESS;
683 }
684
685 static test_return_t get_free_port_TEST(void *)
686 {
687 in_port_t ret_port;
688 test_true((ret_port= get_free_port()));
689 test_true(get_free_port() != default_port());
690 test_true(get_free_port() != get_free_port());
691
692 return TEST_SUCCESS;
693 }
694
695 static test_return_t fatal_TEST(void *)
696 {
697 test_compare(fatal_calls++, fatal::disabled_counter());
698 throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Testing va_args based fatal(): %d", 10);
699
700 return TEST_SUCCESS;
701 }
702
703 static test_return_t number_of_cpus_TEST(void *)
704 {
705 test_true(number_of_cpus() >= 1);
706
707 return TEST_SUCCESS;
708 }
709
710 static test_return_t check_dns_TEST(void *)
711 {
712 test_warn(libtest::check_dns(), "Broken DNS server/no DNS server found");
713
714 return TEST_SUCCESS;
715 }
716
717 static test_return_t Timer_TEST(void *)
718 {
719 int64_t minutes= random() % 50;
720 minutes++;
721
722 Timer check;
723
724 check.reset();
725 check.offset(minutes, 2, 200);
726
727 test_compare(check.minutes(), minutes);
728
729 return TEST_SUCCESS;
730 }
731
732 static test_return_t lookup_true_TEST(void *)
733 {
734 test_warn(libtest::lookup("exist.gearman.info"), "dns is not currently working");
735 return TEST_SUCCESS;
736 }
737
738 static test_return_t lookup_false_TEST(void *)
739 {
740 if (libtest::lookup("does_not_exist.gearman.info"))
741 {
742 Error << "Broken DNS server detected";
743 return TEST_SKIPPED;
744 }
745
746 return TEST_SUCCESS;
747 }
748
749 static test_return_t create_tmpfile_TEST(void *)
750 {
751 std::string tmp= create_tmpfile(__func__);
752 test_compare(-1, access(tmp.c_str(), R_OK));
753 test_compare(-1, access(tmp.c_str(), F_OK));
754
755 Application touch_app("/usr/bin/touch");
756 const char *args[]= { tmp.c_str(), 0 };
757 test_compare(Application::SUCCESS, touch_app.run(args));
758 test_compare(Application::SUCCESS, touch_app.join());
759
760 test_compare(0, access(tmp.c_str(), R_OK));
761 test_compare(0, unlink(tmp.c_str()));
762
763 return TEST_SUCCESS;
764 }
765
766 static test_return_t fatal_message_TEST(void *)
767 {
768 test_compare(fatal_calls++, fatal::disabled_counter());
769 fatal_message("Fatal test");
770
771 return TEST_SUCCESS;
772 }
773
774 static test_return_t default_port_TEST(void *)
775 {
776 in_port_t ret_port= default_port();
777 test_compare(ret_port, libtest::default_port());
778 test_compare(ret_port, libtest::default_port());
779
780 return TEST_SUCCESS;
781 }
782
783 static test_return_t check_for_gearman(void *)
784 {
785 test_skip(true, HAVE_LIBGEARMAN);
786 test_skip(true, has_gearmand());
787
788 testing_service= "gearmand";
789
790 return TEST_SUCCESS;
791 }
792
793 static test_return_t check_for_drizzle(void *)
794 {
795 test_skip(true, HAVE_LIBDRIZZLE);
796 test_skip(true, has_drizzled());
797
798 testing_service= "drizzled";
799
800 return TEST_SUCCESS;
801 }
802
803
804 test_st drizzled_tests[] ={
805 {"drizzled startup-shutdown", 0, drizzled_cycle_test },
806 {0, 0, 0}
807 };
808
809 test_st gearmand_tests[] ={
810 #if 0
811 {"pause", 0, pause_test },
812 #endif
813 {"gearmand startup-shutdown", 0, gearmand_cycle_test },
814 {"_compare(gearman_return_t)", 0, _compare_gearman_return_t_test },
815 {"server_startup(fail)", 0, server_startup_fail_TEST },
816 {0, 0, 0}
817 };
818
819 static test_return_t clear_servers(void* object)
820 {
821 server_startup_st *servers= (server_startup_st*)object;
822 test_true(servers);
823 servers->clear();
824
825 testing_service.clear();
826
827 return TEST_SUCCESS;
828 }
829
830 static test_return_t check_for_libmemcached(void* object)
831 {
832 test_skip(true, HAVE_LIBMEMCACHED);
833 test_skip(true, has_memcached());
834
835 server_startup_st *servers= (server_startup_st*)object;
836 test_true(servers);
837 servers->clear();
838
839 testing_service= "memcached";
840
841 return TEST_SUCCESS;
842 }
843
844 test_st memcached_TESTS[] ={
845 {"memcached startup-shutdown", 0, server_startup_TEST },
846 {"memcached(socket file) startup-shutdown", 0, socket_server_startup_TEST },
847 {"_compare(memcached_return_t)", 0, _compare_memcached_return_t_test },
848 {"server_startup(fail)", 0, server_startup_fail_TEST },
849 {0, 0, 0}
850 };
851
852 test_st test_skip_TESTS[] ={
853 {"true, true", 0, test_skip_true_TEST },
854 {"true, false", 0, test_skip_false_TEST },
855 {0, 0, 0}
856 };
857
858 test_st environment_tests[] ={
859 {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test },
860 {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test },
861 {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test },
862 {"GDB_COMMAND", 0, GDB_COMMAND_test },
863 {0, 0, 0}
864 };
865
866 test_st tests_log[] ={
867 {"TEST_SUCCESS", false, test_success_test },
868 {"TEST_FAILURE", false, test_failure_test },
869 {"TEST_SUCCESS == 0", false, test_success_equals_one_test },
870 {0, 0, 0}
871 };
872
873 test_st local_log[] ={
874 {"test_is_local()", 0, local_test },
875 {"test_is_local(NOT)", 0, local_not_test },
876 {0, 0, 0}
877 };
878
879 test_st directories_tests[] ={
880 {"var exists", 0, var_exists_test },
881 {"var/tmp exists", 0, var_tmp_exists_test },
882 {"var/run exists", 0, var_run_exists_test },
883 {"var/log exists", 0, var_log_exists_test },
884 {"var/drizzle exists", 0, var_drizzle_exists_test },
885 {"var/tmp", 0, var_tmp_test },
886 {"var/run", 0, var_run_test },
887 {"var/log", 0, var_log_test },
888 {"var/drizzle", 0, var_drizzle_test },
889 {"var/tmp rm", 0, var_tmp_rm_test },
890 {"var/run rm", 0, var_run_rm_test },
891 {"var/log rm", 0, var_log_rm_test },
892 {"var/drizzle rm", 0, var_drizzle_rm_test },
893 {0, 0, 0}
894 };
895
896 test_st comparison_tests[] ={
897 {"_compare(test_return_t)", 0, _compare_test_return_t_test },
898 {0, 0, 0}
899 };
900
901 test_st cmdline_tests[] ={
902 {"echo fubar", 0, echo_fubar_BINARY },
903 {"core-count", 0, core_count_BINARY },
904 {"wait --quiet", 0, wait_BINARY },
905 {"wait --quiet --help", 0, wait_help_BINARY },
906 {"wait --quiet --version", 0, wait_version_BINARY },
907 {"wait --quiet /etc/services", 0, wait_services_BINARY },
908 {"wait /etc/services", 0, wait_services_BINARY2 },
909 {"wait /etc/services", 0, wait_services_appliction_TEST },
910 {"gdb wait /etc/services", 0, gdb_wait_services_appliction_TEST },
911 {"gdb abort", 0, gdb_abort_services_appliction_TEST },
912 {0, 0, 0}
913 };
914
915 test_st get_free_port_TESTS[] ={
916 {"get_free_port()", 0, get_free_port_TEST },
917 {"default_port()", 0, default_port_TEST },
918 {0, 0, 0}
919 };
920
921 test_st fatal_message_TESTS[] ={
922 {"libtest::fatal", 0, fatal_TEST },
923 {"fatal_message()", 0, fatal_message_TEST },
924 {0, 0, 0}
925 };
926
927 test_st number_of_cpus_TESTS[] ={
928 {"libtest::number_of_cpus()", 0, number_of_cpus_TEST },
929 {0, 0, 0}
930 };
931
932 test_st create_tmpfile_TESTS[] ={
933 {"libtest::create_tmpfile()", 0, create_tmpfile_TEST },
934 {0, 0, 0}
935 };
936
937 test_st timer_TESTS[] ={
938 {"libtest::Timer", 0, Timer_TEST },
939 {0, 0, 0}
940 };
941
942 test_st dns_TESTS[] ={
943 {"libtest::lookup(true)", 0, lookup_true_TEST },
944 {"libtest::lookup(false)", 0, lookup_false_TEST },
945 {"libtest::check_dns()", 0, check_dns_TEST },
946 {0, 0, 0}
947 };
948
949 test_st application_tests[] ={
950 {"vchar_t", 0, vchar_t_TEST },
951 {"vchar_t compare()", 0, vchar_t_compare_neg_TEST },
952 {"true", 0, application_true_BINARY },
953 {"gbd true --fubar", 0, application_gdb_true_BINARY },
954 {"gbd true", 0, application_gdb_true_BINARY2 },
955 {"true --fubar", 0, application_true_fubar_BINARY },
956 {"doesnotexist --fubar", 0, application_doesnotexist_BINARY },
957 {"echo fubar", 0, application_echo_fubar_BINARY },
958 {"echo fubar (as option)", 0, application_echo_fubar_BINARY2 },
959 {0, 0, 0}
960 };
961
962 static test_return_t check_for_curl(void *)
963 {
964 test_skip(true, HAVE_LIBCURL);
965 return TEST_SUCCESS;
966 }
967
968 static test_return_t disable_fatal_exception(void *)
969 {
970 fatal_calls= 0;
971 fatal::disable();
972 return TEST_SUCCESS;
973 }
974
975 static test_return_t enable_fatal_exception(void *)
976 {
977 fatal::enable();
978 return TEST_SUCCESS;
979 }
980
981 test_st http_tests[] ={
982 {"GET", 0, GET_TEST },
983 {"POST", 0, POST_TEST },
984 {"TRACE", 0, TRACE_TEST },
985 {0, 0, 0}
986 };
987
988 collection_st collection[] ={
989 {"environment", 0, 0, environment_tests},
990 {"return values", 0, 0, tests_log},
991 {"test_skip()", 0, 0, test_skip_TESTS },
992 {"local", 0, 0, local_log},
993 {"directories", 0, 0, directories_tests},
994 {"comparison", 0, 0, comparison_tests},
995 {"gearmand", check_for_gearman, clear_servers, gearmand_tests},
996 {"memcached", check_for_libmemcached, clear_servers, memcached_TESTS },
997 {"drizzled", check_for_drizzle, clear_servers, drizzled_tests},
998 {"cmdline", 0, 0, cmdline_tests},
999 {"application", 0, 0, application_tests},
1000 {"http", check_for_curl, 0, http_tests},
1001 {"http", check_for_curl, 0, http_tests},
1002 {"get_free_port()", 0, 0, get_free_port_TESTS },
1003 {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS },
1004 {"number_of_cpus()", 0, 0, number_of_cpus_TESTS },
1005 {"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
1006 {"dns", 0, 0, dns_TESTS },
1007 {"libtest::Timer", 0, 0, timer_TESTS },
1008 {0, 0, 0, 0}
1009 };
1010
1011 static void *world_create(server_startup_st& servers, test_return_t&)
1012 {
1013 return &servers;
1014 }
1015
1016 void get_world(libtest::Framework *world)
1017 {
1018 world->collections(collection);
1019 world->create(world_create);
1020 }