From: Francis Laniel <francis.laniel@amarulasolutions.com>
To: Tom Rini <trini@konsulko.com>
Cc: u-boot@lists.denx.de, Marek Behun <marek.behun@nic.cz>,
Michael Nazzareno Trimarchi <michael@amarulasolutions.com>,
Simon Glass <sjg@chromium.org>, Wolfgang Denk <wd@denx.de>,
Harald Seiler <hws@denx.de>,
Francis Laniel <francis.laniel@amarulasolutions.com>
Subject: [PATCH] for debug purpose only: add print to debug odd behavior.
Date: Mon, 10 Oct 2022 22:52:53 +0200 [thread overview]
Message-ID: <20221010205253.21740-1-francis.laniel@amarulasolutions.com> (raw)
In-Reply-To: <20220617144931.GZ2484912@bill-the-cat>
Hi.
I am really sorry for the delay in answer.
Sadly, I am not able to send a v5 for the moment.
Indeed, I am still struggling with the same bug since a lot of time...
It happens in the Azure pipeline but also locally with test.py.
I am sure the bug is related to memory management as the setexpr test fails
because more memory is released than what expected (as shown by the debug
message printed in this patch).
Nonetheless, I am not able to say what is the root cause of it...
I think this is a side effect "somewhere", as commenting out the "loop_i=" in
the unit test for loop makes the tests pass.
Sometime ago, it happened with sandbox and sandbox_clang and with a recent
rebase it stopped happening on these boards but begins to occur on
sandbox_flattree.
I checked the behavior of the code related to loop and particularly what is done
by set_local_var_2021() with GDB and I did not find any uncorrect behavior.
I am sorry but I do not have a lot of other choices than asking for a bit of
help as I really want to tackle this but I am lacking ideas...
So, did such a bug already occur in U-Boot development process?
If so, what was the root cause and what was done to help finding it?
Best regards and thank you in advance as any help will be really appreciated.
---
cmd/nvedit.c | 7 ++++++-
cmd/setexpr.c | 4 ++++
common/cli_hush_upstream.c | 28 ++++++++++++++++++++++++++++
common/command.c | 4 ++++
include/cli_hush.h | 4 ++++
test/cmd/setexpr.c | 8 ++++++++
test/hush/loop.c | 3 +++
7 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 53e6b57b60..cf6ac9d7f2 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -40,6 +40,8 @@
#include <linux/stddef.h>
#include <asm/byteorder.h>
#include <asm/io.h>
+#include <cli_hush.h>
+#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -275,8 +277,9 @@ static int _do_env_set(int flag, int argc, char *const argv[], int env_flag)
*/
for (i = 2, len = 0; i < argc; ++i)
len += strlen(argv[i]) + 1;
-
+ debug_foo("\t\t\t%s: before malloc: ut_check_free(): %lu\n", __func__, ut_check_free());
value = malloc(len);
+// debug_foo("\t\t\t%s: after malloc: ut_check_free(): %lu\n", __func__, ut_check_free());
if (value == NULL) {
printf("## Can't malloc %d bytes\n", len);
return 1;
@@ -294,7 +297,9 @@ static int _do_env_set(int flag, int argc, char *const argv[], int env_flag)
e.key = name;
e.data = value;
hsearch_r(e, ENV_ENTER, &ep, &env_htab, env_flag);
+// debug_foo("\t\t\t%s: before free: ut_check_free(): %lu\n", __func__, ut_check_free());
free(value);
+ debug_foo("\t\t\t%s: after free: ut_check_free(): %lu\n", __func__, ut_check_free());
if (!ep) {
printf("## Error inserting \"%s\" variable, errno=%d\n",
name, errno);
diff --git a/cmd/setexpr.c b/cmd/setexpr.c
index 4d671e7ef1..a815dba4f7 100644
--- a/cmd/setexpr.c
+++ b/cmd/setexpr.c
@@ -18,6 +18,8 @@
#include <mapmem.h>
#include <linux/sizes.h>
#include "printf.h"
+#include <cli_hush.h>
+#include <test/ut.h>
#define MAX_STR_LEN 128
@@ -412,7 +414,9 @@ static int do_setexpr(struct cmd_tbl *cmdtp, int flag, int argc,
/* plain assignment: "setexpr name value" */
if (argc == 3) {
if (w == CMD_DATA_SIZE_STR) {
+ debug_foo("\t\t%s: before env_set: ut_check_free(): %lu\n", __func__, ut_check_free());
ret = env_set(argv[1], aval.sval);
+ debug_foo("\t\t%s: after env_set: ut_check_free(): %lu\n", __func__, ut_check_free());
free(aval.sval);
} else {
ret = env_set_hex(argv[1], aval.ival);
diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index bf7e51f2f3..14c1b8dc19 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -381,6 +381,10 @@
#endif
#endif /* !__U_BOOT__ */
+#ifdef __U_BOOT__
+#include <test/ut.h>
+#endif
+
/* So far, all bash compat is controlled by one config option */
/* Separate defines document which part of code implements what */
#define BASH_PATTERN_SUBST ENABLE_HUSH_BASH_COMPAT
@@ -9760,6 +9764,28 @@ static int redirect_and_varexp_helper(
}
#endif /* !__U_BOOT__ */
+bool foo = false;
+
+void set_debug_foo(void)
+{
+ foo = true;
+}
+
+void reset_debug_foo(void)
+{
+ foo = false;
+}
+
+void debug_foo(char *fmt, ...)
+{
+ if (foo) {
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+ }
+}
+
static NOINLINE int run_pipe(struct pipe *pi)
{
static const char *const null_ptr = NULL;
@@ -10269,9 +10295,11 @@ static NOINLINE int run_pipe(struct pipe *pi)
next_infd = pipefds.rd;
#else /* __U_BOOT__ */
/* Process the command */
+ debug_foo("%s: before cmd_process: ut_check_free(): %lu\n", __func__, ut_check_free());
rcode = cmd_process(G.do_repeat ? CMD_FLAG_REPEAT : 0,
command->argc, command->argv,
&(G.flag_repeat), NULL);
+ debug_foo("%s: after cmd_process: ut_check_free(): %lu\n", __func__, ut_check_free());
if (argv_expanded) {
/*
diff --git a/common/command.c b/common/command.c
index 41c91c6d8c..16660d3884 100644
--- a/common/command.c
+++ b/common/command.c
@@ -16,6 +16,8 @@
#include <log.h>
#include <asm/global_data.h>
#include <linux/ctype.h>
+#include <cli_hush.h>
+#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -577,7 +579,9 @@ static int cmd_call(struct cmd_tbl *cmdtp, int flag, int argc,
{
int result;
+ debug_foo("\t%s: before cmd function: ut_check_free(): %lu\n", __func__, ut_check_free());
result = cmdtp->cmd_rep(cmdtp, flag, argc, argv, repeatable);
+ debug_foo("\t%s: after cmd function: ut_check_free(): %lu\n", __func__, ut_check_free());
if (result)
debug("Command failed, result=%d\n", result);
return result;
diff --git a/include/cli_hush.h b/include/cli_hush.h
index 6261aa1806..623b023fdd 100644
--- a/include/cli_hush.h
+++ b/include/cli_hush.h
@@ -12,6 +12,10 @@
#define FLAG_REPARSING (1 << 2) /* >=2nd pass */
#define FLAG_CONT_ON_NEWLINE (1 << 3) /* continue when we see \n */
+void set_debug_foo(void);
+void reset_debug_foo(void);
+void debug_foo(char *fmt, ...);
+
#if CONFIG_IS_ENABLED(HUSH_OLD_PARSER)
extern int u_boot_hush_start(void);
extern int parse_string_outer(const char *, int);
diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c
index 0dc94f7e61..bf15c0a1b5 100644
--- a/test/cmd/setexpr.c
+++ b/test/cmd/setexpr.c
@@ -9,6 +9,7 @@
#include <common.h>
#include <console.h>
#include <mapmem.h>
+#include <cli_hush.h>
#include <dm/test.h>
#include <test/suites.h>
#include <test/ut.h>
@@ -304,12 +305,19 @@ static int setexpr_test_str(struct unit_test_state *uts)
ut_asserteq(1, run_command("setexpr.s fred 0", 0));
ut_assertok(ut_check_delta(start_mem));
+ ut_unsilence_console(uts);
+
ut_assertok(env_set("fred", "12345"));
start_mem = ut_check_free();
+
+ set_debug_foo();
ut_assertok(run_command("setexpr.s fred *0", 0));
+ reset_debug_foo();
ut_asserteq_str("hello", env_get("fred"));
ut_assertok(ut_check_delta(start_mem));
+ ut_silence_console(uts);
+
unmap_sysmem(buf);
return 0;
diff --git a/test/hush/loop.c b/test/hush/loop.c
index 8803dc6ae4..ab849f7fac 100644
--- a/test/hush/loop.c
+++ b/test/hush/loop.c
@@ -26,6 +26,9 @@ static int hush_test_for(struct unit_test_state *uts)
if (gd->flags & GD_FLG_HUSH_2021_PARSER) {
/* Reset local variable. */
+ /*
+ * BUG Comment this below line out make the tests pass.
+ */
ut_assertok(run_command("loop_i=", 0));
} else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
puts("Beware: this test set local variable loop_i and it cannot be unset!");
--
2.25.1
next prev parent reply other threads:[~2022-10-10 20:54 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-16 22:31 [RFC PATCH v4 00/28] Modernize U-Boot shell Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 01/28] video: sandbox: Add dummy function for sandbox_sdl_remove_display() Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 02/28] test: Add framework to test hush behavior Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 03/28] test: hush: Test hush if/else Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 04/28] test/py: hush_if_test: Remove the test file Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 05/28] test: hush: Test hush variable expansion Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 06/28] test: hush: Test hush commands list Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 07/28] test: hush: Test hush loops Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 08/28] cli: Add Busybox upstream hush.c file Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 09/28] cli: Port Busybox 2021 hush to U-Boot Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 10/28] cli: Add menu for hush parser Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 11/28] global_data.h: add GD_FLG_HUSH_OLD_PARSER flag Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 12/28] cmd: Add new parser command Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 13/28] cli: Enables using hush 2021 parser as command line parser Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 14/28] cli: hush_2021: Enable variables expansion for hush 2021 Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 15/28] cli: hush_2021: Add functions to be called from run_command() Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 16/28] cli: add hush 2021 as parser for run_command*() Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 17/28] test: hush: Fix instructions list tests for hush 2021 Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 18/28] test: hush: Fix variable expansion " Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 19/28] cli: hush_2021: Enable using \< and \> as string compare operators Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 20/28] cli: hush_2021: Enable if keyword Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 21/28] test: hush: Fix if tests for hush 2021 Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 22/28] cli: hush_2021: Enable loops Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 23/28] test: hush: Fix loop tests for hush 2021 Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 24/28] Modernize U-Boot shell Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 25/28] cli: hush_2021: Add upstream commits up to 6th February 2022 Francis Laniel
2022-06-20 19:11 ` Tom Rini
2022-08-12 20:56 ` Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 26/28] for test purpose only: Comment out dollar tests which prints error messages Francis Laniel
2022-06-17 14:02 ` Tom Rini
2022-08-12 21:12 ` Francis Laniel
2022-06-16 22:31 ` [RFC PATCH v4 27/28] for test purpose only: Comment out failed function which fails only in CI Francis Laniel
2022-06-17 14:49 ` Tom Rini
2022-10-10 20:52 ` Francis Laniel [this message]
2022-06-16 22:31 ` [RFC PATCH v4 28/28] board: keymile: common: Use environment to store IVM_* variables Francis Laniel
2022-06-17 14:48 ` Tom Rini
2022-06-20 14:46 ` Aleksandar Gerasimovski
2022-06-20 15:27 ` Holger Brunck
2022-06-20 15:35 ` Tom Rini
2022-06-20 16:08 ` Holger Brunck
2022-06-20 17:33 ` Tom Rini
2022-08-12 21:01 ` Francis Laniel
2022-08-15 8:13 ` Holger Brunck
2022-06-17 14:50 ` [RFC PATCH v4 00/28] Modernize U-Boot shell 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=20221010205253.21740-1-francis.laniel@amarulasolutions.com \
--to=francis.laniel@amarulasolutions.com \
--cc=hws@denx.de \
--cc=marek.behun@nic.cz \
--cc=michael@amarulasolutions.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=wd@denx.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