]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Introduce virsh self-test
authorJán Tomko <jtomko@redhat.com>
Fri, 17 Jun 2016 17:28:12 +0000 (19:28 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 20 Jun 2016 16:16:33 +0000 (18:16 +0200)
A new hidden command for virsh that will iterate over
all command groups and commands and print help for every single one.

This involves running vshCmddefOptParse so we can get an error if
one of the command's option structure is invalid.

.gitignore
tests/Makefile.am
tests/virsh-self-test [new file with mode: 0755]
tools/virsh.c

index 39c0423103c2e22ecfd346d440517f05b9929a6b..8ce7e185c067eb44c9403c99407ffa3000cf27ef 100644 (file)
 /tests/*test
 /tests/commandhelper
 /tests/qemucapsprobe
+!/tests/virsh-self-test
 !/tests/virt-aa-helper-test
 /tests/objectlocking
 /tests/objectlocking-files.txt
index b4fbcc4b6c233ce5be6e3e243dcfacdfa6734eca..874b9d14d07c2ca18d58b09542f450eb002a90e9 100644 (file)
@@ -368,6 +368,7 @@ libvirtd_test_scripts =             \
        virsh-read-bufsiz               \
        virsh-read-non-seekable         \
        virsh-schedinfo                 \
+       virsh-self-test                 \
        virsh-start                     \
        virsh-synopsis                  \
        virsh-undefine                  \
diff --git a/tests/virsh-self-test b/tests/virsh-self-test
new file mode 100755 (executable)
index 0000000..c51fcf4
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+# run virsh self-test to make sure command option structures are valid
+
+# Copyright (C) 2016 Red Hat, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+. "$(dirname $0)/test-lib.sh"
+
+fail=0
+
+test_url=test:///default
+
+test_intro "virsh-self-test"
+$abs_top_builddir/tools/virsh -c $test_url self-test > /dev/null
+status=$?
+test_result 1 "virsh-self-test" $status
+
+if test "$status" = "1" ; then
+   fail=1
+fi
+
+test_final $counter $fail
+
+(exit $fail); exit $fail
index 2a807d99af71d60fa9c523f321582b7acdc82148..5dc482d90e62e645c95ac2852899903707d24e5b 100644 (file)
@@ -341,6 +341,45 @@ virshConnectionHandler(vshControl *ctl)
     return NULL;
 }
 
+/* -----------------
+ * Command self-test
+ * ----------------- */
+
+static const vshCmdInfo info_selftest[] = {
+    {.name = "help",
+     .data = N_("internal command for testing virsh")
+    },
+    {.name = "desc",
+     .data = N_("internal use only")
+    },
+    {.name = NULL}
+};
+
+/* Prints help for every command.
+ * That runs vshCmddefOptParse which validates
+ * the per-command options structure. */
+static bool
+cmdSelfTest(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
+{
+    const vshCmdGrp *grp;
+    const vshCmdDef *def;
+
+    vshPrint(ctl, "Do not use the following output:\n\n");
+
+    for (grp = cmdGroups; grp->name; grp++) {
+        for (def = grp->commands; def->name; def++) {
+            if (def->flags & VSH_CMD_FLAG_ALIAS)
+                continue;
+
+            if (!vshCmddefHelp(ctl, def->name))
+                return false;
+        }
+    }
+
+    return true;
+}
+
+
 /* ---------------
  * Misc utils
  * ---------------
@@ -857,6 +896,12 @@ static const vshCmdDef virshCmds[] = {
      .info = info_connect,
      .flags = VSH_CMD_FLAG_NOCONNECT
     },
+    {.name = "self-test",
+     .handler = cmdSelfTest,
+     .opts = NULL,
+     .info = info_selftest,
+     .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS
+    },
     {.name = NULL}
 };