[PATCH 04/35] virshtest: Add support for testing commands read from input file and adapt alias tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add support for reading a file and passing it to virsh in 'batch' mode
so that multiple commands can be easily tested with one invocation of
virsh.

To show how it's used adapt the alias handling tests to be invoked all
at once.

As in batch mode the arguments are read from a string and separated
inside virsh, one test is kept separate to be parsed in argv mode.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tests/virshtest.c                  | 25 +++++++++++++++++++++----
 tests/virshtestdata/echo-alias.in  |  3 +++
 tests/virshtestdata/echo-alias.out |  3 +++
 3 files changed, 27 insertions(+), 4 deletions(-)
 create mode 100644 tests/virshtestdata/echo-alias.in
 create mode 100644 tests/virshtestdata/echo-alias.out

diff --git a/tests/virshtest.c b/tests/virshtest.c
index e0b5cd3150..376fb861ed 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -561,6 +561,26 @@ mymain(void)
                    testIOThreadPin, NULL) != 0)
         ret = -1;

+# define DO_TEST_SCRIPT(testname_, testfilter, ...) \
+    { \
+        const char *testname = testname_; \
+        g_autofree char *infile = g_strdup_printf("%s/virshtestdata/%s.in", \
+                                                  abs_srcdir, testname); \
+        const char *myargv[] = { __VA_ARGS__, NULL, NULL }; \
+        const char **tmp = myargv; \
+        const struct testInfo info = { testname, testfilter, myargv, NULL }; \
+        g_autofree char *scriptarg = NULL; \
+        if (virFileReadAll(infile, 256 * 1024, &scriptarg) < 0) { \
+            fprintf(stderr, "\nfailed to load '%s'\n", infile); \
+            ret = -1; \
+        } \
+        while (*tmp) \
+            tmp++; \
+        *tmp = scriptarg; \
+        if (virTestRun(testname, testCompare, &info) < 0) \
+            ret = -1; \
+    } while (0);
+
     /* It's a bit awkward listing result before argument, but that's a
      * limitation of C99 vararg macros.  */
 # define DO_TEST(i, result, ...) \
@@ -644,11 +664,8 @@ mymain(void)
             "echo \t '-'\"-\" \t --shell \t a");

     /* Tests of alias handling.  */
-    DO_TEST(31, "hello\n", "echo", "--string", "hello");
-    DO_TEST(32, "hello\n", "echo --string hello");
+    DO_TEST_SCRIPT("echo-alias", NULL, VIRSH_DEFAULT);
     DO_TEST(33, "hello\n", "echo", "--str", "hello");
-    DO_TEST(34, "hello\n", "echo --str hello");
-    DO_TEST(35, "hello\n", "echo --hi");

     /* Tests of multiple commands.  */
     DO_TEST(36, "a\nb\n", " echo a; echo b;");
diff --git a/tests/virshtestdata/echo-alias.in b/tests/virshtestdata/echo-alias.in
new file mode 100644
index 0000000000..f123437490
--- /dev/null
+++ b/tests/virshtestdata/echo-alias.in
@@ -0,0 +1,3 @@
+echo --string hello
+echo --str hello
+echo --hi;
diff --git a/tests/virshtestdata/echo-alias.out b/tests/virshtestdata/echo-alias.out
new file mode 100644
index 0000000000..640bb73cf1
--- /dev/null
+++ b/tests/virshtestdata/echo-alias.out
@@ -0,0 +1,3 @@
+hello
+hello
+hello
-- 
2.44.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux