tests: use common_setup/common_shutdown to avoid leaks.

It also does more checks (like taken() checks).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-11-15 04:22:46 +10:30
parent 68043c2e8c
commit 57328fe59e
17 changed files with 60 additions and 54 deletions

View File

@@ -6,6 +6,7 @@
#include <ccan/array_size/array_size.h>
#include <ccan/tal/grab_file/grab_file.h>
#include <ccan/tal/path/path.h>
#include <common/setup.h>
bool deprecated_apis = false;
@@ -174,8 +175,7 @@ int main(int argc, char *argv[])
jsmntok_t toks[5000];
const jsmntok_t *t;
setup_locale();
setup_tmpctx();
common_setup(argv[0]);
if (argv[1])
json = grab_file(tmpctx, argv[1]);
@@ -187,8 +187,7 @@ int main(int argc, char *argv[])
"bolt12/format-string-test.json"));
if (!json) {
printf("test file not found, skipping\n");
tal_free(tmpctx);
exit(0);
goto out;
}
}
@@ -213,6 +212,7 @@ int main(int argc, char *argv[])
"lno", &dlen, &fail) != NULL);
assert(actual == valid);
}
tal_free(tmpctx);
out:
common_shutdown();
return 0;
}

View File

@@ -129,8 +129,7 @@ int main(int argc, char *argv[])
"bolt12/merkle-test.json"));
if (!json) {
printf("test file not found, skipping\n");
tal_free(tmpctx);
exit(0);
goto out;
}
}
@@ -179,6 +178,8 @@ int main(int argc, char *argv[])
abort();
printf(" - WRAPPED OK\n");
}
out:
common_shutdown();
return 0;
}

View File

@@ -1,4 +1,5 @@
#include "../fp16.c"
#include <common/setup.h>
#include <common/type_to_string.h>
#include <stdio.h>
#include <wire/wire.h>
@@ -106,12 +107,12 @@ void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNE
{ fprintf(stderr, "towire_u8_array called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
int main(void)
int main(int argc, char *argv[])
{
/* 5 bit exponent, 11 bit mantissa. */
u32 exponent, mantissa;
setup_locale();
common_setup(argv[0]);
/* These can be represented exactly. */
for (exponent = 0; exponent < (1 << 5); exponent++) {
@@ -140,4 +141,6 @@ int main(void)
/* Round up works, even if it causes overflow. */
assert(fp16_to_u64(u64_to_fp16(0xffffffff, true)) == (1ULL << 32));
common_shutdown();
}

View File

@@ -11,6 +11,7 @@
#include <common/gossmap.h>
#include <common/gossip_store.h>
#include <common/route.h>
#include <common/setup.h>
#include <common/type_to_string.h>
#include <bitcoin/chainparams.h>
#include <stdio.h>
@@ -180,10 +181,8 @@ static bool route_can_carry_unless_disabled(const struct gossmap *map,
return route_can_carry_even_disabled(map, c, dir, amount, arg);
}
int main(void)
int main(int argc, char *argv[])
{
setup_locale();
struct node_id a, b, c, d;
struct gossmap_node *a_node, *b_node, *c_node, *d_node;
const struct dijkstra *dij;
@@ -194,10 +193,7 @@ int main(void)
char gossip_version = GOSSIP_STORE_VERSION;
char gossipfilename[] = "/tmp/run-route-specific-gossipstore.XXXXXX";
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
common_setup(argv[0]);
node_id_from_hexstr("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf",
strlen("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf"),
&a);
@@ -309,7 +305,6 @@ int main(void)
AMOUNT_MSAT(499968+1), 0);
assert(!route);
tal_free(tmpctx);
secp256k1_context_destroy(secp256k1_ctx);
common_shutdown();
return 0;
}

View File

@@ -4,6 +4,7 @@
#include <common/gossmap.h>
#include <common/gossip_store.h>
#include <common/route.h>
#include <common/setup.h>
#include <common/type_to_string.h>
#include <bitcoin/chainparams.h>
#include <stdio.h>
@@ -174,9 +175,9 @@ static void node_id_from_privkey(const struct privkey *p, struct node_id *id)
node_id_from_pubkey(id, &k);
}
int main(void)
int main(int argc, char *argv[])
{
setup_locale();
common_setup(argv[0]);
struct node_id a, b, c, d;
struct gossmap_node *a_node, *b_node, *c_node, *d_node;
@@ -189,9 +190,6 @@ int main(void)
char gossip_version = GOSSIP_STORE_VERSION;
char gossipfilename[] = "/tmp/run-route-gossipstore.XXXXXX";
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
chainparams = chainparams_for_network("regtest");
store_fd = mkstemp(gossipfilename);
@@ -313,7 +311,6 @@ int main(void)
assert(amount_msat_eq(route[0].amount, AMOUNT_MSAT(3000000 + 6)));
assert(route[0].delay == 15);
tal_free(tmpctx);
secp256k1_context_destroy(secp256k1_ctx);
common_shutdown();
return 0;
}