Browse Source

Remove sigaction from run-param

Developer errors result in command_fail being called
just like other errors.  The bad_programmer() Test is now updated
and passing.

Signed-off-by: Mark Beckwith <wythe@intrig.com>
ppa-0.6.1
Mark Beckwith 7 years ago
committed by Christian Decker
parent
commit
381c32af75
  1. 110
      lightningd/test/run-param.c

110
lightningd/test/run-param.c

@ -10,13 +10,17 @@
#include <ccan/err/err.h> #include <ccan/err/err.h>
#include <unistd.h> #include <unistd.h>
char *fail_msg; char *fail_msg = NULL;
bool failed = false; bool failed = false;
static bool check_fail(void) { static bool check_fail(void) {
if (!failed) if (!failed)
return false; return false;
failed = false; failed = false;
if (taken(fail_msg)) {
tal_free(fail_msg);
fail_msg = NULL;
}
return true; return true;
} }
@ -248,115 +252,61 @@ static void null_params(void)
} }
#if DEVELOPER #if DEVELOPER
#if 0
jmp_buf jump;
static void handle_abort(int sig)
{
longjmp(jump, 1);
}
static int set_assert(void)
{
struct sigaction act;
int old_stderr;
memset(&act, '\0', sizeof(act));
act.sa_handler = &handle_abort;
if (sigaction(SIGABRT, &act, NULL) < 0)
err(1, "set_assert");
/* Don't spam with assert messages. */
old_stderr = dup(STDERR_FILENO);
close(STDERR_FILENO);
return old_stderr;
}
static void restore_assert(int old_stderr)
{
struct sigaction act;
dup2(old_stderr, STDERR_FILENO);
close(old_stderr);
memset(&act, '\0', sizeof(act));
act.sa_handler = SIG_DFL;
if (sigaction(SIGABRT, &act, NULL) < 0)
err(1, "restore_assert");
}
#endif
/* /*
* Check to make sure there are no programming mistakes. * Check to make sure there are no programming mistakes.
*/ */
static void bad_programmer(void) static void bad_programmer(void)
{ {
#if 0
u64 ival; u64 ival;
u64 ival2; u64 ival2;
double dval; double dval;
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) { assert(!param(cmd, j->buffer, j->toks,
param(cmd, j->buffer, j->toks,
p_req("repeat", json_tok_u64, &ival), p_req("repeat", json_tok_u64, &ival),
p_req("double", json_tok_double, &dval), p_req("double", json_tok_double, &dval),
p_req("repeat", json_tok_u64, &ival2), NULL); p_req("repeat", json_tok_u64, &ival2), NULL));
/* shouldn't get here */ assert(check_fail());
restore_assert(old_stderr); assert(strstr(fail_msg, "programmer error"));
assert(false);
}
if (setjmp(jump) == 0) { assert(!param(cmd, j->buffer, j->toks,
param(cmd, j->buffer, j->toks,
p_req("repeat", json_tok_u64, &ival), p_req("repeat", json_tok_u64, &ival),
p_req("double", json_tok_double, &dval), p_req("double", json_tok_double, &dval),
p_req("repeat", json_tok_u64, &ival), NULL); p_req("repeat", json_tok_u64, &ival), NULL));
restore_assert(old_stderr); assert(check_fail());
assert(false); assert(strstr(fail_msg, "programmer error"));
}
if (setjmp(jump) == 0) { assert(!param(cmd, j->buffer, j->toks,
param(cmd, j->buffer, j->toks,
p_req("u64", json_tok_u64, &ival), p_req("u64", json_tok_u64, &ival),
p_req("repeat", json_tok_double, &dval), p_req("repeat", json_tok_double, &dval),
p_req("repeat", json_tok_double, &dval), NULL); p_req("repeat", json_tok_double, &dval), NULL));
restore_assert(old_stderr); assert(check_fail());
assert(false); assert(strstr(fail_msg, "programmer error"));
}
/* check for repeated arguments */ /* check for repeated arguments */
if (setjmp(jump) == 0) { assert(!param(cmd, j->buffer, j->toks,
param(cmd, j->buffer, j->toks,
p_req("u64", json_tok_u64, &ival), p_req("u64", json_tok_u64, &ival),
p_req("repeated-arg", json_tok_u64, &ival), NULL); p_req("repeated-arg", json_tok_u64, &ival), NULL));
restore_assert(old_stderr); assert(check_fail());
assert(false); assert(strstr(fail_msg, "programmer error"));
}
if (setjmp(jump) == 0) { assert(!param(cmd, j->buffer, j->toks,
param(cmd, j->buffer, j->toks, p_req("u64", (param_cb) NULL, &ival), NULL));
p_req("u64", (param_cb) NULL, &ival), NULL); assert(check_fail());
restore_assert(old_stderr); assert(strstr(fail_msg, "programmer error"));
assert(false);
}
if (setjmp(jump) == 0) {
/* Add required param after optional */ /* Add required param after optional */
struct json *j = j = json_parse(cmd, "[ '25', '546', '26', '1.1' ]");
json_parse(cmd, "[ '25', '546', '26', '1.1' ]");
unsigned int msatoshi; unsigned int msatoshi;
double riskfactor; double riskfactor;
param(cmd, j->buffer, j->toks, assert(!param(cmd, j->buffer, j->toks,
p_req("u64", json_tok_u64, &ival), p_req("u64", json_tok_u64, &ival),
p_req("double", json_tok_double, &dval), p_req("double", json_tok_double, &dval),
p_opt_def("msatoshi", json_tok_number, &msatoshi, 100), p_opt_def("msatoshi", json_tok_number, &msatoshi, 100),
p_req("riskfactor", json_tok_double, &riskfactor), NULL); p_req("riskfactor", json_tok_double, &riskfactor), NULL));
restore_assert(old_stderr); assert(check_fail());
assert(false); assert(strstr(fail_msg, "programmer error"));
}
restore_assert(old_stderr);
#endif
} }
#endif #endif

Loading…
Cancel
Save