In order to achieve leaner test suite functionality and in the future decouple functionality such as:
mbed-ls is Python module used to detect and list mbed-enabled devices connected to host computer. package will support Windows 7, Ubuntu and MacOS. It will be delivered as redistributable Python module (package) and command line tool.
Currently mbed-ls module is under development but already decoupled mbed-ls functionality is delivered to mbed SDK's test suite.
You will be able for example to use this tool from command line!
$ mbedls
+---------------------+-------------------+-------------------+--------------------------------+
|platform_name |mount_point |serial_port |target_id |
+---------------------+-------------------+-------------------+--------------------------------+
|KL25Z |I: |COM89 |02000203240881BBD9F47C43 |
|NUCLEO_F302R8 |E: |COM34 |07050200623B61125D5EF72A |
+---------------------+-------------------+-------------------+--------------------------------+
New command line switch --auto and --tc are added to workspace_tools/singletest.py script and replace (not completely, you will be still able to use configuration files just because they are more powerful than mbed-ls) existing file based test configuration.
Currently you will execute your automated tests like this:
$ singletest.py -i test_spec.json -M muts_all.json
With mbed-ls tools you will be able to auto-detect all connected to your host devices and just decide which toolchains you want to include.
Below command is replacement for -i and -M combo. Tests will be built using default compiler for each detected mbed-enabled platform.
Note: Now mbed-ls tools will detect devices for you, pair serial ports and disks (mount points) and based on TargetID determine mbed-enabled target generic name.
$ singletest.py --auto
or just for example specify that you want to build tests using default toolchains (per platform) and GCC_ARM for all platforms.
$ singletest.py --auto --tc default,GCC_ARM
New --auto command is compatible with existing command line switches so you can for example:
$ singletest.py --auto --config
MBEDLS: Detecting connected mbed-enabled devices...
MBEDLS: Detected NUCLEO_F302R8, port: COM34, mounted: E:
MBEDLS: Detected KL25Z, port: COM89, mounted: I:
MUTs configuration in auto-detected:
+-------+-------------+---------------+------+-------+
| index | peripherals | mcu | disk | port |
+-------+-------------+---------------+------+-------+
| 1 | | NUCLEO_F302R8 | E: | COM34 |
| 2 | | KL25Z | I: | COM89 |
+-------+-------------+---------------+------+-------+
Test specification in auto-detected:
+---------------+-----+------+
| mcu | ARM | uARM |
+---------------+-----+------+
| KL25Z | Yes | - |
| NUCLEO_F302R8 | - | Yes |
+---------------+-----+------+
-f):$ singletest.py -S -f F302
+---------------+-----------+---------+-----------+--------+--------+-----------+------------+---------------+
| Platform | ARM | uARM | GCC_ARM | GCC_CS | GCC_CR | IAR | GCC_CW_EWL | GCC_CW_NEWLIB |
+---------------+-----------+---------+-----------+--------+--------+-----------+------------+---------------+
| NUCLEO_F302R8 | Supported | Default | Supported | - | - | Supported | - | - |
+---------------+-----------+---------+-----------+--------+--------+-----------+------------+---------------+
*Default - default on-line compiler
*Supported - supported off-line compiler
Total platforms: 1
Total permutations: 4
$ singletest.py --auto --config --tc all
MBEDLS: Detecting connected mbed-enabled devices...
MBEDLS: Detected NUCLEO_F302R8, port: COM34, mounted: E:
MBEDLS: Detected KL25Z, port: COM89, mounted: I:
MUTs configuration in auto-detected:
+-------+-------------+---------------+------+-------+
| index | peripherals | mcu | disk | port |
+-------+-------------+---------------+------+-------+
| 1 | | NUCLEO_F302R8 | E: | COM34 |
| 2 | | KL25Z | I: | COM89 |
+-------+-------------+---------------+------+-------+
Test specification in auto-detected:
+---------------+-----+---------+------------+---------------+-----+------+
| mcu | ARM | GCC_ARM | GCC_CW_EWL | GCC_CW_NEWLIB | IAR | uARM |
+---------------+-----+---------+------------+---------------+-----+------+
| KL25Z | Yes | Yes | Yes# | Yes# | Yes | - |
| NUCLEO_F302R8 | Yes | Yes | -# | -# | Yes | Yes |
+---------------+-----+---------+------------+---------------+-----+------+
Toolchain conflicts:
# Toolchain GCC_CW_EWL path not found: C:/Freescale/CW MCU v10.3/MCU/ARM_GCC_Support/ewl/lib
# Toolchain GCC_CW_NEWLIB path not found: C:/Freescale/CW MCU v10.3/Cross_Tools/arm-none-eabi-gcc-4_6_2/bin
-V to see test printouts in real time, choose test(s) you want to execute with -n option and define your favorite toolchain(s) with --tc:$ singletest.py --auto --tc GCC_ARM -V -n DTCT_1
MBEDLS: Detecting connected mbed-enabled devices...
MBEDLS: Detected NUCLEO_F302R8, port: COM34, mounted: E:
Building library CMSIS (NUCLEO_F302R8, GCC_ARM)
Building library MBED (NUCLEO_F302R8, GCC_ARM)
Building project DETECT (NUCLEO_F302R8, GCC_ARM)
Executing 'python host_test.py -d E: -f "C:\Work\mbed-przemek\build\test\NUCLEO_F302R8\GCC_ARM\DTCT_1\detect.bin" -p COM34 -t 10 -C 1.5 -m NUCLEO_F302R8'
Test::Output::Start
MBED: Instrumentation: "COM34" and disk: "E:"
HOST: Copy image onto target...
HOST: Initialize serial port...
HOST: Reset target...
HOST: Property 'timeout' = '10'
HOST: Property 'host_test_name' = 'detect_auto'
HOST: Property 'description' = 'Simple detect test'
HOST: Property 'test_id' = 'DTCT_1'
HOST: Start test...
{{start}}
HOST: Detecting target name...
MBED: Target 'NUCLEO_F302R8'
HOST: MUT Target name 'NUCLEO_F302R8', expected 'NUCLEO_F302R8'... [OK]
MBED: Test ID 'DTCT_1'
MBED: UUID '04dab79c-a6c8-4bf0-8b1e-3771b4540bb8'
{{success}}
{{end}}
Test::Output::Finish
TargetTest::NUCLEO_F302R8::GCC_ARM::DTCT_1::Simple detect test [OK] in 1.07 of 10 sec
Test summary:
+--------+---------------+-----------+---------+--------------------+--------------------+---------------+-------+
| Result | Target | Toolchain | Test ID | Test Description | Elapsed Time (sec) | Timeout (sec) | Loops |
+--------+---------------+-----------+---------+--------------------+--------------------+---------------+-------+
| OK | NUCLEO_F302R8 | GCC_ARM | DTCT_1 | Simple detect test | 1.07 | 10 | 1/1 |
+--------+---------------+-----------+---------+--------------------+--------------------+---------------+-------+
Result: 1 OK
Completed in 4.33 sec
Structure for host tests and C/C++ test source code changed. In the future tests will be deployed together with corresponding modules. For now mbed SDK tests have to improve. We want to remove dependency on workspace_tools/tests.py test meta-data and move test / test runner handshake inside test source code.
TEST_* are used to notify host test system about prefered host test handler. Now test will decide which host test should handle it, not extra meta-data.#include "mbed.h" #include "test_env.h" int main() { TEST_TIMEOUT(10); TEST_HOSTTEST(detect_auto); TEST_DESCRIPTION(Simple detect test); TEST_START("DTCT_1"); notify_start(); printf("MBED: Target '%s'\r\n", TEST_SUITE_TARGET_NAME); printf("MBED: Test ID '%s'\r\n", TEST_SUITE_TEST_ID); printf("MBED: UUID '%s'\r\n", TEST_SUITE_UUID); TEST_RESULT(true); }
Note, things like:
TEST_TIMEOUT().TEST_DESCRIPTION().TEST_HOSTTEST().TEST_RESULT() macro - if applicable. Host test can decide about test case result in many cases.Colorama is new package dependency added so CLI is now colorful (Hard to say if this is good or bad).
Below sample of new color format:

Solution tested with 8 of mbed-enabled boards. Both test auto-detection for test_env and unit tests using CppUTest works well.
This solution will be tested with greater number of boards soon, so pelase wait for notification in this pool request.
https://github.com/mbedmicro/mbed/pull/900
—
Reply to this email directly or view it on GitHub.![]()
In libraries/tests/mbed/env/test_env.h:
> @@ -22,6 +22,36 @@ void notify_performance_coefficient(const char* measurement_name, const int valu > void notify_performance_coefficient(const char* measurement_name, const unsigned int value); > void notify_performance_coefficient(const char* measurement_name, const double value); > > +// Host test auto-detection API > +void notify_host_test_name(const char *host_test); > +void notify_timeout(int timeout); > +void notify_test_id(const char *test_id); > +void notify_test_description(const char *description); > + > +// Host test auto-detection API > +#define TEST_START(TESTID) notify_test_id(TESTID); notify_start()
I would use prefix with the name of this test env, it's either part of mbed or any other. The other libraries can easily have similar macros TEST_DESCRIPTION or similar.
In libraries/tests/rtos/mbed/mutex/main.cpp:
> @@ -16,8 +16,7 @@
> #define STACK_SIZE DEFAULT_STACK_SIZE
> #endif
>
> -void print_char(char c = '*')
> -{
why are you changing the style? It is not the one which is mostly used in files here
In libraries/tests/rtos/mbed/file/main.cpp:
> for (int i = 0; i < SIZE; i++) {
> data_written[i] = rand() % 0xff;
> fprintf(f, "%c", data_written[i]);
> printf("%02X ", data_written[i]);
> if (i && ((i % 20) == 19))
> - printf("\r\n");
> + printf(NL);
Is NL as new line? Is it a macro? I can't find the macro definition.
Isn't this NL host specific? We should use a newline.
In libraries/tests/rtos/mbed/file/main.cpp:
> for (int i = 0; i < SIZE; i++) {
> data_written[i] = rand() % 0xff;
> fprintf(f, "%c", data_written[i]);
> printf("%02X ", data_written[i]);
> if (i && ((i % 20) == 19))
> - printf("\r\n");
> + printf(NL);
Yes, NL is a macro in test)_env.h file I presume. It is defined like this I think:
#define NL "\n" #define RCNL "\r\n"
In libraries/tests/mbed/env/test_env.h:
> @@ -22,6 +22,36 @@ void notify_performance_coefficient(const char* measurement_name, const int valu > void notify_performance_coefficient(const char* measurement_name, const unsigned int value); > void notify_performance_coefficient(const char* measurement_name, const double value); > > +// Host test auto-detection API > +void notify_host_test_name(const char *host_test); > +void notify_timeout(int timeout); > +void notify_test_id(const char *test_id); > +void notify_test_description(const char *description); > + > +// Host test auto-detection API > +#define TEST_START(TESTID) notify_test_id(TESTID); notify_start()
Yes, you are right, I will change it to something more mbed specific / descriptive.
In libraries/tests/rtos/mbed/mutex/main.cpp:
> @@ -16,8 +16,7 @@
> #define STACK_SIZE DEFAULT_STACK_SIZE
> #endif
>
> -void print_char(char c = '*')
> -{
I do not understand, which style here is the most popular one?
I'm alligning all tests to the same style which is something like this:
void function(int param1, char param2 = '*') { /* FUNCTION BODY */ }
In libraries/tests/rtos/mbed/mutex/main.cpp:
> @@ -16,8 +16,7 @@
> #define STACK_SIZE DEFAULT_STACK_SIZE
> #endif
>
> -void print_char(char c = '*')
> -{
Ok I see.
Merged #900.