| Message ID | 20260430080627.849636-4-dario.binacchi@amarulasolutions.com |
|---|---|
| State | New |
| Headers |
Return-Path:
<linux-amarula+bncBCQ4XFG47UFRBE43ZTHQMGQECQ2BG6Y@amarulasolutions.com>
X-Original-To: linux-amarula@patchwork.amarulasolutions.com
Delivered-To: linux-amarula@patchwork.amarulasolutions.com
Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com
[209.85.218.71])
by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 68BD23F0D7
for <linux-amarula@patchwork.amarulasolutions.com>;
Thu, 30 Apr 2026 10:06:44 +0200 (CEST)
Received: by mail-ej1-f71.google.com with SMTP id
a640c23a62f3a-b8704795d25sf40455866b.2
for <linux-amarula@patchwork.amarulasolutions.com>;
Thu, 30 Apr 2026 01:06:44 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1777536404; cv=pass;
d=google.com; s=arc-20240605;
b=gtGJ68VCH1b2bmDjmpXcWTyRGHmxOF9KMmtzoPHL6CANeeyFoxeILHIQlBfFfQticY
EhVIM6sFuKcNvID1LDEiKYOa74YIDDcmqrTXjdt2i1tn9Hf2p6q8kqZuoUqLylyq5ekf
/e3tNUpFkYQAIK/ga00l21w+BwOdM00DPZE3GtR39Zq/MvuFoVJv93rAXylQR0WcIOdu
EzBXhn0Cfch8kuLbl46iRsMMlsCYNlaigx8/pYfXHniNpdOy29J2KnDgIdCn73Syb1y2
ngwdG24OhhsV2ygslNRD7HUbep2QA1aCD8HliBJbIwKEarirvyCvTvFNARGgeMM649gu
N6+w==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20240605;
h=list-unsubscribe:list-archive:list-help:list-post:list-id
:mailing-list:precedence:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:dkim-signature;
bh=woqYgBetikOjxpVNAxRh6OWx5E6xroq7FMRK1Pd/5xA=;
fh=tfR3KjpG9FgRskNtid2wbqJH9IbXkQMwQET4MwpHr5A=;
b=TcypoBgE5zbo3Zej1a8esw8R+9wvhaMo8leqFgZwBbWXBqLfTL/TO+BlqLRIlDOsOF
wDRk42ylP5/SSIZmUYM9K6PHBkllmPy/Q6CSIJ+1miyXXK/lbVI1uQQ1Fd0P/bPqloTs
1ek0rmggph6SYdEfwEzwsTlliS5z0GSHBUYKQKetxRAUcqvs0KZELC4ZGnikrpGL4i5M
UiNXl10ry8Mo2fIFbxoMZFf3LiyHfMH3JvIUIhKd5w7pB/zPDzwtHa4uiG+XXzRl32sF
7G1aGmoX8AJhopH75VJxfpjPYBASIxu+l8/qW1ecNny2KKmdmHl81rAYmD5J1CNt2q+s
p9Kg==;
darn=patchwork.amarulasolutions.com
ARC-Authentication-Results: i=2; mx.google.com;
dkim=pass header.i=@amarulasolutions.com header.s=google
header.b=Dswar4J3;
spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com
designates 209.85.220.41 as permitted sender)
smtp.mailfrom=dario.binacchi@amarulasolutions.com;
dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com;
dara=neutral header.i=@amarulasolutions.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=amarulasolutions.com; s=google; t=1777536404; x=1778141204;
darn=patchwork.amarulasolutions.com;
h=list-unsubscribe:list-archive:list-help:list-post:list-id
:mailing-list:precedence:x-original-authentication-results
:x-original-sender:mime-version:references:in-reply-to:message-id
:date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to;
bh=woqYgBetikOjxpVNAxRh6OWx5E6xroq7FMRK1Pd/5xA=;
b=n/nfK2eVG0+WqjspP1fBDT+wCVebuUcyjtdpqaRKi8N/xzfD7n/aNX+J20xU38V7D/
wSKNyFw9594OGEi20CMV5OY9aK8bIqNUl1lhmyp854ykVLSTl6f3sTACfqmTUsbx7c7r
3VoZgKkvRoEUV90SR1ZUawC9MSM+3Qe2Znt38=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20251104; t=1777536404; x=1778141204;
h=list-unsubscribe:list-archive:list-help:list-post
:x-spam-checked-in-group:list-id:mailing-list:precedence
:x-original-authentication-results:x-original-sender:mime-version
:references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg
:x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id
:reply-to;
bh=woqYgBetikOjxpVNAxRh6OWx5E6xroq7FMRK1Pd/5xA=;
b=oJeX8yxPIe+BvhP4KyFKFxVKLupl0OHvSG1EHWOHXrJYan6aXsorkJEi755P+fr3M8
iFvMOmn2zp+o/N5PKizvIqvgrv8guBuNqMG0PapaXUhOyQA35UJlBkCRdcMkV7hhsvHw
Ei2vnXfZXkWdmH8CNDVl4jaC5ubJGflGVENTsXVBZUjkTL0dLyUGAGnBPO0VfcFmp5wA
Up4GPKqc3k8RSO5YPf7oY3cyDO0Sk0Z5sqO1J+g+KzH5VWFVh0adfBhp6kBlpcS1wEuc
CK+kspqY8q4mYaFrXfI5Gpt9MXyHIOrgp0C4pDWte06QYi1TOeDpo2oGzNPjct38LbHT
+XPA==
X-Forwarded-Encrypted: i=2;
AFNElJ9Hh7GOef6dMaFC1aLpF1NVm9EWbPoQVNDIEqidVx58baAjaQ3UKfsXSd9rfX0CQ7PCpLQa1d30HuyPRs13@patchwork.amarulasolutions.com
X-Gm-Message-State: AOJu0Yyj/l8cki6UZsBwYHGTVZonqjbARjKuv+Dbv3XWncBhdNUT2dAs
E0J9XRZedKzQaMTh7RKJH3wlDLfhSLs4SfmtAWwZbETw1JOkk//eslSkcWK24OyAyRiUsg==
X-Received: by 2002:a05:6402:360d:b0:671:dffb:f450 with SMTP id
4fb4d7f45d1cf-67b5d7e1dbemr809083a12.11.1777536403825;
Thu, 30 Apr 2026 01:06:43 -0700 (PDT)
X-BeenThere: linux-amarula@amarulasolutions.com;
h="AUV6zMMY67piB49hvH40FjHebL6gX901+0n+JpNzsbwXCRyjpw=="
Received: by 2002:aa7:d757:0:b0:679:cb2a:de38 with SMTP id
4fb4d7f45d1cf-67b4ee01b9els584567a12.2.-pod-prod-05-eu;
Thu, 30 Apr 2026 01:06:42 -0700 (PDT)
X-Received: by 2002:a17:906:4fce:b0:b9c:c3ca:a724 with SMTP id
a640c23a62f3a-bbac4cce26cmr106198566b.8.1777536402105;
Thu, 30 Apr 2026 01:06:42 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1777536402; cv=none;
d=google.com; s=arc-20240605;
b=H92hUkskMnefvTTmReZmF60JdIusHj8go5Uce6cMVlJJC93/s8wKddCj3SxuzW/yH2
hsXPvffNfE1UOwAcrTPzMKfyI7GC/kRX2YRTnEtNkvJ3/VCnhb/mSL5uh/Fh1/YXcslB
NwfgaH3xR0r4RyNAcz/w288eliQR7nNAy6JbosuRFHznjR9CS282c8CGDh6nbB2YHV5M
end92rwPBaFVMQjCazyA7VDudc0EmpTFSJ54MM9I08dt/Qeq4RfLlic+BDSnnf5jh1C/
nzERGvYTEbXhhHmCkiYtPoKLnxtIrdIW2bkDFaUrI4U7drTCq2uSPGSzrqrWYaP67ccb
ILlA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20240605;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:dkim-signature;
bh=ww/f9aAS1MjQvIGRcDgGP8JqUvShvBL+WVU2d+FjAR4=;
fh=afDizQ+XeKFIYMapWzHAkHLhN/H8qHZIH8gBsoTNkIw=;
b=OXvsYGt6FAvTTgHMy/RzCgZUFi/wbGulV+EtYUcRPrS6VfOun9Ut6M/J94X7BUil0U
yRcO79vFw0Z+sYK2TDrP29px+vMP6SYdYRGkSJ5JfrNEkfz4MxBL2bRbsgNvSs7wbU2N
4uOMO9yzfgogoGQsk+y4sSwrTdXCttvfzWOePlG0sfmry19VmGZK7LbDy5ChsyboFGlc
Lh3Cs7duaFkT+4wBvmQH1eBDNuimvayR3UJMPRMqClsqFAznXYXQy2rTdNar/ehp9UQF
gJrMxlW2O80zgN3GYoWPCgqxSfCfwtHtZBKPx+5cx4NGIOzEUT6QkRt881XaloWUVuSU
AfhA==;
dara=google.com
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass header.i=@amarulasolutions.com header.s=google
header.b=Dswar4J3;
spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com
designates 209.85.220.41 as permitted sender)
smtp.mailfrom=dario.binacchi@amarulasolutions.com;
dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com;
dara=neutral header.i=@amarulasolutions.com
Received: from mail-sor-f41.google.com (mail-sor-f41.google.com.
[209.85.220.41])
by mx.google.com with SMTPS id
a640c23a62f3a-bb980a6fcdesor99847166b.4.2026.04.30.01.06.42
for <linux-amarula@amarulasolutions.com>
(Google Transport Security);
Thu, 30 Apr 2026 01:06:42 -0700 (PDT)
Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com
designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
X-Gm-Gg: AeBDiesflRw9OeAyaFL2QQT2/UlVVKZLnjyetv8DT0hHCppfFei42OvwdS5azBvQ6jK
H+CznOnYdatVnQXpDazyueCnuemWjSuwKMqIkQ+utylSVkwjlyuyl5sy5sy2kaTriSULGlO5UQa
RyFetmJ3ovCsYXdnailem2o85X/t8qpt27yGJo0wMsFvaW2nDsbcjEoUB08837jvNbu8sFilprd
E9oxx+3izGuA3jUykL8ycpjfQjKbCTKHquQqo3xdyXZJ00RrgegdVClCxlsGkE98n+Xe0DtAMw4
HtDvaLAWqhNimHe6eOR0Bw2k1lSQFeWJzR1Lr949hwxLWOvhr/RR5GeH9xqwcDjxfk+wDN0PNXe
KpqK0mmDH/fMlqEUrXKrC9abySlx+4auinjM5A4rvDFj7l5aq1FeUALFi60CYqYgtOvJrAb5Ljo
UjR0TdcUi202xEjxWR69z3jTgxm/KtyvItBgfZpAAPXI/R3ZGOaneIKEnxlqtu9UGjposeqZcwN
9iWV+JdpKU+vYNC3Ql6rW0DZ8bok+YtZXQ2v1nYWsL9XOLWo+tEvGgXZGU+1biJgO3tc86uAgKv
u/UBLEOcadjzLOIgGVqrpPKGpUrdwPnC9BQ=
X-Received: by 2002:a17:907:1c19:b0:bb8:c3d9:3a33 with SMTP id
a640c23a62f3a-bbac52dcf9cmr107066766b.12.1777536401339;
Thu, 30 Apr 2026 01:06:41 -0700 (PDT)
Received: from dario-ThinkPad-P14s-Gen-5.homenet.telecomitalia.it
(host-82-56-22-134.retail.telecomitalia.it. [82.56.22.134])
by smtp.gmail.com with ESMTPSA id
ffacd0b85a97d-449c576d0a2sm668071f8f.31.2026.04.30.01.06.39
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 30 Apr 2026 01:06:40 -0700 (PDT)
From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
To: u-boot@lists.denx.de
Cc: linux-amarula@amarulasolutions.com,
Dario Binacchi <dario.binacchi@amarulasolutions.com>,
Simon Glass <sjg@chromium.org>,
Dinesh Maniyam <dinesh.maniyam@altera.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Marek Vasut <marek.vasut+renesas@mailbox.org>,
Mattijs Korpershoek <mkorpershoek@kernel.org>,
Quentin Schulz <quentin.schulz@cherry.de>,
Tom Rini <trini@konsulko.com>
Subject: [PATCH v8 3/8] test: cmd: add unit tests for part command
Date: Thu, 30 Apr 2026 10:06:04 +0200
Message-ID: <20260430080627.849636-4-dario.binacchi@amarulasolutions.com>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <20260430080627.849636-1-dario.binacchi@amarulasolutions.com>
References: <20260430080627.849636-1-dario.binacchi@amarulasolutions.com>
MIME-Version: 1.0
X-Original-Sender: dario.binacchi@amarulasolutions.com
X-Original-Authentication-Results: mx.google.com; dkim=pass
header.i=@amarulasolutions.com header.s=google header.b=Dswar4J3;
spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com
designates 209.85.220.41 as permitted sender)
smtp.mailfrom=dario.binacchi@amarulasolutions.com;
dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com;
dara=neutral header.i=@amarulasolutions.com
Content-Type: text/plain; charset="UTF-8"
Precedence: list
Mailing-list: list linux-amarula@amarulasolutions.com;
contact linux-amarula+owners@amarulasolutions.com
List-ID: <linux-amarula.amarulasolutions.com>
X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com
X-Google-Group-Id: 476853432473
List-Post:
<https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/post>,
<mailto:linux-amarula@amarulasolutions.com>
List-Help:
<https://support.google.com/a/amarulasolutions.com/bin/topic.py?topic=25838>,
<mailto:linux-amarula+help@amarulasolutions.com>
List-Archive:
<https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/>
List-Unsubscribe:
<mailto:googlegroups-manage+476853432473+unsubscribe@googlegroups.com>,
<https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/subscribe>
|
| Series |
Support metadata-driven A/B boot for STM32MP25
|
|
Commit Message
Dario Binacchi
April 30, 2026, 8:06 a.m. UTC
Add unit tests for the 'part' command, specifically for the 'number', 'start', and 'size' subcommands. These tests establish a baseline for the current partition lookup functionality by name. This foundation will be used by subsequent patches to extend the command, ensuring consistent behavior as new features are introduced. Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> Reviewed-by: Simon Glass <sjg@chromium.org> --- Changes in v8: - Skip the test in case the CONFIG_MCC is not enabled or the mmc device is not found. Changes in v6: - Add Reviewed-by of Simon Glass to patch 3/8 "test: cmd: add unit tests for part command" Changes in v4: - Place the part command tests in the cmd suite rather than the dm suite. - Order the include files according the U-Boot coding style. Changes in v3: - Wrap the lines exceeding 80 columns - Combine run_command() and ut_asserteq() -> ut_asserteq(1, run_command( test/cmd/Makefile | 1 + test/cmd/part.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 test/cmd/part.c
Comments
On 4/30/26 10:06, Dario Binacchi wrote: > Add unit tests for the 'part' command, specifically for the 'number', > 'start', and 'size' subcommands. > > These tests establish a baseline for the current partition lookup > functionality by name. This foundation will be used by subsequent > patches to extend the command, ensuring consistent behavior as new > features are introduced. > > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > Reviewed-by: Simon Glass <sjg@chromium.org> > > --- > > Changes in v8: > - Skip the test in case the CONFIG_MCC is not enabled or the mmc > device is not found. > > Changes in v6: > - Add Reviewed-by of Simon Glass to patch 3/8 "test: cmd: add unit > tests for part command" > > Changes in v4: > - Place the part command tests in the cmd suite rather than the dm > suite. > - Order the include files according the U-Boot coding style. > > Changes in v3: > - Wrap the lines exceeding 80 columns > - Combine run_command() and ut_asserteq() -> ut_asserteq(1, run_command( > > test/cmd/Makefile | 1 + > test/cmd/part.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 184 insertions(+) > create mode 100644 test/cmd/part.c > > diff --git a/test/cmd/Makefile b/test/cmd/Makefile > index 5f2815b1bb65..8d6932f1176c 100644 > --- a/test/cmd/Makefile > +++ b/test/cmd/Makefile > @@ -26,6 +26,7 @@ obj-$(CONFIG_CMD_LOADM) += loadm.o > obj-$(CONFIG_CMD_MEMINFO) += meminfo.o > obj-$(CONFIG_CMD_MEMORY) += mem_copy.o > obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o > +obj-$(CONFIG_CMD_PART) += part.o > ifdef CONFIG_CMD_PCI > obj-$(CONFIG_CMD_PCI_MPS) += pci_mps.o > endif > diff --git a/test/cmd/part.c b/test/cmd/part.c > new file mode 100644 > index 000000000000..cac57a1a0e35 > --- /dev/null > +++ b/test/cmd/part.c > @@ -0,0 +1,183 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Test for part command > + * > + * Copyright (C) 2026 Amarula Solutions > + * Written by Dario Binacchi <dario.binacchi@amarulasolutions.com> > + */ > + > +#include <command.h> > +#include <dm.h> > +#include <env.h> > +#include <part.h> > +#include <vsprintf.h> > +#include <dm/test.h> > +#include <test/cmd.h> > +#include <test/test.h> > +#include <test/ut.h> > + > +static struct disk_partition gpt_parts[] = { > + { > + .start = 48, > + .size = 1, > + .name = "test1", > + .uuid = "c5bce7a2-03f0-4d03-9048-01ff23b9d527", > + }, > + { > + .start = 49, > + .size = 2, > + .name = "test2", > + .uuid = "9df346e8-2c53-4cd8-b9ac-3af83f9a9b74", > + }, > +}; > + > +static char disk_guid[UUID_STR_LEN + 1] = > + "8d60b397-1bb6-4d33-80ee-b1587d24c2f8"; > + > +static int setup_gpt_partitions(struct unit_test_state *uts, > + unsigned int mmc_dev_num) > +{ > + struct blk_desc *mmc_dev_desc; > + char dev_str[10]; > + int i, ret; > + > + if (!CONFIG_IS_ENABLED(MMC)) > + return -EAGAIN; Hi Dario Is there any reason to return -EAGAIN ? -ENODEV seems more appropriate ? Thanks Patrice > + > + snprintf(dev_str, sizeof(dev_str), "%u", mmc_dev_num); > + > + ret = blk_get_device_by_str("mmc", dev_str, &mmc_dev_desc); > + if (ret == -ENODEV) > + return -EAGAIN; > + > + ut_asserteq(mmc_dev_num, ret); > + > + if (CONFIG_IS_ENABLED(RANDOM_UUID)) { > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) > + gen_rand_uuid_str(gpt_parts[i].uuid, > + UUID_STR_FORMAT_STD); > + > + gen_rand_uuid_str(disk_guid, UUID_STR_FORMAT_STD); > + } > + > + ut_assertok(gpt_restore(mmc_dev_desc, disk_guid, gpt_parts, > + ARRAY_SIZE(gpt_parts))); > + return 0; > +} > + > +static int cmd_test_part_number(struct unit_test_state *uts) > +{ > + unsigned int mmc_dev_num = 2; > + char expected[10]; > + int i, ret; > + > + ret = setup_gpt_partitions(uts, mmc_dev_num); > + if (ret == -EAGAIN) > + return ret; > + > + ut_assertok(ret); > + > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { > + env_set("partnum", NULL); > + ut_assertok(run_commandf("part number mmc %u %s partnum", > + mmc_dev_num, gpt_parts[i].name)); > + snprintf(expected, sizeof(expected), "0x%x", i + 1); > + ut_asserteq_str(expected, env_get("partnum")); > + } > + > + env_set("partnum", NULL); > + ut_asserteq(1, run_commandf("part number mmc %u bogus partnum", > + mmc_dev_num)); > + ut_assertnull(env_get("partnum")); > + > + return 0; > +} > +CMD_TEST(cmd_test_part_number, UTF_CONSOLE); > + > +static int cmd_test_part_start(struct unit_test_state *uts) > +{ > + unsigned int mmc_dev_num = 2; > + char expected[32]; > + int i, ret; > + > + ret = setup_gpt_partitions(uts, mmc_dev_num); > + if (ret == -EAGAIN) > + return ret; > + > + ut_assertok(ret); > + > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { > + env_set("partstart", NULL); > + ut_assertok(run_commandf("part start mmc %u %d partstart", > + mmc_dev_num, i + 1)); > + snprintf(expected, sizeof(expected), "%lx", > + (unsigned long)gpt_parts[i].start); > + ut_asserteq_str(expected, env_get("partstart")); > + } > + > + env_set("partstart", NULL); > + ut_asserteq(1, run_commandf("part start mmc %u 3 partstart", > + mmc_dev_num)); > + ut_assertnull(env_get("partstart")); > + > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { > + env_set("partstart", NULL); > + ut_assertok(run_commandf("part start mmc %u %s partstart", > + mmc_dev_num, gpt_parts[i].name)); > + snprintf(expected, sizeof(expected), "%lx", > + (unsigned long)gpt_parts[i].start); > + ut_asserteq_str(expected, env_get("partstart")); > + } > + > + env_set("partstart", NULL); > + ut_asserteq(1, run_commandf("part start mmc %u bogus partstart", > + mmc_dev_num)); > + ut_assertnull(env_get("partstart")); > + > + return 0; > +} > +CMD_TEST(cmd_test_part_start, UTF_CONSOLE); > + > +static int cmd_test_part_size(struct unit_test_state *uts) > +{ > + unsigned int mmc_dev_num = 2; > + char expected[32]; > + int i, ret; > + > + ret = setup_gpt_partitions(uts, mmc_dev_num); > + if (ret == -EAGAIN) > + return ret; > + > + ut_assertok(ret); > + > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { > + env_set("partsize", NULL); > + ut_assertok(run_commandf("part size mmc %u %d partsize", > + mmc_dev_num, i + 1)); > + snprintf(expected, sizeof(expected), "%lx", > + (unsigned long)gpt_parts[i].size); > + ut_asserteq_str(expected, env_get("partsize")); > + } > + > + env_set("partsize", NULL); > + ut_asserteq(1, run_commandf("part size mmc %u 3 partsize", > + mmc_dev_num)); > + ut_assertnull(env_get("partsize")); > + > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { > + env_set("partsize", NULL); > + ut_assertok(run_commandf("part size mmc %u %s partsize", > + mmc_dev_num, gpt_parts[i].name)); > + snprintf(expected, sizeof(expected), "%lx", > + (unsigned long)gpt_parts[i].size); > + ut_asserteq_str(expected, env_get("partsize")); > + } > + > + env_set("partsize", NULL); > + ut_asserteq(1, run_commandf("part size mmc %u bogus partsize", > + mmc_dev_num)); > + ut_assertnull(env_get("partsize")); > + > + return 0; > +} > +CMD_TEST(cmd_test_part_size, UTF_CONSOLE); To unsubscribe from this group and stop receiving emails from it, send an email to linux-amarula+unsubscribe@amarulasolutions.com.
Hi Patrice, On Tue, May 5, 2026 at 9:26 AM Patrice CHOTARD <patrice.chotard@foss.st.com> wrote: > > > On 4/30/26 10:06, Dario Binacchi wrote: > > Add unit tests for the 'part' command, specifically for the 'number', > > 'start', and 'size' subcommands. > > > > These tests establish a baseline for the current partition lookup > > functionality by name. This foundation will be used by subsequent > > patches to extend the command, ensuring consistent behavior as new > > features are introduced. > > > > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > > Reviewed-by: Simon Glass <sjg@chromium.org> > > > > --- > > > > Changes in v8: > > - Skip the test in case the CONFIG_MCC is not enabled or the mmc > > device is not found. > > > > Changes in v6: > > - Add Reviewed-by of Simon Glass to patch 3/8 "test: cmd: add unit > > tests for part command" > > > > Changes in v4: > > - Place the part command tests in the cmd suite rather than the dm > > suite. > > - Order the include files according the U-Boot coding style. > > > > Changes in v3: > > - Wrap the lines exceeding 80 columns > > - Combine run_command() and ut_asserteq() -> ut_asserteq(1, run_command( > > > > test/cmd/Makefile | 1 + > > test/cmd/part.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 184 insertions(+) > > create mode 100644 test/cmd/part.c > > > > diff --git a/test/cmd/Makefile b/test/cmd/Makefile > > index 5f2815b1bb65..8d6932f1176c 100644 > > --- a/test/cmd/Makefile > > +++ b/test/cmd/Makefile > > @@ -26,6 +26,7 @@ obj-$(CONFIG_CMD_LOADM) += loadm.o > > obj-$(CONFIG_CMD_MEMINFO) += meminfo.o > > obj-$(CONFIG_CMD_MEMORY) += mem_copy.o > > obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o > > +obj-$(CONFIG_CMD_PART) += part.o > > ifdef CONFIG_CMD_PCI > > obj-$(CONFIG_CMD_PCI_MPS) += pci_mps.o > > endif > > diff --git a/test/cmd/part.c b/test/cmd/part.c > > new file mode 100644 > > index 000000000000..cac57a1a0e35 > > --- /dev/null > > +++ b/test/cmd/part.c > > @@ -0,0 +1,183 @@ > > +// SPDX-License-Identifier: GPL-2.0+ > > +/* > > + * Test for part command > > + * > > + * Copyright (C) 2026 Amarula Solutions > > + * Written by Dario Binacchi <dario.binacchi@amarulasolutions.com> > > + */ > > + > > +#include <command.h> > > +#include <dm.h> > > +#include <env.h> > > +#include <part.h> > > +#include <vsprintf.h> > > +#include <dm/test.h> > > +#include <test/cmd.h> > > +#include <test/test.h> > > +#include <test/ut.h> > > + > > +static struct disk_partition gpt_parts[] = { > > + { > > + .start = 48, > > + .size = 1, > > + .name = "test1", > > + .uuid = "c5bce7a2-03f0-4d03-9048-01ff23b9d527", > > + }, > > + { > > + .start = 49, > > + .size = 2, > > + .name = "test2", > > + .uuid = "9df346e8-2c53-4cd8-b9ac-3af83f9a9b74", > > + }, > > +}; > > + > > +static char disk_guid[UUID_STR_LEN + 1] = > > + "8d60b397-1bb6-4d33-80ee-b1587d24c2f8"; > > + > > +static int setup_gpt_partitions(struct unit_test_state *uts, > > + unsigned int mmc_dev_num) > > +{ > > + struct blk_desc *mmc_dev_desc; > > + char dev_str[10]; > > + int i, ret; > > + > > + if (!CONFIG_IS_ENABLED(MMC)) > > + return -EAGAIN; > > Hi Dario > > Is there any reason to return -EAGAIN ? -ENODEV seems more appropriate ? > In the testing framework, returning -EAGAIN explicitly signals that the test should be skipped*.* As highlighted in the documentation for ut_run_test(): *Return: 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if any failed* Since the necessary preconditions weren't met for some configuration in our case, I decided to skip. Thanks and regards, Dario > Thanks > Patrice > > > + > > + snprintf(dev_str, sizeof(dev_str), "%u", mmc_dev_num); > > + > > + ret = blk_get_device_by_str("mmc", dev_str, &mmc_dev_desc); > > + if (ret == -ENODEV) > > + return -EAGAIN; > > + > > + ut_asserteq(mmc_dev_num, ret); > > + > > + if (CONFIG_IS_ENABLED(RANDOM_UUID)) { > > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) > > + gen_rand_uuid_str(gpt_parts[i].uuid, > > + UUID_STR_FORMAT_STD); > > + > > + gen_rand_uuid_str(disk_guid, UUID_STR_FORMAT_STD); > > + } > > + > > + ut_assertok(gpt_restore(mmc_dev_desc, disk_guid, gpt_parts, > > + ARRAY_SIZE(gpt_parts))); > > + return 0; > > +} > > + > > +static int cmd_test_part_number(struct unit_test_state *uts) > > +{ > > + unsigned int mmc_dev_num = 2; > > + char expected[10]; > > + int i, ret; > > + > > + ret = setup_gpt_partitions(uts, mmc_dev_num); > > + if (ret == -EAGAIN) > > + return ret; > > + > > + ut_assertok(ret); > > + > > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { > > + env_set("partnum", NULL); > > + ut_assertok(run_commandf("part number mmc %u %s partnum", > > + mmc_dev_num, gpt_parts[i].name)); > > + snprintf(expected, sizeof(expected), "0x%x", i + 1); > > + ut_asserteq_str(expected, env_get("partnum")); > > + } > > + > > + env_set("partnum", NULL); > > + ut_asserteq(1, run_commandf("part number mmc %u bogus partnum", > > + mmc_dev_num)); > > + ut_assertnull(env_get("partnum")); > > + > > + return 0; > > +} > > +CMD_TEST(cmd_test_part_number, UTF_CONSOLE); > > + > > +static int cmd_test_part_start(struct unit_test_state *uts) > > +{ > > + unsigned int mmc_dev_num = 2; > > + char expected[32]; > > + int i, ret; > > + > > + ret = setup_gpt_partitions(uts, mmc_dev_num); > > + if (ret == -EAGAIN) > > + return ret; > > + > > + ut_assertok(ret); > > + > > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { > > + env_set("partstart", NULL); > > + ut_assertok(run_commandf("part start mmc %u %d partstart", > > + mmc_dev_num, i + 1)); > > + snprintf(expected, sizeof(expected), "%lx", > > + (unsigned long)gpt_parts[i].start); > > + ut_asserteq_str(expected, env_get("partstart")); > > + } > > + > > + env_set("partstart", NULL); > > + ut_asserteq(1, run_commandf("part start mmc %u 3 partstart", > > + mmc_dev_num)); > > + ut_assertnull(env_get("partstart")); > > + > > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { > > + env_set("partstart", NULL); > > + ut_assertok(run_commandf("part start mmc %u %s partstart", > > + mmc_dev_num, gpt_parts[i].name)); > > + snprintf(expected, sizeof(expected), "%lx", > > + (unsigned long)gpt_parts[i].start); > > + ut_asserteq_str(expected, env_get("partstart")); > > + } > > + > > + env_set("partstart", NULL); > > + ut_asserteq(1, run_commandf("part start mmc %u bogus partstart", > > + mmc_dev_num)); > > + ut_assertnull(env_get("partstart")); > > + > > + return 0; > > +} > > +CMD_TEST(cmd_test_part_start, UTF_CONSOLE); > > + > > +static int cmd_test_part_size(struct unit_test_state *uts) > > +{ > > + unsigned int mmc_dev_num = 2; > > + char expected[32]; > > + int i, ret; > > + > > + ret = setup_gpt_partitions(uts, mmc_dev_num); > > + if (ret == -EAGAIN) > > + return ret; > > + > > + ut_assertok(ret); > > + > > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { > > + env_set("partsize", NULL); > > + ut_assertok(run_commandf("part size mmc %u %d partsize", > > + mmc_dev_num, i + 1)); > > + snprintf(expected, sizeof(expected), "%lx", > > + (unsigned long)gpt_parts[i].size); > > + ut_asserteq_str(expected, env_get("partsize")); > > + } > > + > > + env_set("partsize", NULL); > > + ut_asserteq(1, run_commandf("part size mmc %u 3 partsize", > > + mmc_dev_num)); > > + ut_assertnull(env_get("partsize")); > > + > > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { > > + env_set("partsize", NULL); > > + ut_assertok(run_commandf("part size mmc %u %s partsize", > > + mmc_dev_num, gpt_parts[i].name)); > > + snprintf(expected, sizeof(expected), "%lx", > > + (unsigned long)gpt_parts[i].size); > > + ut_asserteq_str(expected, env_get("partsize")); > > + } > > + > > + env_set("partsize", NULL); > > + ut_asserteq(1, run_commandf("part size mmc %u bogus partsize", > > + mmc_dev_num)); > > + ut_assertnull(env_get("partsize")); > > + > > + return 0; > > +} > > +CMD_TEST(cmd_test_part_size, UTF_CONSOLE); > >
Hi everyone, I am resending my previous reply because I received a delivery failure notification last week indicating that Patrice's mailbox was full. Patrice, did you have a chance to verify if the tests are passing fine now? Please let me know if everything looks good or if you need me to make any further modifications. Thanks and regards Dario On Tue, May 5, 2026 at 9:55 AM Dario Binacchi < dario.binacchi@amarulasolutions.com> wrote: > Hi Patrice, > > On Tue, May 5, 2026 at 9:26 AM Patrice CHOTARD < > patrice.chotard@foss.st.com> wrote: > >> >> >> On 4/30/26 10:06, Dario Binacchi wrote: >> > Add unit tests for the 'part' command, specifically for the 'number', >> > 'start', and 'size' subcommands. >> > >> > These tests establish a baseline for the current partition lookup >> > functionality by name. This foundation will be used by subsequent >> > patches to extend the command, ensuring consistent behavior as new >> > features are introduced. >> > >> > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> >> > Reviewed-by: Simon Glass <sjg@chromium.org> >> > >> > --- >> > >> > Changes in v8: >> > - Skip the test in case the CONFIG_MCC is not enabled or the mmc >> > device is not found. >> > >> > Changes in v6: >> > - Add Reviewed-by of Simon Glass to patch 3/8 "test: cmd: add unit >> > tests for part command" >> > >> > Changes in v4: >> > - Place the part command tests in the cmd suite rather than the dm >> > suite. >> > - Order the include files according the U-Boot coding style. >> > >> > Changes in v3: >> > - Wrap the lines exceeding 80 columns >> > - Combine run_command() and ut_asserteq() -> ut_asserteq(1, run_command( >> > >> > test/cmd/Makefile | 1 + >> > test/cmd/part.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++ >> > 2 files changed, 184 insertions(+) >> > create mode 100644 test/cmd/part.c >> > >> > diff --git a/test/cmd/Makefile b/test/cmd/Makefile >> > index 5f2815b1bb65..8d6932f1176c 100644 >> > --- a/test/cmd/Makefile >> > +++ b/test/cmd/Makefile >> > @@ -26,6 +26,7 @@ obj-$(CONFIG_CMD_LOADM) += loadm.o >> > obj-$(CONFIG_CMD_MEMINFO) += meminfo.o >> > obj-$(CONFIG_CMD_MEMORY) += mem_copy.o >> > obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o >> > +obj-$(CONFIG_CMD_PART) += part.o >> > ifdef CONFIG_CMD_PCI >> > obj-$(CONFIG_CMD_PCI_MPS) += pci_mps.o >> > endif >> > diff --git a/test/cmd/part.c b/test/cmd/part.c >> > new file mode 100644 >> > index 000000000000..cac57a1a0e35 >> > --- /dev/null >> > +++ b/test/cmd/part.c >> > @@ -0,0 +1,183 @@ >> > +// SPDX-License-Identifier: GPL-2.0+ >> > +/* >> > + * Test for part command >> > + * >> > + * Copyright (C) 2026 Amarula Solutions >> > + * Written by Dario Binacchi <dario.binacchi@amarulasolutions.com> >> > + */ >> > + >> > +#include <command.h> >> > +#include <dm.h> >> > +#include <env.h> >> > +#include <part.h> >> > +#include <vsprintf.h> >> > +#include <dm/test.h> >> > +#include <test/cmd.h> >> > +#include <test/test.h> >> > +#include <test/ut.h> >> > + >> > +static struct disk_partition gpt_parts[] = { >> > + { >> > + .start = 48, >> > + .size = 1, >> > + .name = "test1", >> > + .uuid = "c5bce7a2-03f0-4d03-9048-01ff23b9d527", >> > + }, >> > + { >> > + .start = 49, >> > + .size = 2, >> > + .name = "test2", >> > + .uuid = "9df346e8-2c53-4cd8-b9ac-3af83f9a9b74", >> > + }, >> > +}; >> > + >> > +static char disk_guid[UUID_STR_LEN + 1] = >> > + "8d60b397-1bb6-4d33-80ee-b1587d24c2f8"; >> > + >> > +static int setup_gpt_partitions(struct unit_test_state *uts, >> > + unsigned int mmc_dev_num) >> > +{ >> > + struct blk_desc *mmc_dev_desc; >> > + char dev_str[10]; >> > + int i, ret; >> > + >> > + if (!CONFIG_IS_ENABLED(MMC)) >> > + return -EAGAIN; >> >> Hi Dario >> >> Is there any reason to return -EAGAIN ? -ENODEV seems more appropriate ? >> > > In the testing framework, returning -EAGAIN explicitly signals that the > test should be skipped*.* > > As highlighted in the documentation for ut_run_test(): > > *Return: 0 if all tests passed, -EAGAIN if the test should be skipped, -1 > if any failed* > > > Since the necessary preconditions weren't met for some configuration in > our case, I decided to skip. > > Thanks and regards, > > Dario > > >> Thanks >> Patrice >> >> > + >> > + snprintf(dev_str, sizeof(dev_str), "%u", mmc_dev_num); >> > + >> > + ret = blk_get_device_by_str("mmc", dev_str, &mmc_dev_desc); >> > + if (ret == -ENODEV) >> > + return -EAGAIN; >> > + >> > + ut_asserteq(mmc_dev_num, ret); >> > + >> > + if (CONFIG_IS_ENABLED(RANDOM_UUID)) { >> > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) >> > + gen_rand_uuid_str(gpt_parts[i].uuid, >> > + UUID_STR_FORMAT_STD); >> > + >> > + gen_rand_uuid_str(disk_guid, UUID_STR_FORMAT_STD); >> > + } >> > + >> > + ut_assertok(gpt_restore(mmc_dev_desc, disk_guid, gpt_parts, >> > + ARRAY_SIZE(gpt_parts))); >> > + return 0; >> > +} >> > + >> > +static int cmd_test_part_number(struct unit_test_state *uts) >> > +{ >> > + unsigned int mmc_dev_num = 2; >> > + char expected[10]; >> > + int i, ret; >> > + >> > + ret = setup_gpt_partitions(uts, mmc_dev_num); >> > + if (ret == -EAGAIN) >> > + return ret; >> > + >> > + ut_assertok(ret); >> > + >> > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { >> > + env_set("partnum", NULL); >> > + ut_assertok(run_commandf("part number mmc %u %s partnum", >> > + mmc_dev_num, gpt_parts[i].name)); >> > + snprintf(expected, sizeof(expected), "0x%x", i + 1); >> > + ut_asserteq_str(expected, env_get("partnum")); >> > + } >> > + >> > + env_set("partnum", NULL); >> > + ut_asserteq(1, run_commandf("part number mmc %u bogus partnum", >> > + mmc_dev_num)); >> > + ut_assertnull(env_get("partnum")); >> > + >> > + return 0; >> > +} >> > +CMD_TEST(cmd_test_part_number, UTF_CONSOLE); >> > + >> > +static int cmd_test_part_start(struct unit_test_state *uts) >> > +{ >> > + unsigned int mmc_dev_num = 2; >> > + char expected[32]; >> > + int i, ret; >> > + >> > + ret = setup_gpt_partitions(uts, mmc_dev_num); >> > + if (ret == -EAGAIN) >> > + return ret; >> > + >> > + ut_assertok(ret); >> > + >> > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { >> > + env_set("partstart", NULL); >> > + ut_assertok(run_commandf("part start mmc %u %d partstart", >> > + mmc_dev_num, i + 1)); >> > + snprintf(expected, sizeof(expected), "%lx", >> > + (unsigned long)gpt_parts[i].start); >> > + ut_asserteq_str(expected, env_get("partstart")); >> > + } >> > + >> > + env_set("partstart", NULL); >> > + ut_asserteq(1, run_commandf("part start mmc %u 3 partstart", >> > + mmc_dev_num)); >> > + ut_assertnull(env_get("partstart")); >> > + >> > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { >> > + env_set("partstart", NULL); >> > + ut_assertok(run_commandf("part start mmc %u %s partstart", >> > + mmc_dev_num, gpt_parts[i].name)); >> > + snprintf(expected, sizeof(expected), "%lx", >> > + (unsigned long)gpt_parts[i].start); >> > + ut_asserteq_str(expected, env_get("partstart")); >> > + } >> > + >> > + env_set("partstart", NULL); >> > + ut_asserteq(1, run_commandf("part start mmc %u bogus partstart", >> > + mmc_dev_num)); >> > + ut_assertnull(env_get("partstart")); >> > + >> > + return 0; >> > +} >> > +CMD_TEST(cmd_test_part_start, UTF_CONSOLE); >> > + >> > +static int cmd_test_part_size(struct unit_test_state *uts) >> > +{ >> > + unsigned int mmc_dev_num = 2; >> > + char expected[32]; >> > + int i, ret; >> > + >> > + ret = setup_gpt_partitions(uts, mmc_dev_num); >> > + if (ret == -EAGAIN) >> > + return ret; >> > + >> > + ut_assertok(ret); >> > + >> > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { >> > + env_set("partsize", NULL); >> > + ut_assertok(run_commandf("part size mmc %u %d partsize", >> > + mmc_dev_num, i + 1)); >> > + snprintf(expected, sizeof(expected), "%lx", >> > + (unsigned long)gpt_parts[i].size); >> > + ut_asserteq_str(expected, env_get("partsize")); >> > + } >> > + >> > + env_set("partsize", NULL); >> > + ut_asserteq(1, run_commandf("part size mmc %u 3 partsize", >> > + mmc_dev_num)); >> > + ut_assertnull(env_get("partsize")); >> > + >> > + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { >> > + env_set("partsize", NULL); >> > + ut_assertok(run_commandf("part size mmc %u %s partsize", >> > + mmc_dev_num, gpt_parts[i].name)); >> > + snprintf(expected, sizeof(expected), "%lx", >> > + (unsigned long)gpt_parts[i].size); >> > + ut_asserteq_str(expected, env_get("partsize")); >> > + } >> > + >> > + env_set("partsize", NULL); >> > + ut_asserteq(1, run_commandf("part size mmc %u bogus partsize", >> > + mmc_dev_num)); >> > + ut_assertnull(env_get("partsize")); >> > + >> > + return 0; >> > +} >> > +CMD_TEST(cmd_test_part_size, UTF_CONSOLE); >> >> > > -- > *Dario Binacchi* > Senior Embedded Software Engineer > M. +39 328 0625246 > dario.binacchi@amarulasolutions.com > ――――――――――――――― > Amarula Solutions SRL > Via Felice Cavallotti 25D, 41012 Carpi, MO, IT > info@amarulasolutions.com > www.amarulasolutions.com >
On 5/12/26 09:08, Dario Binacchi wrote: > Hi everyone, > > I am resending my previous reply because I received a delivery failure > notification last week indicating that Patrice's mailbox was full. > > Patrice, did you have a chance to verify if the tests are passing fine now? > Please let me know if everything looks good or if you need > > me to make any further modifications. > > Thanks and regards > > Dario Hi Dario My mailbox has been cleaned ;-), i expected to respin this series for test tomorrow or next week. Thanks Patrice > > On Tue, May 5, 2026 at 9:55 AM Dario Binacchi < > dario.binacchi@amarulasolutions.com> wrote: > >> Hi Patrice, >> >> On Tue, May 5, 2026 at 9:26 AM Patrice CHOTARD < >> patrice.chotard@foss.st.com> wrote: >> >>> >>> >>> On 4/30/26 10:06, Dario Binacchi wrote: >>>> Add unit tests for the 'part' command, specifically for the 'number', >>>> 'start', and 'size' subcommands. >>>> >>>> These tests establish a baseline for the current partition lookup >>>> functionality by name. This foundation will be used by subsequent >>>> patches to extend the command, ensuring consistent behavior as new >>>> features are introduced. >>>> >>>> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> >>>> Reviewed-by: Simon Glass <sjg@chromium.org> >>>> >>>> --- >>>> >>>> Changes in v8: >>>> - Skip the test in case the CONFIG_MCC is not enabled or the mmc >>>> device is not found. >>>> >>>> Changes in v6: >>>> - Add Reviewed-by of Simon Glass to patch 3/8 "test: cmd: add unit >>>> tests for part command" >>>> >>>> Changes in v4: >>>> - Place the part command tests in the cmd suite rather than the dm >>>> suite. >>>> - Order the include files according the U-Boot coding style. >>>> >>>> Changes in v3: >>>> - Wrap the lines exceeding 80 columns >>>> - Combine run_command() and ut_asserteq() -> ut_asserteq(1, run_command( >>>> >>>> test/cmd/Makefile | 1 + >>>> test/cmd/part.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++ >>>> 2 files changed, 184 insertions(+) >>>> create mode 100644 test/cmd/part.c >>>> >>>> diff --git a/test/cmd/Makefile b/test/cmd/Makefile >>>> index 5f2815b1bb65..8d6932f1176c 100644 >>>> --- a/test/cmd/Makefile >>>> +++ b/test/cmd/Makefile >>>> @@ -26,6 +26,7 @@ obj-$(CONFIG_CMD_LOADM) += loadm.o >>>> obj-$(CONFIG_CMD_MEMINFO) += meminfo.o >>>> obj-$(CONFIG_CMD_MEMORY) += mem_copy.o >>>> obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o >>>> +obj-$(CONFIG_CMD_PART) += part.o >>>> ifdef CONFIG_CMD_PCI >>>> obj-$(CONFIG_CMD_PCI_MPS) += pci_mps.o >>>> endif >>>> diff --git a/test/cmd/part.c b/test/cmd/part.c >>>> new file mode 100644 >>>> index 000000000000..cac57a1a0e35 >>>> --- /dev/null >>>> +++ b/test/cmd/part.c >>>> @@ -0,0 +1,183 @@ >>>> +// SPDX-License-Identifier: GPL-2.0+ >>>> +/* >>>> + * Test for part command >>>> + * >>>> + * Copyright (C) 2026 Amarula Solutions >>>> + * Written by Dario Binacchi <dario.binacchi@amarulasolutions.com> >>>> + */ >>>> + >>>> +#include <command.h> >>>> +#include <dm.h> >>>> +#include <env.h> >>>> +#include <part.h> >>>> +#include <vsprintf.h> >>>> +#include <dm/test.h> >>>> +#include <test/cmd.h> >>>> +#include <test/test.h> >>>> +#include <test/ut.h> >>>> + >>>> +static struct disk_partition gpt_parts[] = { >>>> + { >>>> + .start = 48, >>>> + .size = 1, >>>> + .name = "test1", >>>> + .uuid = "c5bce7a2-03f0-4d03-9048-01ff23b9d527", >>>> + }, >>>> + { >>>> + .start = 49, >>>> + .size = 2, >>>> + .name = "test2", >>>> + .uuid = "9df346e8-2c53-4cd8-b9ac-3af83f9a9b74", >>>> + }, >>>> +}; >>>> + >>>> +static char disk_guid[UUID_STR_LEN + 1] = >>>> + "8d60b397-1bb6-4d33-80ee-b1587d24c2f8"; >>>> + >>>> +static int setup_gpt_partitions(struct unit_test_state *uts, >>>> + unsigned int mmc_dev_num) >>>> +{ >>>> + struct blk_desc *mmc_dev_desc; >>>> + char dev_str[10]; >>>> + int i, ret; >>>> + >>>> + if (!CONFIG_IS_ENABLED(MMC)) >>>> + return -EAGAIN; >>> >>> Hi Dario >>> >>> Is there any reason to return -EAGAIN ? -ENODEV seems more appropriate ? >>> >> >> In the testing framework, returning -EAGAIN explicitly signals that the >> test should be skipped*.* >> >> As highlighted in the documentation for ut_run_test(): >> >> *Return: 0 if all tests passed, -EAGAIN if the test should be skipped, -1 >> if any failed* >> >> >> Since the necessary preconditions weren't met for some configuration in >> our case, I decided to skip. >> >> Thanks and regards, >> >> Dario >> >> >>> Thanks >>> Patrice >>> >>>> + >>>> + snprintf(dev_str, sizeof(dev_str), "%u", mmc_dev_num); >>>> + >>>> + ret = blk_get_device_by_str("mmc", dev_str, &mmc_dev_desc); >>>> + if (ret == -ENODEV) >>>> + return -EAGAIN; >>>> + >>>> + ut_asserteq(mmc_dev_num, ret); >>>> + >>>> + if (CONFIG_IS_ENABLED(RANDOM_UUID)) { >>>> + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) >>>> + gen_rand_uuid_str(gpt_parts[i].uuid, >>>> + UUID_STR_FORMAT_STD); >>>> + >>>> + gen_rand_uuid_str(disk_guid, UUID_STR_FORMAT_STD); >>>> + } >>>> + >>>> + ut_assertok(gpt_restore(mmc_dev_desc, disk_guid, gpt_parts, >>>> + ARRAY_SIZE(gpt_parts))); >>>> + return 0; >>>> +} >>>> + >>>> +static int cmd_test_part_number(struct unit_test_state *uts) >>>> +{ >>>> + unsigned int mmc_dev_num = 2; >>>> + char expected[10]; >>>> + int i, ret; >>>> + >>>> + ret = setup_gpt_partitions(uts, mmc_dev_num); >>>> + if (ret == -EAGAIN) >>>> + return ret; >>>> + >>>> + ut_assertok(ret); >>>> + >>>> + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { >>>> + env_set("partnum", NULL); >>>> + ut_assertok(run_commandf("part number mmc %u %s partnum", >>>> + mmc_dev_num, gpt_parts[i].name)); >>>> + snprintf(expected, sizeof(expected), "0x%x", i + 1); >>>> + ut_asserteq_str(expected, env_get("partnum")); >>>> + } >>>> + >>>> + env_set("partnum", NULL); >>>> + ut_asserteq(1, run_commandf("part number mmc %u bogus partnum", >>>> + mmc_dev_num)); >>>> + ut_assertnull(env_get("partnum")); >>>> + >>>> + return 0; >>>> +} >>>> +CMD_TEST(cmd_test_part_number, UTF_CONSOLE); >>>> + >>>> +static int cmd_test_part_start(struct unit_test_state *uts) >>>> +{ >>>> + unsigned int mmc_dev_num = 2; >>>> + char expected[32]; >>>> + int i, ret; >>>> + >>>> + ret = setup_gpt_partitions(uts, mmc_dev_num); >>>> + if (ret == -EAGAIN) >>>> + return ret; >>>> + >>>> + ut_assertok(ret); >>>> + >>>> + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { >>>> + env_set("partstart", NULL); >>>> + ut_assertok(run_commandf("part start mmc %u %d partstart", >>>> + mmc_dev_num, i + 1)); >>>> + snprintf(expected, sizeof(expected), "%lx", >>>> + (unsigned long)gpt_parts[i].start); >>>> + ut_asserteq_str(expected, env_get("partstart")); >>>> + } >>>> + >>>> + env_set("partstart", NULL); >>>> + ut_asserteq(1, run_commandf("part start mmc %u 3 partstart", >>>> + mmc_dev_num)); >>>> + ut_assertnull(env_get("partstart")); >>>> + >>>> + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { >>>> + env_set("partstart", NULL); >>>> + ut_assertok(run_commandf("part start mmc %u %s partstart", >>>> + mmc_dev_num, gpt_parts[i].name)); >>>> + snprintf(expected, sizeof(expected), "%lx", >>>> + (unsigned long)gpt_parts[i].start); >>>> + ut_asserteq_str(expected, env_get("partstart")); >>>> + } >>>> + >>>> + env_set("partstart", NULL); >>>> + ut_asserteq(1, run_commandf("part start mmc %u bogus partstart", >>>> + mmc_dev_num)); >>>> + ut_assertnull(env_get("partstart")); >>>> + >>>> + return 0; >>>> +} >>>> +CMD_TEST(cmd_test_part_start, UTF_CONSOLE); >>>> + >>>> +static int cmd_test_part_size(struct unit_test_state *uts) >>>> +{ >>>> + unsigned int mmc_dev_num = 2; >>>> + char expected[32]; >>>> + int i, ret; >>>> + >>>> + ret = setup_gpt_partitions(uts, mmc_dev_num); >>>> + if (ret == -EAGAIN) >>>> + return ret; >>>> + >>>> + ut_assertok(ret); >>>> + >>>> + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { >>>> + env_set("partsize", NULL); >>>> + ut_assertok(run_commandf("part size mmc %u %d partsize", >>>> + mmc_dev_num, i + 1)); >>>> + snprintf(expected, sizeof(expected), "%lx", >>>> + (unsigned long)gpt_parts[i].size); >>>> + ut_asserteq_str(expected, env_get("partsize")); >>>> + } >>>> + >>>> + env_set("partsize", NULL); >>>> + ut_asserteq(1, run_commandf("part size mmc %u 3 partsize", >>>> + mmc_dev_num)); >>>> + ut_assertnull(env_get("partsize")); >>>> + >>>> + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { >>>> + env_set("partsize", NULL); >>>> + ut_assertok(run_commandf("part size mmc %u %s partsize", >>>> + mmc_dev_num, gpt_parts[i].name)); >>>> + snprintf(expected, sizeof(expected), "%lx", >>>> + (unsigned long)gpt_parts[i].size); >>>> + ut_asserteq_str(expected, env_get("partsize")); >>>> + } >>>> + >>>> + env_set("partsize", NULL); >>>> + ut_asserteq(1, run_commandf("part size mmc %u bogus partsize", >>>> + mmc_dev_num)); >>>> + ut_assertnull(env_get("partsize")); >>>> + >>>> + return 0; >>>> +} >>>> +CMD_TEST(cmd_test_part_size, UTF_CONSOLE); >>> >>> >> >> -- >> *Dario Binacchi* >> Senior Embedded Software Engineer >> M. +39 328 0625246 >> dario.binacchi@amarulasolutions.com >> ――――――――――――――― >> Amarula Solutions SRL >> Via Felice Cavallotti 25D, 41012 Carpi, MO, IT >> info@amarulasolutions.com >> www.amarulasolutions.com >> > > To unsubscribe from this group and stop receiving emails from it, send an email to linux-amarula+unsubscribe@amarulasolutions.com.
diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 5f2815b1bb65..8d6932f1176c 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_CMD_LOADM) += loadm.o obj-$(CONFIG_CMD_MEMINFO) += meminfo.o obj-$(CONFIG_CMD_MEMORY) += mem_copy.o obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o +obj-$(CONFIG_CMD_PART) += part.o ifdef CONFIG_CMD_PCI obj-$(CONFIG_CMD_PCI_MPS) += pci_mps.o endif diff --git a/test/cmd/part.c b/test/cmd/part.c new file mode 100644 index 000000000000..cac57a1a0e35 --- /dev/null +++ b/test/cmd/part.c @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test for part command + * + * Copyright (C) 2026 Amarula Solutions + * Written by Dario Binacchi <dario.binacchi@amarulasolutions.com> + */ + +#include <command.h> +#include <dm.h> +#include <env.h> +#include <part.h> +#include <vsprintf.h> +#include <dm/test.h> +#include <test/cmd.h> +#include <test/test.h> +#include <test/ut.h> + +static struct disk_partition gpt_parts[] = { + { + .start = 48, + .size = 1, + .name = "test1", + .uuid = "c5bce7a2-03f0-4d03-9048-01ff23b9d527", + }, + { + .start = 49, + .size = 2, + .name = "test2", + .uuid = "9df346e8-2c53-4cd8-b9ac-3af83f9a9b74", + }, +}; + +static char disk_guid[UUID_STR_LEN + 1] = + "8d60b397-1bb6-4d33-80ee-b1587d24c2f8"; + +static int setup_gpt_partitions(struct unit_test_state *uts, + unsigned int mmc_dev_num) +{ + struct blk_desc *mmc_dev_desc; + char dev_str[10]; + int i, ret; + + if (!CONFIG_IS_ENABLED(MMC)) + return -EAGAIN; + + snprintf(dev_str, sizeof(dev_str), "%u", mmc_dev_num); + + ret = blk_get_device_by_str("mmc", dev_str, &mmc_dev_desc); + if (ret == -ENODEV) + return -EAGAIN; + + ut_asserteq(mmc_dev_num, ret); + + if (CONFIG_IS_ENABLED(RANDOM_UUID)) { + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) + gen_rand_uuid_str(gpt_parts[i].uuid, + UUID_STR_FORMAT_STD); + + gen_rand_uuid_str(disk_guid, UUID_STR_FORMAT_STD); + } + + ut_assertok(gpt_restore(mmc_dev_desc, disk_guid, gpt_parts, + ARRAY_SIZE(gpt_parts))); + return 0; +} + +static int cmd_test_part_number(struct unit_test_state *uts) +{ + unsigned int mmc_dev_num = 2; + char expected[10]; + int i, ret; + + ret = setup_gpt_partitions(uts, mmc_dev_num); + if (ret == -EAGAIN) + return ret; + + ut_assertok(ret); + + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partnum", NULL); + ut_assertok(run_commandf("part number mmc %u %s partnum", + mmc_dev_num, gpt_parts[i].name)); + snprintf(expected, sizeof(expected), "0x%x", i + 1); + ut_asserteq_str(expected, env_get("partnum")); + } + + env_set("partnum", NULL); + ut_asserteq(1, run_commandf("part number mmc %u bogus partnum", + mmc_dev_num)); + ut_assertnull(env_get("partnum")); + + return 0; +} +CMD_TEST(cmd_test_part_number, UTF_CONSOLE); + +static int cmd_test_part_start(struct unit_test_state *uts) +{ + unsigned int mmc_dev_num = 2; + char expected[32]; + int i, ret; + + ret = setup_gpt_partitions(uts, mmc_dev_num); + if (ret == -EAGAIN) + return ret; + + ut_assertok(ret); + + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partstart", NULL); + ut_assertok(run_commandf("part start mmc %u %d partstart", + mmc_dev_num, i + 1)); + snprintf(expected, sizeof(expected), "%lx", + (unsigned long)gpt_parts[i].start); + ut_asserteq_str(expected, env_get("partstart")); + } + + env_set("partstart", NULL); + ut_asserteq(1, run_commandf("part start mmc %u 3 partstart", + mmc_dev_num)); + ut_assertnull(env_get("partstart")); + + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partstart", NULL); + ut_assertok(run_commandf("part start mmc %u %s partstart", + mmc_dev_num, gpt_parts[i].name)); + snprintf(expected, sizeof(expected), "%lx", + (unsigned long)gpt_parts[i].start); + ut_asserteq_str(expected, env_get("partstart")); + } + + env_set("partstart", NULL); + ut_asserteq(1, run_commandf("part start mmc %u bogus partstart", + mmc_dev_num)); + ut_assertnull(env_get("partstart")); + + return 0; +} +CMD_TEST(cmd_test_part_start, UTF_CONSOLE); + +static int cmd_test_part_size(struct unit_test_state *uts) +{ + unsigned int mmc_dev_num = 2; + char expected[32]; + int i, ret; + + ret = setup_gpt_partitions(uts, mmc_dev_num); + if (ret == -EAGAIN) + return ret; + + ut_assertok(ret); + + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partsize", NULL); + ut_assertok(run_commandf("part size mmc %u %d partsize", + mmc_dev_num, i + 1)); + snprintf(expected, sizeof(expected), "%lx", + (unsigned long)gpt_parts[i].size); + ut_asserteq_str(expected, env_get("partsize")); + } + + env_set("partsize", NULL); + ut_asserteq(1, run_commandf("part size mmc %u 3 partsize", + mmc_dev_num)); + ut_assertnull(env_get("partsize")); + + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partsize", NULL); + ut_assertok(run_commandf("part size mmc %u %s partsize", + mmc_dev_num, gpt_parts[i].name)); + snprintf(expected, sizeof(expected), "%lx", + (unsigned long)gpt_parts[i].size); + ut_asserteq_str(expected, env_get("partsize")); + } + + env_set("partsize", NULL); + ut_asserteq(1, run_commandf("part size mmc %u bogus partsize", + mmc_dev_num)); + ut_assertnull(env_get("partsize")); + + return 0; +} +CMD_TEST(cmd_test_part_size, UTF_CONSOLE);