Commit 0f5f3b97 authored by Pekka Pessi's avatar Pekka Pessi

test programs: added -a (--abort) option to most test programs

Updated usage.

darcs-hash:20070228172037-55b16-0f4fdb3d30f034f83a1625e66c00c9f620bdc338.gz
parent bab1813c
......@@ -340,9 +340,10 @@ int host_test(void)
END();
}
void usage(void)
void usage(int exitcode)
{
fprintf(stderr, "usage: %s [-v]\n", name);
fprintf(stderr, "usage: %s [-v] [-a]\n", name);
exit(exitcode);
}
int main(int argc, char *argv[])
......@@ -353,8 +354,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
test_flags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
test_flags |= tst_abort;
else
usage();
usage(1);
}
retval |= bnf_test(); fflush(stdout);
......
......@@ -78,13 +78,6 @@ static int test_query_parser(void);
static msg_t *read_message(char const string[]);
msg_mclass_t const *test_mclass = NULL;
void usage(void)
{
fprintf(stderr,
"usage: %s [-v]\n",
name);
}
char *lastpart(char *path)
{
if (strchr(path, '/'))
......@@ -95,6 +88,14 @@ char *lastpart(char *path)
int tstflags;
void usage(int exitcode)
{
fprintf(stderr,
"usage: %s [-v] [-a]\n",
name);
exit(exitcode);
}
int main(int argc, char *argv[])
{
int retval = 0;
......@@ -105,8 +106,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else
usage();
usage(1);
}
if (!test_mclass)
......
......@@ -161,11 +161,12 @@ int test_decoding(void)
}
void usage(void)
void usage(int exitcode)
{
fprintf(stderr,
"usage: %s [-v]\n",
"usage: %s [-v] [-a]\n",
name);
exit(exitcode);
}
int main(int argc, char *argv[])
......@@ -176,8 +177,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else
usage();
usage(1);
}
retval |= test_encoding(); fflush(stdout);
......
......@@ -1162,9 +1162,10 @@ int test_module_io()
extern su_log_t iptsec_log[];
static
void usage(void)
void usage(int exitcode)
{
fprintf(stderr, "usage: %s [-v] [-l n]\n", name);
fprintf(stderr, "usage: %s [-v] [-a] [-l n]\n", name);
exit(exitcode);
}
int main(int argc, char *argv[])
......@@ -1177,8 +1178,10 @@ int main(int argc, char *argv[])
su_init();
for (i = 1; argv[i]; i++) {
if (argv[i] && strcmp(argv[i], "-v") == 0)
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else if (strncmp(argv[i], "-l", 2) == 0) {
int level = 3;
char *rest = NULL;
......@@ -1191,11 +1194,11 @@ int main(int argc, char *argv[])
level = 3, rest = "";
if (rest == NULL || *rest)
usage();
usage(1);
su_log_set_level(iptsec_log, level);
} else {
usage();
usage(1);
}
}
......
......@@ -59,11 +59,6 @@ static int test_flags = 0;
char const name[] = "test_msg";
void usage(void)
{
fprintf(stderr, "usage: %s [-v]\n", name);
}
static int msg_time_test(void)
{
char buf[32];
......@@ -1688,6 +1683,12 @@ static int random_test(void)
END();
}
void usage(int exitcode)
{
fprintf(stderr, "usage: %s [-v] [-a]\n", name);
exit(exitcode);
}
int main(int argc, char *argv[])
{
int retval = 0;
......@@ -1696,8 +1697,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
test_flags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
test_flags |= tst_abort;
else
usage();
usage(1);
}
retval |= msg_time_test(); fflush(stdout);
......
......@@ -3358,6 +3358,7 @@ char const nta_test_usage[] =
"usage: %s OPTIONS\n"
"where OPTIONS are\n"
" -v | --verbose be verbose\n"
" -a | --abort abort() on error\n"
" -q | --quiet be quiet\n"
" -1 quit on first error\n"
" -l level set logging level (0 by default)\n"
......@@ -3369,10 +3370,10 @@ char const nta_test_usage[] =
#endif
;
void usage(void)
void usage(int exitcode)
{
fprintf(stderr, nta_test_usage, name);
exit(1);
exit(exitcode);
}
int main(int argc, char *argv[])
......@@ -3385,6 +3386,8 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0 || strcmp(argv[i], "--abort") == 0)
tstflags |= tst_abort;
else if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quiet") == 0)
tstflags &= ~tst_verbatim;
else if (strcmp(argv[i], "-1") == 0)
......@@ -3401,7 +3404,7 @@ int main(int argc, char *argv[])
level = 3, rest = "";
if (rest == NULL || *rest)
usage();
usage(1);
su_log_set_level(nta_log, level);
su_log_set_level(tport_log, level);
......@@ -3412,7 +3415,7 @@ int main(int argc, char *argv[])
else if (argv[i + 1])
ag->ag_obp = (url_string_t *)(argv[++i]);
else
usage();
usage(1);
}
else if (strncmp(argv[i], "-m", 2) == 0) {
if (argv[i][2])
......@@ -3420,7 +3423,7 @@ int main(int argc, char *argv[])
else if (argv[i + 1])
ag->ag_m = argv[++i];
else
usage();
usage(1);
}
else if (strcmp(argv[i], "--attach") == 0) {
o_attach = 1;
......@@ -3435,7 +3438,7 @@ int main(int argc, char *argv[])
break;
}
else
usage();
usage(1);
}
if (o_attach) {
......
......@@ -1238,6 +1238,7 @@ char const nta_test_api_usage[] =
"usage: %s OPTIONS\n"
"where OPTIONS are\n"
" -v | --verbose be verbose\n"
" -a | --abort abort() on error\n"
" -q | --quiet be quiet\n"
" -1 quit on first error\n"
" -l level set logging level (0 by default)\n"
......@@ -1247,10 +1248,10 @@ char const nta_test_api_usage[] =
#endif
;
void usage(void)
void usage(int exitcode)
{
fprintf(stderr, nta_test_api_usage, name);
exit(1);
exit(exitcode);
}
int main(int argc, char *argv[])
......@@ -1261,9 +1262,11 @@ int main(int argc, char *argv[])
agent_t ag[1] = {{ { SU_HOME_INIT(ag) }, 0, NULL }};
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-q") == 0)
else if (strcmp(argv[i], "-a") == 0 || strcmp(argv[i], "--abort") == 0)
tstflags |= tst_abort;
else if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quiet") == 0)
tstflags &= ~tst_verbatim;
else if (strcmp(argv[i], "-1") == 0)
quit_on_single_failure = 1;
......@@ -1279,7 +1282,7 @@ int main(int argc, char *argv[])
level = 3, rest = "";
if (rest == NULL || *rest)
usage();
usage(1);
su_log_set_level(nta_log, level);
su_log_set_level(tport_log, level);
......@@ -1297,7 +1300,7 @@ int main(int argc, char *argv[])
break;
}
else
usage();
usage(1);
}
if (o_attach) {
......
......@@ -893,10 +893,10 @@ static RETSIGTYPE sig_alarm(int s)
}
#endif
void usage(void)
void usage(int exitcode)
{
fprintf(stderr, "usage: %s [-v|-q] [-p proxy-uri]\n", name);
exit(1);
fprintf(stderr, "usage: %s [-v|-q] [-a] [-p proxy-uri]\n", name);
exit(exitcode);
}
int main(int argc, char **argv)
......@@ -915,6 +915,8 @@ int main(int argc, char **argv)
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else if (strcmp(argv[i], "-q") == 0)
tstflags &= ~tst_verbatim;
else if (strcmp(argv[i], "-p") == 0 && argv[i + 1])
......@@ -931,7 +933,7 @@ int main(int argc, char **argv)
break;
}
else
usage();
usage(1);
}
t->t_srcdir = srcdir;
......
......@@ -848,9 +848,10 @@ static int test_build(void)
END();
}
void usage(void)
void usage(int exitcode)
{
fprintf(stderr, "usage: %s [-v]\n", name);
fprintf(stderr, "usage: %s [-v] [-a]\n", name);
exit(exitcode);
}
int main(int argc, char *argv[])
......@@ -861,8 +862,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else
usage();
usage(1);
}
null = fopen("/dev/null", "ab");
......
......@@ -44,12 +44,12 @@
#include <sofia-sip/sip_header.h>
#include <sofia-sip/msg_date.h>
void usage(void)
void usage(int exitcode)
{
fprintf(stderr,
"usage: test_date [SIP-date] "
"[YYYYy][DDd][HHh][MMm][SS[s]]\n");
exit(1);
exit(exitcode);
}
int main(int ac, char *av[])
......@@ -85,7 +85,7 @@ int main(int ac, char *av[])
case 's': delta += t2; break;
default:
fprintf(stderr, "test_date: %s is not valid time offset\n" , av[2]);
usage();
usage(1);
break;
}
}
......
......@@ -3217,11 +3217,12 @@ static int test_utils(void)
END();
}
void usage(void)
void usage(int exitcode)
{
fprintf(stderr,
"usage: %s [-v]\n",
"usage: %s [-v] [-a]\n",
name);
exit(exitcode);
}
char *lastpart(char *path)
......@@ -3242,8 +3243,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else
usage();
usage(1);
}
if (!test_mclass)
......
......@@ -1245,12 +1245,12 @@ static RETSIGTYPE sig_alarm(int s)
}
#endif
void usage(void)
void usage(int exitcode)
{
fprintf(stderr,
"usage: %s [-v|-q] [-l level] [-p outbound-proxy-uri]\n",
"usage: %s [-v|-q] [-a] [-l level] [-p outbound-proxy-uri]\n",
name);
exit(1);
exit(exitcode);
}
int main(int argc, char *argv[])
......@@ -1263,6 +1263,8 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else if (strcmp(argv[i], "-q") == 0)
tstflags &= ~tst_verbatim;
else if (strcmp(argv[i], "-1") == 0)
......@@ -1279,7 +1281,7 @@ int main(int argc, char *argv[])
level = 3, rest = "";
if (rest == NULL || *rest)
usage();
usage(1);
su_log_set_level(soa_log, level);
}
......@@ -1296,7 +1298,7 @@ int main(int argc, char *argv[])
break;
}
else
usage();
usage(1);
}
if (o_attach) {
......
......@@ -1964,11 +1964,16 @@ static RETSIGTYPE sig_alarm(int s)
}
#endif
void usage(void)
void usage(int exitcode)
{
fprintf(stderr,
"usage: %s [-v] [-l level] [-] [conf-file] [error-conf-file]\n",
"usage: %s OPTIONS [-] [conf-file] [error-conf-file]\n"
"\twhere OPTIONS are\n"
"\t -v be verbose\n"
"\t -a abort on error\n"
"\t -l level\n",
name);
exit(exitcode);
}
#include <sofia-sip/su_log.h>
......@@ -1990,6 +1995,8 @@ int main(int argc, char **argv)
}
else if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else if (strcmp(argv[i], "--no-alarm") == 0) {
o_alarm = 0;
}
......@@ -2008,11 +2015,11 @@ int main(int argc, char **argv)
level = 3, rest = "";
if (rest == NULL || *rest)
usage();
usage(1);
su_log_set_level(sresolv_log, level);
} else
usage();
usage(1);
}
if (o_attach) {
......
......@@ -145,13 +145,14 @@ enum {
tst_verbatim = 1,
/** If (TSTFLAGS & tst_abort) is non-zero, abort() when failed. */
tst_abort = 2,
/** If (TSTFLAGS & tst_log) is non-zero, log intermediate results. */
tst_log = 4
};
#ifndef TSTFLAGS
#error <TSTFLAGS is not defined>
#endif
#ifdef TSTFLAGS
/** Begin a test function. @HIDE */
#define BEGIN() BEGIN_(TSTFLAGS); { extern int tstdef_dummy
/** End a test function. @HIDE */
......@@ -179,17 +180,12 @@ enum {
/** Test that @a suite has same size as @a expected. @HIDE */
#define TEST_SIZE(suite, expected) TEST_SIZE_(TSTFLAGS, suite, expected)
#else
/* Deprecated */
#define TEST0(flags, suite) TEST_1_(flags, suite)
#define TEST_1(flags, suite) TEST_1_(flags, suite)
#define TEST_VOID(flags, suite) TEST_VOID_(flags, suite)
#define TEST(flags, suite, expect) TEST_(flags, suite, expect)
#define TEST64(flags, suite, expect) TEST64_(flags, suite, expect)
#define TEST_S(flags, suite, expect) TEST_S_(flags, suite, expect)
#define BEGIN(flags) BEGIN_(flags) { extern int tstdef_dummy
#define END(flags) (void) tstdef_dummy; } END_(flags)
#endif
/** Print in torture test with -l option */
#define TEST_LOG(x) \
do { \
if (tstflags & tst_log) \
printf x; \
} while(0)
#define TEST_FAILED(flags) \
((flags) & tst_abort) ? abort() : (void)0; return 1
......
......@@ -52,10 +52,10 @@
char const name[] = "htable_test";
void usage(void)
void usage(int exitcode)
{
fprintf(stderr, "usage: %s [-v|--verbatim]\n", name);
exit(2);
fprintf(stderr, "usage: %s [-v|--verbatim] [-a|--abort]\n", name);
exit(exitcode);
}
static int table_test(int flags);
......@@ -70,8 +70,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbatim") == 0)
flags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0 || strcmp(argv[i], "--abort") == 0)
flags |= tst_abort;
else
usage();
usage(1);
}
retval |= table_test(flags); fflush(stdout);
......
......@@ -58,9 +58,10 @@ static int test_flags = 0;
char const name[] = "test_memmem";
void usage(void)
void usage(int exitcode)
{
fprintf(stderr, "usage: %s [-v]\n", name);
fprintf(stderr, "usage: %s [-v] [-a]\n", name);
exit(exitcode);
}
static int test_notfound(void);
......@@ -225,8 +226,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
test_flags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
test_flags |= tst_abort;
else
usage();
usage(1);
}
retval |= test_notfound(); fflush(stdout);
......
......@@ -681,11 +681,12 @@ int test_speed(void)
}
void usage(void)
void usage(int exitcode)
{
fprintf(stderr,
"usage: %s [-v]\n",
"usage: %s [-v] [-a]\n",
name);
exit(exitcode);
}
int main(int argc, char *argv[])
......@@ -696,8 +697,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else
usage();
usage(1);
}
retval |= test_insert(); fflush(stdout);
......
......@@ -49,15 +49,8 @@ int tstflags;
char const *name = "torture_su";
static int test_sockaddr(void);
void usage(void)
{
fprintf(stderr, "usage: %s [-v]\n", name);
}
/** */
int test_sockaddr(void)
static int test_sockaddr(void)
{
su_localinfo_t hints[1] = {{ LI_CANONNAME }};
su_localinfo_t *li, *res = NULL;
......@@ -494,6 +487,12 @@ int test_md5(void)
END();
}
void usage(int exitcode)
{
fprintf(stderr, "usage: %s [-v] [-a]\n", name);
exit(exitcode);
}
int main(int argc, char *argv[])
{
int retval = 0;
......@@ -504,8 +503,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else
usage();
usage(1);
}
retval |= test_sockaddr();
......
......@@ -679,9 +679,10 @@ static int test_auto(void)
END();
}
void usage(void)
void usage(int exitcode)
{
fprintf(stderr, "usage: %s [-v]\n", name);
fprintf(stderr, "usage: %s [-v] [-a]\n", name);
exit(exitcode);
}
int main(int argc, char *argv[])
......@@ -692,8 +693,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else
usage();
usage(1);
}
retval |= test_alloc();
......
......@@ -43,12 +43,8 @@
char const *name = "torture_su_bm";
int tstflags;
#define TORTURELOG(x) \
do { \
if (tstflags & (2 * tst_verbatim)) \
printf x; \
} while(0)
#define TORTURELOG TEST_LOG
#include "su_bm.c"
int test_bm(void)
......@@ -213,11 +209,12 @@ char const Needle[] =
}
void usage(void)
void usage(int exitcode)
{
fprintf(stderr,
"usage: %s [-v]\n",
"usage: %s [-v] [-a]\n",
name);
exit(exitcode);
}
int main(int argc, char *argv[])
......@@ -234,10 +231,12 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else if (strcmp(argv[i], "-l") == 0)
tstflags |= 2 * tst_verbatim;
tstflags |= tst_log;
else
usage();
usage(1);
}
retval |= test_bm(); fflush(stdout);
......
......@@ -302,11 +302,12 @@ int test_register(void)
END();
}
void usage(void)
void usage(int exitcode)
{
fprintf(stderr,
"usage: %s [-v]\n",
"usage: %s [-v] [-a]\n",
name);
exit(exitcode);
}
int main(int argc, char *argv[])
......@@ -324,8 +325,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)