FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

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