From 215f7f90c6cb4ebd52097c0a9a430491d325e5b8 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 20 Sep 2024 18:59:23 +0000 Subject: [PATCH 1/3] usb: device: class: gs_usb: allow including header from C++ code Add "extern C" guards allowing the gs_usb.h header file to be included from C++ code. Signed-off-by: Henrik Brix Andersen --- include/cannectivity/usb/class/gs_usb.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/cannectivity/usb/class/gs_usb.h b/include/cannectivity/usb/class/gs_usb.h index 17e38f9..f89b5e6 100644 --- a/include/cannectivity/usb/class/gs_usb.h +++ b/include/cannectivity/usb/class/gs_usb.h @@ -28,6 +28,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /** * @name Geschwister Schneider USB/CAN protocol software/hardware version definitions * @{ @@ -631,4 +635,8 @@ struct gs_usb_ops { int gs_usb_register(const struct device *dev, const struct device **channels, size_t nchannels, const struct gs_usb_ops *ops, void *user_data); +#ifdef __cplusplus +} +#endif + #endif /* CANNECTIVITY_INCLUDE_USB_CLASS_GS_USB_H_ */ From 4b7e5079ad703c969699271adcc258c42379f64c Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 20 Sep 2024 19:01:52 +0000 Subject: [PATCH 2/3] tests: usb: gs_usb: add build-only test for C++ header inclusion Add build-only test for verifying the gs_usb.h header file when included from C++ code. Signed-off-by: Henrik Brix Andersen --- tests/subsys/usb/gs_usb/cxx/CMakeLists.txt | 10 +++++++ tests/subsys/usb/gs_usb/cxx/app.overlay | 11 ++++++++ tests/subsys/usb/gs_usb/cxx/prj.conf | 7 +++++ tests/subsys/usb/gs_usb/cxx/src/main.cpp | 7 +++++ tests/subsys/usb/gs_usb/cxx/testcase.yaml | 33 ++++++++++++++++++++++ 5 files changed, 68 insertions(+) create mode 100644 tests/subsys/usb/gs_usb/cxx/CMakeLists.txt create mode 100644 tests/subsys/usb/gs_usb/cxx/app.overlay create mode 100644 tests/subsys/usb/gs_usb/cxx/prj.conf create mode 100644 tests/subsys/usb/gs_usb/cxx/src/main.cpp create mode 100644 tests/subsys/usb/gs_usb/cxx/testcase.yaml diff --git a/tests/subsys/usb/gs_usb/cxx/CMakeLists.txt b/tests/subsys/usb/gs_usb/cxx/CMakeLists.txt new file mode 100644 index 0000000..24b569a --- /dev/null +++ b/tests/subsys/usb/gs_usb/cxx/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2024 Henrik Brix Andersen +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(cxx LANGUAGES CXX) + +FILE(GLOB app_sources src/*.cpp) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/subsys/usb/gs_usb/cxx/app.overlay b/tests/subsys/usb/gs_usb/cxx/app.overlay new file mode 100644 index 0000000..be54e2c --- /dev/null +++ b/tests/subsys/usb/gs_usb/cxx/app.overlay @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2024 Henrik Brix Andersen + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&zephyr_udc0 { + gs_usb0: gs_usb0 { + compatible = "gs_usb"; + }; +}; diff --git a/tests/subsys/usb/gs_usb/cxx/prj.conf b/tests/subsys/usb/gs_usb/cxx/prj.conf new file mode 100644 index 0000000..e0b8122 --- /dev/null +++ b/tests/subsys/usb/gs_usb/cxx/prj.conf @@ -0,0 +1,7 @@ +CONFIG_CPP=y + +CONFIG_USB_DEVICE_STACK=y + +CONFIG_USB_DEVICE_GS_USB_IDENTIFICATION=y +CONFIG_USB_DEVICE_GS_USB_TIMESTAMP=y +CONFIG_USB_DEVICE_GS_USB_TERMINATION=y diff --git a/tests/subsys/usb/gs_usb/cxx/src/main.cpp b/tests/subsys/usb/gs_usb/cxx/src/main.cpp new file mode 100644 index 0000000..298ca37 --- /dev/null +++ b/tests/subsys/usb/gs_usb/cxx/src/main.cpp @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2024 Henrik Brix Andersen + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include diff --git a/tests/subsys/usb/gs_usb/cxx/testcase.yaml b/tests/subsys/usb/gs_usb/cxx/testcase.yaml new file mode 100644 index 0000000..7bcb486 --- /dev/null +++ b/tests/subsys/usb/gs_usb/cxx/testcase.yaml @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Henrik Brix Andersen +# SPDX-License-Identifier: Apache-2.0 + +common: + tags: usb can + depends_on: usb_device + build_only: true + integration_platforms: + - frdm_k64f + platform_exclude: + - native_sim +tests: + usb.gs_usb.cxx98: + extra_configs: + - CONFIG_STD_CPP98=y + usb.gs_usb.cxx11: + extra_configs: + - CONFIG_STD_CPP11=y + usb.gs_usb.cxx14: + extra_configs: + - CONFIG_STD_CPP14=y + usb.gs_usb.cxx17: + extra_configs: + - CONFIG_STD_CPP17=y + usb.gs_usb.cxx2a: + extra_configs: + - CONFIG_STD_CPP2A=y + usb.gs_usb.cxx20: + extra_configs: + - CONFIG_STD_CPP20=y + usb.gs_usb.cxx2b: + extra_configs: + - CONFIG_STD_CPP2B=y From bf349963cb8d084c7f2614f7a94ed20bb9732a80 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 20 Sep 2024 19:04:44 +0000 Subject: [PATCH 3/3] github: run test suites in GitHub CI Run the test suites in GitHub CI. Signed-off-by: Henrik Brix Andersen --- .github/workflows/build.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 862222c..ad95133 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,3 +38,12 @@ jobs: EXTRA_TWISTER_FLAGS="--short-build-path -O/tmp/twister-out" fi west twister -T app -v --inline-logs --integration $EXTRA_TWISTER_FLAGS + + - name: Run tests + working-directory: cannectivity + shell: bash + run: | + if [ "${{ runner.os }}" = "Windows" ]; then + EXTRA_TWISTER_FLAGS="--short-build-path -O/tmp/twister-out" + fi + west twister -T tests -v --inline-logs --integration $EXTRA_TWISTER_FLAGS