From: Evgeny Bachinin <EABachinin@sberdevices.ru>
To: Simon Glass <sjg@chromium.org>,
Hector Palacios <hector.palacios@digi.com>,
Marek Vasut <marex@denx.de>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
John Keeping <john@metanate.com>
Cc: <u-boot@lists.denx.de>, <kernel@sberdevices.ru>,
<evgen89bachinin@gmail.com>,
Evgeny Bachinin <EABachinin@sberdevices.ru>
Subject: [PATCH v2 2/4] unit-test: cover run_commandf() by test-cases
Date: Mon, 20 Mar 2023 11:23:12 +0300 [thread overview]
Message-ID: <20230320082314.2018-3-EABachinin@sberdevices.ru> (raw)
In-Reply-To: <20230320082314.2018-1-EABachinin@sberdevices.ru>
As run_commandf() is variadic version of run_command() and just a wrapper,
hence apply similar run_command's test-cases.
Let's avoid warning about empty string passing:
warning: zero-length gnu_printf format string [-Wformat-zero-length]
assert(run_commandf("") == 0);
Signed-off-by: Evgeny Bachinin <EABachinin@sberdevices.ru>
---
Changes for v2:
- s/EINVAL/ENOSPC/
- rewrite test-case for truncation case
- not apply Reviewed-by due to changes above
test/command_ut.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/test/command_ut.c b/test/command_ut.c
index 9837d10eb5..a74bd109e1 100644
--- a/test/command_ut.c
+++ b/test/command_ut.c
@@ -9,6 +9,8 @@
#include <command.h>
#include <env.h>
#include <log.h>
+#include <string.h>
+#include <linux/errno.h>
static const char test_cmd[] = "setenv list 1\n setenv list ${list}2; "
"setenv list ${list}3\0"
@@ -17,6 +19,8 @@ static const char test_cmd[] = "setenv list 1\n setenv list ${list}2; "
static int do_ut_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
+ char long_str[CONFIG_SYS_CBSIZE + 42];
+
printf("%s: Testing commands\n", __func__);
run_command("env default -f -a", 0);
@@ -60,6 +64,36 @@ static int do_ut_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
assert(run_command("'", 0) == 1);
+ /* Variadic function test-cases */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-zero-length"
+ assert(run_commandf("") == 0);
+#pragma GCC diagnostic pop
+ assert(run_commandf(" ") == 0);
+ assert(run_commandf("'") == 1);
+
+ assert(run_commandf("env %s %s", "delete -f", "list") == 0);
+ /* Expected: "Error: "list" not defined" */
+ assert(run_commandf("printenv list") == 1);
+
+ memset(long_str, 'x', sizeof(long_str));
+ assert(run_commandf("Truncation case: %s", long_str) == -ENOSPC);
+
+ if (IS_ENABLED(CONFIG_HUSH_PARSER)) {
+ assert(run_commandf("env %s %s %s %s", "delete -f", "adder",
+ "black", "foo") == 0);
+ assert(run_commandf("setenv foo 'setenv %s 1\nsetenv %s 2'",
+ "black", "adder") == 0);
+ run_command("run foo", 0);
+ assert(env_get("black"));
+ assert(!strcmp("1", env_get("black")));
+ assert(env_get("adder"));
+ assert(!strcmp("2", env_get("adder")));
+ }
+
+ /* Clean up before exit */
+ run_command("env default -f -a", 0);
+
printf("%s: Everything went swimmingly\n", __func__);
return 0;
}
--
2.17.1
next prev parent reply other threads:[~2023-03-20 8:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-20 8:23 [PATCH v2 0/4] cli: run_commandf() coverage and small fixups Evgeny Bachinin
2023-03-20 8:23 ` [PATCH v2 1/4] cli: run_commandf(): " Evgeny Bachinin
2023-03-20 18:40 ` Simon Glass
2023-03-31 14:15 ` Tom Rini
2023-03-20 8:23 ` Evgeny Bachinin [this message]
2023-03-20 18:40 ` [PATCH v2 2/4] unit-test: cover run_commandf() by test-cases Simon Glass
2023-03-31 14:15 ` Tom Rini
2023-03-20 8:23 ` [PATCH v2 3/4] test: fdt: fix run_commandf() warnings Evgeny Bachinin
2023-03-20 18:40 ` Simon Glass
2023-03-31 14:15 ` Tom Rini
2023-03-20 8:23 ` [PATCH v2 4/4] test: exit: " Evgeny Bachinin
2023-03-20 18:40 ` Simon Glass
2023-03-31 14:15 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230320082314.2018-3-EABachinin@sberdevices.ru \
--to=eabachinin@sberdevices.ru \
--cc=evgen89bachinin@gmail.com \
--cc=hector.palacios@digi.com \
--cc=john@metanate.com \
--cc=kernel@sberdevices.ru \
--cc=marex@denx.de \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox