mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
test/test_state_coverage: ensure we produce all output packets.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
f51e9c81bf
commit
8308e31d6c
1 changed files with 43 additions and 0 deletions
|
@ -110,6 +110,9 @@ struct hist {
|
||||||
|
|
||||||
/* The different inputs. */
|
/* The different inputs. */
|
||||||
enum state_input **inputs_per_state;
|
enum state_input **inputs_per_state;
|
||||||
|
|
||||||
|
/* The different outputs. */
|
||||||
|
enum state_input *outputs;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *state_name(enum state s)
|
static const char *state_name(enum state s)
|
||||||
|
@ -652,6 +655,29 @@ static void eliminate_input(enum state_input **inputs, enum state_input in)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool find_output(const enum state_input *outputs, enum state_input out)
|
||||||
|
{
|
||||||
|
size_t n, i;
|
||||||
|
|
||||||
|
n = tal_count(outputs);
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
if (outputs[i] == out)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void record_output(enum state_input **outputs, enum state_input out)
|
||||||
|
{
|
||||||
|
size_t n;
|
||||||
|
|
||||||
|
if (find_output(*outputs, out))
|
||||||
|
return;
|
||||||
|
|
||||||
|
n = tal_count(*outputs);
|
||||||
|
tal_resize(outputs, n+1);
|
||||||
|
(*outputs)[n] = out;
|
||||||
|
}
|
||||||
|
|
||||||
static struct trail *try_input(const struct state_data *sdata,
|
static struct trail *try_input(const struct state_data *sdata,
|
||||||
enum state_input i,
|
enum state_input i,
|
||||||
struct hist *hist)
|
struct hist *hist)
|
||||||
|
@ -678,6 +704,12 @@ static struct trail *try_input(const struct state_data *sdata,
|
||||||
if (problem)
|
if (problem)
|
||||||
return new_trail(i, sdata, newstate, effect, problem);
|
return new_trail(i, sdata, newstate, effect, problem);
|
||||||
|
|
||||||
|
/* Record any output. */
|
||||||
|
if (effect->send) {
|
||||||
|
record_output(&hist->outputs,
|
||||||
|
input_by_name((const char *)effect->send));
|
||||||
|
}
|
||||||
|
|
||||||
/* Have we been in this overall situation before? */
|
/* Have we been in this overall situation before? */
|
||||||
if (!sithash_update(&hist->sithash, ©)) {
|
if (!sithash_update(&hist->sithash, ©)) {
|
||||||
tal_free(effect);
|
tal_free(effect);
|
||||||
|
@ -893,6 +925,7 @@ int main(void)
|
||||||
/* Map the inputs tested in each state. */
|
/* Map the inputs tested in each state. */
|
||||||
hist.inputs_per_state = map_inputs();
|
hist.inputs_per_state = map_inputs();
|
||||||
sithash_init(&hist.sithash);
|
sithash_init(&hist.sithash);
|
||||||
|
hist.outputs = tal_arr(NULL, enum state_input, 0);
|
||||||
|
|
||||||
/* Initialize universe. */
|
/* Initialize universe. */
|
||||||
sdata_init(&a, &b, STATE_INIT_WITHANCHOR, "A");
|
sdata_init(&a, &b, STATE_INIT_WITHANCHOR, "A");
|
||||||
|
@ -947,5 +980,15 @@ int main(void)
|
||||||
input_name(*hist.inputs_per_state[i]));
|
input_name(*hist.inputs_per_state[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < INPUT_MAX; i++) {
|
||||||
|
/* Not all input values are valid. */
|
||||||
|
if (streq(input_name(i), "unknown"))
|
||||||
|
continue;
|
||||||
|
/* We only expect packets to be output. */
|
||||||
|
if (!input_is_pkt(i))
|
||||||
|
continue;
|
||||||
|
if (!find_output(hist.outputs, i))
|
||||||
|
warnx("Never sent output %s", input_name(i));
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue