From b5d3a663e0cad91bad578664694c0a5ffab0184d Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 5 Jul 2013 21:40:10 -0400 Subject: [PATCH] print: Print the Ocarina version to a file The basic/print.cpp test will write version information to a file using both dprint() and print(). Signed-off-by: Bryan Schumaker --- .gitignore | 1 + include/print.h | 32 ++++++++++++++++++++++++++++++++ include/version.h | 2 +- tests/Sconscript | 15 ++++++++++++++- tests/basic/print-debug.good | 2 ++ tests/basic/print.cpp | 4 +++- tests/basic/print.good | 1 + 7 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 include/print.h create mode 100644 tests/basic/print-debug.good create mode 100644 tests/basic/print.good diff --git a/.gitignore b/.gitignore index 815bcf8a..adc0e912 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.swp *.swo *.pyc +*.run *.test *.tar.gz ocarina.bin diff --git a/include/print.h b/include/print.h new file mode 100644 index 00000000..5631f341 --- /dev/null +++ b/include/print.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2013 Bryan Schumaker. + */ +#ifndef OCARINA_PRINT_H +#define OCARINA_PRINT_H + +#include +#include + +inline void print(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); +} + +#ifdef CONFIG_DEBUG +inline void dprint(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); +} +#else /* CONFIG_DEBUG */ +inline void dprint(const char *fmt, ...) {} +#endif /* CONFIG_DEBUG */ + +#endif /* OCARINA_PRINT_H */ diff --git a/include/version.h b/include/version.h index c4f10938..0bb1e561 100644 --- a/include/version.h +++ b/include/version.h @@ -6,7 +6,7 @@ static inline const char *get_version() { - return "CONFIG_VERSION"; + return CONFIG_VERSION; } #endif /* OCARINA_VERSION_H */ diff --git a/tests/Sconscript b/tests/Sconscript index b5a795e5..586ece69 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -1,9 +1,23 @@ #!/usr/bin/python Import("release", "debug") +def run_test(group, name): + cmd = "tests/%s/%s.test" % (group, name) + out = "tests/%s/%s.run" % (group, name) + good = "tests/%s/%s.good" % (group, name) + test = Command(out, None, + [ "%s > %s" % (cmd, out), + "diff -u %s %s" % (out, good) + ] + ) + return test + def make_test(group, src, name, env): obj = env.StaticObject(name, src) prog = env.Program("%s.test" % name, obj) + test = run_test(group, name) + Depends(test, prog) + Alias("tests", [obj, prog]) Alias("tests/%s" % group, [obj, prog]) Alias("tests/%s/%s" % (group, name), [obj, prog]) @@ -16,6 +30,5 @@ def Test(group, src): Export("Test") - # Read SConscript files basic = SConscript("basic/Sconscript") diff --git a/tests/basic/print-debug.good b/tests/basic/print-debug.good new file mode 100644 index 00000000..d8943d4c --- /dev/null +++ b/tests/basic/print-debug.good @@ -0,0 +1,2 @@ +6.0-debug +6.0-debug diff --git a/tests/basic/print.cpp b/tests/basic/print.cpp index 91d0ccbc..3e9b284f 100644 --- a/tests/basic/print.cpp +++ b/tests/basic/print.cpp @@ -1,10 +1,12 @@ /* * Prints version info to the screen when compiled in debug mode */ - +#include #include int main(int argc, char **argv) { + print("%s\n", get_version()); + dprint("%s\n", get_version()); return 0; } diff --git a/tests/basic/print.good b/tests/basic/print.good new file mode 100644 index 00000000..e0ea36fe --- /dev/null +++ b/tests/basic/print.good @@ -0,0 +1 @@ +6.0