From cea39d4383bbe4fb32b51b21735af33267666ce0 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sun, 16 Oct 2022 14:47:50 +1000 Subject: [PATCH] tests: kconfig: test configdefault extension Test the behaviour of the `configdefault` kconfig extension. Signed-off-by: Jordan Yates --- tests/kconfig/configdefault/CMakeLists.txt | 8 + tests/kconfig/configdefault/Kconfig | 259 +++++++++++++++++++++ tests/kconfig/configdefault/prj.conf | 2 + tests/kconfig/configdefault/src/main.c | 52 +++++ tests/kconfig/configdefault/testcase.yaml | 3 + 5 files changed, 324 insertions(+) create mode 100644 tests/kconfig/configdefault/CMakeLists.txt create mode 100644 tests/kconfig/configdefault/Kconfig create mode 100644 tests/kconfig/configdefault/prj.conf create mode 100644 tests/kconfig/configdefault/src/main.c create mode 100644 tests/kconfig/configdefault/testcase.yaml diff --git a/tests/kconfig/configdefault/CMakeLists.txt b/tests/kconfig/configdefault/CMakeLists.txt new file mode 100644 index 00000000000..93e45bf9ce9 --- /dev/null +++ b/tests/kconfig/configdefault/CMakeLists.txt @@ -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}) diff --git a/tests/kconfig/configdefault/Kconfig b/tests/kconfig/configdefault/Kconfig new file mode 100644 index 00000000000..7c19c642bbe --- /dev/null +++ b/tests/kconfig/configdefault/Kconfig @@ -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 " +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 " +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 " 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" diff --git a/tests/kconfig/configdefault/prj.conf b/tests/kconfig/configdefault/prj.conf new file mode 100644 index 00000000000..9228251051e --- /dev/null +++ b/tests/kconfig/configdefault/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y diff --git a/tests/kconfig/configdefault/src/main.c b/tests/kconfig/configdefault/src/main.c new file mode 100644 index 00000000000..abff0c54671 --- /dev/null +++ b/tests/kconfig/configdefault/src/main.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 CSIRO + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +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"), ""); +} diff --git a/tests/kconfig/configdefault/testcase.yaml b/tests/kconfig/configdefault/testcase.yaml new file mode 100644 index 00000000000..dcf193ec001 --- /dev/null +++ b/tests/kconfig/configdefault/testcase.yaml @@ -0,0 +1,3 @@ +tests: + kconfig.configdefault: + tags: kconfig