tests: kconfig: test configdefault extension
Test the behaviour of the `configdefault` kconfig extension. Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
parent
79e467c92a
commit
cea39d4383
5 changed files with 324 additions and 0 deletions
8
tests/kconfig/configdefault/CMakeLists.txt
Normal file
8
tests/kconfig/configdefault/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.20.0)
|
||||||
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
|
project(kconfig_configdefault)
|
||||||
|
|
||||||
|
FILE(GLOB app_sources src/*.c)
|
||||||
|
target_sources(app PRIVATE ${app_sources})
|
259
tests/kconfig/configdefault/Kconfig
Normal file
259
tests/kconfig/configdefault/Kconfig
Normal file
|
@ -0,0 +1,259 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
# Copyright (c) 2022 CSIRO
|
||||||
|
|
||||||
|
config DEP_Y
|
||||||
|
bool "Dependency that evaluates to enabled"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config DEP_N
|
||||||
|
bool "Dependency that evaluates to disabled"
|
||||||
|
default n
|
||||||
|
|
||||||
|
# configdefault after main def
|
||||||
|
config SYM_Y_1
|
||||||
|
bool "SYM Y 1"
|
||||||
|
|
||||||
|
configdefault SYM_Y_1
|
||||||
|
default y if DEP_Y
|
||||||
|
|
||||||
|
config SYM_N_1
|
||||||
|
bool "SYM N 1"
|
||||||
|
|
||||||
|
configdefault SYM_N_1
|
||||||
|
default y if DEP_N
|
||||||
|
|
||||||
|
# configdefault before main def
|
||||||
|
configdefault SYM_Y_2
|
||||||
|
default y if DEP_Y
|
||||||
|
|
||||||
|
config SYM_Y_2
|
||||||
|
bool "SYM Y 2"
|
||||||
|
|
||||||
|
configdefault SYM_N_2
|
||||||
|
default y if DEP_N
|
||||||
|
|
||||||
|
config SYM_N_2
|
||||||
|
bool "SYM N 2"
|
||||||
|
|
||||||
|
# configdefaults with multiple defaults
|
||||||
|
configdefault SYM_Y_3
|
||||||
|
default y if DEP_Y
|
||||||
|
default y if DEP_N
|
||||||
|
|
||||||
|
config SYM_Y_3
|
||||||
|
bool "SYM Y 3"
|
||||||
|
|
||||||
|
configdefault SYM_N_3
|
||||||
|
default y if DEP_N
|
||||||
|
default y if DEP_N
|
||||||
|
|
||||||
|
config SYM_N_3
|
||||||
|
bool "SYM N 3"
|
||||||
|
|
||||||
|
# multiple configdefaults
|
||||||
|
configdefault SYM_Y_4
|
||||||
|
default y if DEP_Y
|
||||||
|
configdefault SYM_Y_4
|
||||||
|
default y if DEP_N
|
||||||
|
|
||||||
|
config SYM_Y_4
|
||||||
|
bool "SYM Y 4"
|
||||||
|
|
||||||
|
configdefault SYM_N_4
|
||||||
|
default y if DEP_N
|
||||||
|
configdefault SYM_N_4
|
||||||
|
default y if DEP_N
|
||||||
|
|
||||||
|
config SYM_N_4
|
||||||
|
bool "SYM N 4"
|
||||||
|
|
||||||
|
# if surrounding configdefault
|
||||||
|
config SYM_Y_5
|
||||||
|
bool "SYM Y 5"
|
||||||
|
if DEP_Y
|
||||||
|
configdefault SYM_Y_5
|
||||||
|
default y
|
||||||
|
endif
|
||||||
|
|
||||||
|
config SYM_N_5
|
||||||
|
bool "SYM N 5"
|
||||||
|
if DEP_N
|
||||||
|
configdefault SYM_N_5
|
||||||
|
default y
|
||||||
|
endif
|
||||||
|
|
||||||
|
# if surrounding definition
|
||||||
|
if DEP_Y
|
||||||
|
config SYM_Y_6
|
||||||
|
bool "SYM Y 6"
|
||||||
|
endif
|
||||||
|
|
||||||
|
configdefault SYM_Y_6
|
||||||
|
default y
|
||||||
|
|
||||||
|
if DEP_N
|
||||||
|
config SYM_N_6
|
||||||
|
bool "SYM N 6"
|
||||||
|
endif
|
||||||
|
|
||||||
|
configdefault SYM_N_6
|
||||||
|
default y
|
||||||
|
|
||||||
|
# if surrounding complete
|
||||||
|
if DEP_Y
|
||||||
|
config SYM_Y_7
|
||||||
|
bool "SYM Y 7"
|
||||||
|
configdefault SYM_Y_7
|
||||||
|
default y
|
||||||
|
endif
|
||||||
|
|
||||||
|
if DEP_N
|
||||||
|
config SYM_N_7
|
||||||
|
bool "SYM N 7"
|
||||||
|
configdefault SYM_N_7
|
||||||
|
default y
|
||||||
|
endif
|
||||||
|
|
||||||
|
# configdefault default symbol
|
||||||
|
config SYM_Y_8
|
||||||
|
bool "SYM Y 8"
|
||||||
|
|
||||||
|
configdefault SYM_Y_8
|
||||||
|
default DEP_Y
|
||||||
|
|
||||||
|
config SYM_N_8
|
||||||
|
bool "SYM N 8"
|
||||||
|
|
||||||
|
configdefault SYM_N_8
|
||||||
|
default DEP_N
|
||||||
|
|
||||||
|
# configdefault with "prompt if <conditional==true>"
|
||||||
|
configdefault SYM_Y_9
|
||||||
|
default y
|
||||||
|
|
||||||
|
config SYM_Y_9
|
||||||
|
bool "SYM Y 9" if DEP_Y
|
||||||
|
default y if DEP_N
|
||||||
|
|
||||||
|
configdefault SYM_N_9
|
||||||
|
default n if DEP_Y
|
||||||
|
|
||||||
|
config SYM_N_9
|
||||||
|
bool "SYM N 9" if DEP_Y
|
||||||
|
default y
|
||||||
|
|
||||||
|
# configdefault with "prompt if <conditional==false>"
|
||||||
|
configdefault SYM_Y_10
|
||||||
|
default y if DEP_Y
|
||||||
|
|
||||||
|
config SYM_Y_10
|
||||||
|
bool "SYM Y 10" if DEP_N
|
||||||
|
|
||||||
|
configdefault SYM_N_10
|
||||||
|
default n if DEP_Y
|
||||||
|
|
||||||
|
config SYM_N_10
|
||||||
|
bool "SYM N 10" if DEP_N
|
||||||
|
default y
|
||||||
|
|
||||||
|
# configdefault with "prompt if <conditional==true>" and surrounding 'if'
|
||||||
|
configdefault SYM_Y_11
|
||||||
|
default y
|
||||||
|
|
||||||
|
if DEP_Y
|
||||||
|
config SYM_Y_11
|
||||||
|
bool "SYM Y 11" if DEP_Y
|
||||||
|
default y if DEP_N
|
||||||
|
endif
|
||||||
|
|
||||||
|
configdefault SYM_N_11
|
||||||
|
default y
|
||||||
|
|
||||||
|
if DEP_N
|
||||||
|
config SYM_N_11
|
||||||
|
bool "SYM N 11" if DEP_Y
|
||||||
|
default n if DEP_N
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Multiple symbols, no configdefault effect
|
||||||
|
configdefault SYM_Y_12
|
||||||
|
default y if DEP_N
|
||||||
|
|
||||||
|
config SYM_Y_12
|
||||||
|
bool "SYM Y 12"
|
||||||
|
default y if DEP_N
|
||||||
|
depends on DEP_N
|
||||||
|
|
||||||
|
config SYM_Y_12
|
||||||
|
default y
|
||||||
|
|
||||||
|
configdefault SYM_N_12
|
||||||
|
default y if DEP_N
|
||||||
|
|
||||||
|
config SYM_N_12
|
||||||
|
bool "SYM N 12"
|
||||||
|
default y if DEP_N
|
||||||
|
|
||||||
|
config SYM_N_12
|
||||||
|
default n
|
||||||
|
|
||||||
|
# configdefault does not define integer
|
||||||
|
config SYM_INT_UNDEF
|
||||||
|
int "Undefined integer"
|
||||||
|
default 0
|
||||||
|
depends on DEP_N
|
||||||
|
|
||||||
|
configdefault SYM_INT_UNDEF
|
||||||
|
default 1
|
||||||
|
|
||||||
|
# Integer default
|
||||||
|
config SYM_INT_1
|
||||||
|
int "Int 1"
|
||||||
|
depends on DEP_Y
|
||||||
|
|
||||||
|
configdefault SYM_INT_1
|
||||||
|
default 1
|
||||||
|
|
||||||
|
# configdefault doesn't overwrite ordering
|
||||||
|
config SYM_INT_2
|
||||||
|
int "Int 2"
|
||||||
|
default 2
|
||||||
|
|
||||||
|
configdefault SYM_INT_2
|
||||||
|
default 3
|
||||||
|
|
||||||
|
configdefault SYM_INT_3
|
||||||
|
default 3
|
||||||
|
|
||||||
|
configdefault SYM_INT_3
|
||||||
|
default 4
|
||||||
|
|
||||||
|
config SYM_INT_3
|
||||||
|
int "Int 3"
|
||||||
|
default 2
|
||||||
|
|
||||||
|
configdefault SYM_INT_4
|
||||||
|
default 3 if DEP_N
|
||||||
|
|
||||||
|
configdefault SYM_INT_4
|
||||||
|
default 4
|
||||||
|
|
||||||
|
config SYM_INT_4
|
||||||
|
int "Int 4"
|
||||||
|
default 2
|
||||||
|
|
||||||
|
# Hex value
|
||||||
|
configdefault SYM_HEX_20
|
||||||
|
default 0x20
|
||||||
|
|
||||||
|
config SYM_HEX_20
|
||||||
|
hex "Hex 0x20"
|
||||||
|
|
||||||
|
# String value
|
||||||
|
configdefault SYM_STRING
|
||||||
|
default "TEST"
|
||||||
|
|
||||||
|
config SYM_STRING
|
||||||
|
string "Hex 0x20"
|
||||||
|
|
||||||
|
source "Kconfig.zephyr"
|
2
tests/kconfig/configdefault/prj.conf
Normal file
2
tests/kconfig/configdefault/prj.conf
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
CONFIG_ZTEST=y
|
||||||
|
CONFIG_ZTEST_NEW_API=y
|
52
tests/kconfig/configdefault/src/main.c
Normal file
52
tests/kconfig/configdefault/src/main.c
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 CSIRO
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/sys/__assert.h>
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
|
||||||
|
ZTEST_SUITE(test_configdefault, NULL, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
ZTEST(test_configdefault, test_expectedvalues)
|
||||||
|
{
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_DEP_Y), "");
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_DEP_N), "");
|
||||||
|
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_SYM_Y_1), "");
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_SYM_Y_2), "");
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_SYM_Y_3), "");
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_SYM_Y_4), "");
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_SYM_Y_5), "");
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_SYM_Y_6), "");
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_SYM_Y_7), "");
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_SYM_Y_8), "");
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_SYM_Y_9), "");
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_SYM_Y_10), "");
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_SYM_Y_11), "");
|
||||||
|
zassert_true(IS_ENABLED(CONFIG_SYM_Y_12), "");
|
||||||
|
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_N_1), "");
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_N_2), "");
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_N_3), "");
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_N_4), "");
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_N_5), "");
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_N_6), "");
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_N_7), "");
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_N_8), "");
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_N_9), "");
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_N_10), "");
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_N_11), "");
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_N_12), "");
|
||||||
|
|
||||||
|
zassert_false(IS_ENABLED(CONFIG_SYM_INT_UNDEF), "");
|
||||||
|
zassert_equal(1, CONFIG_SYM_INT_1, "");
|
||||||
|
zassert_equal(2, CONFIG_SYM_INT_2, "");
|
||||||
|
zassert_equal(3, CONFIG_SYM_INT_3, "");
|
||||||
|
zassert_equal(4, CONFIG_SYM_INT_4, "");
|
||||||
|
|
||||||
|
zassert_equal(0x20, CONFIG_SYM_HEX_20, "");
|
||||||
|
zassert_mem_equal("TEST", CONFIG_SYM_STRING, strlen("TEST"), "");
|
||||||
|
}
|
3
tests/kconfig/configdefault/testcase.yaml
Normal file
3
tests/kconfig/configdefault/testcase.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
tests:
|
||||||
|
kconfig.configdefault:
|
||||||
|
tags: kconfig
|
Loading…
Add table
Add a link
Reference in a new issue