mirror of
https://github.com/3cky/mbusd.git
synced 2024-12-23 16:27:33 +01:00
compiling test environment with cmake
This commit is contained in:
parent
6b6baeebb1
commit
3db942a753
8
.gitignore
vendored
8
.gitignore
vendored
@ -9,3 +9,11 @@
|
||||
/doc/mbusd.8
|
||||
Makefile
|
||||
*.log
|
||||
*.pyc
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CPackConfig.cmake
|
||||
CPackSourceConfig.cmake
|
||||
cmake_install.cmake
|
||||
.idea
|
||||
*~
|
||||
|
@ -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_*
|
||||
|
@ -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()
|
12
arm_linux_gnueabihf.cmake
Normal file
12
arm_linux_gnueabihf.cmake
Normal file
@ -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)
|
31
tests/test_basics.c
Normal file
31
tests/test_basics.c
Normal file
@ -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 */
|
||||
}
|
Loading…
Reference in New Issue
Block a user