Below is the list of changes that have just been committed into a local
5.1 repository of mkindahl. When mkindahl does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2006-08-24 19:29:39+02:00, mkindahl@stripped +4 -0
Adding bailout() function to allow bail out on exceptional conditions.
Installing signal handlers for all signals that dump core; signal
handler will use bailout() function to print informative message.
unittest/Makefile.am@stripped, 2006-08-24 19:29:36+02:00, mkindahl@stripped +1
-1
Switching to explicitly calling perl to run the test.
unittest/examples/Makefile.am@stripped, 2006-08-24 19:29:36+02:00,
mkindahl@stripped +1 -1
New sample file
unittest/mytap/tap.c@stripped, 2006-08-24 19:29:36+02:00, mkindahl@stripped +52
-2
Adding bailout() function.
Installing signal handler for all signals that throws a core. This
signal handler will print a bail out message and then re-raise the signal.
unittest/mytap/tap.h@stripped, 2006-08-24 19:29:36+02:00, mkindahl@stripped +21
-4
Adding bailout() function.
Adding documentation to plan().
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: mkindahl
# Host: production.mysql.com
# Root: /usersnfs/mkindahl/mysql-5.1-clone
--- 1.5/unittest/mytap/tap.c 2006-08-24 19:29:45 +02:00
+++ 1.6/unittest/mytap/tap.c 2006-08-24 19:29:45 +02:00
@@ -20,10 +20,13 @@
#include "tap.h"
+#include "my_config.h"
+
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
+#include <signal.h>
/**
Test data structure.
@@ -70,7 +73,7 @@
/**
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,29 @@
fprintf(tapout, "\n");
}
+static void
+handle_core_signal(int signo)
+{
+ /*
+ It is not guaranteed that the default handler is re-installed, so
+ we do it here.
+ */
+ signal(signo, SIG_DFL);
+ bailout("Signal %d thrown", signo);
+ raise(signo);
+}
+
+void
+bailout(char const *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ fprintf(tapout, "Bail out! ");
+ vfprintf(tapout, fmt, ap);
+ emit_endl();
+ va_end(ap);
+}
+
void
diag(char const *fmt, ...)
{
@@ -103,14 +129,38 @@
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)
{
--- 1.5/unittest/mytap/tap.h 2006-08-24 19:29:45 +02:00
+++ 1.6/unittest/mytap/tap.h 2006-08-24 19:29:45 +02:00
@@ -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 @@
it was called with <code>NO_PLAN</code>, 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 <em>after</em> you have called the plan() function.
+
@param count The planned number of tests to run.
*/
void plan(int count);
@@ -130,10 +132,9 @@
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
@@ -145,6 +146,22 @@
*/
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.
+
+ @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 bailout(char const *fmt, ...)
+ __attribute__((format(printf,1,2)));
+
/**
Print summary report and return exit status.
--- 1.9/unittest/Makefile.am 2006-08-24 19:29:45 +02:00
+++ 1.10/unittest/Makefile.am 2006-08-24 19:29:45 +02:00
@@ -7,7 +7,7 @@
unittests = mytap mysys
test: unit
- ./unit run $(unittests)
+ perl unit run $(unittests)
unit: $(srcdir)/unit.pl
cp $(srcdir)/unit.pl $@
--- 1.6/unittest/examples/Makefile.am 2006-08-24 19:29:45 +02:00
+++ 1.7/unittest/examples/Makefile.am 2006-08-24 19:29:45 +02:00
@@ -5,5 +5,5 @@
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
| Thread |
|---|
| • bk commit into 5.1 tree (mkindahl:1.2281) | Mats Kindahl | 24 Aug |