A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:a7a43371b306 1 # PAL Test Guide
ram54288 0:a7a43371b306 2 ## Environment Setup
ram54288 0:a7a43371b306 3 Python 2.7.11
ram54288 0:a7a43371b306 4 If you cannot find Python 2.7.11 for your linux you can get it here [Python 2.7.11](https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes-python2.7)
ram54288 0:a7a43371b306 5 Install the needed Python modules on Windows like this:
ram54288 0:a7a43371b306 6 ```
ram54288 0:a7a43371b306 7 python -m pip install tabulate
ram54288 0:a7a43371b306 8 python -m pip install pyserial
ram54288 0:a7a43371b306 9 python -m pip install -U mbed-ls
ram54288 0:a7a43371b306 10 python -m pip install shell
ram54288 0:a7a43371b306 11 python -m pip install pypiwin32
ram54288 0:a7a43371b306 12 ```
ram54288 0:a7a43371b306 13 On Linux you install the same modules like this:
ram54288 0:a7a43371b306 14 ```
ram54288 0:a7a43371b306 15 sudo pip install <module>
ram54288 0:a7a43371b306 16 ```
ram54288 0:a7a43371b306 17
ram54288 0:a7a43371b306 18 ##Test Code files
ram54288 0:a7a43371b306 19 Each API has three files under Test/Unitest or Test/Conformance:
ram54288 0:a7a43371b306 20
ram54288 0:a7a43371b306 21 * **pal_socket_test.c** Contains the test code in the form of functions. One function per test.
ram54288 0:a7a43371b306 22 * **pal_ socket _test_runner.c** Runs the test functions defined above.
ram54288 0:a7a43371b306 23 * **pal_ socket _test_main_mbedos.c** Main application that runs all the tests. May also have test specific initializations for the given target platform.
ram54288 0:a7a43371b306 24
ram54288 0:a7a43371b306 25 Each API can also have a common utilities file under Test/Common
ram54288 0:a7a43371b306 26 **pal_socket_test_utils.c/.h** Utility functions that can be used in various pal_socket test apps.
ram54288 0:a7a43371b306 27 **pal_socket_test.c**
ram54288 0:a7a43371b306 28 Contains tests of the form:
ram54288 0:a7a43371b306 29
ram54288 0:a7a43371b306 30 ```
ram54288 0:a7a43371b306 31 #include "pal_socket.h"
ram54288 0:a7a43371b306 32 #include "unity.h"
ram54288 0:a7a43371b306 33 #include "unity_fixture.h"
ram54288 0:a7a43371b306 34
ram54288 0:a7a43371b306 35 TEST(pal_socket, FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue)
ram54288 0:a7a43371b306 36 {
ram54288 0:a7a43371b306 37 //This should be true because setUp set this up for us before this test
ram54288 0:a7a43371b306 38 TEST_ASSERT_EQUAL_HEX(0x5a5a, FunctionWhichReturnsLocalVariable());
ram54288 0:a7a43371b306 39
ram54288 0:a7a43371b306 40 //This should be true because we can still change our answer
ram54288 0:a7a43371b306 41 Counter = 0x1234;
ram54288 0:a7a43371b306 42 TEST_ASSERT_EQUAL_HEX(0x1234, FunctionWhichReturnsLocalVariable());
ram54288 0:a7a43371b306 43 }
ram54288 0:a7a43371b306 44 ```
ram54288 0:a7a43371b306 45 **pal_ socket _test_runner.c**
ram54288 0:a7a43371b306 46 Looks like this:
ram54288 0:a7a43371b306 47 ```
ram54288 0:a7a43371b306 48 #include "unity.h"
ram54288 0:a7a43371b306 49 #include "unity_fixture.h" // pal Socket API tests
ram54288 0:a7a43371b306 50
ram54288 0:a7a43371b306 51 TEST_GROUP_RUNNER(pal_socket)
ram54288 0:a7a43371b306 52 {
ram54288 0:a7a43371b306 53 #if (PAL_INCLUDE || FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode)
ram54288 0:a7a43371b306 54 RUN_TEST_CASE(pal_socket, FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode);
ram54288 0:a7a43371b306 55 #endif
ram54288 0:a7a43371b306 56 #if (PAL_INCLUDE || FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken)
ram54288 0:a7a43371b306 57 RUN_TEST_CASE(pal_socket, FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken);
ram54288 0:a7a43371b306 58 #endif
ram54288 0:a7a43371b306 59 #if (PAL_INCLUDE || FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue)
ram54288 0:a7a43371b306 60 RUN_TEST_CASE(pal_socket, FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue);
ram54288 0:a7a43371b306 61 #endif
ram54288 0:a7a43371b306 62 #if (PAL_INCLUDE || FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain)
ram54288 0:a7a43371b306 63 RUN_TEST_CASE(pal_socket, FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain);
ram54288 0:a7a43371b306 64 #endif
ram54288 0:a7a43371b306 65 #if (PAL_INCLUDE || FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed)
ram54288 0:a7a43371b306 66 RUN_TEST_CASE(pal_socket, FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed);
ram54288 0:a7a43371b306 67 #endif}
ram54288 0:a7a43371b306 68 ```
ram54288 0:a7a43371b306 69
ram54288 0:a7a43371b306 70
ram54288 0:a7a43371b306 71 **pal_ socket _test_main_mbedos.c**
ram54288 0:a7a43371b306 72 This can vary a lot from platform to platform and test to test, but will contain lines like the following to run the tests:
ram54288 0:a7a43371b306 73 ```
ram54288 0:a7a43371b306 74 extern "C" int UnityMain(int argc, const char* argv[], void (*runAllTests)(void));
ram54288 0:a7a43371b306 75 extern "C" void TEST_pal_socket_GROUP_RUNNER(void);
ram54288 0:a7a43371b306 76
ram54288 0:a7a43371b306 77 // Run a group of tests
ram54288 0:a7a43371b306 78 UnityMain(0, argv, TEST_pal_socket_GROUP_RUNNER);
ram54288 0:a7a43371b306 79 ```
ram54288 0:a7a43371b306 80
ram54288 0:a7a43371b306 81
ram54288 0:a7a43371b306 82 ## Test makefile framework
ram54288 0:a7a43371b306 83 **makefile** – Master make file. It has an entry for each platform target. Includes all_tests.mk.
ram54288 0:a7a43371b306 84 Configuration specific defines are declared as follows and converted to compilation defines on the compilation command line.
ram54288 0:a7a43371b306 85 **TARGET_CONFIGURATION_DEFINES:= HAS_RTOS HAS_FS**
ram54288 0:a7a43371b306 86 They can be also be used to as conditionals in the make file as shown in all_tests.mk
ram54288 0:a7a43371b306 87 ```
ram54288 0:a7a43371b306 88 include make_platform.mk
ram54288 0:a7a43371b306 89
ram54288 0:a7a43371b306 90
ram54288 0:a7a43371b306 91 .PHONY: all clean check
ram54288 0:a7a43371b306 92
ram54288 0:a7a43371b306 93 #====================================================
ram54288 0:a7a43371b306 94 # Platform mbed-os
ram54288 0:a7a43371b306 95 TARGET_PLATFORM:=mbedosClassic
ram54288 0:a7a43371b306 96 TARGET_CONFIGURATION_DEFINES:= HAS_RTOS
ram54288 0:a7a43371b306 97 all: mbedosClassic_all
ram54288 0:a7a43371b306 98 check: mbedosClassic_check
ram54288 0:a7a43371b306 99 clean: mbedosClassic_clean
ram54288 0:a7a43371b306 100 include all_tests.mk
ram54288 0:a7a43371b306 101 #====================================================
ram54288 0:a7a43371b306 102 # Platform morpheus
ram54288 0:a7a43371b306 103 TARGET_PLATFORM:=mbedOS
ram54288 0:a7a43371b306 104 TARGET_CONFIGURATION_DEFINES:= HAS_RTOS
ram54288 0:a7a43371b306 105 all: mbedOS_all
ram54288 0:a7a43371b306 106 check: mbedOS_check
ram54288 0:a7a43371b306 107 clean: mbedOS_clean
ram54288 0:a7a43371b306 108 include all_tests.mk
ram54288 0:a7a43371b306 109 #====================================================
ram54288 0:a7a43371b306 110 ```
ram54288 0:a7a43371b306 111 **make_platform.mk** – Detects the make platform (Windows, Linux) and sets various definitions accordingly. These are referred to by other make files in order to keep them platform independent.
ram54288 0:a7a43371b306 112 **all_tests.mk** – contains an entry for each test application to be built. Included by all target platform make files. It looks like this:
ram54288 0:a7a43371b306 113 ```
ram54288 0:a7a43371b306 114 #====================================================
ram54288 0:a7a43371b306 115 PROJECT=pal_socket
ram54288 0:a7a43371b306 116 TYPE=Unity
ram54288 0:a7a43371b306 117
ram54288 0:a7a43371b306 118 $(PROJECT)_ADDITIONAL_ SOURCES:=
ram54288 0:a7a43371b306 119
ram54288 0:a7a43371b306 120 include BUILD_TEST.mk
ram54288 0:a7a43371b306 121 #====================================================
ram54288 0:a7a43371b306 122 ifeq ($(findstring HAS_RTOS,$(TARGET_CONFIGURATION_DEFINES)),HAS_RTOS)
ram54288 0:a7a43371b306 123 PROJECT=pal_rtos
ram54288 0:a7a43371b306 124 TYPE=Unitest
ram54288 0:a7a43371b306 125
ram54288 0:a7a43371b306 126 $(PROJECT)_ADDITIONAL_SOURCES:=Source/PAL-Impl/Modules/RTOS/$(PROJECT).c \
ram54288 0:a7a43371b306 127 Source/PAL-Impl/Modules/RTOS/$(PROJECT)_static_definitions_sample.c \
ram54288 0:a7a43371b306 128 Source/Port/Reference-Impl/mbedOS/pal_plat_rtos.c
ram54288 0:a7a43371b306 129
ram54288 0:a7a43371b306 130
ram54288 0:a7a43371b306 131 include BUILD_TEST_$(TARGET_PLATFORM).mk
ram54288 0:a7a43371b306 132 endif
ram54288 0:a7a43371b306 133 #====================================================
ram54288 0:a7a43371b306 134 ```
ram54288 0:a7a43371b306 135 **BUILD_TEST_BUILD_TEST_mbedOS.mk, BUILD_TEST_FreeRTOS.mk** – Target platform specific make definitions and rules. Defines targets for building the tests. Included for each test that is to be built.
ram54288 0:a7a43371b306 136 ##Usage:
ram54288 0:a7a43371b306 137 ###Make all tests for all platforms:
ram54288 0:a7a43371b306 138 **make**
ram54288 0:a7a43371b306 139 or make all tests for a specific platform:
ram54288 0:a7a43371b306 140 **make mbedOS_all**
ram54288 0:a7a43371b306 141 **make FreeRTOS_all**
ram54288 0:a7a43371b306 142
ram54288 0:a7a43371b306 143 ### To make and run one set of tests:
ram54288 0:a7a43371b306 144 **make mbedOS_pal_socket**
ram54288 0:a7a43371b306 145
ram54288 0:a7a43371b306 146 ### To make and run only one test from a set:
ram54288 0:a7a43371b306 147 **make mbedOS_pal_socket** PAL_TEST=”FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode”
ram54288 0:a7a43371b306 148 To make a binary that just runs two tests from a set:
ram54288 0:a7a43371b306 149 **make mbedOS_pal_socket PAL_TEST=”FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken”**
ram54288 0:a7a43371b306 150 Note: If you change the argument PAL_TEST, then you will need to force a rebuild with –B.
ram54288 0:a7a43371b306 151
ram54288 0:a7a43371b306 152 ### To run all tests:
ram54288 0:a7a43371b306 153 **make mbedOS_check**
ram54288 0:a7a43371b306 154 ### Run a specific test:
ram54288 0:a7a43371b306 155 **make mbedOS_check_pal_socket**
ram54288 0:a7a43371b306 156
ram54288 0:a7a43371b306 157 ## Eclipse
ram54288 0:a7a43371b306 158 It is possible to use the Build command from eclipse.
ram54288 0:a7a43371b306 159 First set it up to run make as follows. Note that the build directory points to Test:
ram54288 0:a7a43371b306 160
ram54288 0:a7a43371b306 161 ![ARMGCC_DIR](eclipseBuildDialog.png)
ram54288 0:a7a43371b306 162
ram54288 0:a7a43371b306 163 You can control which target you build in the next tab by changing all and clean.
ram54288 0:a7a43371b306 164
ram54288 0:a7a43371b306 165 ![ARMGCC_DIR](eclipseBuildDialog2.png)
ram54288 0:a7a43371b306 166
ram54288 0:a7a43371b306 167
ram54288 0:a7a43371b306 168