Hi,
I thought I’d investigate writing some unit tests.
I’ve tried to follow the instructions here Unit testing and here README.md.
Unfortunately I haven’t got very far and the build fails when I do mbed test --unittests
and there seems to be something wrong with mbed_retarget.h
../mbed-os/UNITTESTS/target_h/platform/mbed_retarget.h:370:5: error: 'nlink_t' does not name a type
370 | nlink_t st_nlink; ///< Number of links to file
I’m hoping this is a school boy error and and someone will be able to set me straight quickly!
Thanks,
Matt
Full output (I’ve replaced the full paths with ‘…’):
..>mbed test --unittests
[mbed] Working path ".." (library)
[mbed] Program path ".."
#####################
Mbed OS unit testing:
#####################
Steps:
[AUTO] Prepare build directory
- Clean: False
- Directory: ..\UNITTESTS\buffers
[SET] Build unit tests
- Debug: False
- CMake generator: MinGW Makefiles
- Make program: mingw32-make
[SET] Run unit tests
- Filter: None
-- Configuring done
-- Generating done
-- Build files have been written to: ../UNITTESTS/buffers/googletest-download
mingw32-make[1]: Entering directory '../UNITTESTS/buffers/googletest-download'
mingw32-make[2]: Entering directory '../UNITTESTS/buffers/googletest-download'
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers/googletest-download'
mingw32-make[2]: Entering directory '../UNITTESTS/buffers/googletest-download'
[ 11%] Performing update step for 'googletest'
[ 22%] No configure step for 'googletest'
[ 33%] No build step for 'googletest'
[ 44%] No install step for 'googletest'
[ 55%] No test step for 'googletest'
[ 66%] Completed 'googletest'
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers/googletest-download'
[100%] Built target googletest
mingw32-make[1]: Leaving directory '../UNITTESTS/buffers/googletest-download'
-- Configuring done
-- Generating done
-- Build files have been written to: ../UNITTESTS/buffers
mingw32-make[1]: Entering directory '../UNITTESTS/buffers'
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
[ 0%] Building CXX object CMakeFiles/platform-ATCmdParser.MbedOS.dir/22b12b313035f56166602402cee21388/usb-device/mbed-os/platform/source/ATCmdParser.cpp.obj
[ 0%] Built target features-cellular-framework-common-util.MbedOS
[ 0%] Building CXX object CMakeFiles/drivers-Watchdog.MbedOS.dir/66fc3341b080d3ab5bcae61b419d8fc7/stm32-usb-investigation/usb-device/mbed-os/drivers/source/Watchdog.cpp.obj
[ 0%] Built target gtest
[ 0%] Built target features-lorawan-loraphy.MbedOS
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
In file included from ../mbed-os/platform/mbed_error.h:21,
from ../mbed-os/drivers/Watchdog.h:23,
from ..\mbed-os\drivers\source\Watchdog.cpp:19:
../mbed-os/UNITTESTS/target_h/platform/mbed_retarget.h:370:5: error: 'nlink_t' does not name a type
370 | nlink_t st_nlink; ///< Number of links to file
| ^~~~~~~
../mbed-os/UNITTESTS/target_h/platform/mbed_retarget.h:372:5: error: 'uid_t' does not name a type; did you mean 'pid_t'?
372 | uid_t st_uid; ///< User ID
| ^~~~~
| pid_t
../mbed-os/UNITTESTS/target_h/platform/mbed_retarget.h:373:5: error: 'gid_t' does not name a type; did you mean 'pid_t'?
373 | gid_t st_gid; ///< Group ID
| ^~~~~
| pid_t
mingw32-make[2]: *** [CMakeFiles\drivers-Watchdog.MbedOS.dir\build.make:63: CMakeFiles/drivers-Watchdog.MbedOS.dir/66fc3341b080d3ab5bcae61b419d8fc7/stm32-usb-investigation/usb-device/mbed-os/drivers/source/Watchdog.cpp.obj] Error 1
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
mingw32-make[1]: *** [CMakeFiles\Makefile2:1837: CMakeFiles/drivers-Watchdog.MbedOS.dir/all] Error 2
mingw32-make[1]: *** Waiting for unfinished jobs....
Scanning dependencies of target features-storage-blockdevice-HeapBlockDevice.MbedOS
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
[ 1%] Building CXX object CMakeFiles/features-storage-blockdevice-HeapBlockDevice.MbedOS.dir/edf9d944f6fd61303e13957fd7445cce/storage/blockdevice/HeapBlockDevice.cpp.obj
[ 0%] Building C object CMakeFiles/features-storage-blockdevice-HeapBlockDevice.MbedOS.dir/stubs/mbed_atomic_stub.c.obj
Scanning dependencies of target features-lorawan-loraphyeu868.MbedOS
In file included from ../mbed-os/UNITTESTS/target_h/platform/platform.h:26,
from ../mbed-os/platform/FileHandle.h:25,
from ../mbed-os/platform/ATCmdParser.h:27,
from ..\mbed-os\platform\source\ATCmdParser.cpp:22:
../mbed-os/UNITTESTS/target_h/platform/mbed_retarget.h:370:5: error: 'nlink_t' does not name a type
370 | nlink_t st_nlink; ///< Number of links to file
| ^~~~~~~
../mbed-os/UNITTESTS/target_h/platform/mbed_retarget.h:372:5: error: 'uid_t' does not name a type; did you mean 'pid_t'?
372 | uid_t st_uid; ///< User ID
| ^~~~~
| pid_t
../mbed-os/UNITTESTS/target_h/platform/mbed_retarget.h:373:5: error: 'gid_t' does not name a type; did you mean 'pid_t'?
373 | gid_t st_gid; ///< Group ID
| ^~~~~
| pid_t
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
Scanning dependencies of target features-lorawan-loramacchannelplan.MbedOS
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
mingw32-make[2]: *** [CMakeFiles\platform-ATCmdParser.MbedOS.dir\build.make:63: CMakeFiles/platform-ATCmdParser.MbedOS.dir/22b12b313035f56166602402cee21388/usb-device/mbed-os/platform/source/ATCmdParser.cpp.obj] Error 1
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
[ 1%] Building CXX object CMakeFiles/features-lorawan-loraphyeu868.MbedOS.dir/d93a89a2c15e25de8529917c1c42e782/mbed-os/features/lorawan/lorastack/phy/LoRaPHYEU868.cpp.obj
mingw32-make[1]: *** [CMakeFiles\Makefile2:676: CMakeFiles/platform-ATCmdParser.MbedOS.dir/all] Error 2
mingw32-make[2]: Entering directory '../UNITTESTS/buffers'
[ 1%] Building CXX object CMakeFiles/features-storage-blockdevice-HeapBlockDevice.MbedOS.dir/stubs/mbed_assert_stub.cpp.obj
[ 1%] Building CXX object CMakeFiles/features-lorawan-loramacchannelplan.MbedOS.dir/c931584e064ca7bbb0a91a10982a6e2f/features/lorawan/lorastack/mac/LoRaMacChannelPlan.cpp.obj
[ 1%] Linking CXX static library libfeatures-storage-blockdevice-HeapBlockDevice.MbedOS.a
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
[ 1%] Built target features-storage-blockdevice-HeapBlockDevice.MbedOS
[ 2%] Linking CXX static library libfeatures-lorawan-loraphyeu868.MbedOS.a
[ 2%] Linking CXX static library libfeatures-lorawan-loramacchannelplan.MbedOS.a
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
[ 2%] Built target features-lorawan-loraphyeu868.MbedOS
mingw32-make[2]: Leaving directory '../UNITTESTS/buffers'
[ 2%] Built target features-lorawan-loramacchannelplan.MbedOS
mingw32-make[1]: Leaving directory '../UNITTESTS/buffers'
mingw32-make: *** [Makefile:140: all] Error 2
Building unit tests failed.
[mbed] ERROR: "..\appdata\local\programs\python\python38\python.exe" returned error.
Code: 2
Path: ".."
Command: "..\appdata\local\programs\python\python38\python.exe ..\mbed-os\UNITTESTS\mbed_unittest.py --build UNITTESTS\buffers"
Tip: You could retry the last command with "-v" flag for verbose output
-
Tool versions:
>cmake --version
cmake version 3.16.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
>python --version
Python 3.8.3
>pip --version
pip 20.2.1 from c:\users\matthewb\appdata\local\programs\python\python38\lib\site-packages\pip (python 3.8)
>mbed --version
1.10.2
>g++ --version
g++ (Rev3, Built by MSYS2 project) 10.1.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I tried changing the path so that Python 2.7 and mingw32 were found but it made no difference:
>python --version
Python 2.7.16
>g++ --version
g++ (MinGW.org GCC-8.2.0-5) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.