asn1: Make templating less fragile: test it more

`lib/asn1/check-gen.c` almost works with templates, and is a pretty
extensive test.  The only thing that fails is everything to do with
IMPLICIT tags (so, `test_implicit()`).

So now we compile `lib/asn1/test.asn1` both, w/ and w/o templating, and
we build two programs from `lib/asn1/check-gen.c`: `check-gen` and
`check-gen-template`, respectively linking with the non-templated and
the templated compilation of `lib/asn1/test.asn1`.

Because the template compiler still doesn't support IMPLICIT tagging
well, we disable testing of IMPLICIT tags in `check-gen-template`.

This will make it much harder to break the template compiler in the
future.
This commit is contained in:
Nicolas Williams
2021-01-21 20:42:48 -06:00
parent 81195acafa
commit 51d3cb376a
3 changed files with 27 additions and 7 deletions

View File

@@ -63,7 +63,7 @@ noinst_PROGRAMS = asn1_gen
libexec_heimdal_PROGRAMS = asn1_compile asn1_print libexec_heimdal_PROGRAMS = asn1_compile asn1_print
TESTS = check-der check-gen check-timegm check-ber check-template TESTS = check-der check-gen check-gen-template check-timegm check-ber check-template
check_PROGRAMS = $(TESTS) check_PROGRAMS = $(TESTS)
asn1_gen_SOURCES = asn1_gen.c asn1_gen_SOURCES = asn1_gen.c
@@ -73,6 +73,9 @@ check_der_SOURCES = check-der.c check-common.c check-common.h
check_template_SOURCES = check-template.c check-common.c check-common.h check_template_SOURCES = check-template.c check-common.c check-common.h
nodist_check_template_SOURCES = $(gen_files_test_template:.x=.c) nodist_check_template_SOURCES = $(gen_files_test_template:.x=.c)
dist_check_gen_template_SOURCES = check-gen.c check-common.c check-common.h
nodist_check_gen_template_SOURCES = $(gen_files_test_template:.x=.c)
dist_check_gen_SOURCES = check-gen.c check-common.c check-common.h dist_check_gen_SOURCES = check-gen.c check-common.c check-common.h
nodist_check_gen_SOURCES = $(gen_files_test:.x=.c) nodist_check_gen_SOURCES = $(gen_files_test:.x=.c)
@@ -138,6 +141,11 @@ asn1_print_LDADD = libasn1.la $(LIB_roken) $(LIB_com_err)
asn1_gen_LDADD = $(check_der_LDADD) asn1_gen_LDADD = $(check_der_LDADD)
check_timegm_LDADD = $(check_der_LDADD) check_timegm_LDADD = $(check_der_LDADD)
check_gen_template_LDADD = \
libasn1.la \
$(LIB_roken)
check_gen_CFLAGS = -DIMPLICIT_TAGGING_WORKS
check_gen_LDADD = \ check_gen_LDADD = \
libasn1.la \ libasn1.la \
$(LIB_roken) $(LIB_roken)

View File

@@ -1016,6 +1016,7 @@ test_choice (void)
return ret; return ret;
} }
#ifdef IMPLICIT_TAGGING_WORKS
static int static int
cmp_TESTImplicit (void *a, void *b) cmp_TESTImplicit (void *a, void *b)
{ {
@@ -1104,6 +1105,7 @@ test_implicit (void)
return ret; return ret;
} }
#endif
static int static int
cmp_TESTAlloc (void *a, void *b) cmp_TESTAlloc (void *a, void *b)
@@ -1881,7 +1883,9 @@ main(int argc, char **argv)
DO_ONE(test_large_tag); DO_ONE(test_large_tag);
DO_ONE(test_choice); DO_ONE(test_choice);
#ifdef IMPLICIT_TAGGING_WORKS
DO_ONE(test_implicit); DO_ONE(test_implicit);
#endif
DO_ONE(test_taglessalloc); DO_ONE(test_taglessalloc);
DO_ONE(test_optional); DO_ONE(test_optional);

View File

@@ -35,6 +35,14 @@
RCSID("$Id$"); RCSID("$Id$");
static FILE *
get_code_file(void)
{
if (!one_code_file && templatefile)
return templatefile;
return codefile;
}
void void
generate_type_seq (const Symbol *s) generate_type_seq (const Symbol *s)
{ {
@@ -72,12 +80,12 @@ generate_type_seq (const Symbol *s)
s->gen_name, s->gen_name, subname, s->gen_name, s->gen_name, subname,
s->gen_name, s->gen_name); s->gen_name, s->gen_name);
fprintf (codefile, "int ASN1CALL\n" fprintf (get_code_file(), "int ASN1CALL\n"
"add_%s(%s *data, const %s *element)\n" "add_%s(%s *data, const %s *element)\n"
"{\n", "{\n",
s->gen_name, s->gen_name, subname); s->gen_name, s->gen_name, subname);
fprintf (codefile, fprintf (get_code_file(),
"int ret;\n" "int ret;\n"
"void *ptr;\n" "void *ptr;\n"
"\n" "\n"
@@ -91,14 +99,14 @@ generate_type_seq (const Symbol *s)
"return 0;\n", "return 0;\n",
subname); subname);
fprintf (codefile, "}\n\n"); fprintf (get_code_file(), "}\n\n");
fprintf (codefile, "int ASN1CALL\n" fprintf (get_code_file(), "int ASN1CALL\n"
"remove_%s(%s *data, unsigned int element)\n" "remove_%s(%s *data, unsigned int element)\n"
"{\n", "{\n",
s->gen_name, s->gen_name); s->gen_name, s->gen_name);
fprintf (codefile, fprintf (get_code_file(),
"void *ptr;\n" "void *ptr;\n"
"\n" "\n"
"if (data->len == 0 || element >= data->len)\n" "if (data->len == 0 || element >= data->len)\n"
@@ -115,5 +123,5 @@ generate_type_seq (const Symbol *s)
"return 0;\n", "return 0;\n",
subname); subname);
fprintf (codefile, "}\n\n"); fprintf (get_code_file(), "}\n\n");
} }