Commit 8e5f17d0 authored by Tim-Philipp Müller's avatar Tim-Philipp Müller
Browse files

check: update internal libcheck to 0.9.8

parent 5fde7d1e
......@@ -7,7 +7,7 @@ AC_MSG_NOTICE([Running check unit test framework checks now...])
CHECK_MAJOR_VERSION=0
CHECK_MINOR_VERSION=9
CHECK_MICRO_VERSION=6
CHECK_MICRO_VERSION=8
CHECK_VERSION=$CHECK_MAJOR_VERSION.$CHECK_MINOR_VERSION.$CHECK_MICRO_VERSION
AC_SUBST(CHECK_MAJOR_VERSION)
......
......@@ -18,7 +18,7 @@
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "../lib/libcompat.h"
#include <string.h>
#include <stdio.h>
......@@ -47,65 +47,6 @@ static void tr_init (TestResult * tr);
static void suite_free (Suite * s);
static void tcase_free (TCase * tc);
#if HAVE_CONFIG_H
#include <config.h>
#endif
#undef malloc
#undef realloc
#undef strsignal
#include <sys/types.h>
void *malloc (size_t n);
void *realloc (void *p, size_t n);
char *strsignal (int sig);
void *rpl_malloc (size_t n);
void *rpl_realloc (void *p, size_t n);
static const char *rpl_strsignal (int sig);
/* Allocate an N-byte block of memory from the heap. If N is zero,
allocate a 1-byte block. */
void *
rpl_malloc (size_t n)
{
if (n == 0)
n = 1;
return malloc (n);
}
/* AC_FUNC_REALLOC in configure defines realloc to rpl_realloc if
realloc(0,0) is NULL to make it GNU compatible and always return a
valid pointer, same for AC_FUNC_MALLOC, malloc, and rpl_malloc.
rpl means `replacement'.
If this ever turns out to be a problem, it might be easiest to just
kill the configure macro calls.
*/
void *
rpl_realloc (void *p, size_t n)
{
if (n == 0)
n = 1;
if (p == 0)
return malloc (n);
return realloc (p, n);
}
/* We simply don't have strsignal on some platforms. This function
should get used if AC_REPLACE_FUNCS([strsignal]) cannot find
something acceptable. Note that Gnulib has a much much much more
advanced version of strsignal, but we don't really care.
*/
static const char *
rpl_strsignal (int sig)
{
static char signame[40];
sprintf (signame, "SIG #%d", sig);
return signame;
}
Suite *
suite_create (const char *name)
{
......@@ -152,6 +93,14 @@ tcase_create (const char *name)
}
}
env = getenv ("CK_TIMEOUT_MULTIPLIER");
if (env != NULL) {
int tmp = atoi (env);
if (tmp >= 0) {
timeout = timeout * tmp;
}
}
tc->timeout = timeout;
tc->tflst = check_list_create ();
tc->unch_sflst = check_list_create ();
......@@ -189,8 +138,8 @@ suite_add_tcase (Suite * s, TCase * tc)
}
void
_tcase_add_test (TCase * tc, TFun fn, const char *name, int _signal, int start,
int end)
_tcase_add_test (TCase * tc, TFun fn, const char *name, int _signal,
int allowed_exit_value, int start, int end)
{
TF *tf;
if (tc == NULL || fn == NULL || name == NULL)
......@@ -200,6 +149,7 @@ _tcase_add_test (TCase * tc, TFun fn, const char *name, int _signal, int start,
tf->loop_start = start;
tf->loop_end = end;
tf->signal = _signal; /* 0 means no signal expected */
tf->allowed_exit_value = allowed_exit_value; /* 0 is default successful exit */
tf->name = name;
list_add_end (tc->tflst, tf);
}
......@@ -249,12 +199,21 @@ tcase_add_fixture (TCase * tc, SFun setup, SFun teardown, int ischecked)
void
tcase_set_timeout (TCase * tc, int timeout)
{
if (timeout >= 0)
if (timeout >= 0) {
char *env = getenv ("CK_TIMEOUT_MULTIPLIER");
if (env != NULL) {
int tmp = atoi (env);
if (tmp >= 0) {
timeout = timeout * tmp;
}
}
tc->timeout = timeout;
}
}
void
tcase_fn_start (const char *fname, const char *file, int line)
tcase_fn_start (const char *fname CK_ATTRIBUTE_UNUSED, const char *file,
int line)
{
send_ctx_info (CK_CTX_TEST);
send_loc_info (file, line);
......@@ -283,8 +242,11 @@ _fail_unless (int result, const char *file, int line, const char *expr, ...)
vsnprintf (buf, BUFSIZ, msg, ap);
va_end (ap);
send_failure_info (buf);
if (cur_fork_status () == CK_FORK)
if (cur_fork_status () == CK_FORK) {
#ifdef _POSIX_VERSION
exit (1);
#endif /* _POSIX_VERSION */
}
}
}
......
......@@ -131,7 +131,11 @@ TCase * CK_EXPORT tcase_create (const char *name);
/* Add a test function with signal handling to a test case (macro version) */
#define tcase_add_test_raise_signal(tc,tf,signal) \
_tcase_add_test((tc),(tf),"" # tf "",(signal), 0, 1)
_tcase_add_test((tc),(tf),"" # tf "",(signal), 0, 0, 1)
/* Add a test function with an expected exit value to a test case (macro version) */
#define tcase_add_exit_test(tc, tf, expected_exit_value) \
_tcase_add_test((tc),(tf),"" # tf "",0,(expected_exit_value),0,1)
/* Add a looping test function to a test case (macro version)
......@@ -140,18 +144,22 @@ TCase * CK_EXPORT tcase_create (const char *name);
available in the test.
*/
#define tcase_add_loop_test(tc,tf,s,e) \
_tcase_add_test((tc),(tf),"" # tf "",0,(s),(e))
_tcase_add_test((tc),(tf),"" # tf "",0,0,(s),(e))
/* Signal version of loop test.
FIXME: add a test case; this is untested as part of Check's tests.
*/
#define tcase_add_loop_test_raise_signal(tc,tf,signal,s,e) \
_tcase_add_test((tc),(tf),"" # tf "",(signal),(s),(e))
_tcase_add_test((tc),(tf),"" # tf "",(signal),0,(s),(e))
/* allowed exit value version of loop test. */
#define tcase_add_loop_exit_test(tc,tf,expected_exit_value,s,e) \
_tcase_add_test((tc),(tf),"" # tf "",0,(expected_exit_value),(s),(e))
/* Add a test function to a test case
(function version -- use this when the macro won't work
*/
void CK_EXPORT _tcase_add_test (TCase *tc, TFun tf, const char *fname, int _signal, int start, int end);
void CK_EXPORT _tcase_add_test (TCase *tc, TFun tf, const char *fname, int _signal, int allowed_exit_value, int start, int end);
/* Add unchecked fixture setup/teardown functions to a test case
......@@ -197,7 +205,7 @@ void CK_EXPORT tcase_fn_start (const char *fname, const char *file, int line);
One must use braces within a START_/END_ pair to declare new variables
*/
#define START_TEST(__testname)\
static void __testname (int CK_ATTRIBUTE_UNUSED _i)\
static void __testname (int _i CK_ATTRIBUTE_UNUSED)\
{\
tcase_fn_start (""# __testname, __FILE__, __LINE__);
......@@ -272,6 +280,9 @@ enum print_output {
CK_NORMAL, /* All failed tests */
CK_VERBOSE, /* All tests */
CK_ENV, /* Look at environment var */
#if @ENABLE_SUBUNIT@
CK_SUBUNIT, /* Run as a subunit child process */
#endif
CK_LAST
};
......
......@@ -18,7 +18,7 @@
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "../lib/libcompat.h"
#include <stdarg.h>
#include <stdlib.h>
......
......@@ -33,6 +33,7 @@ typedef struct TF {
int loop_end;
const char *name;
int signal;
unsigned char allowed_exit_value;
} TF;
struct Suite {
......@@ -83,6 +84,7 @@ enum cl_event {
CLSTART_S,
CLEND_SR,
CLEND_S,
CLSTART_T, /* A test case is about to run */
CLEND_T
};
......
......@@ -18,7 +18,7 @@
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "../lib/libcompat.h"
#include <stdlib.h>
#include <string.h>
......
......@@ -18,19 +18,21 @@
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "../lib/libcompat.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <check.h>
#if HAVE_SUBUNIT_CHILD_H
#include <subunit/child.h>
#endif
#include "check_error.h"
#include "check_list.h"
#include "check_impl.h"
#include "check_log.h"
#include "check_print.h"
#include "check_str.h"
static void srunner_send_evt (SRunner * sr, void *obj, enum cl_event evt);
......@@ -118,6 +120,14 @@ log_suite_end (SRunner * sr, Suite * s)
srunner_send_evt (sr, s, CLEND_S);
}
void
log_test_start (SRunner * sr, TCase * tc, TF * tfun)
{
char buffer[100];
snprintf (buffer, 99, "%s:%s", tc->name, tfun->name);
srunner_send_evt (sr, buffer, CLSTART_T);
}
void
log_test_end (SRunner * sr, TestResult * tr)
{
......@@ -142,7 +152,6 @@ void
stdout_lfun (SRunner * sr, FILE * file, enum print_output printmode,
void *obj, enum cl_event evt)
{
TestResult *tr;
Suite *s;
if (printmode == CK_ENV) {
......@@ -177,8 +186,9 @@ stdout_lfun (SRunner * sr, FILE * file, enum print_output printmode,
case CLEND_S:
s = obj;
break;
case CLSTART_T:
break;
case CLEND_T:
tr = obj;
break;
default:
eprintf ("Bad event type received in stdout_lfun", __FILE__, __LINE__);
......@@ -188,8 +198,9 @@ stdout_lfun (SRunner * sr, FILE * file, enum print_output printmode,
}
void
lfile_lfun (SRunner * sr, FILE * file, enum print_output printmode,
void *obj, enum cl_event evt)
lfile_lfun (SRunner * sr, FILE * file,
enum print_output printmode CK_ATTRIBUTE_UNUSED, void *obj,
enum cl_event evt)
{
TestResult *tr;
Suite *s;
......@@ -212,20 +223,23 @@ lfile_lfun (SRunner * sr, FILE * file, enum print_output printmode,
case CLEND_S:
s = obj;
break;
case CLSTART_T:
break;
case CLEND_T:
tr = obj;
tr_fprint (file, tr, CK_VERBOSE);
break;
default:
eprintf ("Bad event type received in stdout_lfun", __FILE__, __LINE__);
eprintf ("Bad event type received in lfile_lfun", __FILE__, __LINE__);
}
}
void
xml_lfun (SRunner * sr, FILE * file, enum print_output printmode,
void *obj, enum cl_event evt)
xml_lfun (SRunner * sr CK_ATTRIBUTE_UNUSED, FILE * file,
enum print_output printmode CK_ATTRIBUTE_UNUSED, void *obj,
enum cl_event evt)
{
TestResult *tr;
Suite *s;
......@@ -266,6 +280,8 @@ xml_lfun (SRunner * sr, FILE * file, enum print_output printmode,
fprintf (file, " </suite>\n");
s = obj;
break;
case CLSTART_T:
break;
case CLEND_T:
tr = obj;
tr_xmlprint (file, tr, CK_VERBOSE);
......@@ -276,6 +292,67 @@ xml_lfun (SRunner * sr, FILE * file, enum print_output printmode,
}
#if ENABLE_SUBUNIT
void
subunit_lfun (SRunner * sr, FILE * file, enum print_output printmode,
void *obj, enum cl_event evt)
{
TestResult *tr;
Suite *s;
char const *name;
/* assert(printmode == CK_SUBUNIT); */
switch (evt) {
case CLINITLOG_SR:
break;
case CLENDLOG_SR:
break;
case CLSTART_SR:
break;
case CLSTART_S:
s = obj;
break;
case CLEND_SR:
if (printmode > CK_SILENT) {
fprintf (file, "\n");
srunner_fprint (file, sr, printmode);
}
break;
case CLEND_S:
s = obj;
break;
case CLSTART_T:
name = obj;
subunit_test_start (name);
break;
case CLEND_T:
tr = obj;
{
char *name = ck_strdup_printf ("%s:%s", tr->tcname, tr->tname);
char *msg = tr_short_str (tr);
switch (tr->rtype) {
case CK_PASS:
subunit_test_pass (name);
break;
case CK_FAILURE:
subunit_test_fail (name, msg);
break;
case CK_ERROR:
subunit_test_error (name, msg);
break;
default:
eprintf ("Bad result type in subunit_lfun", __FILE__, __LINE__);
free (name);
free (msg);
}
}
break;
default:
eprintf ("Bad event type received in subunit_lfun", __FILE__, __LINE__);
}
}
#endif
FILE *
srunner_open_lfile (SRunner * sr)
......@@ -308,7 +385,14 @@ srunner_init_logging (SRunner * sr, enum print_output print_mode)
{
FILE *f;
sr->loglst = check_list_create ();
srunner_register_lfun (sr, stdout, 0, stdout_lfun, print_mode);
#if ENABLE_SUBUNIT
if (print_mode != CK_SUBUNIT)
#endif
srunner_register_lfun (sr, stdout, 0, stdout_lfun, print_mode);
#if ENABLE_SUBUNIT
else
srunner_register_lfun (sr, stdout, 0, subunit_lfun, print_mode);
#endif
f = srunner_open_lfile (sr);
if (f) {
srunner_register_lfun (sr, f, 1, lfile_lfun, print_mode);
......
......@@ -26,6 +26,7 @@ void log_srunner_end (SRunner *sr);
void log_suite_start (SRunner *sr, Suite *s);
void log_suite_end (SRunner *sr, Suite *s);
void log_test_end (SRunner *sr, TestResult *tr);
void log_test_start (SRunner *sr, TCase *tc, TF *tfun);
void stdout_lfun (SRunner *sr, FILE *file, enum print_output,
void *obj, enum cl_event evt);
......@@ -36,6 +37,9 @@ void lfile_lfun (SRunner *sr, FILE *file, enum print_output,
void xml_lfun (SRunner *sr, FILE *file, enum print_output,
void *obj, enum cl_event evt);
void subunit_lfun (SRunner *sr, FILE *file, enum print_output,
void *obj, enum cl_event evt);
void srunner_register_lfun (SRunner *sr, FILE *lfile, int close,
LFun lfun, enum print_output);
......
......@@ -18,10 +18,9 @@
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "../lib/libcompat.h"
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
......@@ -73,7 +72,7 @@ get_pipe (void)
if (send_file1 != 0) {
return send_file1;
}
printf ("send_file1=%p,send_file2=%p", send_file1, send_file2);
eprintf ("No messaging setup", __FILE__, __LINE__);
return NULL;
......
......@@ -18,26 +18,23 @@
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "../lib/libcompat.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include "_stdint.h"
#include "check.h"
#include "check_error.h"
#include "check_list.h"
#include "check_impl.h"
#include "check_pack.h"
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#ifdef HAVE_PTHREAD
pthread_mutex_t lock_mutex = PTHREAD_MUTEX_INITIALIZER;
#else
#define pthread_mutex_lock(arg)
......@@ -271,7 +268,7 @@ check_type (int type, const char *file, int line)
eprintf ("Bad message type arg %d", file, line, type);
}
#ifdef HAVE_PTHREAD_H
#ifdef HAVE_PTHREAD
pthread_mutex_t mutex_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
......
......@@ -18,8 +18,7 @@
* Boston, MA 02111-1307, USA.
*/
#define _GNU_SOURCE
#include "config.h"
#include "../lib/libcompat.h"
#include <stdio.h>
#include <string.h>
......@@ -57,6 +56,11 @@ srunner_fprint (FILE * file, SRunner * sr, enum print_output print_mode)
static void
srunner_fprint_summary (FILE * file, SRunner * sr, enum print_output print_mode)
{
#if ENABLE_SUBUNIT
if (print_mode == CK_SUBUNIT)
return;
#endif
if (print_mode >= CK_MINIMAL) {
char *str;
......@@ -72,6 +76,11 @@ srunner_fprint_results (FILE * file, SRunner * sr, enum print_output print_mode)
{
List *resultlst;
#if ENABLE_SUBUNIT
if (print_mode == CK_SUBUNIT)
return;
#endif
resultlst = sr->resultlst;
for (list_front (resultlst); !list_at_end (resultlst);
......@@ -98,7 +107,8 @@ tr_fprint (FILE * file, TestResult * tr, enum print_output print_mode)
}
void
tr_xmlprint (FILE * file, TestResult * tr, enum print_output print_mode)
tr_xmlprint (FILE * file, TestResult * tr,
enum print_output print_mode CK_ATTRIBUTE_UNUSED)
{
char result[10];
char *path_name;
......
......@@ -18,12 +18,9 @@
* Boston, MA 02111-1307, USA.
*/
#define _GNU_SOURCE
#include "config.h"
#include "../lib/libcompat.h"
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
......@@ -53,38 +50,44 @@ enum tf_type
CK_NOFORK_FIXTURE
};
/* all functions are defined in the same order they are declared.
functions that depend on forking are gathered all together.
non-static functions are at the end of the file. */
static void srunner_run_init (SRunner * sr, enum print_output print_mode);
static void srunner_run_end (SRunner * sr, enum print_output print_mode);
static void srunner_iterate_suites (SRunner * sr, enum print_output print_mode);
static void srunner_run_tcase (SRunner * sr, TCase * tc);
static void srunner_iterate_tcase_tfuns (SRunner * sr, TCase * tc);
static void srunner_add_failure (SRunner * sr, TestResult * tf);
static int srunner_run_unchecked_setup (SRunner * sr, TCase * tc);
static void srunner_run_unchecked_teardown (SRunner * sr, TCase * tc);
static TestResult *tcase_run_checked_setup (SRunner * sr, TCase * tc);
static void srunner_run_teardown (List * l);
static void srunner_run_unchecked_teardown (TCase * tc);
static void tcase_run_checked_teardown (TCase * tc);
static void srunner_iterate_tcase_tfuns (SRunner * sr, TCase * tc);
static void srunner_add_failure (SRunner * sr, TestResult * tf);
static TestResult *tcase_run_tfun_fork (SRunner * sr, TCase * tc, TF * tf,
int i);
static void srunner_run_tcase (SRunner * sr, TCase * tc);
static TestResult *tcase_run_tfun_nofork (SRunner * sr, TCase * tc, TF * tf,
int i);
static TestResult *receive_result_info_fork (const char *tcname,
const char *tname, int iter, int status, int expected_signal);
static TestResult *receive_result_info_nofork (const char *tcname,
const char *tname, int iter);
static void set_fork_info (TestResult * tr, int status, int expected_signal);
static void set_nofork_info (TestResult * tr);
static char *pass_msg (void);
#ifdef _POSIX_VERSION
static TestResult *tcase_run_tfun_fork (SRunner * sr, TCase * tc, TF * tf,
int i);
static TestResult *receive_result_info_fork (const char *tcname,
const char *tname, int iter, int status, int expected_signal,
unsigned char allowed_exit_value);
static void set_fork_info (TestResult * tr, int status, int expected_signal,
unsigned char allowed_exit_value);
static char *signal_msg (int sig);
static char *signal_error_msg (int signal_received, int signal_expected);
static char *pass_msg (void);
static char *exit_msg (int exitstatus);
static int waserror (int status, int expected_signal);
#define MSG_LEN 100
static int alarm_received;
static pid_t group_pid;
static void
static void CK_ATTRIBUTE_UNUSED