git » libfiu » commit 4856a2c

tests/generated: Let generated tests be wrapped around #ifdefs

author Alberto Bertogli
2012-09-05 09:36:05 UTC
committer Alberto Bertogli
2012-09-05 09:36:05 UTC
parent b96717bef154c059b52099b36a3b91308c462934

tests/generated: Let generated tests be wrapped around #ifdefs

Some of the functions we want to test are not always included in the posix
preload library, but depend on some precompiler expression being defined.

This patch adds support for that in the test generator, which will be used in
subsequent patches.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

tests/generated/generate-test +22 -4

diff --git a/tests/generated/generate-test b/tests/generated/generate-test
index 23c9fa4..8d5dae8 100755
--- a/tests/generated/generate-test
+++ b/tests/generated/generate-test
@@ -87,8 +87,21 @@ int main(void) {
 }
 """
 
+TEST_SKIPPED_TMPL = r"""
+int main(void) {
+	printf("$fp: skipping test\n");
+	return 0;
+}
+"""
+
 def generate(options, outfile):
 	outfile.write("/* AUTOGENERATED FILE - DO NOT EDIT */\n\n")
+
+	outfile.write("#include <fiu.h>\n")
+	outfile.write("#include <fiu-control.h>\n")
+	outfile.write("#include <stdio.h>\n")
+	outfile.write("#include <errno.h>\n")
+
 	includes = options.get("include", [])
 	if isinstance(includes, (str, unicode)):
 		includes = includes.split()
@@ -97,10 +110,8 @@ def generate(options, outfile):
 	else:
 		outfile.write("\n\n")
 
-	outfile.write("#include <fiu.h>\n")
-	outfile.write("#include <fiu-control.h>\n")
-	outfile.write("#include <stdio.h>\n")
-	outfile.write("#include <errno.h>\n")
+	if options['ifdef']:
+		outfile.write("#ifdef %s\n" % options['ifdef'])
 
 	if 'errno_on_fail' in options:
 		options['errno_cond'] = \
@@ -115,6 +126,11 @@ def generate(options, outfile):
 	outfile.write(Template(TEST_FAILURE_TMPL).substitute(options))
 	outfile.write(Template(TEST_MAIN_TMPL).substitute(options))
 
+	if options['ifdef']:
+		outfile.write("#else\n")
+		outfile.write(Template(TEST_SKIPPED_TMPL).substitute(options))
+		outfile.write("#endif\n")
+
 def main():
 	parser = argparse.ArgumentParser(
 			description ="Generate C testcases")
@@ -132,6 +148,8 @@ def main():
 		'include': (),
 		'prep': '',
 
+		'ifdef': '',
+
 		# These are C conditions that are always true.
 		'success_cond': '1',
 		'failure_cond': '1',