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 C62A6C4332F for ; Sat, 15 Oct 2022 04:43:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5199D84BFB; Sat, 15 Oct 2022 06:43:34 +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="WtHh9/j0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 71A4284C53; Sat, 15 Oct 2022 06:43:32 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (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 43A008483E for ; Sat, 15 Oct 2022 06:43:29 +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=1665809008; bh=C+s9QJ4j3seSTCR2NiCOUDsUUUZ4KE4J6CoAty+EN8I=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=WtHh9/j0d0hk9+go+AVEzfc8lB9BoOlVSYqQY0LlRCJA4N4WNSKWSJNoIERA2suVD Io/67gI1e3DtViLO+4hbaOUqQGZltoyKm677J+gFgMjV6oZJEadVoMcqeeYmmAP6Ke jySTzFJFEklaTfHjeYrttz5BHVL1FtJ20+W8YWWo= 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 1Mlw3N-1pRO9D0E1j-00j3xv; Sat, 15 Oct 2022 06:43:28 +0200 Message-ID: <06f0c6aa-a7be-4e82-f665-c003420cd6b3@gmx.de> Date: Sat, 15 Oct 2022 06:43:22 +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> 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:Tv77qynePGiMQXE6s07WthrLruLjQEwXK2eMI8YzAQ+oiv9FGUZ 69Yhdxr7XgaCkKKVpSA9zzZe/2D73Amsjk+f8up1BWgtTw6sjTqboql1uT+JsA+BsS87Fk/ 32i9oEGi87Deo3UCRDBE7GBjBQigtoD4IBsI1zW5uBwJGj0k6ChdPNGlcJd9Tli11MfwkKG 3VoE2qOoMWEErKOga467Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:UKq0yampGaI=:2zXp/0p+zGoomcQfBDFLcq n9Cq9WS6hTsA/34cRwEEm4Kg8DXgBuqd/+7zJP35hRBR96+dATWm1ox+FN1V0ZjRSaA6vmns8 /JXF0torkSv4B5idcJTLFghdOI3eZ361zA1068cwZlfBRNo9Hi8lywt7rcfHk6yWafCzzc55v N1+xvq7dYzL8fVDVcOk7ZhFN3QgOs4OCpayrAfAQ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h4mOjlI5+UHQONyAk8PKIdoNzIXCmw6qUObPews1QlS e7Ih0hoBUmiigxmQ/P/8zBZ0ch8nhf/Fl0jL44dd0kDTghCBaQZy3beH5vv4SbrJpses1dQyi fIWvpk6VHrn+Rt9cOrrcoxOlAUji6N/wURN18LH761qKl8bm6SVCJvXFsCclMFAHLodkCSCi7 0IApB5pEe7eLpTgDL/PmCP+w838KPrlepba2fyDFniY91nffydIILe3p1+4dVTT3nLrQC2wiF /yaWpNrwr0F7M2Tlh40nFyCH6Fp3JAvs/01tEuJlSbALc 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/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_sbke= y.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#pytho= n-or-c > > There is a pending update here too: > > https://patchwork.ozlabs.org/project/uboot/patch/20221013122927.636867-1= 5-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 received 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 will 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 tests: - 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 easily 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. Additional tests in C for library functions managing keys and verifying signatures would improve our code coverage. Best regards Heinrich