1# Unit Tests for FreeRTOS-Plus-TCP library 2This directory is made for the purpose of Unit testing and tries to provide the tools for developing unit tests. To that end, this directory submodules the [CMock](https://github.com/ThrowTheSwitch/CMock) framework (which submodules [Unity](https://github.com/throwtheswitch/unity/tree/cf949f45ca6d172a177b00da2.3.1607b97bc7a7)) and the [FreeRTOS-Kernel](https://github.com/FreeRTOS/FreeRTOS-Kernel/). 3 4## Getting Started 5### Prerequisites 6You can run this on any GNU Make compatible systems. But in case of DOS based systems some tweaking is required with the makefile. 7To compile and run this project successfully, you must have the following: 81. Make (You can check whether you have this by typing `make --version`) 9 - Not found? Try `apt-get install make`. 102. Ruby (You can check whether you have this by typing `ruby --version`) 11 - Not found? Try `apt-get install ruby`. 123. CMake version > 3.13.0 (You can check whether you have this by typing `cmake --version`) 13 - Not found? Try `apt-get install cmake` 14 - Try the `cmake --version` command. If still the version number is >= 3.13.0, skip to (4.) or else, continue. 15 - You will need to get the latest CMake version using curl or wget (or similar command). 16 - Uninstall the current version of CMake using `sudo apt remove --purge --auto-remove cmake`. 17 - Download the 3.13.0 version using `wget https://cmake.org/files/v3.13/cmake-3.13.0.tar.gz`. 18 - Extract the cmake download using `tar -xzvf cmake-3.13.0.tar.gz`. 19 - Go to the extracted folder (`cd cmake-3.13.0`) and run `./bootstrap`. 20 - Run `make -j$(nproc)' and then run `sudo make install`. 21 - Check the version using `cmake --version` command. 224. lcov version 1.14 ( check with --version option ) 23 - 'sudo apt-get install lcov' 245. unifdef version 2.10 ( check with -V option ) 25 - 'sudo apt-get install unifdef' 266. Download the repo and include the submodules using the following commands. 27 - `git clone https://github.com/FreeRTOS/FreeRTOS.git ./FreeRTOS_Dir` 28 - `git submodule update --checkout --init --recursive tools/CMock test/FreeRTOS-Kernel` 29 30### To run the Unit tests: 31Go to the root directory of the FreeRTOS+TCP repo and run the following script: 32~~~ 33#!/bin/bash 34# This script should be run from the root directory of the FreeRTOS+TCP repo. 35 36if [[ ! -d source ]]; then 37 echo "Please run this script from the root directory of the FreeRTOS+TCP repo." 38 exit 1 39fi 40 41UNIT_TEST_DIR="test/unit-test" 42BUILD_DIR="${UNIT_TEST_DIR}/build/" 43 44# Create the build directory using CMake: 45rm -rf ${BUILD_DIR} 46cmake -S ${UNIT_TEST_DIR} -B ${BUILD_DIR} 47 48# Create the executables: 49make -C ${BUILD_DIR} all 50 51pushd ${BUILD_DIR} 52# Run the tests for all units 53ctest -E system --output-on-failure 54popd 55 56# Calculate the coverage 57make -C ${BUILD_DIR} coverage 58lcov --list --rc lcov_branch_coverage=1 ${BUILD_DIR}coverage.info 59~~~ 60 61You should see an output similar to this: 62 63``` 64----------------------- 656 Tests 0 Failures 0 Ignored 66OK 67Capturing coverage data from . 68... <Skipped some lines here for the sake of brevity> 69Overall coverage rate: 70 lines......: 84.8% (56 of 66 lines) 71 functions..: 85.7% (12 of 14 functions) 72 branches...: 50.0% (2 of 4 branches) 73``` 74 75And also: 76 77``` 78Reading tracefile test/unit-test/build/coverage.info 79 |Lines |Functions |Branches 80Filename |Rate Num|Rate Num|Rate Num 81====================================================================== 82[/home/hein/freertos_plus_tcp/] 83FreeRTOS_ARP.c | 100% 238| 100% 14|99.3% 137 84FreeRTOS_DHCP.c |98.7% 314|92.9% 14| 100% 150 85FreeRTOS_Sockets.c | 3.5% 1150| 1.6% 61| 4.2% 722 86FreeRTOS_Stream_Buffer.c | 100% 107| 100% 12| 100% 54 87FreeRTOS_UDP_IP.c | 100% 97| 100% 2| 100% 58 88====================================================================== 89 Total:|41.6% 1906|40.8% 103|38.2% 1121 90``` 91