test/parser: Allow raw config data in test .c files
authorJeremy Kerr <jk@ozlabs.org>
Wed, 15 May 2013 05:11:43 +0000 (13:11 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 16 May 2013 03:53:34 +0000 (11:53 +0800)
Add a little post-processing script (extract-config.awk) to allow us to
put the config data directly into the test .c files, without having to
quote the C string.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
test/parser/Makefile.am
test/parser/extract-config.awk [new file with mode: 0644]
test/parser/parser-test.h

index aa4591f9f2d707305e4b4f9e7e2e03c980d4de19..2e97fbe208e81ba5fa107ced54b1c1f2698a31bb 100644 (file)
@@ -47,5 +47,15 @@ LDADD = $(common_libs) $(test_libs)
 
 libtest_o_SOURCES = utils.c parser-test.h handler.c main.c $(parser_test_objs)
 
+$(check_PROGRAMS): %: %.embedded-config.o
+$(check_PROGRAMS): LDADD += $@.embedded-config.o
 
-EXTRA_DIST = $(check_DATA)
+extract_config = $(srcdir)/extract-config.awk
+
+%.embedded-config.c: %.c $(extract_config)
+       gawk --file=$(extract_config) $^ > $@
+
+EXTRA_DIST = $(check_DATA) $(extract_config)
+
+CLEANFILES = $(foreach f, $(check_PROGRAMS), \
+               $(f).embedded-config.c $(f).embedded-config.o)
diff --git a/test/parser/extract-config.awk b/test/parser/extract-config.awk
new file mode 100644 (file)
index 0000000..e7a5b33
--- /dev/null
@@ -0,0 +1,21 @@
+BEGIN {
+       config=0
+}
+
+/^#if\s*0\s*\/\*\s*PARSER_EMBEDDED_CONFIG/ {
+       config=1
+       print "#include <stdlib.h>"
+       print "const char __embedded_config[] = "
+       next
+}
+!config {
+       next
+}
+/^#endif/ {
+       print ";"
+       print "const size_t __embedded_config_size = sizeof(__embedded_config);"
+       exit
+}
+{
+       print "\t\"" $0 "\\n\""
+}
index 5baa4588588fdd9e4f9c65f75105d21fbfbf45ea..76132d55956f7d4ac52a8ccf6844c9d1de5c884c 100644 (file)
@@ -31,4 +31,10 @@ void test_read_conf_file(struct parser_test *test, const char *filename);
 
 int test_run_parser(struct parser_test *test, const char *parser_name);
 
+/* embedded config */
+extern const char __embedded_config[];
+extern const size_t __embedded_config_size;
+#define test_read_conf_embedded(t) \
+       __test_read_conf_data(t, __embedded_config, __embedded_config_size)
+
 #endif /* PARSER_TEST_H */