Page 1 of 1

Functional testing of XC code

Posted: Fri Sep 23, 2016 8:33 pm
by astewart
So, I've noticed that most (all?) of the libraries on the XMOS github page contain a tests folder with code for testing the functionality of the library code. See, for example, lib_logging (just one test).

However, I haven't been able to find any documentation about the recommended way to create and execute functional tests. The library tests are apparently python-based, but when I try to run the runtests.py script (after adding the XMOS python library in my xTimeComposer install to my python path), and I get an error:

Code: Select all

KeyError: XCC_EXEC_PREFIX
Are there some environment variables or something that I need to set up before I can run these?

Documentation on how to execute the tests, or on the xmostest python module would be appreciated.

Re: Functional testing of XC code

Posted: Fri Sep 23, 2016 9:15 pm
by mon2

Re: Functional testing of XC code

Posted: Mon Sep 26, 2016 8:10 am
by peter
You need to have your tools on the path, so the easiest is to launch an xTIMEcomposer command prompt on Windows or to source the SetupEnv.sh on Linux/OSX. You should then be able to run:

Code: Select all

$ cd lib_logging/tests
$ python runtests.py
I get the following if I do that:

Code: Select all

$ python runtests.py 
Building debug_printf_test/bin/debug_printf_test.xe
Build complete.
Hello World
An int: -5
An int: -5
An unsigned int: 5
An unsigned int: 5
A string: foo
A string: FOO
A hexadecimal int: 0xABCD
A hexadecimal int: 0xABCD
A char: x
A char: X
A pointer: 0
A pointer: 0
A hexadecimal int: 0xABCD
A hexadecimal int: 0x1234
lib_logging::simple_tests::basic_functionality_test PASS

------------
TEST SUMMARY
------------
lib_logging::simple_tests::basic_functionality_test PASS
----------
1/1 PASSED
----------
The XMOS test infrastructure is a very powerful way of testing applications against the simulator or hardware. Unfortunately it is not well documented at the moment so the best thing to do is to copy existing examples. lib_ethernet has some good tests which include a MII/RGMII PHY model in python.

Regards,

Peter

Re: Functional testing of XC code

Posted: Mon Sep 26, 2016 2:10 pm
by astewart
Thanks for the help. I got it working.

It somehow hadn't occurred to me that I should be running the script from within the xmos command prompt.

Two other things I'd like to mention for anyone else that stumbles across this in the future
  • The test script relies on external DLLs being loaded -- make sure you're using a 32-bit version of python if you have a 32-bit version of xTimeComposer installed
  • If running in Windows, you'll likely need to modify runtests.py to get it to work. The accepted fix in this StackOverflow post worked for me. (wrapped script code in a main() function and made a guarded call to main() in runtests.py)