From 0220e4ff877daba889983117fbf2b065ad50b36e Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 25 Aug 2006 13:53:16 +0200 Subject: mytap-changes.patch unittest/Makefile.am: Import patch mytap-changes.patch unittest/README.txt: Import patch mytap-changes.patch unittest/examples/Makefile.am: Import patch mytap-changes.patch unittest/mytap/tap.c: Import patch mytap-changes.patch unittest/mytap/tap.h: Import patch mytap-changes.patch --- unittest/Makefile.am | 7 +++--- unittest/README.txt | 7 +++++- unittest/examples/Makefile.am | 2 +- unittest/mytap/tap.c | 50 +++++++++++++++++++++++++++++++++++++++++-- unittest/mytap/tap.h | 27 +++++++++++++++++++---- 5 files changed, 81 insertions(+), 12 deletions(-) (limited to 'unittest') diff --git a/unittest/Makefile.am b/unittest/Makefile.am index ca3291efde0..6cca1165cfe 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -6,10 +6,9 @@ CLEANFILES = unit unittests = mytap mysys -test: unit - ./unit run $(unittests) +test: + perl unit.pl run $(unittests) unit: $(srcdir)/unit.pl - cp $(srcdir)/unit.pl $@ - chmod 700 $@ + install $(srcdir)/unit.pl $@ diff --git a/unittest/README.txt b/unittest/README.txt index 0d8bb9025d8..cefa8753f8f 100644 --- a/unittest/README.txt +++ b/unittest/README.txt @@ -9,7 +9,9 @@ mytap Source for the MyTAP library mysys Tests for mysys components bitmap-t.c Unit test for MY_BITMAP base64-t.c Unit test for base64 encoding functions -examples Example unit tests +examples Example unit tests. + core-t.c Example of raising a signal in the middle of the test + THIS TEST WILL STOP ALL FURTHER TESTING! simple-t.c Example of a standard TAP unit test skip-t.c Example where some test points are skipped skip_all-t.c Example of a test where the entire test is skipped @@ -24,6 +26,9 @@ To make and execute all unit tests in the directory: make test +Observe that the tests in the examples/ directory are just various +examples of tests and are not expected to pass. + Adding unit tests ----------------- diff --git a/unittest/examples/Makefile.am b/unittest/examples/Makefile.am index f3c70b654a1..8aefb351220 100644 --- a/unittest/examples/Makefile.am +++ b/unittest/examples/Makefile.am @@ -5,5 +5,5 @@ AM_LDFLAGS = -L$(top_builddir)/unittest/mytap LDADD = -lmytap -noinst_PROGRAMS = simple-t skip-t todo-t skip_all-t no_plan-t +noinst_PROGRAMS = simple-t skip-t todo-t skip_all-t no_plan-t core-t diff --git a/unittest/mytap/tap.c b/unittest/mytap/tap.c index d3f5013b4c9..17ec51863d9 100644 --- a/unittest/mytap/tap.c +++ b/unittest/mytap/tap.c @@ -20,10 +20,13 @@ #include "tap.h" +#include "my_config.h" + #include #include #include #include +#include /** Test data structure. @@ -70,7 +73,7 @@ emit_tap(int pass, char const *fmt, va_list ap) /** Emit a TAP directive. - TAP directives are comments after a have the form + TAP directives are comments after that have the form: @code ok 1 # skip reason for skipping @@ -96,6 +99,25 @@ emit_endl() fprintf(tapout, "\n"); } +static void +handle_core_signal(int signo) +{ + BAIL_OUT("Signal %d thrown", signo); +} + +void +BAIL_OUT(char const *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + fprintf(tapout, "Bail out! "); + vfprintf(tapout, fmt, ap); + emit_endl(); + va_end(ap); + exit(255); +} + + void diag(char const *fmt, ...) { @@ -103,14 +125,38 @@ diag(char const *fmt, ...) va_start(ap, fmt); fprintf(tapout, "# "); vfprintf(tapout, fmt, ap); - fprintf(tapout, "\n"); + emit_endl(); va_end(ap); } +typedef struct signal_entry { + int signo; + void (*handler)(int); +} signal_entry; + +static signal_entry install_signal[]= { + { SIGQUIT, handle_core_signal }, + { SIGILL, handle_core_signal }, + { SIGABRT, handle_core_signal }, + { SIGFPE, handle_core_signal }, + { SIGSEGV, handle_core_signal }, + { SIGBUS, handle_core_signal }, + { SIGXCPU, handle_core_signal }, + { SIGXFSZ, handle_core_signal }, + { SIGSYS, handle_core_signal }, + { SIGTRAP, handle_core_signal } +}; void plan(int const count) { + /* + Install signal handler + */ + size_t i; + for (i= 0; i < sizeof(install_signal)/sizeof(*install_signal); ++i) + signal(install_signal[i].signo, install_signal[i].handler); + g_test.plan= count; switch (count) { diff --git a/unittest/mytap/tap.h b/unittest/mytap/tap.h index cc1d0926012..5e24c1c8c99 100644 --- a/unittest/mytap/tap.h +++ b/unittest/mytap/tap.h @@ -21,8 +21,6 @@ #ifndef TAP_H #define TAP_H -#include "my_global.h" - /* @defgroup MyTAP MySQL support for performing unit tests according to TAP. @@ -67,6 +65,10 @@ extern "C" { it was called with NO_PLAN, i.e., the test plan will be printed after all the test lines. + The plan() function will install signal handlers for all signals + that generate a core, so if you want to override these signals, do + it after you have called the plan() function. + @param count The planned number of tests to run. */ void plan(int count); @@ -130,10 +132,9 @@ void skip(int how_many, char const *reason, ...) for (i = 0 ; i < 2 ; ++i) ok(duck[i] == paddling, "is duck %d paddling?", i); } + @endcode @see skip - - @endcode */ #define SKIP_BLOCK_IF(SKIP_IF_TRUE, COUNT, REASON) \ if (SKIP_IF_TRUE) skip((COUNT),(REASON)); else @@ -146,6 +147,24 @@ void skip(int how_many, char const *reason, ...) void diag(char const *fmt, ...) __attribute__((format(printf,1,2))); +/** + Print a bail out message. + + A bail out message can be issued when no further testing can be + done, e.g., when there are missing dependencies. + + The test will exit with status 255. This function does not return. + + @note A bail out message is printed if a signal that generates a + core is raised. + + @param fmt Bail out message in printf() format. +*/ + +void BAIL_OUT(char const *fmt, ...) + __attribute__((noreturn, format(printf,1,2))); + + /** Print summary report and return exit status. -- cgit v1.2.1 From ac03e433646ed99e14f2c49ecd3204934e799b8c Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 25 Aug 2006 16:11:22 +0200 Subject: Adding missing file unittest/examples/core-t.c: BitKeeper file /users/mkindahl/mysql-5.1-clone/unittest/examples/core-t.c --- unittest/examples/core-t.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 unittest/examples/core-t.c (limited to 'unittest') diff --git a/unittest/examples/core-t.c b/unittest/examples/core-t.c new file mode 100644 index 00000000000..3572d72868b --- /dev/null +++ b/unittest/examples/core-t.c @@ -0,0 +1,19 @@ + +#include "my_config.h" + +#include +#include + +/* + This is a simple test to demonstrate what happens if a signal that + generates a core is raised. + + Note that this test will stop all further testing! + */ + +int main() { + plan(3); + ok(1, "First test"); + abort(); + return exit_status(); +} -- cgit v1.2.1 From 1b8dad2b58ba132a65d559f5756d06fe65fa929f Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 29 Aug 2006 22:23:56 +0200 Subject: Various fixes to make MyTAP build on all platforms. unittest/Makefile.am: Not installing unit.pl any more. Adding test-verbose target to see the TAP output (for debugging). unittest/mytap/tap.h: Including portability file. Whitespace changes. Code sample for BAIL_OUT() function. --- unittest/Makefile.am | 6 ++---- unittest/mytap/tap.h | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) (limited to 'unittest') diff --git a/unittest/Makefile.am b/unittest/Makefile.am index 6cca1165cfe..f2f7fc0bf7d 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -1,6 +1,5 @@ SUBDIRS = mytap . mysys examples -noinst_SCRIPTS = unit EXTRA_DIST = unit.pl CLEANFILES = unit @@ -9,6 +8,5 @@ unittests = mytap mysys test: perl unit.pl run $(unittests) -unit: $(srcdir)/unit.pl - install $(srcdir)/unit.pl $@ - +test-verbose: + HARNESS_VERBOSE=1 perl unit.pl run $(unittests) diff --git a/unittest/mytap/tap.h b/unittest/mytap/tap.h index 5e24c1c8c99..51b8c7df04d 100644 --- a/unittest/mytap/tap.h +++ b/unittest/mytap/tap.h @@ -21,9 +21,11 @@ #ifndef TAP_H #define TAP_H -/* - @defgroup MyTAP MySQL support for performing unit tests according to TAP. +#include "my_global.h" +/* + @defgroup MyTAP MySQL support for performing unit tests according to + the Test Anything Protocol (TAP). */ #define NO_PLAN (0) @@ -34,6 +36,7 @@ @internal We are using the "typedef struct X { ... } X" idiom to create class/struct X both in C and C++. */ + typedef struct TEST_DATA { /** Number of tests that is planned to execute. @@ -71,6 +74,7 @@ extern "C" { @param count The planned number of tests to run. */ + void plan(int count); @@ -89,9 +93,11 @@ void plan(int count); @param fmt Format string in printf() format. NULL is allowed, in which case nothing is printed. */ + void ok(int pass, char const *fmt, ...) __attribute__((format(printf,2,3))); + /** Skip a determined number of tests. @@ -116,6 +122,7 @@ void ok(int pass, char const *fmt, ...) @param how_many Number of tests that are to be skipped. @param reason A reason for skipping the tests */ + void skip(int how_many, char const *reason, ...) __attribute__((format(printf,2,3))); @@ -136,17 +143,21 @@ void skip(int how_many, char const *reason, ...) @see skip */ + #define SKIP_BLOCK_IF(SKIP_IF_TRUE, COUNT, REASON) \ if (SKIP_IF_TRUE) skip((COUNT),(REASON)); else + /** Print a diagnostics message. @param fmt Diagnostics message in printf() format. */ + void diag(char const *fmt, ...) __attribute__((format(printf,1,2))); + /** Print a bail out message. @@ -155,6 +166,10 @@ void diag(char const *fmt, ...) The test will exit with status 255. This function does not return. + @code + BAIL_OUT("Lost connection to server %s", server_name); + @endcode + @note A bail out message is printed if a signal that generates a core is raised. @@ -180,6 +195,7 @@ void BAIL_OUT(char const *fmt, ...) @returns EXIT_SUCCESS if all tests passed, EXIT_FAILURE if one or more tests failed. */ + int exit_status(void); @@ -190,9 +206,11 @@ int exit_status(void); automatically call exit(), so there is no need to have checks around it. */ + void skip_all(char const *reason, ...) __attribute__((noreturn, format(printf, 1, 2))); + /** Start section of tests that are not yet ready. @@ -213,14 +231,18 @@ void skip_all(char const *reason, ...) @param message Message that will be printed before the todo tests. */ + void todo_start(char const *message, ...) - __attribute__((format (printf, 1, 2))); + __attribute__((format(printf, 1, 2))); + /** End a section of tests that are not yet ready. */ + void todo_end(); + #ifdef __cplusplus } #endif -- cgit v1.2.1 From 207202aafa211447e79514f060393c780b768ce6 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 30 Aug 2006 14:10:53 +0200 Subject: Changes to make unit tests work on OS X and AIX unittest/unit.pl: Removing reliance on Straps, since it's to unstable. --- unittest/unit.pl | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) (limited to 'unittest') diff --git a/unittest/unit.pl b/unittest/unit.pl index 3092a874192..28ebb44846d 100644 --- a/unittest/unit.pl +++ b/unittest/unit.pl @@ -1,19 +1,5 @@ #!/usr/bin/perl -# Override _command_line in the standard Perl test harness to prevent -# it from using "perl" to run the test scripts. -package MySQL::Straps; - -use base qw(Test::Harness::Straps); - -use strict; - -sub _command_line { - return $_[1] -} - -package main; - use Test::Harness qw(&runtests $verbose); use File::Find; @@ -37,9 +23,6 @@ unit - Run unit tests in directory my $cmd = shift; -# $Test::Harness::Verbose = 1; -# $Test::Harness::Debug = 1; - if (defined $cmd && exists $dispatch{$cmd}) { $dispatch{$cmd}->(@ARGV); } else { @@ -95,14 +78,7 @@ sub run_cmd (@) { if (@files > 0) { # Removing the first './' from the file names foreach (@files) { s!^\./!! } - - # Install the strap above instead of the default strap. Since - # we are replacing the straps under the feet of Test::Harness, - # we need to do some basic initializations in the new straps. - $Test::Harness::Strap = MySQL::Straps->new; - $Test::Harness::Strap->{callback} = \&Test::Harness::strap_callback - if defined &Test::Harness::strap_callback; - + $ENV{'HARNESS_PERL_SWITCHES'} .= q" -e 'exec @ARGV'"; runtests @files; } } -- cgit v1.2.1