~brianaker/libmemcached/1164440

« back to all changes in this revision

Viewing changes to libtest/unittest.cc

  • Committer: Continuous Integration
  • Date: 2012-10-22 05:56:09 UTC
  • mfrom: (1086.1.8 libmemcached-1.0)
  • Revision ID: ci@tangent.org-20121022055609-cbooaw9bcdal4qge
Merge lp:~tangent-org/libmemcached/1.0-build Build: jenkins-Libmemcached-1.0-87

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 
54
54
static std::string testing_service;
55
55
 
 
56
// Used to track setups where we see if failure is happening
 
57
static uint32_t fatal_calls= 0;
 
58
 
56
59
static test_return_t LIBTOOL_COMMAND_test(void *)
57
60
{
58
61
  test_true(getenv("LIBTOOL_COMMAND"));
270
273
 
271
274
  test_skip(true, has_drizzled());
272
275
 
273
 
  test_skip(true, server_startup(*servers, "drizzled", get_free_port(), 0, NULL));
 
276
  test_skip(true, server_startup(*servers, "drizzled", get_free_port(), 0, NULL, false));
274
277
 
275
278
  return TEST_SUCCESS;
276
279
}
280
283
  server_startup_st *servers= (server_startup_st*)object;
281
284
  test_true(servers and servers->validate());
282
285
 
283
 
#if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
284
 
  test_true(has_gearmand());
285
 
#endif
286
 
 
287
286
  test_skip(true, has_gearmand());
288
 
 
289
 
  test_skip(true, server_startup(*servers, "gearmand", get_free_port(), 0, NULL));
 
287
  test_skip(true, server_startup(*servers, "gearmand", get_free_port(), 0, NULL, false));
 
288
  servers->clear();
290
289
 
291
290
  return TEST_SUCCESS;
292
291
}
299
298
 
300
299
  test_skip(true, bool(HAVE_MEMCACHED_LIGHT_BINARY));
301
300
 
302
 
  test_true(server_startup(*servers, "memcached-light", get_free_port(), 0, NULL));
 
301
  test_true(server_startup(*servers, "memcached-light", get_free_port(), 0, NULL, false));
303
302
 
304
303
  return TEST_SUCCESS;
305
304
}
333
332
  server_startup_st *servers= (server_startup_st*)object;
334
333
  test_true(servers);
335
334
 
336
 
  test_compare(servers->start_server(testing_service, LIBTEST_FAIL_PORT, 0, NULL, true), false);
 
335
  fatal::disable();
 
336
  test_compare(servers->start_server(testing_service, LIBTEST_FAIL_PORT, 0, NULL, false), true);
 
337
  fatal::enable();
337
338
 
338
339
  return TEST_SUCCESS;
339
340
}
343
344
  server_startup_st *servers= (server_startup_st*)object;
344
345
  test_true(servers);
345
346
 
346
 
  test_true(servers->start_server(testing_service, get_free_port(), 0, NULL, true));
 
347
  test_compare(servers->start_server(testing_service, get_free_port(), 0, NULL, false), true);
347
348
 
348
349
  test_true(servers->last());
349
350
  pid_t last_pid= servers->last()->pid();
366
367
  server_startup_st *servers= (server_startup_st*)object;
367
368
  test_true(servers);
368
369
 
369
 
  test_true(servers->start_socket_server(testing_service, get_free_port(), 0, NULL, true));
 
370
  test_true(servers->start_socket_server(testing_service, get_free_port(), 0, NULL, false));
370
371
 
371
372
  return TEST_SUCCESS;
372
373
}
384
385
    if (HAVE_LIBMEMCACHED)
385
386
    {
386
387
      test_true(has_memcached_sasl());
387
 
      test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL));
 
388
      test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL, false));
388
389
 
389
390
      return TEST_SUCCESS;
390
391
    }
396
397
 
397
398
static test_return_t application_true_BINARY(void *)
398
399
{
399
 
  Application true_app("true");
 
400
  test_skip(0, access("/usr/bin/true", X_OK ));
 
401
  Application true_app("/usr/bin/true");
400
402
 
401
403
  test_compare(Application::SUCCESS, true_app.run());
402
 
  test_compare(Application::SUCCESS, true_app.wait());
 
404
  test_compare(Application::SUCCESS, true_app.join());
403
405
 
404
406
  return TEST_SUCCESS;
405
407
}
407
409
static test_return_t application_gdb_true_BINARY2(void *)
408
410
{
409
411
  test_skip(0, access("/usr/bin/gdb", X_OK ));
410
 
  Application true_app("true");
 
412
  Application true_app("/usr/bin/true");
411
413
  true_app.use_gdb();
412
414
 
413
415
  test_compare(Application::SUCCESS, true_app.run());
414
 
  test_compare(Application::SUCCESS, true_app.wait());
 
416
  test_compare(Application::SUCCESS, true_app.join());
415
417
 
416
418
  return TEST_SUCCESS;
417
419
}
419
421
static test_return_t application_gdb_true_BINARY(void *)
420
422
{
421
423
  test_skip(0, access("/usr/bin/gdb", X_OK ));
422
 
  Application true_app("true");
 
424
  Application true_app("/usr/bin/true");
423
425
  true_app.use_gdb();
424
426
 
425
427
  const char *args[]= { "--fubar", 0 };
426
428
  test_compare(Application::SUCCESS, true_app.run(args));
427
 
  test_compare(Application::SUCCESS, true_app.wait());
 
429
  test_compare(Application::SUCCESS, true_app.join());
428
430
 
429
431
  return TEST_SUCCESS;
430
432
}
431
433
 
432
434
static test_return_t application_true_fubar_BINARY(void *)
433
435
{
434
 
  Application true_app("true");
 
436
  test_skip(0, access("/usr/bin/true", X_OK ));
 
437
  Application true_app("/usr/bin/true");
435
438
 
436
439
  const char *args[]= { "--fubar", 0 };
437
440
  test_compare(Application::SUCCESS, true_app.run(args));
438
 
  test_compare(Application::SUCCESS, true_app.wait());
 
441
  test_compare(Application::SUCCESS, true_app.join());
439
442
  test_zero(true_app.stdout_result().size());
440
443
 
441
444
  return TEST_SUCCESS;
450
453
 
451
454
  const char *args[]= { "--fubar", 0 };
452
455
#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
453
 
  test_compare(Application::INVALID, true_app.run(args));
 
456
  test_compare(Application::INVALID_POSIX_SPAWN, true_app.run(args));
454
457
#else
455
458
  test_compare(Application::SUCCESS, true_app.run(args));
456
 
  test_compare(Application::INVALID, true_app.wait(false));
 
459
  test_compare(Application::INVALID_POSIX_SPAWN, true_app.join());
457
460
#endif
458
461
 
459
462
  test_zero(true_app.stdout_result().size());
461
464
  return TEST_SUCCESS;
462
465
}
463
466
 
464
 
static test_return_t application_true_fubar_eq_doh_BINARY(void *)
465
 
{
466
 
  Application true_app("true");
467
 
 
468
 
  const char *args[]= { "--fubar=doh", 0 };
469
 
  test_compare(Application::SUCCESS, true_app.run(args));
470
 
  test_compare(Application::SUCCESS, true_app.wait());
471
 
  test_zero(true_app.stdout_result().size());
472
 
 
473
 
  return TEST_SUCCESS;
474
 
}
475
 
 
476
 
static test_return_t application_true_fubar_eq_doh_option_BINARY(void *)
477
 
{
478
 
  Application true_app("true");
479
 
 
480
 
  true_app.add_option("--fubar=", "doh");
481
 
 
482
 
  test_compare(Application::SUCCESS, true_app.run());
483
 
  test_compare(Application::SUCCESS, true_app.wait());
484
 
  test_zero(true_app.stdout_result().size());
485
 
 
486
 
  return TEST_SUCCESS;
487
 
}
488
 
 
489
 
 
490
467
static test_return_t GET_TEST(void *)
491
468
{
492
469
  libtest::http::GET get("http://foo.example.com/");
539
516
 
540
517
static test_return_t application_echo_fubar_BINARY(void *)
541
518
{
542
 
  Application true_app("echo");
543
 
 
544
 
  const char *args[]= { "fubar", 0 };
545
 
  test_compare(Application::SUCCESS, true_app.run(args));
546
 
  test_compare(Application::SUCCESS, true_app.wait());
547
 
 
548
 
  while (true_app.slurp() == false) {} ;
549
 
 
550
 
  libtest::vchar_t response;
551
 
  make_vector(response, test_literal_param("fubar\n"));
552
 
  test_compare(response, true_app.stdout_result());
 
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
  }
553
533
 
554
534
  return TEST_SUCCESS;
555
535
}
556
536
 
557
537
static test_return_t application_echo_fubar_BINARY2(void *)
558
538
{
559
 
  Application true_app("echo");
560
 
 
561
 
  true_app.add_option("fubar");
562
 
 
563
 
  test_compare(Application::SUCCESS, true_app.run());
564
 
  test_compare(Application::SUCCESS, true_app.join());
565
 
 
566
 
  libtest::vchar_t response;
567
 
  make_vector(response, test_literal_param("fubar\n"));
568
 
  test_compare(response, true_app.stdout_result());
569
 
 
570
 
  return TEST_SUCCESS;
571
 
}
572
 
 
573
 
static test_return_t true_BINARY(void *)
 
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 *)
574
566
{
575
567
  const char *args[]= { 0 };
576
 
  test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
577
 
 
578
 
  return TEST_SUCCESS;
579
 
}
580
 
 
581
 
static test_return_t true_fubar_BINARY(void *)
582
 
{
583
 
  const char *args[]= { "--fubar", 0 };
584
 
  test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
585
 
 
586
 
  return TEST_SUCCESS;
587
 
}
588
 
 
589
 
static test_return_t echo_fubar_BINARY(void *)
590
 
{
591
 
  const char *args[]= { "fubar", 0 };
592
 
  test_compare(EXIT_SUCCESS, exec_cmdline("echo", args));
 
568
 
 
569
  test_compare(EXIT_SUCCESS, exec_cmdline("libtest/core-count", args, true));
593
570
 
594
571
  return TEST_SUCCESS;
595
572
}
653
630
 
654
631
  const char *args[]= { "/etc/services", 0 };
655
632
  test_compare(Application::SUCCESS, wait_app.run(args));
656
 
  test_compare(Application::SUCCESS, wait_app.wait());
 
633
  test_compare(Application::SUCCESS, wait_app.join());
657
634
 
658
635
  return TEST_SUCCESS;
659
636
}
673
650
 
674
651
  const char *args[]= { "/etc/services", 0 };
675
652
  test_compare(Application::SUCCESS, wait_app.run(args));
676
 
  test_compare(Application::SUCCESS, wait_app.wait());
 
653
  test_compare(Application::SUCCESS, wait_app.join());
677
654
 
678
655
  return TEST_SUCCESS;
679
656
}
691
668
  abort_app.use_gdb();
692
669
 
693
670
  test_compare(Application::SUCCESS, abort_app.run());
694
 
  test_compare(Application::SUCCESS, abort_app.wait());
 
671
  test_compare(Application::SUCCESS, abort_app.join());
695
672
 
696
673
  std::string gdb_filename= abort_app.gdb_filename();
697
674
  test_skip(0, access(gdb_filename.c_str(), R_OK ));
715
692
  return TEST_SUCCESS;
716
693
}
717
694
 
718
 
static uint32_t fatal_calls= 0;
719
 
 
720
695
static test_return_t fatal_TEST(void *)
721
696
{
722
697
  test_compare(fatal_calls++, fatal::disabled_counter());
777
752
  test_compare(-1, access(tmp.c_str(), R_OK));
778
753
  test_compare(-1, access(tmp.c_str(), F_OK));
779
754
 
780
 
  Application touch_app("touch");
 
755
  Application touch_app("/usr/bin/touch");
781
756
  const char *args[]= { tmp.c_str(), 0 };
782
757
  test_compare(Application::SUCCESS, touch_app.run(args));
783
758
  test_compare(Application::SUCCESS, touch_app.join());
841
816
  {0, 0, 0}
842
817
};
843
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
 
844
830
static test_return_t check_for_libmemcached(void* object)
845
831
{
846
832
  test_skip(true, HAVE_LIBMEMCACHED);
913
899
};
914
900
 
915
901
test_st cmdline_tests[] ={
916
 
  {"true", 0, true_BINARY },
917
 
  {"true --fubar", 0, true_fubar_BINARY },
918
902
  {"echo fubar", 0, echo_fubar_BINARY },
 
903
  {"core-count", 0, core_count_BINARY },
919
904
  {"wait --quiet", 0, wait_BINARY },
920
905
  {"wait --quiet --help", 0, wait_help_BINARY },
921
906
  {"wait --quiet --version", 0, wait_version_BINARY },
969
954
  {"gbd true", 0, application_gdb_true_BINARY2 },
970
955
  {"true --fubar", 0, application_true_fubar_BINARY },
971
956
  {"doesnotexist --fubar", 0, application_doesnotexist_BINARY },
972
 
  {"true --fubar=doh", 0, application_true_fubar_eq_doh_BINARY },
973
 
  {"true --fubar=doh add_option()", 0, application_true_fubar_eq_doh_option_BINARY },
974
957
  {"echo fubar", 0, application_echo_fubar_BINARY },
975
958
  {"echo fubar (as option)", 0, application_echo_fubar_BINARY2 },
976
959
  {0, 0, 0}
984
967
 
985
968
static test_return_t disable_fatal_exception(void *)
986
969
{
 
970
  fatal_calls= 0;
987
971
  fatal::disable();
988
972
  return TEST_SUCCESS;
989
973
}
990
974
 
991
975
static test_return_t enable_fatal_exception(void *)
992
976
{
993
 
  fatal::disable();
 
977
  fatal::enable();
994
978
  return TEST_SUCCESS;
995
979
}
996
980
 
1008
992
  {"local", 0, 0, local_log},
1009
993
  {"directories", 0, 0, directories_tests},
1010
994
  {"comparison", 0, 0, comparison_tests},
1011
 
  {"gearmand", check_for_gearman, 0, gearmand_tests},
1012
 
  {"memcached", check_for_libmemcached, 0, memcached_TESTS },
1013
 
  {"drizzled", check_for_drizzle, 0, drizzled_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},
1014
998
  {"cmdline", 0, 0, cmdline_tests},
1015
999
  {"application", 0, 0, application_tests},
1016
1000
  {"http", check_for_curl, 0, http_tests},