diff --git a/.gitignore b/.gitignore index 2d195a8..ff4efa3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ third-party/concurrentqueue/tests *.wav *.orig examples/csharp/bin -examples/csharp/obj \ No newline at end of file +examples/csharp/obj +test/system \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 27f83fa..1d01c64 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,7 +3,8 @@ variables: stages: - build - - test + - unit_test + - hardware_test #------------------------------------------------------------------------------- # Windows @@ -21,10 +22,10 @@ build windows/x64: tags: - icsneo-windows -test windows/x64: - stage: test +unit_test windows/x64: + stage: unit_test script: - - build\libicsneo-tests.exe + - build\libicsneo-unit-tests.exe dependencies: - build windows/x64 needs: @@ -45,10 +46,10 @@ build windows/x86: tags: - icsneo-windows -test windows/x86: - stage: test +unit_test windows/x86: + stage: unit_test script: - - build\libicsneo-tests.exe + - build\libicsneo-unit-tests.exe dependencies: - build windows/x86 needs: @@ -66,7 +67,7 @@ test windows/x86: script: - apt update -y - apt upgrade -y - - apt install -y g++ ninja-build cmake libusb-1.0-0-dev libpcap-dev + - apt install -y g++ ninja-build cmake libusb-1.0-0-dev libpcap-dev git - sh ci/build-posix.sh artifacts: when: always @@ -77,12 +78,12 @@ test windows/x86: - linux-build .test_linux_ubuntu_gcc: &test_linux_ubuntu_gcc - stage: test + stage: unit_test script: - apt update -y - apt upgrade -y - apt install -y libusb-1.0-0-dev libpcap-dev - - build/libicsneo-tests + - build/libicsneo-unit-tests tags: - linux-build timeout: 5m @@ -92,7 +93,7 @@ test windows/x86: script: - apt update -y - apt upgrade -y - - apt install -y clang lld ninja-build cmake libusb-1.0-0-dev libpcap-dev + - apt install -y clang lld ninja-build cmake libusb-1.0-0-dev libpcap-dev git - CC=clang CXX=clang++ LDFLAGS=-fuse-ld=lld sh ci/build-posix.sh artifacts: when: always @@ -103,12 +104,12 @@ test windows/x86: - linux-build .test_linux_ubuntu_clang: &test_linux_ubuntu_clang - stage: test + stage: unit_test script: - apt update -y - apt upgrade -y - apt install -y libusb-1.0-0-dev libpcap-dev - - build/libicsneo-tests + - build/libicsneo-unit-tests tags: - linux-build timeout: 5m @@ -117,7 +118,7 @@ build linux/ubuntu/2004/amd64/gcc: <<: *build_linux_ubuntu_gcc image: ubuntu:20.04 -test linux/ubuntu/2004/amd64/gcc: +unit_test linux/ubuntu/2004/amd64/gcc: <<: *test_linux_ubuntu_gcc image: ubuntu:20.04 dependencies: @@ -129,7 +130,7 @@ build linux/ubuntu/2004/amd64/clang: <<: *build_linux_ubuntu_clang image: ubuntu:20.04 -test linux/ubuntu/2004/amd64/clang: +unit_test linux/ubuntu/2004/amd64/clang: <<: *test_linux_ubuntu_clang image: ubuntu:20.04 dependencies: @@ -141,7 +142,7 @@ build linux/ubuntu/2204/amd64/gcc: <<: *build_linux_ubuntu_gcc image: ubuntu:22.04 -test linux/ubuntu/2204/amd64/gcc: +unit_test linux/ubuntu/2204/amd64/gcc: <<: *test_linux_ubuntu_gcc image: ubuntu:22.04 dependencies: @@ -153,7 +154,7 @@ build linux/ubuntu/2204/amd64/clang: <<: *build_linux_ubuntu_clang image: ubuntu:22.04 -test linux/ubuntu/2204/amd64/clang: +unit_test linux/ubuntu/2204/amd64/clang: <<: *test_linux_ubuntu_clang image: ubuntu:22.04 dependencies: @@ -174,7 +175,7 @@ test linux/ubuntu/2204/amd64/clang: - echo max_parallel_downloads=10 >>/etc/dnf/dnf.conf - echo fastestmirror=True >>/etc/dnf/dnf.conf - dnf upgrade -y - - dnf install -y g++ libpcap-devel cmake ninja-build libusb1-devel + - dnf install -y g++ libpcap-devel cmake ninja-build libusb1-devel git - sh ci/build-posix.sh artifacts: when: always @@ -185,7 +186,7 @@ test linux/ubuntu/2204/amd64/clang: - linux-build .test_linux_fedora_gcc: &test_linux_fedora_gcc - stage: test + stage: unit_test cache: paths: - /var/cache/dnf @@ -194,7 +195,7 @@ test linux/ubuntu/2204/amd64/clang: - echo fastestmirror=True >>/etc/dnf/dnf.conf - dnf upgrade -y - dnf install -y libpcap-devel libusb1-devel - - build/libicsneo-tests + - build/libicsneo-unit-tests tags: - linux-build timeout: 5m @@ -208,7 +209,7 @@ test linux/ubuntu/2204/amd64/clang: - echo max_parallel_downloads=10 >>/etc/dnf/dnf.conf - echo fastestmirror=True >>/etc/dnf/dnf.conf - dnf upgrade -y - - dnf install -y clang lld libpcap-devel cmake ninja-build libusb1-devel + - dnf install -y clang lld libpcap-devel cmake ninja-build libusb1-devel git - CC=clang CXX=clang++ LDFLAGS=-fuse-ld=lld sh ci/build-posix.sh artifacts: when: always @@ -219,7 +220,7 @@ test linux/ubuntu/2204/amd64/clang: - linux-build .test_linux_fedora_clang: &test_linux_fedora_clang - stage: test + stage: unit_test cache: paths: - /var/cache/dnf @@ -228,7 +229,7 @@ test linux/ubuntu/2204/amd64/clang: - echo fastestmirror=True >>/etc/dnf/dnf.conf - dnf upgrade -y - dnf install -y libpcap-devel libusb1-devel - - build/libicsneo-tests + - build/libicsneo-unit-tests tags: - linux-build timeout: 5m @@ -237,7 +238,7 @@ build linux/fedora/37/amd64/gcc: <<: *build_linux_fedora_gcc image: fedora:37 -test linux/fedora/37/amd64/gcc: +unit_test linux/fedora/37/amd64/gcc: <<: *test_linux_fedora_gcc image: fedora:37 dependencies: @@ -249,7 +250,7 @@ build linux/fedora/37/amd64/clang: <<: *build_linux_fedora_clang image: fedora:37 -test linux/fedora/37/amd64/clang: +unit_test linux/fedora/37/amd64/clang: <<: *test_linux_fedora_clang image: fedora:37 dependencies: @@ -261,7 +262,7 @@ build linux/fedora/38/amd64/gcc: <<: *build_linux_fedora_gcc image: fedora:38 -test linux/fedora/38/amd64/gcc: +unit_test linux/fedora/38/amd64/gcc: <<: *test_linux_fedora_gcc image: fedora:38 dependencies: @@ -273,7 +274,7 @@ build linux/fedora/38/amd64/clang: <<: *build_linux_fedora_clang image: fedora:38 -test linux/fedora/38/amd64/clang: +unit_test linux/fedora/38/amd64/clang: <<: *test_linux_fedora_clang image: fedora:38 dependencies: @@ -285,7 +286,7 @@ build linux/fedora/39/amd64/gcc: <<: *build_linux_fedora_gcc image: fedora:39 -test linux/fedora/39/amd64/gcc: +unit_test linux/fedora/39/amd64/gcc: <<: *test_linux_fedora_gcc image: fedora:39 dependencies: @@ -297,10 +298,77 @@ build linux/fedora/39/amd64/clang: <<: *build_linux_fedora_clang image: fedora:39 -test linux/fedora/39/amd64/clang: +unit_test linux/fedora/39/amd64/clang: <<: *test_linux_fedora_clang image: fedora:39 dependencies: - build linux/fedora/39/amd64/clang needs: - build linux/fedora/39/amd64/clang + +.hw_test: &hw_test + stage: hardware_test + tags: + - libicsneo_hil + timeout: 5m + script: + - echo $GUEST_OS_TAG + - echo $DEVICE_PORT + - /opt/libvirt-driver/prepare.sh + - /opt/libvirt-driver/run.sh + after_script: + - /opt/libvirt-driver/cleanup.sh + +hardware_test system-test-fedora38-red2: + <<: *hw_test + variables: + GUEST_OS_TAG: fedora38 + DEVICE_PORT: ETH_A + needs: + - job: build linux/fedora/38/amd64/clang + artifacts: true + +hardware_test system-test-fedora38-vcan42: + <<: *hw_test + variables: + GUEST_OS_TAG: fedora38 + DEVICE_PORT: USB_D + needs: + - job: build linux/fedora/38/amd64/clang + artifacts: true + +hardware_test system-test-ubuntu2204-red2: + <<: *hw_test + variables: + GUEST_OS_TAG: ubuntu22.04 + DEVICE_PORT: ETH_A + needs: + - job: build linux/ubuntu/2204/amd64/clang + artifacts: true + +hardware_test system-test-ubuntu2204-vcan42: + <<: *hw_test + variables: + GUEST_OS_TAG: ubuntu22.04 + DEVICE_PORT: USB_D + needs: + - job: build linux/ubuntu/2204/amd64/clang + artifacts: true + +hardware_test system-test-win10-red2: + <<: *hw_test + variables: + GUEST_OS_TAG: win10 + DEVICE_PORT: ETH_A + needs: + - job: build windows/x64 + artifacts: true + +hardware_test system-test-win10-vcan42: + <<: *hw_test + variables: + GUEST_OS_TAG: win10 + DEVICE_PORT: USB_D + needs: + - job: build windows/x64 + artifacts: true \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index dd2d027..4c2e98e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,8 @@ if(POLICY CMP0135) cmake_policy(SET CMP0135 NEW) endif() -option(LIBICSNEO_BUILD_TESTS "Build all tests." OFF) +option(LIBICSNEO_BUILD_UNIT_TESTS "Build unit tests." OFF) +option(LIBICSNEO_BUILD_SYSTEM_TESTS "Build system tests." OFF) option(LIBICSNEO_BUILD_DOCS "Build documentation. Don't use in Visual Studio." OFF) option(LIBICSNEO_BUILD_EXAMPLES "Build examples." ON) option(LIBICSNEO_BUILD_ICSNEOC "Build dynamic C library" ON) @@ -491,7 +492,7 @@ if(LIBICSNEO_BUILD_ICSNEOLEGACY_STATIC) endif() # googletest -if(LIBICSNEO_BUILD_TESTS) +if(LIBICSNEO_BUILD_UNIT_TESTS) if(WIN32) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) endif() @@ -504,28 +505,44 @@ if(LIBICSNEO_BUILD_TESTS) include_directories("${gtest_SOURCE_DIR}/include") endif() - add_executable(libicsneo-tests - test/main.cpp - test/diskdriverreadtest.cpp - test/diskdriverwritetest.cpp - test/eventmanagertest.cpp - test/ethernetpacketizertest.cpp - test/i2cencoderdecodertest.cpp - test/linencoderdecodertest.cpp - test/a2bencoderdecodertest.cpp - test/mdioencoderdecodertest.cpp - test/livedataencoderdecodertest.cpp - test/ringbuffertest.cpp + add_executable(libicsneo-unit-tests + test/unit/main.cpp + test/unit/diskdriverreadtest.cpp + test/unit/diskdriverwritetest.cpp + test/unit/eventmanagertest.cpp + test/unit/ethernetpacketizertest.cpp + test/unit/i2cencoderdecodertest.cpp + test/unit/linencoderdecodertest.cpp + test/unit/a2bencoderdecodertest.cpp + test/unit/mdioencoderdecodertest.cpp + test/unit/livedataencoderdecodertest.cpp + test/unit/ringbuffertest.cpp ) - target_link_libraries(libicsneo-tests gtest gtest_main) - target_link_libraries(libicsneo-tests icsneocpp) + target_link_libraries(libicsneo-unit-tests gtest gtest_main) + target_link_libraries(libicsneo-unit-tests icsneocpp) - target_include_directories(libicsneo-tests PUBLIC ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) + target_include_directories(libicsneo-unit-tests PUBLIC ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) enable_testing() - add_test(NAME libicsneo-test-suite COMMAND libicsneo-tests) + add_test(NAME libicsneo-unit-test-suite COMMAND libicsneo-unit-tests) +endif() + +if(LIBICSNEO_BUILD_SYSTEM_TESTS) + if(DEFINED ENV{LIBICSNEO_SYSTEM_TESTS}) + include(FetchContent) + file(MAKE_DIRECTORY test/system) + FetchContent_Declare( + SystemTests + GIT_REPOSITORY $ENV{LIBICSNEO_SYSTEM_TESTS} + GIT_TAG main + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test/system + ) + FetchContent_MakeAvailable(SystemTests) + else() + message("System test repo not defined!") + endif() endif() set(CPACK_PROJECT_NAME ${PROJECT_NAME}) diff --git a/ci/build-posix.sh b/ci/build-posix.sh index cec9a88..c07d495 100644 --- a/ci/build-posix.sh +++ b/ci/build-posix.sh @@ -1,7 +1,7 @@ #!/bin/sh cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release -DLIBICSNEO_BUILD_EXAMPLES=ON \ - -DLIBICSNEO_BUILD_TESTS=ON -DLIBICSNEO_ENABLE_TCP=ON || exit 1 + -DLIBICSNEO_BUILD_UNIT_TESTS=ON -DLIBICSNEO_BUILD_SYSTEM_TESTS=ON -DLIBICSNEO_ENABLE_TCP=OFF || exit 1 cmake --build build || exit 1 diff --git a/ci/build-windows.bat b/ci/build-windows.bat index b708583..502cc07 100644 --- a/ci/build-windows.bat +++ b/ci/build-windows.bat @@ -6,7 +6,7 @@ REM build cd build set CFLAGS=/WX set CXXFLAGS=/WX -cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLIBICSNEO_BUILD_TESTS=ON -DLIBICSNEO_ENABLE_TCP=ON .. +cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLIBICSNEO_BUILD_UNIT_TESTS=ON -DLIBICSNEO_BUILD_SYSTEM_TESTS=ON -DLIBICSNEO_ENABLE_TCP=ON .. if %errorlevel% neq 0 exit /b %errorlevel% cmake --build . if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/include/icsneo/device/tree/neovired2/neovired2settings.h b/include/icsneo/device/tree/neovired2/neovired2settings.h index aa5180d..e462911 100644 --- a/include/icsneo/device/tree/neovired2/neovired2settings.h +++ b/include/icsneo/device/tree/neovired2/neovired2settings.h @@ -109,19 +109,19 @@ public: switch(net.getNetID()) { case Network::NetID::HSCAN: return &(cfg->can1); - case Network::NetID::MSCAN: - return &(cfg->can2); case Network::NetID::HSCAN2: - return &(cfg->can3); + return &(cfg->can2); case Network::NetID::HSCAN3: - return &(cfg->can4); + return &(cfg->can3); case Network::NetID::HSCAN4: - return &(cfg->can5); + return &(cfg->can4); case Network::NetID::HSCAN5: - return &(cfg->can6); + return &(cfg->can5); case Network::NetID::HSCAN6: - return &(cfg->can7); + return &(cfg->can6); case Network::NetID::HSCAN7: + return &(cfg->can7); + case Network::NetID::MSCAN: return &(cfg->can8); default: return nullptr; @@ -134,19 +134,19 @@ public: switch(net.getNetID()) { case Network::NetID::HSCAN: return &(cfg->canfd1); - case Network::NetID::MSCAN: - return &(cfg->canfd2); case Network::NetID::HSCAN2: - return &(cfg->canfd3); + return &(cfg->canfd2); case Network::NetID::HSCAN3: - return &(cfg->canfd4); + return &(cfg->canfd3); case Network::NetID::HSCAN4: - return &(cfg->canfd5); + return &(cfg->canfd4); case Network::NetID::HSCAN5: - return &(cfg->canfd6); + return &(cfg->canfd5); case Network::NetID::HSCAN6: - return &(cfg->canfd7); + return &(cfg->canfd6); case Network::NetID::HSCAN7: + return &(cfg->canfd7); + case Network::NetID::MSCAN: return &(cfg->canfd8); default: return nullptr; diff --git a/test/a2bencoderdecodertest.cpp b/test/unit/a2bencoderdecodertest.cpp similarity index 100% rename from test/a2bencoderdecodertest.cpp rename to test/unit/a2bencoderdecodertest.cpp diff --git a/test/diskdriverreadtest.cpp b/test/unit/diskdriverreadtest.cpp similarity index 100% rename from test/diskdriverreadtest.cpp rename to test/unit/diskdriverreadtest.cpp diff --git a/test/diskdrivertest.h b/test/unit/diskdrivertest.h similarity index 100% rename from test/diskdrivertest.h rename to test/unit/diskdrivertest.h diff --git a/test/diskdriverwritetest.cpp b/test/unit/diskdriverwritetest.cpp similarity index 100% rename from test/diskdriverwritetest.cpp rename to test/unit/diskdriverwritetest.cpp diff --git a/test/ethernetpacketizertest.cpp b/test/unit/ethernetpacketizertest.cpp similarity index 100% rename from test/ethernetpacketizertest.cpp rename to test/unit/ethernetpacketizertest.cpp diff --git a/test/eventmanagertest.cpp b/test/unit/eventmanagertest.cpp similarity index 100% rename from test/eventmanagertest.cpp rename to test/unit/eventmanagertest.cpp diff --git a/test/i2cencoderdecodertest.cpp b/test/unit/i2cencoderdecodertest.cpp similarity index 100% rename from test/i2cencoderdecodertest.cpp rename to test/unit/i2cencoderdecodertest.cpp diff --git a/test/linencoderdecodertest.cpp b/test/unit/linencoderdecodertest.cpp similarity index 100% rename from test/linencoderdecodertest.cpp rename to test/unit/linencoderdecodertest.cpp diff --git a/test/livedataencoderdecodertest.cpp b/test/unit/livedataencoderdecodertest.cpp similarity index 100% rename from test/livedataencoderdecodertest.cpp rename to test/unit/livedataencoderdecodertest.cpp diff --git a/test/main.cpp b/test/unit/main.cpp similarity index 100% rename from test/main.cpp rename to test/unit/main.cpp diff --git a/test/mdioencoderdecodertest.cpp b/test/unit/mdioencoderdecodertest.cpp similarity index 100% rename from test/mdioencoderdecodertest.cpp rename to test/unit/mdioencoderdecodertest.cpp diff --git a/test/ringbuffertest.cpp b/test/unit/ringbuffertest.cpp similarity index 100% rename from test/ringbuffertest.cpp rename to test/unit/ringbuffertest.cpp