From 4a3a029024c00c05662d10a46bac6600e410c713 Mon Sep 17 00:00:00 2001 From: Matthias Bolte Date: Thu, 26 May 2011 19:45:41 +0200 Subject: [PATCH] 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. --- src/openvz/openvz_conf.c | 2 +- src/openvz/openvz_conf.h | 1 + tests/Makefile.am | 18 ++++++++ tests/openvzutilstest.c | 91 ++++++++++++++++++++++++++++++++++++++ tests/openvzutilstest.conf | 41 +++++++++++++++++ 5 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 tests/openvzutilstest.c create mode 100644 tests/openvzutilstest.conf diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index c106b07f63..2cccd8131e 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -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; diff --git a/src/openvz/openvz_conf.h b/src/openvz/openvz_conf.h index 9a57551e78..d5a57a6160 100644 --- a/src/openvz/openvz_conf.h +++ b/src/openvz/openvz_conf.h @@ -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); diff --git a/tests/Makefile.am b/tests/Makefile.am index bc171d22d6..7ae50a2f63 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 \ diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c new file mode 100644 index 0000000000..fe6a2ea7fd --- /dev/null +++ b/tests/openvzutilstest.c @@ -0,0 +1,91 @@ +#include + +#ifdef WITH_OPENVZ + +# include +# include +# include + +# 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 */ diff --git a/tests/openvzutilstest.conf b/tests/openvzutilstest.conf new file mode 100644 index 0000000000..a1b93b7c88 --- /dev/null +++ b/tests/openvzutilstest.conf @@ -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" -- GitLab