From 79f13fa429bca1e468b80fb5cea1b5a0b52896e3 Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Fri, 19 Jul 2019 12:01:41 -0500 Subject: [PATCH] bolt-gen: add compilation tests Add a test for checking that the bolt-gens do the right thing for a fairly exhaustive test case set (and that it compiles). Note that this doesn't check that we've got the memory assignment pieces worked out. It's got a kind of exotic reliance on the update-mocks in that in order to depend on as little of the wire/ code as possible (we only import wire/wire.h), we include an AUTOGENERATE comment in the test_cases CSV file, and then run update-mocks as part of the build for that file. --- Makefile | 1 + tools/Makefile | 2 + tools/test/Makefile | 40 ++++++++++++++++++++ tools/test/run-test-wire.c | 12 ++++++ tools/test/test_cases | 77 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 132 insertions(+) create mode 100644 tools/Makefile create mode 100644 tools/test/Makefile create mode 100644 tools/test/run-test-wire.c create mode 100644 tools/test/test_cases diff --git a/Makefile b/Makefile index f66bd0489..81ade2012 100644 --- a/Makefile +++ b/Makefile @@ -227,6 +227,7 @@ include lightningd/Makefile include cli/Makefile include doc/Makefile include devtools/Makefile +include tools/Makefile include plugins/Makefile # Git doesn't maintain timestamps, so we only regen if git says we should. diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 000000000..c4e8afa67 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,2 @@ +#! /usr/bin/make +include tools/test/Makefile diff --git a/tools/test/Makefile b/tools/test/Makefile new file mode 100644 index 000000000..9ab911a01 --- /dev/null +++ b/tools/test/Makefile @@ -0,0 +1,40 @@ +#! /usr/bin/make +# +# Rudimentary tests for the wire parsers, using a set of test +# definitions. (Covers more of the test definitions) +# +# We generate the files, and then we attempt to compile +# and run a test case. +check-units: check-tools + +TOOL_GEN_SRC := tools/test/gen_test.c +TOOL_GEN_HEADER := tools/test/gen_test.h +TOOL_TEST_SRC := $(wildcard tools/test/run-*.c) +TOOL_TEST_OBJS := $(TOOL_TEST_SRC:.c=.o) +TOOL_TEST_PROGRAMS := $(TOOL_TEST_OBJS:.o=) + +TOOL_TEST_COMMON_OBJS := \ + common/utils.o + +TOOLS_WIRE_DEPS := $(BOLT_DEPS) tools/test/test_cases $(wildcard tools/gen/*_template) + +$(TOOL_TEST_SRC): $(TOOL_GEN_HEADER) +$(TOOL_TEST_OBJS): $(TOOL_GEN_SRC) +$(TOOL_TEST_PROGRAMS): $(TOOL_TEST_COMMON_OBJS) +$(TOOL_GEN_SRC) $(TOOL_GEN_HEADER): $(TOOLS_WIRE_DEPS) + +tools/test/gen_test.h: + tools/generate-bolts.py --page header $@ test_type < tools/test/test_cases > $@ + +tools/test/gen_test.c: + tools/generate-bolts.py --page impl ${@:.c=.h} test_type < tools/test/test_cases > $@ + @tools/update-mocks.sh "$@" + +ALL_TEST_PROGRAMS += $(TOOL_TEST_PROGRAMS) + +check-tools: $(TOOL_TEST_PROGRAMS:%=unittest/%) + +clean: tools-test-clean + +tools-test-clean: + $(RM) $(TOOL_GEN_FILES) $(TOOL_TEST_OBJS) diff --git a/tools/test/run-test-wire.c b/tools/test/run-test-wire.c new file mode 100644 index 000000000..f43d7c413 --- /dev/null +++ b/tools/test/run-test-wire.c @@ -0,0 +1,12 @@ +#include "gen_test.c" + +#include +#include + +#include + +int main(void) +{ + setup_locale(); + +} diff --git a/tools/test/test_cases b/tools/test/test_cases new file mode 100644 index 000000000..29f9de681 --- /dev/null +++ b/tools/test/test_cases @@ -0,0 +1,77 @@ +#include +# TODO: add enums! +# TODO: msgs expansions +# AUTOGENERATED MOCKS START +# AUTOGENERATED MOCKS END + +# omnibus method +msgtype,test_msg,16 +# test array u8 (helper) +msgdata,test_msg,test_arr_u8,u8,10 +# test array assignable +msgdata,test_msg,test_arr_assignable,u16,5 +# test var len u8 (helper) +msgdata,test_msg,len_var_u8,u16, +msgdata,test_msg,test_var_len_u8_arr,byte,len_var_u8 +# test variable length assignable +msgdata,test_msg,len_var_ass,u16, +msgdata,test_msg,test_var_len_ass_arr,u32,len_var_ass +# test array struct +msgdata,test_msg,test_struct_arr,test_short_id,10 +# test var-len struct +msgdata,test_msg,len_test_struct_varlen,u16, +msgdata,test_msg,test_struct_varlen,test_short_id,len_test_struct_varlen +# test var-len var-size struct +msgdata,test_msg,len_varsize_struct,u16, +msgdata,test_msg,test_varsize_struct_varlen,test_features,len_varsize_struct +# assignable +msgdata,test_msg,test_assignable,u16, +# test struct +msgdata,test_msg,test_struct,test_short_id, +# test var-size struct +msgdata,test_msg,test_varsize_struct,test_features, +# test optional struct +msgdata,test_msg,test_optional_struct,?test_short_id, +# test optional var-size struct +msgdata,test_msg,test_optional_varsize_struct,?test_features, +msgdata,test_msg,test_sbt_struct_nested,subtype_nested, +msgdata,test_msg,test_sbt_varsize_struct,subtype_varsize_struct, +msgdata,test_msg,test_sbt_varsize_var_assign,subtype_var_assign, +msgdata,test_msg,test_sbt_var_len,subtype_var_len, +msgdata,test_msg,test_sbt_varlen_varsize,subtype_varlen_varsize, + +# A subtype with a nested subtype +subtype,subtype_nested +subtypedata,subtype_nested,field_1,test_short_id, + +# subtype with a nested varsize size struct +subtype,subtype_varsize_struct +subtypedata,subtype_varsize_struct,field_0,test_features, + +# A subtype to test varsize things of +# - A two level subtype comment +subtype,subtype_var_assign +# variable length set of assignables +subtypedata,subtype_var_assign,len_1,u8, +subtypedata,subtype_var_assign,field_1,u16,len_1 + +# variable length set of structs +subtype,subtype_var_len +subtypedata,subtype_var_len,len_2,u8, +subtypedata,subtype_var_len,field_2,test_short_id,len_2 + +subtype,subtype_varlen_varsize +# variable length set of variable size structs +subtypedata,subtype_varlen_varsize,len,u8, +subtypedata,subtype_varlen_varsize,field_1,test_features,len + +# normal struct +subtype,test_short_id +subtypedata,test_short_id,u64,u64, + +# var-sized struct +subtype,test_features +subtypedata,test_features,len_lf,u16, +subtypedata,test_features,localfeatures,u8,len_lf +subtypedata,test_features,len_gf,u16, +subtypedata,test_features,globalfeatures,u8,len_gf