From 16041280c79757c770ca4150b6bddc346184f090 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Tue, 8 Dec 2020 15:09:52 -0500 Subject: [PATCH 1/9] ci: add initial clang action Action to verify clang builds on select platforms. Signed-off-by: Anas Nashif --- .github/workflows/clang.yaml | 88 ++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .github/workflows/clang.yaml diff --git a/.github/workflows/clang.yaml b/.github/workflows/clang.yaml new file mode 100644 index 0000000000000..6f4fdaa9c7c2f --- /dev/null +++ b/.github/workflows/clang.yaml @@ -0,0 +1,88 @@ +name: Build with Clang/LLVM + +on: pull_request + +jobs: + clang-build-cancel: + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{ github.token }} + clang-build: + runs-on: ubuntu-latest + needs: clang-build-cancel + container: + image: zephyrprojectrtos/ci:v0.17.0-alpha2 + options: '--entrypoint /bin/bash' + strategy: + fail-fast: false + matrix: + subset: [1, 2, 3, 4, 5, 6, 7 , 8, 9, 10] + env: + ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.12.4 + CLANG_ROOT_DIR: /usr/lib/llvm-12 + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{ github.token }} + - name: Update PATH for west + run: | + echo "$HOME/.local/bin" >> $GITHUB_PATH + + - name: checkout + uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + + - name: west setup + run: | + west init -l . || true + west update + + - name: Check Environment + run: | + cmake --version + ${CLANG_ROOT_DIR}/bin/clang --version + gcc --version + ls -la + + - name: Run Tests with Twister + run: | + #source zephyr-env.sh + export ZEPHYR_BASE=${PWD} + export ZEPHYR_TOOLCHAIN_VARIANT=llvm + ./scripts/twister --inline-logs -N -v --integration -p native_posix -p qemu_x86 --subset ${{matrix.subset}}/10 --retry-failed 3 + + - name: Upload Unit Test Results + if: always() + uses: actions/upload-artifact@v2 + with: + name: Unit Test Results (Subset ${{ matrix.subset }}) + path: twister-out/twister.xml + + publish-test-results: + name: "Publish Unit Tests Results" + needs: clang-build + runs-on: ubuntu-20.04 + # the build-and-test job might be skipped, we don't need to run this job then + if: success() || failure() + + steps: + - name: Download Artifacts + uses: actions/download-artifact@v2 + with: + path: artifacts + + - name: Display structure of downloaded files + run: ls -R + + - name: Publish Unit Test Results + uses: EnricoMi/publish-unit-test-result-action@v1.6 + with: + check_name: Unit Test Results + github_token: ${{ secrets.GITHUB_TOKEN }} + files: "**/twister.xml" From 1c0adfb46c6ee5752246e5e1758f2843203f201e Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Mon, 19 Apr 2021 00:11:19 -0400 Subject: [PATCH 2/9] tests: dsp: filtering: exclude on llvm optimize attribute is not supported by LLVM. Signed-off-by: Anas Nashif --- include/toolchain/llvm.h | 24 +++++++++++++++++++++ tests/lib/cmsis_dsp/filtering/testcase.yaml | 1 + 2 files changed, 25 insertions(+) create mode 100644 include/toolchain/llvm.h diff --git a/include/toolchain/llvm.h b/include/toolchain/llvm.h new file mode 100644 index 0000000000000..dc4421aef6591 --- /dev/null +++ b/include/toolchain/llvm.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 Intel Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ +#define ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ + +#ifndef _LINKER +#if defined(_ASMLANGUAGE) + +#include + +#else /* defined(_ASMLANGUAGE) */ + +#define __no_optimization __attribute__((optnone)) + +#include +#endif /* _ASMLANGUAGE */ + +#endif /* !_LINKER */ + +#endif /* ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ */ diff --git a/tests/lib/cmsis_dsp/filtering/testcase.yaml b/tests/lib/cmsis_dsp/filtering/testcase.yaml index f94207d892e1d..e9b2b6b0add86 100644 --- a/tests/lib/cmsis_dsp/filtering/testcase.yaml +++ b/tests/lib/cmsis_dsp/filtering/testcase.yaml @@ -6,6 +6,7 @@ common: - mps2_an521 - native_posix tags: cmsis_dsp + toolchain_exclude: llvm tests: libraries.cmsis_dsp.filtering: From 1f666e14af63013e8bbe30133c48c3d366f9a037 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Mon, 19 Apr 2021 00:12:57 -0400 Subject: [PATCH 3/9] toolchain: add llvm abstraction Add abstraction for llvm to allow for toolchain customizations that are different from the gcc defaults. Signed-off-by: Anas Nashif --- include/toolchain.h | 2 ++ include/toolchain/llvm.h | 9 --------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/include/toolchain.h b/include/toolchain.h index ea905a083b3ec..88639a83c42d2 100644 --- a/include/toolchain.h +++ b/include/toolchain.h @@ -37,6 +37,8 @@ #include #elif defined(__CCAC__) #include +#elif defined(__llvm__) +#include #elif defined(__GNUC__) || (defined(_LINKER) && defined(__GCC_LINKER_CMD__)) #include #else diff --git a/include/toolchain/llvm.h b/include/toolchain/llvm.h index dc4421aef6591..afcac9c279ec6 100644 --- a/include/toolchain/llvm.h +++ b/include/toolchain/llvm.h @@ -7,18 +7,9 @@ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ #define ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ -#ifndef _LINKER -#if defined(_ASMLANGUAGE) - -#include - -#else /* defined(_ASMLANGUAGE) */ #define __no_optimization __attribute__((optnone)) - #include -#endif /* _ASMLANGUAGE */ -#endif /* !_LINKER */ #endif /* ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ */ From e7d48b1298303c564dd68bd47af95342ca9415b0 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Mon, 19 Apr 2021 10:12:42 -0400 Subject: [PATCH 4/9] cmake: llvm: llvm has no newlib llvm does not have newlib integrated for all architectures. Signed-off-by: Anas Nashif --- cmake/toolchain/llvm/generic.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmake/toolchain/llvm/generic.cmake b/cmake/toolchain/llvm/generic.cmake index 741a2b4557236..b25e8cee284b1 100644 --- a/cmake/toolchain/llvm/generic.cmake +++ b/cmake/toolchain/llvm/generic.cmake @@ -27,8 +27,6 @@ set(CMAKE_C_COMPILER_TARGET ${triple}) set(CMAKE_ASM_COMPILER_TARGET ${triple}) set(CMAKE_CXX_COMPILER_TARGET ${triple}) -if("${ARCH}" STREQUAL "posix") - set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib") -endif() +set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib") message(STATUS "Found toolchain: host (clang/ld)") From e3797ff720d3641de956eebbaef63c7559071f98 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Wed, 21 Apr 2021 10:30:34 -0400 Subject: [PATCH 5/9] tests: kernel: modify debug message for LLVM On native_posix types are getting confused and we are getting a warning. Get same results by removing the usage of PRIxPTR. Signed-off-by: Anas Nashif --- tests/kernel/common/src/timeout_order.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/kernel/common/src/timeout_order.c b/tests/kernel/common/src/timeout_order.c index cf4c06a9a0548..6d76e461e1455 100644 --- a/tests/kernel/common/src/timeout_order.c +++ b/tests/kernel/common/src/timeout_order.c @@ -23,8 +23,7 @@ static void thread(void *p1, void *p2, void *p3) uintptr_t id = (uintptr_t)p1; k_timer_status_sync(&timer[id]); - printk("%s %" PRIxPTR " synced on timer %" PRIxPTR "\n", - __func__, id, id); + printk("%s %lu synced on timer %lu\n", __func__, POINTER_TO_UINT(id), POINTER_TO_UINT(id)); /* no need to protect cur, all threads have the same prio */ results[cur++] = id; From e16c8cee6e49062ce1615ae735e6b579a92398f2 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Wed, 21 Apr 2021 12:39:33 +0200 Subject: [PATCH 6/9] lib: os: cbprintf: Suppress sizeof-array-decay warning Z_CBPRINTF_ARG_SIZE macro is called for each argument in logging macros. If argument is a string literal an intention of this macro is to return size of a pointer. Suppressing warning which appears in that case. Signed-off-by: Krzysztof Chruscinski --- include/sys/cbprintf_internal.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/sys/cbprintf_internal.h b/include/sys/cbprintf_internal.h index ffb483b241ad3..752991b92375e 100644 --- a/include/sys/cbprintf_internal.h +++ b/include/sys/cbprintf_internal.h @@ -259,6 +259,18 @@ union z_cbprintf_hdr { void *raw; }; +/* When using clang additional warning needs to be suppressed since each + * argument of fmt string is used for sizeof() which results in the warning + * if argument is a stirng literal. Suppression is added here instead of + * the macro which generates the warning to not slow down the compiler. + */ +#if __clang__ == 1 +#define Z_CBPRINTF_SUPPRESS_SIZEOF_ARRAY_DECAY \ + _Pragma("GCC diagnostic ignored \"-Wsizeof-array-decay\"") +#else +#define Z_CBPRINTF_SUPPRESS_SIZEOF_ARRAY_DECAY +#endif + /** @brief Statically package a formatted string with arguments. * * @param buf buffer. If null then only length is calculated. @@ -277,6 +289,7 @@ union z_cbprintf_hdr { do { \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \ + Z_CBPRINTF_SUPPRESS_SIZEOF_ARRAY_DECAY \ BUILD_ASSERT(!IS_ENABLED(CONFIG_XTENSA) || \ (IS_ENABLED(CONFIG_XTENSA) && \ !(_align_offset % CBPRINTF_PACKAGE_ALIGNMENT)), \ From e5cdd9316d05809a991d3dd7447b1dbec1e2f5c3 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Wed, 21 Apr 2021 10:51:13 -0400 Subject: [PATCH 7/9] tests: fs: define PATH_MAX if missing With LLVM and native_posix, this is not defined and is not available in limits.h. Workaround the issue for now. Signed-off-by: Anas Nashif --- tests/subsys/fs/multi-fs/src/test_common_dir.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/subsys/fs/multi-fs/src/test_common_dir.c b/tests/subsys/fs/multi-fs/src/test_common_dir.c index 067b9a24c03b9..8bb9a7165f165 100644 --- a/tests/subsys/fs/multi-fs/src/test_common_dir.c +++ b/tests/subsys/fs/multi-fs/src/test_common_dir.c @@ -11,6 +11,10 @@ #include #include "test_common.h" +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + int test_rmdir(const char *dir_path); int test_mkdir(const char *dir_path, const char *file) From ad543c4a5d697ab35520d4598bfd1f8e7d59b79b Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Wed, 21 Apr 2021 11:23:46 -0400 Subject: [PATCH 8/9] disable qemu Signed-off-by: Anas Nashif --- .github/workflows/clang.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang.yaml b/.github/workflows/clang.yaml index 6f4fdaa9c7c2f..aa4a340f2624d 100644 --- a/.github/workflows/clang.yaml +++ b/.github/workflows/clang.yaml @@ -55,7 +55,7 @@ jobs: #source zephyr-env.sh export ZEPHYR_BASE=${PWD} export ZEPHYR_TOOLCHAIN_VARIANT=llvm - ./scripts/twister --inline-logs -N -v --integration -p native_posix -p qemu_x86 --subset ${{matrix.subset}}/10 --retry-failed 3 + ./scripts/twister --inline-logs -N -v --integration -p native_posix --subset ${{matrix.subset}}/10 --retry-failed 3 - name: Upload Unit Test Results if: always() From cba53d7e3469faa883443be2e613d67515640472 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Wed, 21 Apr 2021 11:41:26 -0400 Subject: [PATCH 9/9] reduce matrix Signed-off-by: Anas Nashif --- .github/workflows/clang.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clang.yaml b/.github/workflows/clang.yaml index aa4a340f2624d..57b833f822047 100644 --- a/.github/workflows/clang.yaml +++ b/.github/workflows/clang.yaml @@ -19,10 +19,11 @@ jobs: strategy: fail-fast: false matrix: - subset: [1, 2, 3, 4, 5, 6, 7 , 8, 9, 10] + subset: [1] env: ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.12.4 CLANG_ROOT_DIR: /usr/lib/llvm-12 + MATRIX_SIZE: 1 steps: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.6.0 @@ -55,7 +56,7 @@ jobs: #source zephyr-env.sh export ZEPHYR_BASE=${PWD} export ZEPHYR_TOOLCHAIN_VARIANT=llvm - ./scripts/twister --inline-logs -N -v --integration -p native_posix --subset ${{matrix.subset}}/10 --retry-failed 3 + ./scripts/twister --inline-logs -N -v --integration -p native_posix -T tests/kernel/common --subset ${{matrix.subset}}/${MATRIX_SIZE} --retry-failed 3 - name: Upload Unit Test Results if: always()