diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 685a629a3..a72148c47 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,6 +28,8 @@ jobs: uses: ./.github/workflows/hostap.yml nginx: uses: ./.github/workflows/nginx.yml + zephyr: + uses: ./.github/workflows/zephyr.yml # TODO: Currently this test fails. Enable it once it becomes passing. # haproxy: # uses: ./.github/workflows/haproxy.yml diff --git a/.github/workflows/zephyr.yml b/.github/workflows/zephyr.yml new file mode 100644 index 000000000..0a33b1583 --- /dev/null +++ b/.github/workflows/zephyr.yml @@ -0,0 +1,95 @@ +name: Zephyr tests + +on: + workflow_call: + +jobs: + run_test: + name: Build and run + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - name: Install dependencies + run: | + # Don't prompt for anything + export DEBIAN_FRONTEND=noninteractive + sudo apt-get update + # most of the ci-base zephyr docker image packages + sudo apt-get install -y zip bridge-utils uml-utilities \ + git cmake ninja-build gperf ccache dfu-util device-tree-compiler wget \ + python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ + make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 \ + autoconf automake bison build-essential ca-certificates cargo ccache chrpath cmake \ + cpio device-tree-compiler dfu-util diffstat dos2unix doxygen file flex g++ gawk gcc \ + gcovr git git-core gnupg gperf gtk-sharp2 help2man iproute2 lcov libcairo2-dev \ + libglib2.0-dev libgtk2.0-0 liblocale-gettext-perl libncurses5-dev libpcap-dev \ + libpopt0 libsdl1.2-dev libsdl2-dev libssl-dev libtool libtool-bin locales make \ + net-tools ninja-build openssh-client parallel pkg-config python3-dev python3-pip \ + python3-ply python3-setuptools python-is-python3 qemu rsync socat srecord sudo \ + texinfo unzip wget ovmf xz-utils + + - name: Install west + run: sudo pip install west + + - name: Init west workspace + run: west init zephyr + + - name: Update west.yml + working-directory: zephyr/zephyr + run: | + REF=$(echo '${{ github.ref }}' | sed -e 's/\//\\\//g') + sed -e 's/remotes:/remotes:\n \- name: wolfssl\n url\-base: https:\/\/github.com\/${{ github.repository_owner }}/' -i west.yml + sed -e "s/projects:/projects:\n \- name: wolfssl\n path: modules\/crypto\/wolfssl\n remote: wolfssl\n revision: $REF/" -i west.yml + + - name: Update west workspace + working-directory: zephyr + run: west update -n -o=--depth=1 + + - name: Export zephyr + working-directory: zephyr + run: west zephyr-export + + - name: Install pip dependencies + working-directory: zephyr + run: sudo pip install -r zephyr/scripts/requirements.txt + + - name: Install zephyr SDK + run: | + wget -q https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.1/zephyr-sdk-0.16.1_linux-x86_64.tar.xz + tar xf zephyr-sdk-0.16.1_linux-x86_64.tar.xz + cd zephyr-sdk-0.16.1 + ./setup.sh -h -c + + - name: Run wolfssl test + id: wolfssl-test + working-directory: zephyr + run: | + ./zephyr/scripts/twister --testsuite-root modules/crypto/wolfssl --test zephyr/samples/wolfssl_test/sample.crypto.wolfssl_test -vvv + rm -rf zephyr/twister-out + + - name: Run wolfssl TLS sock test + id: wolfssl-tls-sock + working-directory: zephyr + run: | + ./zephyr/scripts/twister --testsuite-root modules/crypto/wolfssl --test zephyr/samples/wolfssl_tls_sock/sample.crypto.wolfssl_tls_sock -vvv + rm -rf zephyr/twister-out + + - name: Run wolfssl TLS thread test + id: wolfssl-tls-thread + working-directory: zephyr + run: | + ./zephyr/scripts/twister --testsuite-root modules/crypto/wolfssl --test zephyr/samples/wolfssl_tls_thread/sample.crypto.wolfssl_tls_thread -vvv + rm -rf zephyr/twister-out + + - name: Zip failure logs + if: ${{ failure() && (steps.wolfssl-test.outcome == 'failure' || steps.wolfssl-tls-sock.outcome == 'failure' || steps.wolfssl-tls-thread.outcome == 'failure') }} + run: | + zip -9 -r logs.zip zephyr/twister-out + + - name: Upload failure logs + if: ${{ failure() && (steps.wolfssl-test.outcome == 'failure' || steps.wolfssl-tls-sock.outcome == 'failure' || steps.wolfssl-tls-thread.outcome == 'failure') }} + uses: actions/upload-artifact@v3 + with: + name: zephyr-client-test-logs + path: logs.zip + retention-days: 5 diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 22b505844..26eb033ef 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -253,10 +253,6 @@ #include #endif /* WOLFSSL_ESPIDF */ -#ifdef HAVE_PTHREAD - #include -#endif - #if defined(HAVE_PTHREAD) || \ (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \ !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \ diff --git a/zephyr/README.md b/zephyr/README.md index ec2f0fd1f..098d51c96 100644 --- a/zephyr/README.md +++ b/zephyr/README.md @@ -60,6 +60,14 @@ then "Open Terminal". ## Build and Run wolfCrypt Test Application +If you want to run build apps without running `west zephyr-export` then it is +possible by setting the `CMAKE_PREFIX_PATH` variable to the location of the +zephyr sdk and building from the `zephyr` directory. For example: + +``` +CMAKE_PREFIX_PATH=/path/to/zephyr-sdk- west build -p always -b qemu_x86 ../modules/crypto/wolfssl/zephyr/samples/wolfssl_test/ +``` + build and execute `wolfssl_test` ``` diff --git a/zephyr/samples/wolfssl_benchmark/prj.conf b/zephyr/samples/wolfssl_benchmark/prj.conf index 2cf271408..15d4ebba3 100644 --- a/zephyr/samples/wolfssl_benchmark/prj.conf +++ b/zephyr/samples/wolfssl_benchmark/prj.conf @@ -1,7 +1,5 @@ - # Configure stack and heap sizes CONFIG_MAIN_STACK_SIZE=32768 -CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=16384 # Pthreads CONFIG_PTHREAD_IPC=y diff --git a/zephyr/samples/wolfssl_benchmark/sample.yaml b/zephyr/samples/wolfssl_benchmark/sample.yaml index 8b45f1788..4c5d1fcea 100644 --- a/zephyr/samples/wolfssl_benchmark/sample.yaml +++ b/zephyr/samples/wolfssl_benchmark/sample.yaml @@ -2,9 +2,14 @@ sample: description: wolfCrypt benchmark sample app name: wolfCrypt benchmark common: - min_flash: 65 - min_ram: 36 tags: crypto wolfssl userspace random + harness: console + harness_config: + type: one_line + regex: + - "Benchmark complete" tests: - crypto.wolfssl_benchmark: - platform_allow: qemu_x86 nrf5340dk_nrf5340_cpuapp_ns nrf5340dk_nrf5340_cpuapp + sample.crypto.wolfssl_benchmark: + platform_allow: qemu_x86 + integration_platforms: + - qemu_x86 diff --git a/zephyr/samples/wolfssl_test/prj.conf b/zephyr/samples/wolfssl_test/prj.conf index c2f997430..a989213b4 100644 --- a/zephyr/samples/wolfssl_test/prj.conf +++ b/zephyr/samples/wolfssl_test/prj.conf @@ -1,7 +1,7 @@ # Configure stack and heap sizes CONFIG_MAIN_STACK_SIZE=32768 -CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=16384 +CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=16384 # Pthreads CONFIG_PTHREAD_IPC=y diff --git a/zephyr/samples/wolfssl_test/sample.yaml b/zephyr/samples/wolfssl_test/sample.yaml index 72069ff6c..a1c4f8192 100644 --- a/zephyr/samples/wolfssl_test/sample.yaml +++ b/zephyr/samples/wolfssl_test/sample.yaml @@ -2,9 +2,14 @@ sample: description: wolfCrypt test sample app name: wolfCrypt test common: - min_flash: 65 - min_ram: 36 - tags: crypto wolfssl userspace random + harness: console + harness_config: + type: one_line + regex: + - "Exiting main with return code: 0" tests: - crypto.wolfssl_test: - platform_allow: qemu_x86 nrf5340dk_nrf5340_cpuapp_ns nrf5340dk_nrf5340_cpuapp + sample.crypto.wolfssl_test: + timeout: 120 + platform_allow: qemu_x86 + integration_platforms: + - qemu_x86 diff --git a/zephyr/samples/wolfssl_tls_sock/prj.conf b/zephyr/samples/wolfssl_tls_sock/prj.conf index 9ca0cef9b..969299b32 100644 --- a/zephyr/samples/wolfssl_tls_sock/prj.conf +++ b/zephyr/samples/wolfssl_tls_sock/prj.conf @@ -2,7 +2,7 @@ CONFIG_MAIN_STACK_SIZE=16384 CONFIG_ENTROPY_GENERATOR=y CONFIG_INIT_STACKS=y -CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=8192 +CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192 # General config CONFIG_NEWLIB_LIBC=y diff --git a/zephyr/samples/wolfssl_tls_sock/sample.yaml b/zephyr/samples/wolfssl_tls_sock/sample.yaml index 86f7f9a79..ea002827e 100644 --- a/zephyr/samples/wolfssl_tls_sock/sample.yaml +++ b/zephyr/samples/wolfssl_tls_sock/sample.yaml @@ -1,9 +1,16 @@ -common: - harness: crypto - tags: crypto sample: description: wolfSSL TLS test application name: wolfSSL TLS Test +common: + harness: console + harness_config: + type: multi_line + regex: + - "Server Return: 0" + - "Client Return: 0" tests: - test: - platform_whitelist: qemu_x86 + sample.crypto.wolfssl_tls_sock: + timeout: 60 + platform_allow: qemu_x86 + integration_platforms: + - qemu_x86 diff --git a/zephyr/samples/wolfssl_tls_sock/src/tls_sock.c b/zephyr/samples/wolfssl_tls_sock/src/tls_sock.c index d821f1edd..a57598b9d 100644 --- a/zephyr/samples/wolfssl_tls_sock/src/tls_sock.c +++ b/zephyr/samples/wolfssl_tls_sock/src/tls_sock.c @@ -296,8 +296,10 @@ static void wolfssl_memstats(WOLFSSL* ssl) /* Start the server thread. */ void start_thread(THREAD_CB func, func_args* args, THREAD_TYPE* thread) { + /* Casting to k_thread_entry_t should be fine since we just ignore the + * extra arguments being passed in */ k_thread_create(thread, server_stack, K_THREAD_STACK_SIZEOF(server_stack), - func, args, NULL, NULL, 5, 0, K_NO_WAIT); + (k_thread_entry_t)func, args, NULL, NULL, 5, 0, K_NO_WAIT); } void join_thread(THREAD_TYPE thread) @@ -350,7 +352,7 @@ int wolfssl_server_accept_tcp(WOLFSSL* ssl, SOCKET_T* fd, SOCKET_T* acceptfd) } /* Thread to do the server operations. */ -void server_thread(void* arg1, void* arg2, void* arg3) +void server_thread(void* arg1) { int ret = 0; WOLFSSL_CTX* server_ctx = NULL; diff --git a/zephyr/samples/wolfssl_tls_thread/prj.conf b/zephyr/samples/wolfssl_tls_thread/prj.conf index e675b38a5..4a1e290a6 100644 --- a/zephyr/samples/wolfssl_tls_thread/prj.conf +++ b/zephyr/samples/wolfssl_tls_thread/prj.conf @@ -2,7 +2,7 @@ CONFIG_MAIN_STACK_SIZE=16384 CONFIG_ENTROPY_GENERATOR=y CONFIG_INIT_STACKS=y -CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=65536 +CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=65536 # Pthreads CONFIG_PTHREAD_IPC=y diff --git a/zephyr/samples/wolfssl_tls_thread/sample.yaml b/zephyr/samples/wolfssl_tls_thread/sample.yaml index 86f7f9a79..270648b60 100644 --- a/zephyr/samples/wolfssl_tls_thread/sample.yaml +++ b/zephyr/samples/wolfssl_tls_thread/sample.yaml @@ -1,9 +1,18 @@ -common: - harness: crypto - tags: crypto sample: description: wolfSSL TLS test application name: wolfSSL TLS Test +common: + harness: console + harness_config: + type: multi_line + regex: + - "Server Return: 0" + - "Server Error: 0" + - "Client Return: 0" + - "Client Error: 0" tests: - test: - platform_whitelist: qemu_x86 + sample.crypto.wolfssl_tls_thread: + timeout: 60 + platform_allow: qemu_x86 + integration_platforms: + - qemu_x86 diff --git a/zephyr/samples/wolfssl_tls_thread/src/tls_threaded.c b/zephyr/samples/wolfssl_tls_thread/src/tls_threaded.c index 3a59669f8..e1a96616b 100644 --- a/zephyr/samples/wolfssl_tls_thread/src/tls_threaded.c +++ b/zephyr/samples/wolfssl_tls_thread/src/tls_threaded.c @@ -519,8 +519,10 @@ static void wolfssl_memstats(WOLFSSL* ssl) /* Start the server thread. */ void start_thread(THREAD_CB func, func_args* args, THREAD_TYPE* thread) { + /* Casting to k_thread_entry_t should be fine since we just ignore the + * extra arguments being passed in */ k_thread_create(thread, server_stack, K_THREAD_STACK_SIZEOF(server_stack), - func, args, NULL, NULL, 5, 0, K_NO_WAIT); + (k_thread_entry_t)func, args, NULL, NULL, 5, 0, K_NO_WAIT); } void join_thread(THREAD_TYPE thread) @@ -530,7 +532,7 @@ void join_thread(THREAD_TYPE thread) /* Thread to do the server operations. */ -void server_thread(void* arg1, void* arg2, void* arg3) +void server_thread(void* arg1) { int ret = 0; WOLFSSL_CTX* server_ctx = NULL;