mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
tests: Use more specific names for variables
Instead of fakesysfsdir, which is very generic, use fakesysfspcidir and fakesysfscgroupdir. This makes it explicit what part of the fake sysfs filesystem they're referring to, and also leaves open the possibility of handling files in two unrelated parts of the fake sysfs filesystem. No functional changes.
This commit is contained in:
parent
46468c62ff
commit
d2939c0f4d
@ -48,12 +48,12 @@ static int (*realmkdir)(const char *path, mode_t mode);
|
||||
* vircgroupmock.c:462:22: error: static variable 'fakesysfsdir' is used in an inline function with external linkage [-Werror,-Wstatic-in-inline]
|
||||
*/
|
||||
char *fakerootdir;
|
||||
char *fakesysfsdir;
|
||||
char *fakesysfscgroupdir;
|
||||
const char *fakedevicedir0 = FAKEDEVDIR0;
|
||||
const char *fakedevicedir1 = FAKEDEVDIR1;
|
||||
|
||||
|
||||
# define SYSFS_PREFIX "/not/really/sys/fs/cgroup/"
|
||||
# define SYSFS_CGROUP_PREFIX "/not/really/sys/fs/cgroup/"
|
||||
# define SYSFS_CPU_PRESENT "/sys/devices/system/cpu/present"
|
||||
# define SYSFS_CPU_PRESENT_MOCKED "devices_system_cpu_present"
|
||||
|
||||
@ -186,11 +186,11 @@ static int make_controller(const char *path, mode_t mode)
|
||||
int ret = -1;
|
||||
const char *controller;
|
||||
|
||||
if (!STRPREFIX(path, fakesysfsdir)) {
|
||||
if (!STRPREFIX(path, fakesysfscgroupdir)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
controller = path + strlen(fakesysfsdir) + 1;
|
||||
controller = path + strlen(fakesysfscgroupdir) + 1;
|
||||
|
||||
if (STREQ(controller, "cpu"))
|
||||
return symlink("cpu,cpuacct", path);
|
||||
@ -417,7 +417,7 @@ static void init_syms(void)
|
||||
|
||||
static void init_sysfs(void)
|
||||
{
|
||||
if (fakerootdir && fakesysfsdir)
|
||||
if (fakerootdir && fakesysfscgroupdir)
|
||||
return;
|
||||
|
||||
if (!(fakerootdir = getenv("LIBVIRT_FAKE_ROOT_DIR"))) {
|
||||
@ -425,24 +425,24 @@ static void init_sysfs(void)
|
||||
abort();
|
||||
}
|
||||
|
||||
if (virAsprintfQuiet(&fakesysfsdir, "%s%s",
|
||||
fakerootdir, SYSFS_PREFIX) < 0)
|
||||
if (virAsprintfQuiet(&fakesysfscgroupdir, "%s%s",
|
||||
fakerootdir, SYSFS_CGROUP_PREFIX) < 0)
|
||||
abort();
|
||||
|
||||
if (virFileMakePath(fakesysfsdir) < 0) {
|
||||
fprintf(stderr, "Cannot create %s\n", fakesysfsdir);
|
||||
if (virFileMakePath(fakesysfscgroupdir) < 0) {
|
||||
fprintf(stderr, "Cannot create %s\n", fakesysfscgroupdir);
|
||||
abort();
|
||||
}
|
||||
|
||||
# define MAKE_CONTROLLER(subpath) \
|
||||
do { \
|
||||
char *path; \
|
||||
if (asprintf(&path, "%s/%s", fakesysfsdir, subpath) < 0)\
|
||||
abort(); \
|
||||
if (make_controller(path, 0755) < 0) { \
|
||||
fprintf(stderr, "Cannot initialize %s\n", path); \
|
||||
abort(); \
|
||||
} \
|
||||
# define MAKE_CONTROLLER(subpath) \
|
||||
do { \
|
||||
char *path; \
|
||||
if (asprintf(&path, "%s/%s", fakesysfscgroupdir, subpath) < 0) \
|
||||
abort(); \
|
||||
if (make_controller(path, 0755) < 0) { \
|
||||
fprintf(stderr, "Cannot initialize %s\n", path); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
MAKE_CONTROLLER("cpu");
|
||||
@ -454,7 +454,8 @@ static void init_sysfs(void)
|
||||
MAKE_CONTROLLER("memory");
|
||||
MAKE_CONTROLLER("freezer");
|
||||
|
||||
if (make_file(fakesysfsdir, SYSFS_CPU_PRESENT_MOCKED, "8-23,48-159\n") < 0)
|
||||
if (make_file(fakesysfscgroupdir,
|
||||
SYSFS_CPU_PRESENT_MOCKED, "8-23,48-159\n") < 0)
|
||||
abort();
|
||||
}
|
||||
|
||||
@ -528,12 +529,12 @@ int access(const char *path, int mode)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
|
||||
init_sysfs();
|
||||
char *newpath;
|
||||
if (asprintf(&newpath, "%s/%s",
|
||||
fakesysfsdir,
|
||||
path + strlen(SYSFS_PREFIX)) < 0) {
|
||||
fakesysfscgroupdir,
|
||||
path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@ -559,12 +560,12 @@ int __lxstat(int ver, const char *path, struct stat *sb)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
|
||||
init_sysfs();
|
||||
char *newpath;
|
||||
if (asprintf(&newpath, "%s/%s",
|
||||
fakesysfsdir,
|
||||
path + strlen(SYSFS_PREFIX)) < 0) {
|
||||
fakesysfscgroupdir,
|
||||
path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@ -590,12 +591,12 @@ int lstat(const char *path, struct stat *sb)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
|
||||
init_sysfs();
|
||||
char *newpath;
|
||||
if (asprintf(&newpath, "%s/%s",
|
||||
fakesysfsdir,
|
||||
path + strlen(SYSFS_PREFIX)) < 0) {
|
||||
fakesysfscgroupdir,
|
||||
path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@ -621,12 +622,12 @@ int __xstat(int ver, const char *path, struct stat *sb)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
|
||||
init_sysfs();
|
||||
char *newpath;
|
||||
if (asprintf(&newpath, "%s/%s",
|
||||
fakesysfsdir,
|
||||
path + strlen(SYSFS_PREFIX)) < 0) {
|
||||
fakesysfscgroupdir,
|
||||
path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@ -656,16 +657,16 @@ int stat(const char *path, struct stat *sb)
|
||||
if (STREQ(path, SYSFS_CPU_PRESENT)) {
|
||||
init_sysfs();
|
||||
if (asprintf(&newpath, "%s/%s",
|
||||
fakesysfsdir,
|
||||
fakesysfscgroupdir,
|
||||
SYSFS_CPU_PRESENT_MOCKED) < 0) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
} else if (STRPREFIX(path, SYSFS_PREFIX)) {
|
||||
} else if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
|
||||
init_sysfs();
|
||||
if (asprintf(&newpath, "%s/%s",
|
||||
fakesysfsdir,
|
||||
path + strlen(SYSFS_PREFIX)) < 0) {
|
||||
fakesysfscgroupdir,
|
||||
path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@ -692,12 +693,12 @@ int mkdir(const char *path, mode_t mode)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
|
||||
init_sysfs();
|
||||
char *newpath;
|
||||
if (asprintf(&newpath, "%s/%s",
|
||||
fakesysfsdir,
|
||||
path + strlen(SYSFS_PREFIX)) < 0) {
|
||||
fakesysfscgroupdir,
|
||||
path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@ -719,18 +720,18 @@ int open(const char *path, int flags, ...)
|
||||
if (STREQ(path, SYSFS_CPU_PRESENT)) {
|
||||
init_sysfs();
|
||||
if (asprintf(&newpath, "%s/%s",
|
||||
fakesysfsdir,
|
||||
fakesysfscgroupdir,
|
||||
SYSFS_CPU_PRESENT_MOCKED) < 0) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (STRPREFIX(path, SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
|
||||
init_sysfs();
|
||||
if (asprintf(&newpath, "%s/%s",
|
||||
fakesysfsdir,
|
||||
path + strlen(SYSFS_PREFIX)) < 0) {
|
||||
fakesysfscgroupdir,
|
||||
path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
@ -50,9 +50,9 @@ static DIR * (*realopendir)(const char *name);
|
||||
* vircgroupmock.c:462:22: error: static variable 'fakesysfsdir' is used in an inline function with external linkage [-Werror,-Wstatic-in-inline]
|
||||
*/
|
||||
char *fakerootdir;
|
||||
char *fakesysfsdir;
|
||||
char *fakesysfspcidir;
|
||||
|
||||
# define PCI_SYSFS_PREFIX "/sys/bus/pci/"
|
||||
# define SYSFS_PCI_PREFIX "/sys/bus/pci/"
|
||||
|
||||
# define STDERR(...) \
|
||||
fprintf(stderr, "%s %zu: ", __FUNCTION__, (size_t) __LINE__); \
|
||||
@ -201,8 +201,8 @@ pci_read_file(const char *path,
|
||||
char *newpath;
|
||||
|
||||
if (virAsprintfQuiet(&newpath, "%s/%s",
|
||||
fakesysfsdir,
|
||||
path + strlen(PCI_SYSFS_PREFIX)) < 0) {
|
||||
fakesysfspcidir,
|
||||
path + strlen(SYSFS_PCI_PREFIX)) < 0) {
|
||||
errno = ENOMEM;
|
||||
goto cleanup;
|
||||
}
|
||||
@ -232,10 +232,10 @@ getrealpath(char **newpath,
|
||||
{
|
||||
init_env();
|
||||
|
||||
if (STRPREFIX(path, PCI_SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_PCI_PREFIX)) {
|
||||
if (virAsprintfQuiet(newpath, "%s/%s",
|
||||
fakesysfsdir,
|
||||
path + strlen(PCI_SYSFS_PREFIX)) < 0) {
|
||||
fakesysfspcidir,
|
||||
path + strlen(SYSFS_PCI_PREFIX)) < 0) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@ -343,7 +343,7 @@ pci_device_new_from_stub(const struct pciDevice *data)
|
||||
if (VIR_ALLOC_QUIET(dev) < 0 ||
|
||||
virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config",
|
||||
abs_srcdir, id) < 0 ||
|
||||
virAsprintfQuiet(&devpath, "%s/devices/%s", fakesysfsdir, data->id) < 0)
|
||||
virAsprintfQuiet(&devpath, "%s/devices/%s", fakesysfspcidir, data->id) < 0)
|
||||
ABORT_OOM();
|
||||
|
||||
VIR_FREE(id);
|
||||
@ -449,7 +449,7 @@ pci_driver_new(const char *name, int fail, ...)
|
||||
|
||||
if (VIR_ALLOC_QUIET(driver) < 0 ||
|
||||
VIR_STRDUP_QUIET(driver->name, name) < 0 ||
|
||||
virAsprintfQuiet(&driverpath, "%s/drivers/%s", fakesysfsdir, name) < 0)
|
||||
virAsprintfQuiet(&driverpath, "%s/drivers/%s", fakesysfspcidir, name) < 0)
|
||||
ABORT_OOM();
|
||||
|
||||
driver->fail = fail;
|
||||
@ -532,9 +532,9 @@ pci_driver_bind(struct pciDriver *driver,
|
||||
|
||||
/* Make symlink under device tree */
|
||||
if (virAsprintfQuiet(&devpath, "%s/devices/%s/driver",
|
||||
fakesysfsdir, dev->id) < 0 ||
|
||||
fakesysfspcidir, dev->id) < 0 ||
|
||||
virAsprintfQuiet(&driverpath, "%s/drivers/%s",
|
||||
fakesysfsdir, driver->name) < 0) {
|
||||
fakesysfspcidir, driver->name) < 0) {
|
||||
errno = ENOMEM;
|
||||
goto cleanup;
|
||||
}
|
||||
@ -546,9 +546,9 @@ pci_driver_bind(struct pciDriver *driver,
|
||||
VIR_FREE(devpath);
|
||||
VIR_FREE(driverpath);
|
||||
if (virAsprintfQuiet(&devpath, "%s/devices/%s",
|
||||
fakesysfsdir, dev->id) < 0 ||
|
||||
fakesysfspcidir, dev->id) < 0 ||
|
||||
virAsprintfQuiet(&driverpath, "%s/drivers/%s/%s",
|
||||
fakesysfsdir, driver->name, dev->id) < 0) {
|
||||
fakesysfspcidir, driver->name, dev->id) < 0) {
|
||||
errno = ENOMEM;
|
||||
goto cleanup;
|
||||
}
|
||||
@ -579,9 +579,9 @@ pci_driver_unbind(struct pciDriver *driver,
|
||||
|
||||
/* Make symlink under device tree */
|
||||
if (virAsprintfQuiet(&devpath, "%s/devices/%s/driver",
|
||||
fakesysfsdir, dev->id) < 0 ||
|
||||
fakesysfspcidir, dev->id) < 0 ||
|
||||
virAsprintfQuiet(&driverpath, "%s/drivers/%s/%s",
|
||||
fakesysfsdir, driver->name, dev->id) < 0) {
|
||||
fakesysfspcidir, driver->name, dev->id) < 0) {
|
||||
errno = ENOMEM;
|
||||
goto cleanup;
|
||||
}
|
||||
@ -801,20 +801,20 @@ init_syms(void)
|
||||
static void
|
||||
init_env(void)
|
||||
{
|
||||
if (fakerootdir && fakesysfsdir)
|
||||
if (fakerootdir && fakesysfspcidir)
|
||||
return;
|
||||
|
||||
if (!(fakerootdir = getenv("LIBVIRT_FAKE_ROOT_DIR")))
|
||||
ABORT("Missing LIBVIRT_FAKE_ROOT_DIR env variable\n");
|
||||
|
||||
if (virAsprintfQuiet(&fakesysfsdir, "%s%s",
|
||||
fakerootdir, PCI_SYSFS_PREFIX) < 0)
|
||||
if (virAsprintfQuiet(&fakesysfspcidir, "%s%s",
|
||||
fakerootdir, SYSFS_PCI_PREFIX) < 0)
|
||||
ABORT_OOM();
|
||||
|
||||
if (virFileMakePath(fakesysfsdir) < 0)
|
||||
ABORT("Unable to create: %s", fakesysfsdir);
|
||||
if (virFileMakePath(fakesysfspcidir) < 0)
|
||||
ABORT("Unable to create: %s", fakesysfspcidir);
|
||||
|
||||
make_file(fakesysfsdir, "drivers_probe", NULL, -1);
|
||||
make_file(fakesysfspcidir, "drivers_probe", NULL, -1);
|
||||
|
||||
# define MAKE_PCI_DRIVER(name, ...) \
|
||||
pci_driver_new(name, 0, __VA_ARGS__, -1, -1)
|
||||
@ -861,7 +861,7 @@ access(const char *path, int mode)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, PCI_SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_PCI_PREFIX)) {
|
||||
char *newpath;
|
||||
if (getrealpath(&newpath, path) < 0)
|
||||
return -1;
|
||||
@ -880,7 +880,7 @@ __lxstat(int ver, const char *path, struct stat *sb)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, PCI_SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_PCI_PREFIX)) {
|
||||
char *newpath;
|
||||
if (getrealpath(&newpath, path) < 0)
|
||||
return -1;
|
||||
@ -899,7 +899,7 @@ lstat(const char *path, struct stat *sb)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, PCI_SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_PCI_PREFIX)) {
|
||||
char *newpath;
|
||||
if (getrealpath(&newpath, path) < 0)
|
||||
return -1;
|
||||
@ -918,7 +918,7 @@ __xstat(int ver, const char *path, struct stat *sb)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, PCI_SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_PCI_PREFIX)) {
|
||||
char *newpath;
|
||||
if (getrealpath(&newpath, path) < 0)
|
||||
return -1;
|
||||
@ -937,7 +937,7 @@ stat(const char *path, struct stat *sb)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, PCI_SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_PCI_PREFIX)) {
|
||||
char *newpath;
|
||||
if (getrealpath(&newpath, path) < 0)
|
||||
return -1;
|
||||
@ -956,7 +956,7 @@ canonicalize_file_name(const char *path)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, PCI_SYSFS_PREFIX)) {
|
||||
if (STRPREFIX(path, SYSFS_PCI_PREFIX)) {
|
||||
char *newpath;
|
||||
if (getrealpath(&newpath, path) < 0)
|
||||
return NULL;
|
||||
@ -976,7 +976,7 @@ open(const char *path, int flags, ...)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, PCI_SYSFS_PREFIX) &&
|
||||
if (STRPREFIX(path, SYSFS_PCI_PREFIX) &&
|
||||
getrealpath(&newpath, path) < 0)
|
||||
return -1;
|
||||
|
||||
@ -993,7 +993,7 @@ open(const char *path, int flags, ...)
|
||||
|
||||
/* Catch both: /sys/bus/pci/drivers/... and
|
||||
* /sys/bus/pci/device/.../driver/... */
|
||||
if (ret >= 0 && STRPREFIX(path, PCI_SYSFS_PREFIX) &&
|
||||
if (ret >= 0 && STRPREFIX(path, SYSFS_PCI_PREFIX) &&
|
||||
strstr(path, "driver") && add_fd(ret, path) < 0) {
|
||||
realclose(ret);
|
||||
ret = -1;
|
||||
@ -1011,7 +1011,7 @@ opendir(const char *path)
|
||||
|
||||
init_syms();
|
||||
|
||||
if (STRPREFIX(path, PCI_SYSFS_PREFIX) &&
|
||||
if (STRPREFIX(path, SYSFS_PCI_PREFIX) &&
|
||||
getrealpath(&newpath, path) < 0)
|
||||
return NULL;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user