Re: [libvirt PATCH v3 08/11] nodedev: Add testing for 'mdevctl start'

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

 



On 6/16/20 4:27 PM, Jonathon Jongsma wrote:
Test that we run 'mdevctl' with the proper arguments when creating new
mediated devices with virNodeDeviceCreateXML().

Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
---
  build-aux/syntax-check.mk                     |   2 +-
  tests/Makefile.am                             |  14 +
  ...019_36ea_4111_8f0a_8c9a70e21366-start.argv |   1 +
  ...019_36ea_4111_8f0a_8c9a70e21366-start.json |   1 +
  ...d39_495e_4243_ad9f_beb3f14c23d9-start.argv |   1 +
  ...d39_495e_4243_ad9f_beb3f14c23d9-start.json |   1 +
  ...916_1ca8_49ac_b176_871d16c13076-start.argv |   1 +
  ...916_1ca8_49ac_b176_871d16c13076-start.json |   1 +
  tests/nodedevmdevctltest.c                    | 262 ++++++++++++++++++
  ...v_d069d019_36ea_4111_8f0a_8c9a70e21366.xml |   7 +
  ...v_d2441d39_495e_4243_ad9f_beb3f14c23d9.xml |   9 +
  ...v_fedc4916_1ca8_49ac_b176_871d16c13076.xml |   8 +
  12 files changed, 307 insertions(+), 1 deletion(-)
  create mode 100644 tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-start.argv
  create mode 100644 tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-start.json
  create mode 100644 tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-start.argv
  create mode 100644 tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-start.json
  create mode 100644 tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-start.argv
  create mode 100644 tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-start.json
  create mode 100644 tests/nodedevmdevctltest.c
  create mode 100644 tests/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366.xml
  create mode 100644 tests/nodedevschemadata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9.xml
  create mode 100644 tests/nodedevschemadata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076.xml



diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c
new file mode 100644
index 0000000000..8d226e012b
--- /dev/null
+++ b/tests/nodedevmdevctltest.c
@@ -0,0 +1,262 @@
+#include <config.h>
+
+#include "internal.h"
+#include "testutils.h"
+#include "datatypes.h"
+#include "node_device/node_device_driver.h"
+#include "vircommand.h"
+#define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW
+#include "vircommandpriv.h"
+
+#define VIR_FROM_THIS VIR_FROM_NODEDEV
+
+struct startTestInfo {
+    const char *virt_type;
+    int create;
+    const char *filename;
+};
+
+/* capture stdin passed to command */
+static void
+testCommandDryRunCallback(const char *const*args G_GNUC_UNUSED,
+                          const char *const*env G_GNUC_UNUSED,
+                          const char *input,
+                          char **output G_GNUC_UNUSED,
+                          char **error G_GNUC_UNUSED,
+                          int *status G_GNUC_UNUSED,
+                          void *opaque G_GNUC_UNUSED)
+{
+    char **stdinbuf = opaque;
+
+    *stdinbuf = g_strdup(input);
+}
+
+/* We don't want the result of the test to depend on the path to the mdevctl
+ * binary on the developer's machine, so replace the path to mdevctl with a
+ * placeholder string before comparing to the expected output */
+static int
+nodedevCompareToFile(const char *actual,
+                     const char *filename)
+{
+    g_autofree char *replacedCmdline = NULL;
+
+    replacedCmdline = virStringReplace(actual, MDEVCTL, "$MDEVCTL_BINARY$");
+
+    return virTestCompareToFile(replacedCmdline, filename);

This is not exactly what we have talked about, but it more or less works. Thing is, virTestCompareToFile() replaces ALL occurrences ov MDEVCTL and we want just the first one. But I doubt there will ever be more.

Michal




[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