mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 12:41:29 +00:00
openvz: Add simple testcase for config file parsing function
This testcase passes before the regression is added in f0443765, fails after that commit and passes again after the regression was fixed.
This commit is contained in:
parent
83ea7c1b76
commit
4a3a029024
@ -645,7 +645,7 @@ openvzWriteVPSConfigParam(int vpsid, const char *param, const char *value)
|
||||
*
|
||||
* Returns <0 on error, 0 if not found, 1 if found.
|
||||
*/
|
||||
static int
|
||||
int
|
||||
openvzReadConfigParam(const char *conf_file, const char *param, char **value)
|
||||
{
|
||||
char *line = NULL;
|
||||
|
@ -57,6 +57,7 @@ int openvz_readline(int fd, char *ptr, int maxlen);
|
||||
int openvzExtractVersion(struct openvz_driver *driver);
|
||||
int openvzReadVPSConfigParam(int vpsid, const char *param, char **value);
|
||||
int openvzWriteVPSConfigParam(int vpsid, const char *param, const char *value);
|
||||
int openvzReadConfigParam(const char *conf_file, const char *param, char **value);
|
||||
int openvzCopyDefaultConfig(int vpsid);
|
||||
virCapsPtr openvzCapsInit(void);
|
||||
int openvzLoadDomains(struct openvz_driver *driver);
|
||||
|
@ -91,6 +91,10 @@ if WITH_QEMU
|
||||
check_PROGRAMS += qemuxml2argvtest qemuxml2xmltest qemuargv2xmltest qemuhelptest
|
||||
endif
|
||||
|
||||
if WITH_OPENVZ
|
||||
check_PROGRAMS += openvzutilstest
|
||||
endif
|
||||
|
||||
if WITH_ESX
|
||||
check_PROGRAMS += esxutilstest
|
||||
endif
|
||||
@ -197,6 +201,10 @@ TESTS += qemuxml2argvtest qemuxml2xmltest qemuargv2xmltest qemuhelptest
|
||||
TESTS += nwfilterxml2xmltest
|
||||
endif
|
||||
|
||||
if WITH_OPENVZ
|
||||
TESTS += openvzutilstest
|
||||
endif
|
||||
|
||||
if WITH_ESX
|
||||
TESTS += esxutilstest
|
||||
endif
|
||||
@ -301,6 +309,16 @@ else
|
||||
EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c qemuhelptest.c testutilsqemu.c testutilsqemu.h
|
||||
endif
|
||||
|
||||
if WITH_OPENVZ
|
||||
openvzutilstest_SOURCES = \
|
||||
openvzutilstest.c \
|
||||
testutils.c testutils.h
|
||||
openvzutilstest_LDADD = ../src/libvirt_driver_openvz.la $(LDADDS)
|
||||
else
|
||||
EXTRA_DIST += openvzutilstest.c
|
||||
endif
|
||||
EXTRA_DIST += openvzutilstest.conf
|
||||
|
||||
if WITH_ESX
|
||||
esxutilstest_SOURCES = \
|
||||
esxutilstest.c \
|
||||
|
91
tests/openvzutilstest.c
Normal file
91
tests/openvzutilstest.c
Normal file
@ -0,0 +1,91 @@
|
||||
#include <config.h>
|
||||
|
||||
#ifdef WITH_OPENVZ
|
||||
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <unistd.h>
|
||||
|
||||
# include "internal.h"
|
||||
# include "memory.h"
|
||||
# include "testutils.h"
|
||||
# include "util.h"
|
||||
# include "openvz/openvz_conf.h"
|
||||
|
||||
struct testConfigParam {
|
||||
const char *param;
|
||||
const char *value;
|
||||
int ret;
|
||||
};
|
||||
|
||||
static struct testConfigParam configParams[] = {
|
||||
{ "OSTEMPLATE", "rhel-5-lystor", 1 },
|
||||
{ "IP_ADDRESS", "194.44.18.88", 1 },
|
||||
{ "THIS_PARAM_IS_MISSING", NULL, 0 },
|
||||
};
|
||||
|
||||
static int
|
||||
testReadConfigParam(const void *data ATTRIBUTE_UNUSED)
|
||||
{
|
||||
int result = -1;
|
||||
int i;
|
||||
char *conf = NULL;
|
||||
char *value = NULL;
|
||||
|
||||
if (virAsprintf(&conf, "%s/openvzutilstest.conf", abs_srcdir) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_CARDINALITY(configParams); ++i) {
|
||||
if (openvzReadConfigParam(conf, configParams[i].param,
|
||||
&value) != configParams[i].ret) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (configParams[i].ret != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (STRNEQ(configParams[i].value, value)) {
|
||||
virtTestDifference(stderr, configParams[i].value, value);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
result = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(conf);
|
||||
VIR_FREE(value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
# define DO_TEST(_name) \
|
||||
do { \
|
||||
if (virtTestRun("OpenVZ "#_name, 1, test##_name, \
|
||||
NULL) < 0) { \
|
||||
result = -1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
DO_TEST(ReadConfigParam);
|
||||
|
||||
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
VIRT_TEST_MAIN(mymain)
|
||||
|
||||
#else
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return EXIT_AM_SKIP;
|
||||
}
|
||||
|
||||
#endif /* WITH_OPENVZ */
|
41
tests/openvzutilstest.conf
Normal file
41
tests/openvzutilstest.conf
Normal file
@ -0,0 +1,41 @@
|
||||
# sample config from http://blog.lystor.org.ua/2009/11/openvz-configuration-example.html
|
||||
|
||||
ONBOOT="yes"
|
||||
|
||||
# Primary parameters
|
||||
NUMPROC="8000:8000"
|
||||
AVNUMPROC="2257:2257"
|
||||
NUMTCPSOCK="8000:8000"
|
||||
NUMOTHERSOCK="8000:8000"
|
||||
VMGUARPAGES="360000:360000"
|
||||
|
||||
# Secondary parameters
|
||||
KMEMSIZE="184953241:203448565"
|
||||
TCPSNDBUF="28883080:61651080"
|
||||
TCPRCVBUF="28883080:61651080"
|
||||
OTHERSOCKBUF="14441540:47209540"
|
||||
DGRAMRCVBUF="14441540:14441540"
|
||||
OOMGUARPAGES="360000:360000"
|
||||
PRIVVMPAGES="360000:360000"
|
||||
|
||||
# Auxiliary parameters
|
||||
LOCKEDPAGES="9030:9030"
|
||||
SHMPAGES="15506:15506"
|
||||
PHYSPAGES="0:2147483647"
|
||||
NUMFILE="72224:72224"
|
||||
NUMFLOCK="1000:1100"
|
||||
NUMPTY="512:512"
|
||||
NUMSIGINFO="1024:1024"
|
||||
DCACHESIZE="40389343:41601024"
|
||||
NUMIPTENT="200:200"
|
||||
DISKSPACE="107733379:118506717"
|
||||
DISKINODES="55287781:60816560"
|
||||
CPUUNITS="150550"
|
||||
|
||||
# Disk quota parameters (in form of softlimit:hardlimit)
|
||||
DISKSPACE=""
|
||||
DISKINODES=""
|
||||
QUOTATIME=""
|
||||
DISK_QUOTA=no
|
||||
OSTEMPLATE="rhel-5-lystor"
|
||||
IP_ADDRESS="194.44.18.88"
|
Loading…
x
Reference in New Issue
Block a user