diff --git a/.gitignore b/.gitignore index 91dd509..43cb270 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,11 @@ /doc/mbusd.8 Makefile *.log +*.pyc +CMakeCache.txt +CMakeFiles +CPackConfig.cmake +CPackSourceConfig.cmake +cmake_install.cmake +.idea +*~ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4c68481..ea59a9b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ --- stages: - build + - test .mbusd_job_template: &mbusd_job_template # Hidden key that defines an anchor image: debian:stable @@ -13,28 +14,44 @@ stages: # create an archive with a name of the current stage and branch name name: "${CI_BUILD_STAGE}_${CI_BUILD_REF_NAME}" untracked: true - expire_in: 12 mos + expire_in: 1 mos paths: - - src/mbusd + - output.dir/mbusd - doc/mbusd.8 +build:linux_armhf: + <<: *mbusd_job_template + stage: build + script: + - mkdir output.dir/ + - cd output.dir + - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../arm_linux_gnueabihf.cmake ../ + - make build:linux_x86: <<: *mbusd_job_template stage: build script: - - "autoreconf -i" - - "./configure" - - "make" + - mkdir output.dir/ + - cd output.dir + - cmake -D CMAKE_BUILD_TYPE=Debug ../ + - make +test_x86: + stage: test + #https://forum.gitlab.com/t/testing-copy-yaml-file-to-build-folder/8309 + before_script: + - apt-get install --fix-missing -y python3-dev python3-pip python3-setuptools socat + - python -m pip install pymodbus service_identity -build:deb_armhf: - <<: *mbusd_job_template - stage: build - - script: - - "autoreconf -i" - - "./configure --host=arm-linux-gnueabihf -prefix=${CSTOOL_DIR}/linux_arm_tool" - - "make" - + dependencies: + - build:linux_x86 + script: + - mkdir -p output.dir/ + - cd output.dir + - cmake -DTESTS=True ../ + - make VERBOSE=1 + + # execute all tests + - ./test_* diff --git a/CMakeLists.txt b/CMakeLists.txt index e18c2d5..2d59bdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,3 +72,8 @@ add_executable(mbusd ${mbusd_SOURCES}) # add make install capabilites install(TARGETS mbusd DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}/) install(FILES doc/mbusd.8 DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man8/) + +option(TESTS "Enable unittests" OFF) +if(TESTS) + add_executable(test_basic tests/test_basics.c) +endif() \ No newline at end of file diff --git a/arm_linux_gnueabihf.cmake b/arm_linux_gnueabihf.cmake new file mode 100644 index 0000000..94a5d0c --- /dev/null +++ b/arm_linux_gnueabihf.cmake @@ -0,0 +1,12 @@ +# this one is important +SET(CMAKE_SYSTEM_NAME Linux) + +# specify the cross compiler +SET(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc) +## for c++ support `install g++-arm-linux-gnueabihf` +#SET(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) \ No newline at end of file diff --git a/tests/test_basics.c b/tests/test_basics.c new file mode 100644 index 0000000..76090b8 --- /dev/null +++ b/tests/test_basics.c @@ -0,0 +1,31 @@ +#include "greatest/greatest.h" + +/* A test runs various assertions, then calls PASS(), FAIL(), or SKIP(). */ +TEST x_should_equal_1(void) { + int x = 1; + ASSERT_EQ(1, x); /* default message */ + ASSERT_EQm("yikes, x doesn't equal 1", 1, x); /* custom message */ + /* printf expected and actual values as "%d" if they differ */ + ASSERT_EQ_FMT(1, x, "%d"); + PASS(); +} + +/* Suites can group multiple tests with common setup. */ +SUITE(the_suite) { + RUN_TEST(x_should_equal_1); +} + +/* Add definitions that need to be in the test runner's main file. */ +GREATEST_MAIN_DEFS(); + +int main(int argc, char **argv) { + GREATEST_MAIN_BEGIN(); /* command-line options, initialization. */ + + /* Individual tests can be run directly. */ + /* RUN_TEST(x_should_equal_1); */ + + /* Tests can also be gathered into test suites. */ + RUN_SUITE(the_suite); + + GREATEST_MAIN_END(); /* display results */ +} \ No newline at end of file