]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: vircommand: Add direct accessor for 'args' array for tests
authorPeter Krempa <pkrempa@redhat.com>
Wed, 13 May 2026 12:59:50 +0000 (14:59 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 25 May 2026 11:28:57 +0000 (13:28 +0200)
Introduce virCommandArgListAccess which returns 'args' and 'nargs'

Upcoming patches will add code which censores/stabilizes FD numbers in
test outputs. This will be done by rewriting the argument of the command
before comparing it with test output. Add a test-only function to
directly access 'args' and 'nargs' of a virCommand to do this
modification.

This accessor will also be used instead of 'virCommandGetArgList' in
'testCompareXMLToArgvValidateSchema' to avoid needles copy of all
arguments.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/util/vircommand.c
src/util/vircommandpriv.h

index a76da45fb962a9f75fefdc247c4f1cea6273c262..6c653ff4f09dc186be5cdb1e127a1df2625a217c 100644 (file)
@@ -2210,6 +2210,7 @@ virCommandAddEnvPassCommon;
 virCommandAddEnvString;
 virCommandAddEnvXDG;
 virCommandAllowCap;
+virCommandArgListAccess;
 virCommandClearCaps;
 virCommandDaemonize;
 virCommandDoAsyncIO;
index 2d13cf629cb350ed47a3e589a2d8c66a9a48db65..ba366ca3985d63a3dbb075ee5cbb03a59a1e64d0 100644 (file)
@@ -2172,6 +2172,26 @@ virCommandGetArgList(virCommand *cmd,
 }
 
 
+/**
+ * virCommandArgListAccess:
+ * @cmd: command struct
+ * @args: filled with pointer to list of args of @cmd
+ * @nargs: filled with number of arguments
+ *
+ * For use only in tests.
+ *
+ * Allows access to the arguments, including modification.
+ */
+void
+virCommandArgListAccess(virCommand *cmd,
+                        char ***args,
+                        size_t *nargs)
+{
+    *args = cmd->args;
+    *nargs = cmd->nargs;
+}
+
+
 /*
  * virCommandGetBinaryPath:
  * @cmd: virCommand* containing all information about the program
index d579810bb5bcd4b1505b7e03e4fc1a5e02dbe36a..ca58269afa2abcc2b606be14199ce73733a6fc21 100644 (file)
@@ -51,3 +51,7 @@ void virCommandSetDryRun(virCommandDryRunToken *tok,
 void virCommandPeekSendBuffers(virCommand *cmd,
                                virCommandSendBuffer **buffers,
                                int *nbuffers);
+
+void virCommandArgListAccess(virCommand *cmd,
+                             char ***args,
+                             size_t *nargs);