The virconftest is different from all our other tests in that
the C program only tests a single in/out config file pair. It
relies on a shell wrapper to invoke it once for each test
file.
This gets rid of the shell wrapper and makes the C program
actually run over each test file using the normal test pattern.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
tests/Makefile.am | 7 ++---
tests/virconftest.c | 78 ++++++++++++++++++++++++++++++++++++++++++----------
tests/virconftest.sh | 26 ------------------
3 files changed, 67 insertions(+), 44 deletions(-)
delete mode 100755 tests/virconftest.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fb2380d..51a8179 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -158,11 +158,11 @@ EXTRA_DIST = \
xml2sexprdata \
xml2vmxdata
-test_helpers = commandhelper ssh virconftest
+test_helpers = commandhelper ssh
test_programs = virshtest sockettest \
virhostcputest virbuftest \
commandtest seclabeltest \
- virhashtest \
+ virhashtest virconftest \
viratomictest \
utiltest shunloadtest \
virtimetest viruritest virkeyfiletest \
@@ -360,7 +360,6 @@ test_scripts =
libvirtd_test_scripts = \
libvirtd-fail \
libvirtd-pool \
- virconftest.sh \
virsh-cpuset \
virsh-define-dev-segfault \
virsh-int-overflow \
@@ -893,7 +892,7 @@ virshtest_SOURCES = \
virshtest_LDADD = $(LDADDS)
virconftest_SOURCES = \
- virconftest.c
+ virconftest.c testutils.h testutils.c
virconftest_LDADD = $(LDADDS)
virhostcputest_SOURCES = \
diff --git a/tests/virconftest.c b/tests/virconftest.c
index 4d05d8d..c71b491 100644
--- a/tests/virconftest.c
+++ b/tests/virconftest.c
@@ -1,3 +1,24 @@
+/*
+ * virconftest.c: Test the config file API
+ *
+ * Copyright (C) 2006-2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <
http://www.gnu.org/licenses/>.
+ *
+ */
+
#include <config.h>
#include <unistd.h>
@@ -7,42 +28,71 @@
#include <errno.h>
#include "virconf.h"
#include "viralloc.h"
+#include "testutils.h"
+
+
+#define VIR_FROM_THIS VIR_FROM_NONE
-int main(int argc, char **argv)
+static int testConfRoundTrip(const void *opaque)
{
- int ret, exit_code = EXIT_FAILURE;
+ const char *name = opaque;
+ int ret = -1;
virConfPtr conf = NULL;
int len = 10000;
char *buffer = NULL;
+ char *srcfile = NULL;
+ char *dstfile = NULL;
- if (argc != 2) {
- fprintf(stderr, "Usage: %s conf_file\n", argv[0]);
+ if (virAsprintf(&srcfile, "%s/virconfdata/%s.conf",
+ abs_srcdir, name) < 0 ||
+ virAsprintf(&dstfile, "%s/virconfdata/%s.out",
+ abs_srcdir, name) < 0)
goto cleanup;
- }
if (VIR_ALLOC_N_QUIET(buffer, len) < 0) {
fprintf(stderr, "out of memory\n");
goto cleanup;
}
- conf = virConfReadFile(argv[1], 0);
+ conf = virConfReadFile(srcfile, 0);
if (conf == NULL) {
- fprintf(stderr, "Failed to process %s\n", argv[1]);
+ fprintf(stderr, "Failed to process %s\n", srcfile);
goto cleanup;
}
ret = virConfWriteMem(buffer, &len, conf);
if (ret < 0) {
- fprintf(stderr, "Failed to serialize %s back\n", argv[1]);
- goto cleanup;
- }
- if (fwrite(buffer, 1, len, stdout) != len) {
- fprintf(stderr, "Write failed: %s\n", strerror(errno));
+ fprintf(stderr, "Failed to serialize %s back\n", srcfile);
goto cleanup;
}
- exit_code = EXIT_SUCCESS;
+ if (virTestCompareToFile(buffer, dstfile) < 0)
+ goto cleanup;
+ ret = 0;
cleanup:
+ VIR_FREE(srcfile);
+ VIR_FREE(dstfile);
VIR_FREE(buffer);
virConfFree(conf);
- return exit_code;
+ return ret;
}
+
+
+static int
+mymain(void)
+{
+ int ret = 0;
+
+ if (virTestRun("fc4", testConfRoundTrip, "fc4") < 0)
+ ret = -1;
+
+ if (virTestRun("libvirtd", testConfRoundTrip, "libvirtd") <
0)
+ ret = -1;
+
+ if (virTestRun("no-newline", testConfRoundTrip, "no-newline")
< 0)
+ ret = -1;
+
+ return ret;
+}
+
+
+VIRT_TEST_MAIN(mymain)
diff --git a/tests/virconftest.sh b/tests/virconftest.sh
deleted file mode 100755
index 0fd5bbe..0000000
--- a/tests/virconftest.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/sh
-
-. "$(dirname $0)/test-lib.sh"
-
-test_intro $this_test
-
-fail=0
-i=0
-data_dir=$abs_srcdir/confdata
-for f in $(cd "$data_dir" && echo *.conf)
-do
- i=`expr $i + 1`
- "$abs_builddir/test_conf" "$data_dir/$f" >
"$f-actual"
- expected="$data_dir"/`echo "$f" | sed s+\.conf$+\.out+`
- if compare "$expected" "$f-actual"; then
- ret=0
- else
- ret=1
- fail=1
- fi
- test_result $i "$f" $ret
-done
-
-test_final $i $fail
-
-(exit $fail); exit $fail
--
2.7.4