Skip to content

Commit

Permalink
tests: add snippet test suite
Browse files Browse the repository at this point in the history
Add an initial test suite for the basic SNIPPET_ROOT, SNIPPET, and
'append' features in snippet.yml.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
  • Loading branch information
mbolivar-nordic committed Mar 24, 2023
1 parent e36febd commit fb7477a
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/cmake/snippets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

set(SNIPPET_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/extra_snippet_root")
set(SNIPPET foo bar)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(test_snippets)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
14 changes: 14 additions & 0 deletions tests/cmake/snippets/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

mainmenu "Snippet tests"

menu "Zephyr"
source "Kconfig.zephyr"
endmenu

config FOO
int "Helper option for testing snippet foo"
default 1
help
This option's value should be overridden by the foo snippet.
4 changes: 4 additions & 0 deletions tests/cmake/snippets/app.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/ {
/* This node will be deleted by the bar snippet. */
deleted-by-bar {};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/ {
/delete-node/ deleted-by-bar;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: bar
append:
DTC_OVERLAY_FILE: bar.overlay
2 changes: 2 additions & 0 deletions tests/cmake/snippets/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
1 change: 1 addition & 0 deletions tests/cmake/snippets/snippets/foo/foo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_FOO=2
3 changes: 3 additions & 0 deletions tests/cmake/snippets/snippets/foo/snippet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: foo
append:
OVERLAY_CONFIG: foo.conf
20 changes: 20 additions & 0 deletions tests/cmake/snippets/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/ztest.h>
#include <zephyr/devicetree.h>

ZTEST_SUITE(snippet_tests, NULL, NULL, NULL, NULL, NULL);

ZTEST(snippet_tests, test_foo)
{
zassert_equal(CONFIG_FOO, 2, "foo snippet should set CONFIG_FOO=2");
}

ZTEST(snippet_tests, test_bar)
{
zassert_equal(DT_NODE_EXISTS(DT_PATH(deleted_by_bar)), 0,
"bar snippet should delete /deleted-by-bar node");
}
6 changes: 6 additions & 0 deletions tests/cmake/snippets/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tests:
cmake.snippets:
tags: snippets
platform_allow: native_posix qemu_x86 qemu_x86_64 qemu_cortex_m3
integration_platforms:
- native_posix

0 comments on commit fb7477a

Please sign in to comment.