Skip to contentSkip to conversation

tests/qtest/rtl8139-test: Make the test less verbose by default

PATCH In review Thomas Huth 3 participants 4 messages Feb 15, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/qtest/rtl8139-test: Make the test less verbose by default

We are facing the issues that some test logs in the gitlab CI are too big (and thus cut off). The rtl8139-test is one of the few qtests that prints many lines of output by default when running with V=1, so it contributes to this problem. Almost all other qtests are silent with V=1 and only print debug messages with V=2 and higher. Thus let's change the rtl8139-test to behave more like the other tests and only print the debug messages with V=2 (or higher).

---
 tests/qtest/rtl8139-test.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
tests/qtest/rtl8139-test.c +13 -2
index 8fa3313cc3..1beb83805c 100644
@@ -12,6 +12,8 @@
 #include "libqos/pci-pc.h"
 #include "qemu/timer.h"
 
+static int verbosity_level;
+
 /* Tests only initialization so far. TODO: Replace with functional tests */
 static void nop(void)
 {
@@ -45,12 +47,16 @@ static QPCIDevice *get_device(void)
 static unsigned __attribute__((unused)) in_##name(void) \
 { \
     unsigned res = qpci_io_read##len(dev, dev_bar, (val));     \
-    g_test_message("*%s -> %x", #name, res); \
+    if (verbosity_level >= 2) { \
+        g_test_message("*%s -> %x", #name, res); \
+    } \
     return res; \
 } \
 static void out_##name(unsigned v) \
 { \
-    g_test_message("%x -> *%s", v, #name); \
+    if (verbosity_level >= 2) { \
+        g_test_message("%x -> *%s", v, #name); \
+    } \
     qpci_io_write##len(dev, dev_bar, (val), v);        \
 }
 
@@ -195,6 +201,11 @@ static void test_init(void)
 int main(int argc, char **argv)
 {
     int ret;
+    char *v_env = getenv("V");
+
+    if (v_env) {
+        verbosity_level = atoi(v_env);
+    }
 
     qtest_start("-device rtl8139");
 
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Thomas Huth

We are facing the issues that some test logs in the gitlab CI are too big (and thus cut off). The rtl8139-test is one of the few qtests that prints many lines of output by default when running with V=1, so it contributes to this problem. Almost all other qtests are silent with V=1 and only print debug messages with V=2 and higher. Thus let's change the rtl8139-test to behave more like the other tests and only print the debug messages with V=2 (or higher).

Quoted 4 lines
---
 tests/qtest/rtl8139-test.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
Quoted 34 lines
tests/qtest/rtl8139-test.c +8 -2
index 8fa3313cc3..1beb83805c 100644
@@ -12,6 +12,8 @@
 #include "libqos/pci-pc.h"
 #include "qemu/timer.h"
 
+static int verbosity_level;
+
 /* Tests only initialization so far. TODO: Replace with functional tests */
 static void nop(void)
 {
@@ -45,12 +47,16 @@ static QPCIDevice *get_device(void)
 static unsigned __attribute__((unused)) in_##name(void) \
 { \
     unsigned res = qpci_io_read##len(dev, dev_bar, (val));     \
-    g_test_message("*%s -> %x", #name, res); \
+    if (verbosity_level >= 2) { \
+        g_test_message("*%s -> %x", #name, res); \
+    } \
     return res; \
 } \
 static void out_##name(unsigned v) \
 { \
-    g_test_message("%x -> *%s", v, #name); \
+    if (verbosity_level >= 2) { \
+        g_test_message("%x -> *%s", v, #name); \
+    } \
     qpci_io_write##len(dev, dev_bar, (val), v);        \
 }
 

tests/qtest/rtl8139-test.c static void test_init(void) · line 208

Quoted 8 lines
tests/qtest/rtl8139-test.c +5 -0
@@ -195,6 +201,11 @@ static void test_init(void)
 int main(int argc, char **argv)
 {
     int ret;
+    char *v_env = getenv("V");
+
+    if (v_env) {
+        verbosity_level = atoi(v_env);
+    }

*Not* something I'm requesting you to do now, just an observation / idea.

We've copied this pattern into several tests.

It is starting to feel like we should have a header with a 'qtests_env_setup()' method we call as first thing in main, and exporting 'verbosity_level' from the header.

Perhaps also with a 'qtest_verbose(...)' macro that wraps

  if (verbosity_level >= 2) {
     g_test_message(...)
  }

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw
Quoted 67 lines · Daniel P. Berrangé
Quoted 8 lines · Thomas Huth

We are facing the issues that some test logs in the gitlab CI are too big (and thus cut off). The rtl8139-test is one of the few qtests that prints many lines of output by default when running with V=1, so it contributes to this problem. Almost all other qtests are silent with V=1 and only print debug messages with V=2 and higher. Thus let's change the rtl8139-test to behave more like the other tests and only print the debug messages with V=2 (or higher).

Quoted 4 lines
---
 tests/qtest/rtl8139-test.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
Quoted 34 lines
tests/qtest/rtl8139-test.c +8 -2
index 8fa3313cc3..1beb83805c 100644
@@ -12,6 +12,8 @@
 #include "libqos/pci-pc.h"
 #include "qemu/timer.h"
 
+static int verbosity_level;
+
 /* Tests only initialization so far. TODO: Replace with functional tests */
 static void nop(void)
 {
@@ -45,12 +47,16 @@ static QPCIDevice *get_device(void)
 static unsigned __attribute__((unused)) in_##name(void) \
 { \
     unsigned res = qpci_io_read##len(dev, dev_bar, (val));     \
-    g_test_message("*%s -> %x", #name, res); \
+    if (verbosity_level >= 2) { \
+        g_test_message("*%s -> %x", #name, res); \
+    } \
     return res; \
 } \
 static void out_##name(unsigned v) \
 { \
-    g_test_message("%x -> *%s", v, #name); \
+    if (verbosity_level >= 2) { \
+        g_test_message("%x -> *%s", v, #name); \
+    } \
     qpci_io_write##len(dev, dev_bar, (val), v);        \
 }
 

tests/qtest/rtl8139-test.c static void test_init(void) · line 208

Quoted 8 lines
tests/qtest/rtl8139-test.c +5 -0
@@ -195,6 +201,11 @@ static void test_init(void)
 int main(int argc, char **argv)
 {
     int ret;
+    char *v_env = getenv("V");
+
+    if (v_env) {
+        verbosity_level = atoi(v_env);
+    }

*Not* something I'm requesting you to do now, just an observation / idea.

We've copied this pattern into several tests.

It is starting to feel like we should have a header with a 'qtests_env_setup()' method we call as first thing in main, and exporting 'verbosity_level' from the header.

Quoted 5 lines

Perhaps also with a 'qtest_verbose(...)' macro that wraps

  if (verbosity_level >= 2) {
     g_test_message(...)
  }

Could we maybe play with g_test_verbose and g_test_quiet? The docs say "The default is neither g_test_verbose() nor g_test_quiet()." So perhaps:

V= --quiet, g_test_quiet
V=1 no option, default verbosity
V=2 --verbose, g_test_verbose

Then test g_test_quiet|verbose instead of reading from env directly.

#3 lore raw
Quoted 69 lines · Fabiano Rosas
Quoted 67 lines · Daniel P. Berrangé
Quoted 8 lines · Thomas Huth

We are facing the issues that some test logs in the gitlab CI are too big (and thus cut off). The rtl8139-test is one of the few qtests that prints many lines of output by default when running with V=1, so it contributes to this problem. Almost all other qtests are silent with V=1 and only print debug messages with V=2 and higher. Thus let's change the rtl8139-test to behave more like the other tests and only print the debug messages with V=2 (or higher).

Quoted 4 lines
---
  tests/qtest/rtl8139-test.c | 15 +++++++++++++--
  1 file changed, 13 insertions(+), 2 deletions(-)
Quoted 34 lines
tests/qtest/rtl8139-test.c +8 -2
index 8fa3313cc3..1beb83805c 100644
@@ -12,6 +12,8 @@
  #include "libqos/pci-pc.h"
  #include "qemu/timer.h"
 
+static int verbosity_level;
+
  /* Tests only initialization so far. TODO: Replace with functional tests */
  static void nop(void)
  {
@@ -45,12 +47,16 @@ static QPCIDevice *get_device(void)
  static unsigned __attribute__((unused)) in_##name(void) \
  { \
      unsigned res = qpci_io_read##len(dev, dev_bar, (val));     \
-    g_test_message("*%s -> %x", #name, res); \
+    if (verbosity_level >= 2) { \
+        g_test_message("*%s -> %x", #name, res); \
+    } \
      return res; \
  } \
  static void out_##name(unsigned v) \
  { \
-    g_test_message("%x -> *%s", v, #name); \
+    if (verbosity_level >= 2) { \
+        g_test_message("%x -> *%s", v, #name); \
+    } \
      qpci_io_write##len(dev, dev_bar, (val), v);        \
  }
 

tests/qtest/rtl8139-test.c static void test_init(void) · line 208

Quoted 8 lines
tests/qtest/rtl8139-test.c +5 -0
@@ -195,6 +201,11 @@ static void test_init(void)
  int main(int argc, char **argv)
  {
      int ret;
+    char *v_env = getenv("V");
+
+    if (v_env) {
+        verbosity_level = atoi(v_env);
+    }

*Not* something I'm requesting you to do now, just an observation / idea.

We've copied this pattern into several tests.

It is starting to feel like we should have a header with a 'qtests_env_setup()' method we call as first thing in main, and exporting 'verbosity_level' from the header.

Quoted 5 lines
Quoted 5 lines

Perhaps also with a 'qtest_verbose(...)' macro that wraps

   if (verbosity_level >= 2) {
      g_test_message(...)
   }

Agree, we could generalize this stuff somehow ... maybe also simply adding a qtest_log(int level, char *format, ...) function that does the getenv() checking on the first invocation, or something like that.

Quoted 9 lines

Could we maybe play with g_test_verbose and g_test_quiet? The docs say "The default is neither g_test_verbose() nor g_test_quiet()." So perhaps:

V= --quiet, g_test_quiet
V=1 no option, default verbosity
V=2 --verbose, g_test_verbose

Then test g_test_quiet|verbose instead of reading from env directly.

Sounds like an option, too ... but we would not have a V=3 level that way (which is already used in qom-test.c - not sure whether we really need it, though, we could use V=2 for all debug messages, too).

Thomas