Skip to content

Commit c402c4a

Browse files
committed
Add GitHub Action to build unit tests
This commit adds a simple unit test based on the Zephyr Test Framework (Ztest). Signed-off-by: Yasushi SHOJI <[email protected]>
1 parent 73b3f27 commit c402c4a

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

.github/workflows/test.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Zephyr Build and Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build-zephyr:
7+
runs-on: ubuntu-22.04
8+
container:
9+
image: ghcr.io/zephyrproject-rtos/ci:v0.26.4
10+
options: '--entrypoint /bin/bash'
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
board:
15+
- qemu_cortex_m3
16+
env:
17+
ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.16.1
18+
ZEPHYR_TOOLCHAIN_VARIANT: zephyr
19+
steps:
20+
- name: Apply container owner mismatch workaround
21+
run: |
22+
# FIXME: The owner UID of the GITHUB_WORKSPACE directory may not
23+
# match the container user UID because of the way GitHub
24+
# Actions runner is implemented. Remove this workaround when
25+
# GitHub comes up with a fundamental fix for this problem.
26+
git config --global --add safe.directory ${GITHUB_WORKSPACE}
27+
28+
- name: Update PATH for west
29+
run: |
30+
echo "$HOME/.local/bin" >> $GITHUB_PATH
31+
32+
- name: Configure Git
33+
run: |
34+
git config --global user.email [email protected]
35+
git config --global user.name "Github Actions"
36+
37+
- name: Setup Git (pull request)
38+
if: ${{ github.base_ref }}
39+
env:
40+
BASE_REF: ${{ github.base_ref }}
41+
run: |
42+
git rebase origin/${BASE_REF}
43+
git checkout -b this_pr
44+
45+
- name: Setup build system packages on Linux
46+
run: |
47+
sudo apt-get -y update
48+
sudo apt-get -y install nodejs
49+
50+
- name: Checkout
51+
uses: actions/checkout@v3
52+
53+
- name: West Setup
54+
run: |
55+
west init -l . || true
56+
west config --global update.narrow true
57+
west config --global build.board_warn false
58+
west update 2>&1 1> west.update.log || west update 2>&1 1> west.update.log
59+
60+
- name: Build the PR
61+
run: |
62+
west build -b ${{ matrix.board }} .

prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ZTEST=y

src/main.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#include <zephyr.h>
8-
#include <sys/printk.h>
7+
#include <ztest.h>
98

10-
void main(void)
9+
static void test_assert(void)
1110
{
12-
printk("Hello World! %s\n", CONFIG_BOARD);
11+
zassert_true(1, "1 was false");
12+
zassert_false(0, "0 was true");
13+
zassert_is_null(NULL, "NULL was not NULL");
14+
zassert_not_null("foo", "\"foo\" was NULL");
15+
zassert_equal(1, 1, "1 was not equal to 1");
16+
zassert_equal_ptr(NULL, NULL, "NULL was not equal to NULL");
17+
}
18+
19+
void test_main(void)
20+
{
21+
ztest_test_suite(tests,
22+
ztest_unit_test(test_assert));
23+
24+
ztest_run_test_suite(tests);
1325
}

0 commit comments

Comments
 (0)