Browse Source

test/run-params: suppress stderr for expected failures.

And use err() instead of perror/exit(0) (we should have exit(1) there anyway).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
32ccfa5b29
  1. 48
      lightningd/test/run-params.c

48
lightningd/test/run-params.c

@ -7,6 +7,8 @@
#include <common/json.c> #include <common/json.c>
#include <common/json_escaped.c> #include <common/json_escaped.c>
#include <ccan/array_size/array_size.h> #include <ccan/array_size/array_size.h>
#include <ccan/err/err.h>
#include <unistd.h>
bool failed; bool failed;
char *fail_msg; char *fail_msg;
@ -181,7 +183,7 @@ static void tok_tok(void)
} }
/* check for valid but duplicate json name-value pairs */ /* check for valid but duplicate json name-value pairs */
static void dup(void) static void dup_names(void)
{ {
struct json *j = struct json *j =
json_parse(cmd, json_parse(cmd,
@ -246,26 +248,32 @@ static void handle_abort(int sig)
longjmp(jump, 1); longjmp(jump, 1);
} }
static void set_assert(void) static int set_assert(void)
{ {
struct sigaction act; struct sigaction act;
int old_stderr;
memset(&act, '\0', sizeof(act)); memset(&act, '\0', sizeof(act));
act.sa_handler = &handle_abort; act.sa_handler = &handle_abort;
if (sigaction(SIGABRT, &act, NULL) < 0) { if (sigaction(SIGABRT, &act, NULL) < 0)
perror("set_assert"); err(1, "set_assert");
exit(0);
} /* Don't spam with assert messages. */
old_stderr = dup(STDERR_FILENO);
close(STDERR_FILENO);
return old_stderr;
} }
static void restore_assert(void) static void restore_assert(int old_stderr)
{ {
struct sigaction act; struct sigaction act;
dup2(old_stderr, STDERR_FILENO);
close(old_stderr);
memset(&act, '\0', sizeof(act)); memset(&act, '\0', sizeof(act));
act.sa_handler = SIG_DFL; act.sa_handler = SIG_DFL;
if (sigaction(SIGABRT, &act, NULL) < 0) { if (sigaction(SIGABRT, &act, NULL) < 0)
perror("reset_assert"); err(1, "restore_assert");
exit(0);
}
} }
/* /*
@ -276,8 +284,8 @@ static void bad_programmer(void)
u64 ival; u64 ival;
u64 ival2; u64 ival2;
double dval; double dval;
set_assert();
struct json *j = json_parse(cmd, "[ '25', '546', '26' ]"); struct json *j = json_parse(cmd, "[ '25', '546', '26' ]");
int old_stderr = set_assert();
/* check for repeated names */ /* check for repeated names */
if (setjmp(jump) == 0) { if (setjmp(jump) == 0) {
@ -286,7 +294,7 @@ static void bad_programmer(void)
param_req("double", json_tok_double, &dval), param_req("double", json_tok_double, &dval),
param_req("repeat", json_tok_u64, &ival2), NULL); param_req("repeat", json_tok_u64, &ival2), NULL);
/* shouldn't get here */ /* shouldn't get here */
restore_assert(); restore_assert(old_stderr);
assert(false); assert(false);
} }
@ -295,7 +303,7 @@ static void bad_programmer(void)
param_req("repeat", json_tok_u64, &ival), param_req("repeat", json_tok_u64, &ival),
param_req("double", json_tok_double, &dval), param_req("double", json_tok_double, &dval),
param_req("repeat", json_tok_u64, &ival), NULL); param_req("repeat", json_tok_u64, &ival), NULL);
restore_assert(); restore_assert(old_stderr);
assert(false); assert(false);
} }
@ -304,7 +312,7 @@ static void bad_programmer(void)
param_req("u64", json_tok_u64, &ival), param_req("u64", json_tok_u64, &ival),
param_req("repeat", json_tok_double, &dval), param_req("repeat", json_tok_double, &dval),
param_req("repeat", json_tok_double, &dval), NULL); param_req("repeat", json_tok_double, &dval), NULL);
restore_assert(); restore_assert(old_stderr);
assert(false); assert(false);
} }
@ -314,14 +322,14 @@ static void bad_programmer(void)
param_req("u64", json_tok_u64, &ival), param_req("u64", json_tok_u64, &ival),
param_req("repeated-arg", json_tok_u64, &ival), param_req("repeated-arg", json_tok_u64, &ival),
NULL); NULL);
restore_assert(); restore_assert(old_stderr);
assert(false); assert(false);
} }
if (setjmp(jump) == 0) { if (setjmp(jump) == 0) {
param_parse(cmd, j->buffer, j->toks, param_parse(cmd, j->buffer, j->toks,
param_req("u64", NULL, &ival), NULL); param_req("u64", NULL, &ival), NULL);
restore_assert(); restore_assert(old_stderr);
assert(false); assert(false);
} }
@ -338,10 +346,10 @@ static void bad_programmer(void)
json_tok_number, &msatoshi), json_tok_number, &msatoshi),
param_req("riskfactor", json_tok_double, param_req("riskfactor", json_tok_double,
&riskfactor), NULL); &riskfactor), NULL);
restore_assert(); restore_assert(old_stderr);
assert(false); assert(false);
} }
restore_assert(); restore_assert(old_stderr);
} }
#endif #endif
@ -433,7 +441,7 @@ int main(void)
#if DEVELOPER #if DEVELOPER
bad_programmer(); bad_programmer();
#endif #endif
dup(); dup_names();
five_hundred_params(); five_hundred_params();
sendpay(); sendpay();
tal_free(tmpctx); tal_free(tmpctx);

Loading…
Cancel
Save