diff --git a/.gitignore b/.gitignore index 172de23..f54f8cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ datasheets firmware/test/ctypesgen/.svn firmware/test/main.py* +firmware/test/.testcommand *.s#* *.b#* diff --git a/firmware/test/Makefile b/firmware/test/Makefile new file mode 100644 index 0000000..e0ff9aa --- /dev/null +++ b/firmware/test/Makefile @@ -0,0 +1,21 @@ +# +# Makes new test cases +# + +ECHO := echo +SED := sed + +# +# +# +.PHONY: new +new: +ifdef name + @$(ECHO) + @$(ECHO) "Creating $(name)_tc..." + @$(SED) "s/\[template\]/$(name)/g" template/template.h > tc/$(name).h + @$(SED) "s/\[template\]/$(name)/g" template/template.py > tc/$(name).py + @$(ECHO) "Done" +else + @$(ECHO) "Please specify a name for the test case!! Like 'make name=my_tc'" +endif diff --git a/firmware/test/README.md b/firmware/test/README.md index 2076ba1..c01ed2f 100644 --- a/firmware/test/README.md +++ b/firmware/test/README.md @@ -47,6 +47,10 @@ program is then run, and one loop of `tc_main` runs the test case. #### Writing a new test case +``` +From this directory you can just run 'make name=' +``` + * Choose a testcase name `[tc-name]` * Create `tc/[tc-name].py` and `tc/[tc_name].h`. Use a pre-existing test case as a template. * Add `#include [tc-name].h` to the section at the top of `main.c` diff --git a/firmware/test/template/template.h b/firmware/test/template/template.h new file mode 100644 index 0000000..bb80c65 --- /dev/null +++ b/firmware/test/template/template.h @@ -0,0 +1,33 @@ +#ifndef __verification__ +#define __verification__ +#endif + +/****************************//* [template]_tc *//****************************/ +/** + * Write a description of your test case here + */ + +/* Parameters in */ +struct [template]_tc_params { + + /* Input paramters to your test case go here */ + +} [template]_tc_params; +/* Results out */ +struct [template]_tc_results { + + /* Result values should be populated here */ + +} [template]_tc_results; +/* Function */ +__verification__ void [template]_tc(void) { + + /** + * The main body of the test case goes here. + * + * Use the input parameters to run the test case. Populate the + * results structure at the end + */ + + [template]_tc_results.result = 2 * [template]_tc_params.input; +} diff --git a/firmware/test/template/template.py b/firmware/test/template/template.py new file mode 100644 index 0000000..8cf14b4 --- /dev/null +++ b/firmware/test/template/template.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +# ------------------------------------------------------------------------------ +# Imports +# ------------------------------------------------------------------------------ + +import sys +sys.path.append("./test") +import main + +from random import randint + +# ------------------------------------------------------------------------------ +# Test Script +# ------------------------------------------------------------------------------ + +class [template]_tc: + def __init__(self): + self.name = self.__class__.__name__ + self.iterations = 20 + + + def get_test(self): + """Returns some suitable test parameters""" + params = main.struct_[template]_tc_params() + + """ + Assign input parameters here + """ + + return params + + def is_correct(self, params, result, print_info): + """Returns if a result is correct for the given parameters""" + + """ + Compare result and params here, decide sth. + Can use print_info + """ + + return True