0d50447783ce0c1278d6c07e1b072336ea7e4223
[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(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
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 static test_return_t skip_shim(bool a, bool b)
294 {
295 test_skip(a, b);
296 return TEST_SUCCESS;
297 }
298
299 static test_return_t test_skip_true_TEST(void*)
300 {
301 test_compare(true, true);
302 test_compare(false, false);
303 test_compare(TEST_SUCCESS, skip_shim(true, true));
304 test_compare(TEST_SUCCESS, skip_shim(false, false));
305
306 return TEST_SUCCESS;
307 }
308
309 static test_return_t test_skip_false_TEST(void*)
310 {
311 test_compare(TEST_SKIPPED, skip_shim(true, false));
312 test_compare(TEST_SKIPPED, skip_shim(false, true));
313 return TEST_SUCCESS;
314 }
315
316 static test_return_t server_startup_fail_TEST(void *object)
317 {
318 server_startup_st *servers= (server_startup_st*)object;
319 test_true(servers);
320
321 fatal::disable();
322 test_compare(servers->start_server(testing_service, LIBTEST_FAIL_PORT, 0, NULL, false), true);
323 fatal::enable();
324
325 return TEST_SUCCESS;
326 }
327
328 static test_return_t server_startup_TEST(void *object)
329 {
330 server_startup_st *servers= (server_startup_st*)object;
331 test_true(servers);
332
333 test_compare(servers->start_server(testing_service, get_free_port(), 0, NULL, false), true);
334
335 test_true(servers->last());
336 pid_t last_pid= servers->last()->pid();
337
338 test_compare(servers->last()->pid(), last_pid);
339 test_true(last_pid > 1);
340 test_compare(kill(last_pid, 0), 0);
341
342 test_true(servers->shutdown());
343 #if 0
344 test_compare(servers->last()->pid(), -1);
345 test_compare(kill(last_pid, 0), -1);
346 #endif
347
348 return TEST_SUCCESS;
349 }
350
351 static test_return_t socket_server_startup_TEST(void *object)
352 {
353 server_startup_st *servers= (server_startup_st*)object;
354 test_true(servers);
355
356 test_true(servers->start_socket_server(testing_service, get_free_port(), 0, NULL, false));
357
358 return TEST_SUCCESS;
359 }
360
361 #if 0
362 static test_return_t memcached_sasl_test(void *object)
363 {
364 server_startup_st *servers= (server_startup_st*)object;
365 test_true(servers);
366
367 test_skip(false, bool(getenv("TESTS_ENVIRONMENT")));
368
369 if (MEMCACHED_SASL_BINARY)
370 {
371 if (HAVE_LIBMEMCACHED)
372 {
373 test_true(has_memcached_sasl());
374 test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL, false));
375
376 return TEST_SUCCESS;
377 }
378 }
379
380 return TEST_SKIPPED;
381 }
382 #endif
383
384 static test_return_t application_true_BINARY(void *)
385 {
386 test_skip(0, access("/usr/bin/true", X_OK ));
387 Application true_app("/usr/bin/true");
388
389 test_compare(Application::SUCCESS, true_app.run());
390 test_compare(Application::SUCCESS, true_app.join());
391
392 return TEST_SUCCESS;
393 }
394
395 static test_return_t application_gdb_true_BINARY2(void *)
396 {
397 test_skip(0, access("/usr/bin/gdb", X_OK ));
398 Application true_app("/usr/bin/true");
399 true_app.use_gdb();
400
401 test_compare(Application::SUCCESS, true_app.run());
402 test_compare(Application::SUCCESS, true_app.join());
403
404 return TEST_SUCCESS;
405 }
406
407 static test_return_t application_gdb_true_BINARY(void *)
408 {
409 test_skip(0, access("/usr/bin/gdb", X_OK ));
410 Application true_app("/usr/bin/true");
411 true_app.use_gdb();
412
413 const char *args[]= { "--fubar", 0 };
414 test_compare(Application::SUCCESS, true_app.run(args));
415 test_compare(Application::SUCCESS, true_app.join());
416
417 return TEST_SUCCESS;
418 }
419
420 static test_return_t application_true_fubar_BINARY(void *)
421 {
422 test_skip(0, access("/usr/bin/true", X_OK ));
423 Application true_app("/usr/bin/true");
424
425 const char *args[]= { "--fubar", 0 };
426 test_compare(Application::SUCCESS, true_app.run(args));
427 test_compare(Application::SUCCESS, true_app.join());
428 test_zero(true_app.stdout_result().size());
429
430 return TEST_SUCCESS;
431 }
432
433 static test_return_t application_doesnotexist_BINARY(void *)
434 {
435
436 test_skip_valgrind();
437 Application true_app("doesnotexist");
438 true_app.will_fail();
439
440 const char *args[]= { "--fubar", 0 };
441 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
442 test_compare(Application::INVALID_POSIX_SPAWN, true_app.run(args));
443 #else
444 test_compare(Application::SUCCESS, true_app.run(args));
445 test_compare(Application::INVALID_POSIX_SPAWN, true_app.join());
446 #endif
447
448 test_zero(true_app.stdout_result().size());
449
450 return TEST_SUCCESS;
451 }
452
453 static test_return_t GET_TEST(void *)
454 {
455 libtest::http::GET get("http://foo.example.com/");
456
457 test_compare(false, get.execute());
458
459 return TEST_SUCCESS;
460 }
461
462 static test_return_t POST_TEST(void *)
463 {
464 libtest::vchar_t body;
465 libtest::http::POST post("http://foo.example.com/", body);
466
467 test_compare(false, post.execute());
468
469 return TEST_SUCCESS;
470 }
471
472 static test_return_t TRACE_TEST(void *)
473 {
474 libtest::vchar_t body;
475 libtest::http::TRACE trace("http://foo.example.com/", body);
476
477 test_compare(false, trace.execute());
478
479 return TEST_SUCCESS;
480 }
481
482
483 static test_return_t vchar_t_TEST(void *)
484 {
485 libtest::vchar_t response;
486 libtest::make_vector(response, test_literal_param("fubar\n"));
487 test_compare(response, response);
488
489 return TEST_SUCCESS;
490 }
491
492 static test_return_t vchar_t_compare_neg_TEST(void *)
493 {
494 libtest::vchar_t response;
495 libtest::vchar_t response2;
496 libtest::make_vector(response, test_literal_param("fubar\n"));
497 libtest::make_vector(response2, test_literal_param(__func__));
498 test_true(response != response2);
499
500 return TEST_SUCCESS;
501 }
502
503 static test_return_t application_echo_fubar_BINARY(void *)
504 {
505 if (0)
506 {
507 test_skip(0, access("/bin/echo", X_OK ));
508 Application true_app("/bin/echo");
509
510 const char *args[]= { "fubar", 0 };
511 test_compare(Application::SUCCESS, true_app.run(args));
512
513 while (true_app.slurp() == false) {} ;
514
515 libtest::vchar_t response;
516 make_vector(response, test_literal_param("fubar\n"));
517 test_compare(response, true_app.stdout_result());
518 }
519
520 return TEST_SUCCESS;
521 }
522
523 static test_return_t application_echo_fubar_BINARY2(void *)
524 {
525 if (0)
526 {
527 test_skip(0, access("/bin/echo", X_OK ));
528 Application true_app("/bin/echo");
529
530 true_app.add_option("fubar");
531
532 test_compare(Application::SUCCESS, true_app.run());
533 test_compare(Application::SUCCESS, true_app.join());
534
535 libtest::vchar_t response;
536 make_vector(response, test_literal_param("fubar\n"));
537 test_compare(response, true_app.stdout_result());
538 }
539
540 return TEST_SUCCESS;
541 }
542
543 static test_return_t echo_fubar_BINARY(void *)
544 {
545 const char *args[]= { "fubar", 0 };
546 test_compare(EXIT_SUCCESS, exec_cmdline("/bin/echo", args));
547
548 return TEST_SUCCESS;
549 }
550
551 static test_return_t core_count_BINARY(void *)
552 {
553 const char *args[]= { 0 };
554
555 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/core-count", args, true));
556
557 return TEST_SUCCESS;
558 }
559
560 static test_return_t wait_BINARY(void *)
561 {
562 const char *args[]= { "--quiet", 0 };
563
564 test_compare(EXIT_FAILURE, exec_cmdline("libtest/wait", args, true));
565
566 return TEST_SUCCESS;
567 }
568
569 static test_return_t wait_help_BINARY(void *)
570 {
571 const char *args[]= { "--quiet", "--help", 0 };
572
573 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
574
575 return TEST_SUCCESS;
576 }
577
578 static test_return_t wait_version_BINARY(void *)
579 {
580 const char *args[]= { "--quiet", "--version", 0 };
581
582 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
583
584 return TEST_SUCCESS;
585 }
586
587 static test_return_t wait_services_BINARY(void *)
588 {
589 test_skip(0, access("/etc/services", R_OK ));
590
591 const char *args[]= { "--quiet", "/etc/services", 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_BINARY2(void *)
599 {
600 test_skip(0, access("/etc/services", R_OK ));
601
602 const char *args[]= { "/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_appliction_TEST(void *)
610 {
611 test_skip(0, access("/usr/bin/gdb", X_OK ));
612 test_skip(0, access("/etc/services", R_OK ));
613
614 libtest::Application wait_app("libtest/wait", true);
615 wait_app.use_gdb();
616
617 const char *args[]= { "/etc/services", 0 };
618 test_compare(Application::SUCCESS, wait_app.run(args));
619 test_compare(Application::SUCCESS, wait_app.join());
620
621 return TEST_SUCCESS;
622 }
623
624 static test_return_t gdb_wait_services_appliction_TEST(void *)
625 {
626 test_skip(true, false);
627 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
628 test_skip(0, TARGET_OS_OSX);
629 #endif
630
631 test_skip(0, access("/usr/bin/gdb", X_OK ));
632 test_skip(0, access("/etc/services", R_OK ));
633
634 libtest::Application wait_app("libtest/wait", true);
635 wait_app.use_gdb();
636
637 const char *args[]= { "/etc/services", 0 };
638 test_compare(Application::SUCCESS, wait_app.run(args));
639 test_compare(Application::SUCCESS, wait_app.join());
640
641 return TEST_SUCCESS;
642 }
643
644 static test_return_t gdb_abort_services_appliction_TEST(void *)
645 {
646 test_skip(true, false);
647 test_skip(0, access("/usr/bin/gdb", X_OK ));
648
649 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
650 test_skip(0, TARGET_OS_OSX);
651 #endif
652
653 libtest::Application abort_app("libtest/abort", true);
654 abort_app.use_gdb();
655
656 test_compare(Application::SUCCESS, abort_app.run());
657 test_compare(Application::SUCCESS, abort_app.join());
658
659 std::string gdb_filename= abort_app.gdb_filename();
660 test_skip(0, access(gdb_filename.c_str(), R_OK ));
661 const char *args[]= { "SIGABRT", gdb_filename.c_str(), 0 };
662 test_compare(EXIT_SUCCESS, exec_cmdline("grep", args));
663
664 // Sanity test
665 args[0]= "THIS_WILL_NOT_BE_FOUND";
666 test_compare(EXIT_FAILURE, exec_cmdline("grep", args));
667
668 return TEST_SUCCESS;
669 }
670
671 static test_return_t get_free_port_TEST(void *)
672 {
673 in_port_t ret_port;
674 test_true((ret_port= get_free_port()));
675 test_true(get_free_port() != default_port());
676 test_true(get_free_port() != get_free_port());
677
678 return TEST_SUCCESS;
679 }
680
681 static test_return_t fatal_TEST(void *)
682 {
683 test_compare(fatal_calls++, fatal::disabled_counter());
684 throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Testing va_args based fatal(): %d", 10);
685
686 return TEST_SUCCESS;
687 }
688
689 static test_return_t number_of_cpus_TEST(void *)
690 {
691 test_true(number_of_cpus() >= 1);
692
693 return TEST_SUCCESS;
694 }
695
696 static test_return_t check_dns_TEST(void *)
697 {
698 test_warn(libtest::check_dns(), "Broken DNS server/no DNS server found");
699
700 return TEST_SUCCESS;
701 }
702
703 static test_return_t Timer_TEST(void *)
704 {
705 int64_t minutes= random() % 50;
706 minutes++;
707
708 Timer check;
709
710 check.reset();
711 check.offset(minutes, 2, 200);
712
713 test_compare(check.minutes(), minutes);
714
715 return TEST_SUCCESS;
716 }
717
718 static test_return_t lookup_true_TEST(void *)
719 {
720 test_warn(libtest::lookup("exist.gearman.info"), "dns is not currently working");
721 return TEST_SUCCESS;
722 }
723
724 static test_return_t lookup_false_TEST(void *)
725 {
726 if (libtest::lookup("does_not_exist.gearman.info"))
727 {
728 Error << "Broken DNS server detected";
729 return TEST_SKIPPED;
730 }
731
732 return TEST_SUCCESS;
733 }
734
735 static test_return_t create_tmpfile_TEST(void *)
736 {
737 test_skip(0, access("/usr/bin/touch", X_OK ));
738 std::string tmp= create_tmpfile(__func__);
739 test_compare(-1, access(tmp.c_str(), R_OK));
740 test_compare(-1, access(tmp.c_str(), F_OK));
741
742 Application touch_app("/usr/bin/touch");
743 const char *args[]= { tmp.c_str(), 0 };
744 test_compare(Application::SUCCESS, touch_app.run(args));
745 test_compare(Application::SUCCESS, touch_app.join());
746
747 test_compare(0, access(tmp.c_str(), R_OK));
748 test_compare(0, unlink(tmp.c_str()));
749
750 return TEST_SUCCESS;
751 }
752
753 static test_return_t fatal_message_TEST(void *)
754 {
755 test_compare(fatal_calls++, fatal::disabled_counter());
756 fatal_message("Fatal test");
757
758 return TEST_SUCCESS;
759 }
760
761 static test_return_t default_port_TEST(void *)
762 {
763 in_port_t ret_port= default_port();
764 test_compare(ret_port, libtest::default_port());
765 test_compare(ret_port, libtest::default_port());
766
767 return TEST_SUCCESS;
768 }
769
770 static test_return_t check_for_gearman(void *)
771 {
772 test_skip(true, HAVE_LIBGEARMAN);
773 test_skip(true, has_gearmand());
774 #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
775 if (GEARMAND_BINARY)
776 {
777 test_zero(access(GEARMAND_BINARY, X_OK ));
778 }
779 else
780 {
781 return TEST_SKIPPED;
782 }
783 #endif
784
785 testing_service= "gearmand";
786
787 return TEST_SUCCESS;
788 }
789
790 static test_return_t check_for_drizzle(void *)
791 {
792 test_skip(true, HAVE_LIBDRIZZLE);
793 test_skip(true, has_drizzled());
794
795 testing_service= "drizzled";
796
797 return TEST_SUCCESS;
798 }
799
800
801 test_st drizzled_tests[] ={
802 {"drizzled startup-shutdown", 0, drizzled_cycle_test },
803 {0, 0, 0}
804 };
805
806 test_st gearmand_tests[] ={
807 #if 0
808 {"pause", 0, pause_test },
809 #endif
810 {"gearmand startup-shutdown", 0, gearmand_cycle_test },
811 {"_compare(gearman_return_t)", 0, _compare_gearman_return_t_test },
812 {"server_startup(fail)", 0, server_startup_fail_TEST },
813 {0, 0, 0}
814 };
815
816 static test_return_t clear_servers(void* object)
817 {
818 server_startup_st *servers= (server_startup_st*)object;
819 test_true(servers);
820 servers->clear();
821
822 testing_service.clear();
823
824 return TEST_SUCCESS;
825 }
826
827 static test_return_t check_for_libmemcached(void* object)
828 {
829 test_skip(true, HAVE_LIBMEMCACHED);
830 test_skip(true, has_memcached());
831
832 server_startup_st *servers= (server_startup_st*)object;
833 test_true(servers);
834 servers->clear();
835
836 testing_service= "memcached";
837
838 return TEST_SUCCESS;
839 }
840
841 test_st memcached_TESTS[] ={
842 {"memcached startup-shutdown", 0, server_startup_TEST },
843 {"memcached(socket file) startup-shutdown", 0, socket_server_startup_TEST },
844 {"_compare(memcached_return_t)", 0, _compare_memcached_return_t_test },
845 {"server_startup(fail)", 0, server_startup_fail_TEST },
846 {0, 0, 0}
847 };
848
849 test_st test_skip_TESTS[] ={
850 {"true, true", 0, test_skip_true_TEST },
851 {"true, false", 0, test_skip_false_TEST },
852 {0, 0, 0}
853 };
854
855 test_st environment_tests[] ={
856 {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test },
857 {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test },
858 {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test },
859 {"GDB_COMMAND", 0, GDB_COMMAND_test },
860 {0, 0, 0}
861 };
862
863 test_st tests_log[] ={
864 {"TEST_SUCCESS", false, test_success_test },
865 {"TEST_FAILURE", false, test_failure_test },
866 {"TEST_SUCCESS == 0", false, test_success_equals_one_test },
867 {0, 0, 0}
868 };
869
870 test_st local_log[] ={
871 {"test_is_local()", 0, local_test },
872 {"test_is_local(NOT)", 0, local_not_test },
873 {0, 0, 0}
874 };
875
876 test_st directories_tests[] ={
877 {"var exists", 0, var_exists_test },
878 {"var/tmp exists", 0, var_tmp_exists_test },
879 {"var/run exists", 0, var_run_exists_test },
880 {"var/log exists", 0, var_log_exists_test },
881 {"var/drizzle exists", 0, var_drizzle_exists_test },
882 {"var/tmp", 0, var_tmp_test },
883 {"var/run", 0, var_run_test },
884 {"var/log", 0, var_log_test },
885 {"var/drizzle", 0, var_drizzle_test },
886 {"var/tmp rm", 0, var_tmp_rm_test },
887 {"var/run rm", 0, var_run_rm_test },
888 {"var/log rm", 0, var_log_rm_test },
889 {"var/drizzle rm", 0, var_drizzle_rm_test },
890 {0, 0, 0}
891 };
892
893 test_st comparison_tests[] ={
894 {"_compare(test_return_t)", 0, _compare_test_return_t_test },
895 {0, 0, 0}
896 };
897
898 test_st cmdline_tests[] ={
899 {"echo fubar", 0, echo_fubar_BINARY },
900 {"core-count", 0, core_count_BINARY },
901 {"wait --quiet", 0, wait_BINARY },
902 {"wait --quiet --help", 0, wait_help_BINARY },
903 {"wait --quiet --version", 0, wait_version_BINARY },
904 {"wait --quiet /etc/services", 0, wait_services_BINARY },
905 {"wait /etc/services", 0, wait_services_BINARY2 },
906 {"wait /etc/services", 0, wait_services_appliction_TEST },
907 {"gdb wait /etc/services", 0, gdb_wait_services_appliction_TEST },
908 {"gdb abort", 0, gdb_abort_services_appliction_TEST },
909 {0, 0, 0}
910 };
911
912 test_st get_free_port_TESTS[] ={
913 {"get_free_port()", 0, get_free_port_TEST },
914 {"default_port()", 0, default_port_TEST },
915 {0, 0, 0}
916 };
917
918 test_st fatal_message_TESTS[] ={
919 {"libtest::fatal", 0, fatal_TEST },
920 {"fatal_message()", 0, fatal_message_TEST },
921 {0, 0, 0}
922 };
923
924 test_st number_of_cpus_TESTS[] ={
925 {"libtest::number_of_cpus()", 0, number_of_cpus_TEST },
926 {0, 0, 0}
927 };
928
929 test_st create_tmpfile_TESTS[] ={
930 {"libtest::create_tmpfile()", 0, create_tmpfile_TEST },
931 {0, 0, 0}
932 };
933
934 test_st timer_TESTS[] ={
935 {"libtest::Timer", 0, Timer_TEST },
936 {0, 0, 0}
937 };
938
939 test_st dns_TESTS[] ={
940 {"libtest::lookup(true)", 0, lookup_true_TEST },
941 {"libtest::lookup(false)", 0, lookup_false_TEST },
942 {"libtest::check_dns()", 0, check_dns_TEST },
943 {0, 0, 0}
944 };
945
946 test_st application_tests[] ={
947 {"vchar_t", 0, vchar_t_TEST },
948 {"vchar_t compare()", 0, vchar_t_compare_neg_TEST },
949 {"true", 0, application_true_BINARY },
950 {"gbd true --fubar", 0, application_gdb_true_BINARY },
951 {"gbd true", 0, application_gdb_true_BINARY2 },
952 {"true --fubar", 0, application_true_fubar_BINARY },
953 {"doesnotexist --fubar", 0, application_doesnotexist_BINARY },
954 {"echo fubar", 0, application_echo_fubar_BINARY },
955 {"echo fubar (as option)", 0, application_echo_fubar_BINARY2 },
956 {0, 0, 0}
957 };
958
959 static test_return_t check_for_curl(void *)
960 {
961 test_skip(true, HAVE_LIBCURL);
962 return TEST_SUCCESS;
963 }
964
965 static test_return_t disable_fatal_exception(void *)
966 {
967 fatal_calls= 0;
968 fatal::disable();
969 return TEST_SUCCESS;
970 }
971
972 static test_return_t enable_fatal_exception(void *)
973 {
974 fatal::enable();
975 return TEST_SUCCESS;
976 }
977
978 test_st http_tests[] ={
979 {"GET", 0, GET_TEST },
980 {"POST", 0, POST_TEST },
981 {"TRACE", 0, TRACE_TEST },
982 {0, 0, 0}
983 };
984
985 collection_st collection[] ={
986 {"environment", 0, 0, environment_tests},
987 {"return values", 0, 0, tests_log},
988 {"test_skip()", 0, 0, test_skip_TESTS },
989 {"local", 0, 0, local_log},
990 {"directories", 0, 0, directories_tests},
991 {"comparison", 0, 0, comparison_tests},
992 {"gearmand", check_for_gearman, clear_servers, gearmand_tests},
993 {"memcached", check_for_libmemcached, clear_servers, memcached_TESTS },
994 {"drizzled", check_for_drizzle, clear_servers, drizzled_tests},
995 {"cmdline", 0, 0, cmdline_tests},
996 {"application", 0, 0, application_tests},
997 {"http", check_for_curl, 0, http_tests},
998 {"http", check_for_curl, 0, http_tests},
999 {"get_free_port()", 0, 0, get_free_port_TESTS },
1000 {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS },
1001 {"number_of_cpus()", 0, 0, number_of_cpus_TESTS },
1002 {"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
1003 {"dns", 0, 0, dns_TESTS },
1004 {"libtest::Timer", 0, 0, timer_TESTS },
1005 {0, 0, 0, 0}
1006 };
1007
1008 static void *world_create(server_startup_st& servers, test_return_t&)
1009 {
1010 return &servers;
1011 }
1012
1013 void get_world(libtest::Framework *world)
1014 {
1015 world->collections(collection);
1016 world->create(world_create);
1017 }