Functional testing of XC code

Non-technical related questions should go here.
astewart
Junior Member
Posts: 4
Joined: Mon Sep 19, 2016 4:50 pm

Functional testing of XC code

Postby astewart » Fri Sep 23, 2016 8:33 pm

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.
mon2
XCore Expert
Posts: 606
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Postby mon2 » Fri Sep 23, 2016 9:15 pm

peter
XCore Addict
Posts: 206
Joined: Wed Mar 10, 2010 12:46 pm

Postby peter » Mon Sep 26, 2016 8:10 am

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
astewart
Junior Member
Posts: 4
Joined: Mon Sep 19, 2016 4:50 pm

Postby astewart » Mon Sep 26, 2016 2:10 pm

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)

Return to “General Questions”

Who is online

Users browsing this forum: No registered users and 3 guests