unittest: use common_setup / common_shutdown almost everywhere.

Avoids much cut & paste.  Some tests don't need any of it, but most
want at least some of this infrastructure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2020-12-02 10:40:04 +10:30
parent 39f4ca98b5
commit ca2bd98082
43 changed files with 147 additions and 208 deletions

View File

@@ -10,6 +10,7 @@ ALL_C_SOURCES += $(WIRE_TEST_SRC)
ALL_TEST_PROGRAMS += $(WIRE_TEST_PROGRAMS)
WIRE_TEST_COMMON_OBJS := \
common/setup.o \
common/utils.o
update-mocks: $(WIRE_TEST_SRC:%=update-mocks/%)

View File

@@ -13,6 +13,7 @@
#include <common/amount.h>
#include <common/bigsize.h>
#include <bitcoin/chainparams.h>
#include <common/setup.h>
#include <common/sphinx.h>
#include <wire/peer_wire.h>
@@ -955,10 +956,8 @@ static bool node_announcement_eq(const struct msg_node_announcement *a,
#define test_corruption_tlv(a, b, type) \
test_bitflip_and_short(a, b, type, false)
int main(void)
int main(int argc, char *argv[])
{
setup_locale();
struct msg_channel_announcement ca, *ca2;
struct msg_funding_locked fl, *fl2;
struct msg_announcement_signatures as, *as2;
@@ -984,8 +983,7 @@ int main(void)
u8 *msg;
const struct chainparams **chains;
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
common_setup(argv[0]);
memset(&ca, 2, sizeof(ca));
set_node_id(&ca.node_id_1);
@@ -1170,8 +1168,7 @@ int main(void)
assert(node_announcement_eq(&na, na2));
test_corruption(&na, na2, node_announcement);
/* No memory leaks please */
secp256k1_context_destroy(secp256k1_ctx);
tal_free(ctx);
common_shutdown();
return 0;
}

View File

@@ -12,6 +12,7 @@ static const char *reason;
#include <common/amount.c>
#include <common/bigsize.c>
#include <common/node_id.c>
#include <common/setup.h>
#if EXPERIMENTAL_FEATURES
#include <wire/peer_exp_wiregen.c>
@@ -445,13 +446,9 @@ static bool ignored_fields(const struct tlv_n1 *tlv_n1)
&& tlv_n1->tlv4 == NULL;
}
int main(void)
int main(int argc, char *argv[])
{
setup_locale();
wally_init(0);
secp256k1_ctx = wally_get_secp_context();
setup_tmpctx();
common_setup(argv[0]);
if (!pubkey_from_hexstr("023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb", 66, &tlv3_node_id.node_id))
abort();
@@ -636,6 +633,5 @@ int main(void)
p2, tal_count(p2)));
}
}
tal_free(tmpctx);
wally_cleanup(0);
common_shutdown();
}