Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9723AC4332F for ; Wed, 19 Oct 2022 21:34:23 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EE0F284ADF; Wed, 19 Oct 2022 23:34:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de 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; secure) header.d=gmx.net header.i=@gmx.net header.b="RC60vSLD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D7B8184D2B; Wed, 19 Oct 2022 23:34:18 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 57C3384966 for ; Wed, 19 Oct 2022 23:34:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666215253; bh=66KhtqlYnkaFeq/yBeMzUmiKzDIf6Ycfovc+49r1cTg=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=RC60vSLDoezW7VwtS4CEJQmyl41riaQ8hp85B/zo/W7LmCjFZoAZ2GeJICOquchAh NHI4XjWuUEcl8GnUdGqSPi9GrfPGJ1bZFvoqCdY9/De/yCSASnsPY0YQMsxGj9wBDD ZmhxiFOORjpHApKgVT8DxfDM1Anr8pJjHYkZ/z7Q= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.94] ([84.118.157.2]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MS3ir-1ofNoE0hBL-00TSuc; Wed, 19 Oct 2022 23:34:13 +0200 Message-ID: <4554325d-e9be-b355-b299-b98f5621842f@gmx.de> Date: Wed, 19 Oct 2022 23:34:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH v3 6/6] test: add test for eficonfig secure boot key management To: Simon Glass Cc: Masahisa Kojima , u-boot@lists.denx.de, Takahiro Akashi , Ilias Apalodimas References: <20221014065705.5249-1-masahisa.kojima@linaro.org> <20221014065705.5249-7-masahisa.kojima@linaro.org> <06f0c6aa-a7be-4e82-f665-c003420cd6b3@gmx.de> Content-Language: en-US From: Heinrich Schuchardt In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:0anJPX/7BMajAmU6AZZYWmiRIpaohwD7YWQr1Jyqt6KbwJgj5zp ulQhGqdo8bzVVPHz05MNzlOIV6eltN5DkqyEyTXjcr9sY5vSegC5yx7/2YuiFcdhdvTnkt3 JrlBL3x4mW262OzcsS9Na2bCWQlTXnHgx+AVCsvdaC21DnZjOGMJhIc68nICy2VXlFxaK0k nu8hdQj6E55IMJHU/TZXA== X-UI-Out-Filterresults: notjunk:1;V03:K0:9UPkRbmdiCI=:jIxvqVfmcFCmBdDymoyEDQ jQgpMMCZP413nwlENlHAMoSAx2ysPRu29cHP6cOyeifaKawPCe2kllwQ5kg2Qp4WAj4G+Q6mo dJW8Tgo5S7K/y6VqGbTEDWTBJsVKoZjoSUI4q7d9az6oB9ZuCDvoFQ29OMJcVSfX/waHX/d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RK4flyK8l1gbfSN3xpwY43temN2iS JGlYVpV6DzyqdOWeM8hl14xlmrF8X2EIlcfElHK04OCyagMfRju7hnpp6ugBVefKRHgY9nj5w lUhnmMp3sNQ+Psbi724hZ5EuMlZF1tOGehNH7zgl3n3S6WJtqq56bVWx9Aqsh/uHQ7btvM+AL 5Tpk8SN7jhSRo2CDezLBglI8DtvJSfxAqQ9NK0p74GEdXnWB+msp1lw+tvCnbsvROdPV4h2ol bnbdjOKPyL88IZ9lfShRR6JhYM2SDG2lsiGoqgkgBGPS5FCzimg39fp/t2CBhc2C3/79atb4q SW7B5CM25XST+6W7iKtI7LNi4Vf3soUYwXN2nLoJTxYGf 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 On 10/19/22 15:17, Simon Glass wrote: > iHi Heinrich, > > On Fri, 14 Oct 2022 at 22:43, Heinrich Schuchardt w= rote: >> >> On 10/15/22 03:10, Simon Glass wrote: >>> Hi Ilias, >>> >>> On Fri, 14 Oct 2022 at 09:59, Ilias Apalodimas >>> wrote: >>>> >>>> Hi Simon, >>>> >>>> On Fri, 14 Oct 2022 at 18:56, Simon Glass wrote: >>>>> >>>>> Hi, >>>>> >>>>> On Fri, 14 Oct 2022 at 00:58, Masahisa Kojima >>>>> wrote: >>>>>> >>>>>> Provide a unit test for the eficonfig secure boot key >>>>>> management menu. >>>>>> >>>>>> Signed-off-by: Masahisa Kojima >>>>>> --- >>>>>> No change since v2 >>>>>> >>>>>> newly created in v2 >>>>>> >>>>>> test/py/tests/test_eficonfig/conftest.py | 84 +++- >>>>>> test/py/tests/test_eficonfig/defs.py | 14 + >>>>>> .../test_eficonfig/test_eficonfig_sbkey.py | 472 ++++++++++++= ++++++ >>>>>> 3 files changed, 568 insertions(+), 2 deletions(-) >>>>>> create mode 100644 test/py/tests/test_eficonfig/defs.py >>>>>> create mode 100644 test/py/tests/test_eficonfig/test_eficonfig_s= bkey.py >>>>> >>>>> Please can this test be in C? Also, using down-arrow to select menus >>>>> is brittle. Add a function to select the one you want, e.g. by name. >>>>> >>>> >>>> Is there a very specific reason why we should do stuff like that in C= ? >>> >>> Yes, see here. >>> >>>> Python is way easier to extend and test in our case. >>> >>> In what way? It seems a lot more complicated, plus the brittle nature >>> of this test suggests it will be a hassle to maintain. >>> >>> https://u-boot.readthedocs.io/en/latest/develop/tests_writing.html#pyt= hon-or-c >>> >>> There is a pending update here too: >>> >>> https://patchwork.ozlabs.org/project/uboot/patch/20221013122927.636867= -15-sjg@chromium.org/ >> >> The discussion touches different aspects: >> >> ** What does it take to make a GUI easily testable? ** >> >> Relying on cursor movement for testing is fragile. This is why GUIs >> often assign to each executable element the following: >> >> * Access key, e.g >> A key combination that when entered will have the the same >> effect as selecting the GUI item >> * Access string, '@SAVE' >> A string that when typed into the command field will have >> the same effect as selecting the GUI item >> >> Let's look at U-Boot's menu entry definition: >> >> struct bootmenu_entry { >> unsigned short int num; // unique number 0 .. MAX_COUNT >> char key[3]; // key identifier of number >> char *title; // title of entry >> char *command; // hush command of entry >> enum boot_type type; // boot type of entry >> u16 bootorder; // order for each boot type >> struct bootmenu_data *menu; // this bootmenu >> struct bootmenu_entry *next; // next menu entry (num+1) >> } >> >> Our structure lacks an accessor element that can be used to select a >> menu item without using cursor actions. >> >> Compound keystrokes like are send as multiple bytes on the >> console, e.g. 1b 5b 31 37 3b 35 7e. >> >> We may define a field shortcut of type char *. If the string is receive= d >> by the menu loop, let it activate the matching menu entry. Let cursor >> actions (up, down, enter, space '+', '-') interrupt matching the >> shortcut string. >> >> Instead we could also use a convention for the title: >> >> If a letter in the title is preceded by '&', this is the shortcut key. >> This letter will be shown highlighted in the menu and the ampersand wil= l >> not be shown. >> >> This is probably easier to implement. >> >> Adding the shortcut facility will allow both for easier testing and >> faster navigation. >> >> ** Choice of programming language ** >> >> Several aspects control the choice of the programming language for test= s: >> >> - Testing single library functions is only possible in C. >> - Checking contents of internal structures is only possible in C. >> - Testing the U-Boot's CLI is easily accessible in our Python framework= . >> - Preparation of complex test data is easier to do in Python. >> - Mixed language tests should be avoided if not strictly necessary. >> It is much easier to maintain a single code source for a test. >> >> ** What to do for secure boot key management? ** >> >> Secure boot key management requires complex preparation which fits well >> into out Python testing framework. >> >> Once we provide shortcut keys to U-Boot menus the entries will be easil= y >> accessible from Python. >> >> As we want to avoid complexity due to mixed language tests we should >> stick to Python for testing key management at the user level. > > The test setup should be in Python (and needs to be) but the actual > test should be in C, in general. > >>From what I can tell these tests should be split up, one for each test c= ase. > > Using keyboard shortcuts for menus would certainly help, but you still > have the dependency between the menu code in C and the Python code > that uses it. The complexity of this dependency is quite significant. > > Can we not design this all for easier testing? The functionality > should be broken down a little more so we can change the configs in a > test (e.g. using the eficonfig command), then check that booting does > what we expect. > > Overall I feel that this 'black box' testing is not a good approach > and we should try to test the components. It is OK to have a > happy-path test but here we are just writing hundreds of lines of > Python to get a very high-level signal about correctness. From other projects I am used to differentiate between unit tests and integration tests. An integration test is what checks that all the parts work together while a unit test checks a single functionality works as designed. A description can be found in https://circleci.com/blog/unit-testing-vs-integration-testing/#c-consent-m= odal For an integration test this Python script is fine (except for the menu navigation. As I said in my last mail additional tests on a lower level may be added. But unit tests cannot replace an integration test. Best regards Heinrich > >> >> Additional tests in C for library functions managing keys and verifying >> signatures would improve our code coverage. >> >> Best regards >> >> Heinrich > > Regards, > Simon