From patchwork Mon Aug 1 13:57:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1662621 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=DiW6csA8; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LxKTN5jMmz9sGP for ; Mon, 1 Aug 2022 23:58:14 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9924383F8E; Mon, 1 Aug 2022 15:58:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="DiW6csA8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 85CEF8171B; Mon, 1 Aug 2022 15:58:08 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1920683F9A for ; Mon, 1 Aug 2022 15:58:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x230.google.com with SMTP id w72so8792354oiw.6 for ; Mon, 01 Aug 2022 06:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=nHPiGL99nk9LZ2+q8vutHeanYAcEPvqhloI2eRwY+OQ=; b=DiW6csA8dafOrJTKIGZRhX3EdC4KdDMPW+ICSAkJ7X8NsYjQIQ/ZA4b5hIZx/RWmne vDRwCilYdErsKXCpwtPhC7OKS0vs8djtVQNNSYrk9PX7UWsh0fAO0FpqNHSe1IcKkJNK rI2l3k3hOfscaCyJavrGe/HeoanZBjeYXF9HY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=nHPiGL99nk9LZ2+q8vutHeanYAcEPvqhloI2eRwY+OQ=; b=Y3lab8ScBmd4OAIYJ0cp6CB38JuKQnlYo0L9aYo4Y/R8lpYdiJTsRqWyuOTo+NWyMX PAQ8gfxGROtEMjlPS0aBNQklvn/FnuLJMWK2mm76dEJvfDO3zFiX+X2rippSetxWrJKI D5VmccVbC+iqP3PJ3jMcbmuzzFDkg9Un2hfsZFpr0B9f6+5cCr20QLCZGaBdKGWOmjSp 2jF9PtgwCob8Jp6c9ethpDZWiewbAdxb9EEfQpkcWrMre8S1iuBhHcnFjKVr9pzuA6nM I7QHB9PfP/LeG13w07vaOf90yl1ei7DGxjdk++ZDU8B/WSmaU+hhVEmS59ScWQfQp0Mk 0hbw== X-Gm-Message-State: AJIora9OJVCh1pbtF5A/+RDSkKvu5wAkPV44fzLdfl47czKbQOs5lEBT Rmzi25VGTRsqd444enh+184khKiyapngVA== X-Google-Smtp-Source: AGRyM1sbZDaWJAa+Xq2l0WSPGyyO+4NhgAebBsApi8tDULqqWxr/BzDzO1FePnrQdQIf9MjgaE68+g== X-Received: by 2002:aca:ba86:0:b0:33a:c6f7:3001 with SMTP id k128-20020acaba86000000b0033ac6f73001mr6574866oif.5.1659362283450; Mon, 01 Aug 2022 06:58:03 -0700 (PDT) Received: from sjg1.lan (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id z20-20020a9d65d4000000b0061d040305e4sm1550428oth.1.2022.08.01.06.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 06:58:03 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Rasmus Villemoes , Tom Rini , Simon Glass , Andrew Scull , Heinrich Schuchardt Subject: [PATCH v5 1/1] test: Add some tests for kconfig.h Date: Mon, 1 Aug 2022 07:57:59 -0600 Message-Id: <20220801075754.v5.1.Ie47cd2188903124b89a6f580ff486d97f1924eae@changeid> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The macros in this file are a little confusing and we currently have no tests to check that they work as expected. Add some tests which check the macros in C code. Add a few tests which check that the build errors are generated correctly too, using buildman's -a option. Signed-off-by: Simon Glass --- Changes in v5: - Correct a problem with azure not supporting buildman's parent directory - Don't run the tests on sandbox_vpl Changes in v4: - Expand the series with tests and buildman changes test/Kconfig | 3 +- test/Makefile | 4 ++- test/lib/Kconfig | 23 ++++++++++++++ test/lib/Makefile | 5 +++ test/lib/kconfig.c | 58 +++++++++++++++++++++++++++++++++++ test/lib/kconfig_spl.c | 44 ++++++++++++++++++++++++++ test/py/tests/test_kconfig.py | 39 +++++++++++++++++++++++ 7 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 test/lib/Kconfig create mode 100644 test/lib/kconfig.c create mode 100644 test/lib/kconfig_spl.c create mode 100644 test/py/tests/test_kconfig.py diff --git a/test/Kconfig b/test/Kconfig index 9b283a57ba9..a6b463e4d06 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -20,7 +20,7 @@ config SPL_UNIT_TEST config UT_LIB bool "Unit tests for library functions" depends on UNIT_TEST - default y + default y if !SANDBOX_VPL help Enables the 'ut lib' command which tests library functions like memcat(), memcyp(), memmove() and ASN1 compiler/decoder. @@ -99,5 +99,6 @@ config UT_UNICODE source "test/dm/Kconfig" source "test/env/Kconfig" +source "test/lib/Kconfig" source "test/optee/Kconfig" source "test/overlay/Kconfig" diff --git a/test/Makefile b/test/Makefile index 1dfd5677440..178773647a8 100644 --- a/test/Makefile +++ b/test/Makefile @@ -17,6 +17,9 @@ obj-$(CONFIG_$(SPL_)CMDLINE) += command_ut.o obj-$(CONFIG_$(SPL_)UT_COMPRESSION) += compression.o obj-y += dm/ obj-$(CONFIG_FUZZ) += fuzz/ +ifndef CONFIG_SANDBOX_VPL +obj-$(CONFIG_UNIT_TEST) += lib/ +endif obj-$(CONFIG_$(SPL_)CMDLINE) += print_ut.o obj-$(CONFIG_$(SPL_)CMDLINE) += str_ut.o obj-$(CONFIG_UT_TIME) += time_ut.o @@ -25,7 +28,6 @@ obj-y += ut.o ifeq ($(CONFIG_SPL_BUILD),) obj-$(CONFIG_UNIT_TEST) += boot/ obj-$(CONFIG_UNIT_TEST) += common/ -obj-$(CONFIG_UNIT_TEST) += lib/ obj-y += log/ obj-$(CONFIG_$(SPL_)UT_UNICODE) += unicode_ut.o endif diff --git a/test/lib/Kconfig b/test/lib/Kconfig new file mode 100644 index 00000000000..dbb03e4a36f --- /dev/null +++ b/test/lib/Kconfig @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2022 Google LLC + +if SANDBOX + +config TEST_KCONFIG + bool "Enable detection of Kconfig macro errors" + help + This is used to test that the IF_ENABLED_INT() macro causes a build error + if the value is used when the CONFIG Is not enabled. + +config TEST_KCONFIG_ENABLE + bool "Option to enable" + help + This is the option that controls whether the value is present. + +config TEST_KCONFIG_VALUE + int "Value associated with the option" + depends on TEST_KCONFIG_ENABLE + help + This is the value whgch is present if TEST_KCONFIG_ENABLE is enabled. + +endif # SANDBOX diff --git a/test/lib/Makefile b/test/lib/Makefile index d244bb431d4..7e7922fe3b4 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -2,11 +2,13 @@ # # (C) Copyright 2018 # Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc +ifeq ($(CONFIG_SPL_BUILD),) obj-y += cmd_ut_lib.o obj-y += abuf.o obj-$(CONFIG_EFI_LOADER) += efi_device_path.o obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o obj-y += hexdump.o +obj-$(CONFIG_SANDBOX) += kconfig.o obj-y += lmb.o obj-y += longjmp.o obj-$(CONFIG_CONSOLE_RECORD) += test_print.o @@ -19,3 +21,6 @@ obj-$(CONFIG_UT_LIB_RSA) += rsa.o obj-$(CONFIG_AES) += test_aes.o obj-$(CONFIG_GETOPT) += getopt.o obj-$(CONFIG_UT_LIB_CRYPT) += test_crypt.o +else +obj-$(CONFIG_SANDBOX) += kconfig_spl.o +endif diff --git a/test/lib/kconfig.c b/test/lib/kconfig.c new file mode 100644 index 00000000000..472d2c57280 --- /dev/null +++ b/test/lib/kconfig.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test of linux/kconfig.h macros + * + * Copyright 2022 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include + +static int lib_test_is_enabled(struct unit_test_state *uts) +{ + ulong val; + + ut_asserteq(1, IS_ENABLED(CONFIG_CMDLINE)) + ut_asserteq(0, IS_ENABLED(CONFIG__UNDEFINED)) + + ut_asserteq(1, CONFIG_IS_ENABLED(CMDLINE)) + ut_asserteq(0, CONFIG_IS_ENABLED(OF_PLATDATA)) + ut_asserteq(0, CONFIG_IS_ENABLED(_UNDEFINED)) + + ut_asserteq(0xc000, + IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED, CONFIG_BLOBLIST_ADDR)); + ut_asserteq(0xc000, + CONFIG_IF_ENABLED_INT(BLOBLIST_FIXED, BLOBLIST_ADDR)); + + /* + * This fails if CONFIG_TEST_KCONFIG_ENABLE is not enabled, since the + * value is used. Disable for SPL so that the errors in kconfig_spl.c + * are detected, since otherwise a build error when building U-Boot may + * cause SPL to not be built. + */ + if (!IS_ENABLED(CONFIG_SANDBOX_SPL) && + IS_ENABLED(CONFIG_TEST_KCONFIG)) { + val = IF_ENABLED_INT(CONFIG_TEST_KCONFIG_ENABLE, + CONFIG_TEST_KCONFIG_VALUE); + printf("value %ld\n", val); + } + + /* + * This fails if CONFIG_TEST_KCONFIG_ENABLE is not enabled, since the + * value is used. Disable for SPL so that the errors in kconfig_spl.c + * are detected, since otherwise a build error when building U-Boot may + * cause SPL to not be built. + */ + if (!IS_ENABLED(CONFIG_SANDBOX_SPL) && + CONFIG_IS_ENABLED(TEST_KCONFIG)) { + val = CONFIG_IF_ENABLED_INT(TEST_KCONFIG_ENABLE, + TEST_KCONFIG_VALUE); + printf("value2 %ld\n", val); + } + + return 0; +} +LIB_TEST(lib_test_is_enabled, 0); diff --git a/test/lib/kconfig_spl.c b/test/lib/kconfig_spl.c new file mode 100644 index 00000000000..c89ceaec66f --- /dev/null +++ b/test/lib/kconfig_spl.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test of linux/kconfig.h macros for SPL + * + * Copyright 2022 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include + +static int lib_test_spl_is_enabled(struct unit_test_state *uts) +{ + ulong val; + + ut_asserteq(0, CONFIG_IS_ENABLED(CMDLINE)) + ut_asserteq(1, CONFIG_IS_ENABLED(OF_PLATDATA)) + ut_asserteq(0, CONFIG_IS_ENABLED(_UNDEFINED)) + + /* + * This fails if CONFIG_TEST_KCONFIG_ENABLE is not enabled, since the + * value is used. + */ + if (IS_ENABLED(CONFIG_TEST_KCONFIG)) { + val = IF_ENABLED_INT(CONFIG_TEST_KCONFIG_ENABLE, + CONFIG_TEST_KCONFIG_VALUE); + printf("value %ld\n", val); + } + + /* + * This fails if CONFIG_TEST_KCONFIG_ENABLE is not enabled, since the + * value is used. + */ + if (CONFIG_IS_ENABLED(TEST_KCONFIG)) { + val = CONFIG_IF_ENABLED_INT(TEST_KCONFIG_ENABLE, + TEST_KCONFIG_VALUE); + printf("value2 %ld\n", val); + } + + return 0; +} +LIB_TEST(lib_test_spl_is_enabled, 0); diff --git a/test/py/tests/test_kconfig.py b/test/py/tests/test_kconfig.py new file mode 100644 index 00000000000..0b9e6bc3bd1 --- /dev/null +++ b/test/py/tests/test_kconfig.py @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright 2022 Google LLC +# Written by Simon Glass + +import pytest + +import u_boot_utils as util + +# This is needed for Azure, since the default '..' directory is not writeable +TMPDIR = '/tmp/test_kconfig' + +@pytest.mark.slow +@pytest.mark.boardspec('sandbox') +def test_kconfig(u_boot_console): + """Test build failures when IF_ENABLED_INT() option is not enabled""" + cons = u_boot_console + + # This detects build errors in test/lib/kconfig.c + out = util.run_and_log( + cons, ['./tools/buildman/buildman', '-m', '--board', 'sandbox', + '-a', 'TEST_KCONFIG', '-o', TMPDIR], ignore_errors=True) + assert 'invalid_use_of_IF_ENABLED_INT' in out + assert 'invalid_use_of_CONFIG_IF_ENABLED_INT' in out + +@pytest.mark.slow +@pytest.mark.boardspec('sandbox_spl') +def test_kconfig_spl(u_boot_console): + """Test build failures when IF_ENABLED_INT() option is not enabled""" + cons = u_boot_console + + # This detects build errors in test/lib/kconfig_spl.c + out = util.run_and_log( + cons, ['./tools/buildman/buildman', '-m', '--board', 'sandbox_spl', + '-a', 'TEST_KCONFIG', '-o', TMPDIR], ignore_errors=True) + assert 'invalid_use_of_IF_ENABLED_INT' in out + + # There is no CONFIG_SPL_TEST_KCONFIG, so the CONFIG_IF_ENABLED_INT() + # line should not generate an error + assert 'invalid_use_of_CONFIG_IF_ENABLED_INT' not in out