Re: [PATCH 2/2] qemuxml2argvmock: Poison virCommandRun and virFork from test context

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

 



On 12/18/23 15:26, Peter Krempa wrote:
> On Mon, Dec 18, 2023 at 15:17:01 +0100, Michal Prívozník wrote:
>> On 12/18/23 12:02, Peter Krempa wrote:
>>> We don't want to ever run an actuall command in qemuxml2argvtest poison
>>> the helper functions we have for running commands.
>>>
>>> Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
>>> ---
>>>  src/util/vircommand.h    |  4 ++--
>>>  tests/qemuxml2argvmock.c | 19 +++++++++++++++++++
>>>  2 files changed, 21 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/src/util/vircommand.h b/src/util/vircommand.h
>>> index 9bcdce35b9..566ac15947 100644
>>> --- a/src/util/vircommand.h
>>> +++ b/src/util/vircommand.h
>>> @@ -39,7 +39,7 @@ typedef struct _virCommand virCommand;
>>>   * call any function that is not async-signal-safe.  */
>>>  typedef int (*virExecHook)(void *data);
>>>
>>> -pid_t virFork(void) G_GNUC_WARN_UNUSED_RESULT;
>>> +pid_t virFork(void) G_GNUC_WARN_UNUSED_RESULT G_NO_INLINE;
>>>
>>>  virCommand *virCommandNew(const char *binary) ATTRIBUTE_NONNULL(1);
>>>
>>> @@ -184,7 +184,7 @@ int virCommandGetArgList(virCommand *cmd, char ***args);
>>>  int virCommandExec(virCommand *cmd, gid_t *groups, int ngroups) G_GNUC_WARN_UNUSED_RESULT;
>>>
>>>  int virCommandRun(virCommand *cmd,
>>> -                  int *exitstatus) G_GNUC_WARN_UNUSED_RESULT;
>>> +                  int *exitstatus) G_GNUC_WARN_UNUSED_RESULT G_NO_INLINE;
>>>
>>>  int virCommandRunAsync(virCommand *cmd,
>>>                         pid_t *pid) G_GNUC_WARN_UNUSED_RESULT;
>>> diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c
>>> index 2deccd79c4..0ee8fbba79 100644
>>> --- a/tests/qemuxml2argvmock.c
>>> +++ b/tests/qemuxml2argvmock.c
>>> @@ -276,3 +276,22 @@ qemuExtVhostUserGPUPrepareDomain(virQEMUDriver *driver G_GNUC_UNUSED,
>>>  {
>>>      return 0;
>>>  }
>>> +
>>> +
>>> +int
>>> +virCommandRun(virCommand *cmd,
>>> +              int *exitstatus G_GNUC_UNUSED)
>>> +{
>>> +    const char *path = virCommandGetBinaryPath(cmd);
>>> +
>>> +    fprintf(stderr, "\nattempted virCommandRun() (path=%s) from test context\n", NULLSTR(path));
>>> +    return -1;
>>> +}
>>> +
>>> +
>>> +pid_t
>>> +virFork(void)
>>> +{
>>> +    fprintf(stderr, "\nattempted virFork() in test context\n");
>>> +    return -1;
>>> +}
>>
>> Any reason to mock both? Or is it just to provide nicer error message?
> 
> Reasonable error message is reported already by virCommandRun. I just
> wanted to make sure that the test doesn't try to even fork for any other
> reason, thus I've picked our other helper to prevent that too (IIRC
> plain fork() is forbidden by syntax-check).

Yeah, we have a syntax-check to enforce virFork(), so mocking just
virFork() should be fine. In the end, virCommandRun() does call
virFork(). I don't mind and don't want to bikeshed. Feel free to push
your patch as is. I was just curious.

Michal
_______________________________________________
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