Skip to contentSkip to conversation

tests/qtest: misc tweaks to readconfig

PATCH In review Daniel P. Berrangé 4 participants 4 messages Aug 9, 2022 – Aug 11, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/qtest: misc tweaks to readconfig

The property name parameter is ignored when visiting a top level type, but the obvious typo should be fixed to avoid confusion. A few indentation issues were tidied up. We can break out of the loop when finding the RNG device. Finally, close the temp FD immediately when no longer needed.

---
 tests/qtest/readconfig-test.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tests/qtest/readconfig-test.c +6 -6
index 2e604d7c2d..c7a9b0c7dd 100644
@@ -33,13 +33,12 @@ static QTestState *qtest_init_with_config(const char *cfgdata)
     g_assert_cmpint(cfgfd, >=, 0);
 
     ret = qemu_write_full(cfgfd, cfgdata, strlen(cfgdata));
+    close(cfgfd);
     if (ret < 0) {
         unlink(cfgpath);
     }
     g_assert_cmpint(ret, ==, strlen(cfgdata));
 
-    close(cfgfd);
-
     args = g_strdup_printf("-nodefaults -machine none -readconfig %s", cfgpath);
 
     qts = qtest_init(args);
@@ -79,7 +78,7 @@ static void test_x86_memdev(void)
         "size = \"200\"";
 
     qts = qtest_init_with_config(cfgdata);
-   /* Test valid command */
+    /* Test valid command */
     resp = qtest_qmp(qts, "{ 'execute': 'query-memdev' }");
     test_x86_memdev_resp(qdict_get(resp, "return"));
     qobject_unref(resp);
@@ -96,7 +95,7 @@ static void test_spice_resp(QObject *res)
 
     g_assert(res);
     v = qobject_input_visitor_new(res);
-    visit_type_SpiceInfo(v, "spcie", &spice, &error_abort);
+    visit_type_SpiceInfo(v, "spice", &spice, &error_abort);
 
     g_assert(spice);
     g_assert(spice->enabled);
@@ -114,7 +113,7 @@ static void test_spice(void)
         "unix = \"on\"\n";
 
     qts = qtest_init_with_config(cfgdata);
-   /* Test valid command */
+    /* Test valid command */
     resp = qtest_qmp(qts, "{ 'execute': 'query-spice' }");
     test_spice_resp(qdict_get(resp, "return"));
     qobject_unref(resp);
@@ -144,6 +143,7 @@ static void test_object_rng_resp(QObject *res)
         if (g_str_equal(obj->name, "rng0") &&
             g_str_equal(obj->type, "child<rng-builtin>")) {
             seen_rng = true;
+            break;
         }
 
         tmp = tmp->next;
@@ -164,7 +164,7 @@ static void test_object_rng(void)
         "id = \"rng0\"\n";
 
     qts = qtest_init_with_config(cfgdata);
-   /* Test valid command */
+    /* Test valid command */
     resp = qtest_qmp(qts,
                      "{ 'execute': 'qom-list',"
                      "  'arguments': {'path': '/objects' }}");
Signature · 1 line
2.37.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Daniel P. Berrangé

The property name parameter is ignored when visiting a top level type, but the obvious typo should be fixed to avoid confusion. A few indentation issues were tidied up. We can break out of the loop when finding the RNG device. Finally, close the temp FD immediately when no longer needed.

Quoted 74 lines
---
 tests/qtest/readconfig-test.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tests/qtest/readconfig-test.c +1 -2
index 2e604d7c2d..c7a9b0c7dd 100644
@@ -33,13 +33,12 @@ static QTestState *qtest_init_with_config(const char
 *cfgdata)
     g_assert_cmpint(cfgfd, >=, 0);
 
     ret = qemu_write_full(cfgfd, cfgdata, strlen(cfgdata));
+    close(cfgfd);
     if (ret < 0) {
         unlink(cfgpath);
     }
     g_assert_cmpint(ret, ==, strlen(cfgdata));
 
-    close(cfgfd);
-
     args = g_strdup_printf("-nodefaults -machine none -readconfig %s",
 cfgpath);
     qts = qtest_init(args);
tests/qtest/readconfig-test.c +5 -5
@@ -79,7 +78,7 @@ static void test_x86_memdev(void)
         "size = \"200\"";
 
     qts = qtest_init_with_config(cfgdata);
-   /* Test valid command */
+    /* Test valid command */
     resp = qtest_qmp(qts, "{ 'execute': 'query-memdev' }");
     test_x86_memdev_resp(qdict_get(resp, "return"));
     qobject_unref(resp);
@@ -96,7 +95,7 @@ static void test_spice_resp(QObject *res)
 
     g_assert(res);
     v = qobject_input_visitor_new(res);
-    visit_type_SpiceInfo(v, "spcie", &spice, &error_abort);
+    visit_type_SpiceInfo(v, "spice", &spice, &error_abort);
 
     g_assert(spice);
     g_assert(spice->enabled);
@@ -114,7 +113,7 @@ static void test_spice(void)
         "unix = \"on\"\n";
 
     qts = qtest_init_with_config(cfgdata);
-   /* Test valid command */
+    /* Test valid command */
     resp = qtest_qmp(qts, "{ 'execute': 'query-spice' }");
     test_spice_resp(qdict_get(resp, "return"));
     qobject_unref(resp);
@@ -144,6 +143,7 @@ static void test_object_rng_resp(QObject *res)
         if (g_str_equal(obj->name, "rng0") &&
             g_str_equal(obj->type, "child<rng-builtin>")) {
             seen_rng = true;
+            break;
         }
 
         tmp = tmp->next;
@@ -164,7 +164,7 @@ static void test_object_rng(void)
         "id = \"rng0\"\n";
 
     qts = qtest_init_with_config(cfgdata);
-   /* Test valid command */
+    /* Test valid command */
     resp = qtest_qmp(qts,
                      "{ 'execute': 'qom-list',"
                      "  'arguments': {'path': '/objects' }}");
--

2.37.1

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 1/1
#2 lore raw
In reply to Daniel P. Berrangé
Quoted 67 lines · Daniel P. Berrangé

The property name parameter is ignored when visiting a top level type, but the obvious typo should be fixed to avoid confusion. A few indentation issues were tidied up. We can break out of the loop when finding the RNG device. Finally, close the temp FD immediately when no longer needed.

---
  tests/qtest/readconfig-test.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)
tests/qtest/readconfig-test.c +5 -5
index 2e604d7c2d..c7a9b0c7dd 100644
@@ -33,13 +33,12 @@ static QTestState *qtest_init_with_config(const char *cfgdata)
      g_assert_cmpint(cfgfd, >=, 0);
 
      ret = qemu_write_full(cfgfd, cfgdata, strlen(cfgdata));
+    close(cfgfd);
      if (ret < 0) {
          unlink(cfgpath);
      }
      g_assert_cmpint(ret, ==, strlen(cfgdata));
 
-    close(cfgfd);
-
      args = g_strdup_printf("-nodefaults -machine none -readconfig %s", cfgpath);
 
      qts = qtest_init(args);
@@ -79,7 +78,7 @@ static void test_x86_memdev(void)
          "size = \"200\"";
 
      qts = qtest_init_with_config(cfgdata);
-   /* Test valid command */
+    /* Test valid command */
      resp = qtest_qmp(qts, "{ 'execute': 'query-memdev' }");
      test_x86_memdev_resp(qdict_get(resp, "return"));
      qobject_unref(resp);
@@ -96,7 +95,7 @@ static void test_spice_resp(QObject *res)
 
      g_assert(res);
      v = qobject_input_visitor_new(res);
-    visit_type_SpiceInfo(v, "spcie", &spice, &error_abort);
+    visit_type_SpiceInfo(v, "spice", &spice, &error_abort);
 
      g_assert(spice);
      g_assert(spice->enabled);
@@ -114,7 +113,7 @@ static void test_spice(void)
          "unix = \"on\"\n";
 
      qts = qtest_init_with_config(cfgdata);
-   /* Test valid command */
+    /* Test valid command */
      resp = qtest_qmp(qts, "{ 'execute': 'query-spice' }");
      test_spice_resp(qdict_get(resp, "return"));
      qobject_unref(resp);
@@ -144,6 +143,7 @@ static void test_object_rng_resp(QObject *res)
          if (g_str_equal(obj->name, "rng0") &&
              g_str_equal(obj->type, "child<rng-builtin>")) {
              seen_rng = true;
+            break;
          }
 
          tmp = tmp->next;

tests/qtest/readconfig-test.c static void test_object_rng(void) · line 170

Quoted 8 lines
tests/qtest/readconfig-test.c +1 -1
@@ -164,7 +164,7 @@ static void test_object_rng(void)
          "id = \"rng0\"\n";
 
      qts = qtest_init_with_config(cfgdata);
-   /* Test valid command */
+    /* Test valid command */
      resp = qtest_qmp(qts,
                       "{ 'execute': 'qom-list',"
                       "  'arguments': {'path': '/objects' }}");
Reviewed-by Philippe Mathieu-Daudé on v1 1/1
#3 lore raw
In reply to Daniel P. Berrangé
Quoted 11 lines · Daniel P. Berrangé

The property name parameter is ignored when visiting a top level type, but the obvious typo should be fixed to avoid confusion. A few indentation issues were tidied up. We can break out of the loop when finding the RNG device. Finally, close the temp FD immediately when no longer needed.

---
  tests/qtest/readconfig-test.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)