tests: Introduce chxml2xmlmock

As of previous commit, the CH driver checks for /dev/kvm and/or
/dev/mshv presence. In order to make chxml2xmltest work
regardless of host configuration, introduce a mock that pretends
both of these files are accessible.

Fixes: 51c14df967
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Michal Privoznik 2024-03-08 15:03:04 +01:00
parent f432114d9c
commit 0be6e26469
3 changed files with 24 additions and 1 deletions

20
tests/chxml2xmlmock.c Normal file
View File

@ -0,0 +1,20 @@
/*
* Copyright (C) 2024 Red Hat, Inc.
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <config.h>
#include <unistd.h>
#include "internal.h"
#include "virfile.h"
bool
virFileExists(const char *path)
{
if (STREQ(path, "/dev/kvm"))
return true;
if (STREQ(path, "/dev/mshv"))
return true;
return access(path, F_OK) == 0;
}

View File

@ -74,4 +74,4 @@ mymain(void)
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }
VIR_TEST_MAIN(mymain) VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("chxml2xml"))

View File

@ -350,6 +350,9 @@ if conf.has('WITH_CH')
tests += [ tests += [
{ 'name': 'chxml2xmltest', 'link_with': [ ch_driver_impl ] }, { 'name': 'chxml2xmltest', 'link_with': [ ch_driver_impl ] },
] ]
mock_libs += [
{ 'name': 'chxml2xmlmock' },
]
endif endif
if conf.has('WITH_ESX') if conf.has('WITH_ESX')