Re: [PATCH v2 05/17] tests/qtest: rename qtest_send_prefix and roll-up into qtest_send

2025-02-07 Thread Thomas Huth

On 07/02/2025 16.31, Alex Bennée wrote:

qtest_send_prefix never actually sent something over the chardev, all
it does is print the timestamp to the QTEST_LOG when enabled. So
rename the function, make it static, remove the unused CharDev and
simplify all the call sites by handling that directly with
qtest_send (and qtest_log_send).

Signed-off-by: Alex Bennée 
---
  include/system/qtest.h |  1 -
  hw/ppc/spapr_rtas.c|  1 -
  hw/riscv/riscv_hart.c  |  1 -
  system/qtest.c | 26 +++---
  4 files changed, 3 insertions(+), 26 deletions(-)


Reviewed-by: Thomas Huth 




[PATCH v2 05/17] tests/qtest: rename qtest_send_prefix and roll-up into qtest_send

2025-02-07 Thread Alex Bennée
qtest_send_prefix never actually sent something over the chardev, all
it does is print the timestamp to the QTEST_LOG when enabled. So
rename the function, make it static, remove the unused CharDev and
simplify all the call sites by handling that directly with
qtest_send (and qtest_log_send).

Signed-off-by: Alex Bennée 
---
 include/system/qtest.h |  1 -
 hw/ppc/spapr_rtas.c|  1 -
 hw/riscv/riscv_hart.c  |  1 -
 system/qtest.c | 26 +++---
 4 files changed, 3 insertions(+), 26 deletions(-)

diff --git a/include/system/qtest.h b/include/system/qtest.h
index c161d75165..6c501b 100644
--- a/include/system/qtest.h
+++ b/include/system/qtest.h
@@ -24,7 +24,6 @@ static inline bool qtest_enabled(void)
 }
 
 #ifndef CONFIG_USER_ONLY
-void qtest_send_prefix(CharBackend *chr);
 void G_GNUC_PRINTF(2, 3) qtest_sendf(CharBackend *chr, const char *fmt, ...);
 void qtest_set_command_cb(bool (*pc_cb)(CharBackend *chr, gchar **words));
 bool qtest_driver(void);
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index df2e837632..503d441b48 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -565,7 +565,6 @@ static bool spapr_qtest_callback(CharBackend *chr, gchar 
**words)
 g_assert(rc == 0);
 res = qtest_rtas_call(words[1], nargs, args, nret, ret);
 
-qtest_send_prefix(chr);
 qtest_sendf(chr, "OK %"PRIu64"\n", res);
 
 return true;
diff --git a/hw/riscv/riscv_hart.c b/hw/riscv/riscv_hart.c
index ad67cd7645..a55d156668 100644
--- a/hw/riscv/riscv_hart.c
+++ b/hw/riscv/riscv_hart.c
@@ -94,7 +94,6 @@ static bool csr_qtest_callback(CharBackend *chr, gchar 
**words)
 g_assert(rc == 0);
 csr_call(words[1], cpu, csr, &val);
 
-qtest_send_prefix(chr);
 qtest_sendf(chr, "OK 0 "TARGET_FMT_lx"\n", (target_ulong)val);
 
 return true;
diff --git a/system/qtest.c b/system/qtest.c
index bb1efba9fd..28b6fac37c 100644
--- a/system/qtest.c
+++ b/system/qtest.c
@@ -265,7 +265,7 @@ static int hex2nib(char ch)
 }
 }
 
-void qtest_send_prefix(CharBackend *chr)
+static void qtest_log_timestamp(void)
 {
 if (!qtest_log_fp || !qtest_opened) {
 return;
@@ -282,7 +282,7 @@ static void G_GNUC_PRINTF(1, 2) qtest_log_send(const char 
*fmt, ...)
 return;
 }
 
-qtest_send_prefix(NULL);
+qtest_log_timestamp();
 
 va_start(ap, fmt);
 vfprintf(qtest_log_fp, fmt, ap);
@@ -301,6 +301,7 @@ static void qtest_server_char_be_send(void *opaque, const 
char *str)
 
 static void qtest_send(CharBackend *chr, const char *str)
 {
+qtest_log_timestamp();
 qtest_server_send(qtest_server_send_opaque, str);
 }
 
@@ -324,7 +325,6 @@ static void qtest_irq_handler(void *opaque, int n, int 
level)
 if (irq_levels[n] != level) {
 CharBackend *chr = &qtest->qtest_chr;
 irq_levels[n] = level;
-qtest_send_prefix(chr);
 qtest_sendf(chr, "IRQ %s %d\n",
 level ? "raise" : "lower", n);
 }
@@ -380,19 +380,16 @@ static void qtest_process_command(CharBackend *chr, gchar 
**words)
 is_outbound = words[0][14] == 'o';
 dev = DEVICE(object_resolve_path(words[1], NULL));
 if (!dev) {
-qtest_send_prefix(chr);
 qtest_send(chr, "FAIL Unknown device\n");
 return;
 }
 
 if (is_named && !is_outbound) {
-qtest_send_prefix(chr);
 qtest_send(chr, "FAIL Interception of named in-GPIOs not yet 
supported\n");
 return;
 }
 
 if (irq_intercept_dev) {
-qtest_send_prefix(chr);
 if (irq_intercept_dev != dev) {
 qtest_send(chr, "FAIL IRQ intercept already enabled\n");
 } else {
@@ -419,7 +416,6 @@ static void qtest_process_command(CharBackend *chr, gchar 
**words)
 }
 }
 
-qtest_send_prefix(chr);
 if (interception_succeeded) {
 irq_intercept_dev = dev;
 qtest_send(chr, "OK\n");
@@ -438,7 +434,6 @@ static void qtest_process_command(CharBackend *chr, gchar 
**words)
 
 dev = DEVICE(object_resolve_path(words[1], NULL));
 if (!dev) {
-qtest_send_prefix(chr);
 qtest_send(chr, "FAIL Unknown device\n");
 return;
 }
@@ -457,7 +452,6 @@ static void qtest_process_command(CharBackend *chr, gchar 
**words)
 irq = qdev_get_gpio_in_named(dev, name, num);
 
 qemu_set_irq(irq, level);
-qtest_send_prefix(chr);
 qtest_send(chr, "OK\n");
 } else if (strcmp(words[0], "outb") == 0 ||
strcmp(words[0], "outw") == 0 ||
@@ -480,7 +474,6 @@ static void qtest_process_command(CharBackend *chr, gchar 
**words)
 } else if (words[0][3] == 'l') {
 cpu_outl(addr, value);
 }
-qtest_send_prefix(chr);
 qtest_send(chr, "OK\n");
 } else if (strcmp(words[0], "inb") == 0 ||
 strcmp(words[0], "inw") == 0 ||
@@ -