From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcel.a@redhat.com, stefano.stabellini@eu.citrix.com,
agraf@suse.de, mst@redhat.com, pbonzini@redhat.com,
afaerber@suse.de
Subject: [Qemu-devel] [PATCH 4/4] test -m option parameters
Date: Wed, 25 Jun 2014 13:42:23 +0200 [thread overview]
Message-ID: <1403696543-2458-5-git-send-email-imammedo@redhat.com> (raw)
In-Reply-To: <1403696543-2458-1-git-send-email-imammedo@redhat.com>
adds a base for memory hotplug tests, starting with
checking that -m option accepts expected options.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
tests/Makefile | 2 +
tests/memhp-test.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 147 insertions(+), 0 deletions(-)
create mode 100644 tests/memhp-test.c
diff --git a/tests/Makefile b/tests/Makefile
index 7e53d0d..24c7e2b 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -154,6 +154,7 @@ gcov-files-i386-y += hw/pci-bridge/i82801b11.c
check-qtest-i386-y += tests/ioh3420-test$(EXESUF)
gcov-files-i386-y += hw/pci-bridge/ioh3420.c
check-qtest-i386-y += tests/usb-hcd-ehci-test$(EXESUF)
+check-qtest-i386-y += tests/memhp-test$(EXESUF)
gcov-files-i386-y += hw/usb/hcd-ehci.c
gcov-files-i386-y += hw/usb/hcd-uhci.c
gcov-files-i386-y += hw/usb/dev-hid.c
@@ -293,6 +294,7 @@ libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o
libqos-pc-obj-y += tests/libqos/malloc-pc.o
libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o
+tests/memhp-test$(EXESUF): tests/memhp-test.o $(libqos-obj-y)
tests/rtc-test$(EXESUF): tests/rtc-test.o
tests/m48t59-test$(EXESUF): tests/m48t59-test.o
tests/endianness-test$(EXESUF): tests/endianness-test.o
diff --git a/tests/memhp-test.c b/tests/memhp-test.c
new file mode 100644
index 0000000..4698854
--- /dev/null
+++ b/tests/memhp-test.c
@@ -0,0 +1,145 @@
+/*
+ * memory hotplug test cases.
+ *
+ * Copyright (c) 2014 Red Hat Inc.
+ *
+ * Authors:
+ * Igor Mammedov <imammedo@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+#include "libqtest.h"
+#include "include/qemu/option.h"
+
+typedef struct MOption {
+ const char *size;
+ const char *slots;
+ const char *maxmem;
+} MOption;
+
+typedef struct TestData TestData;
+struct TestData {
+ const char *args;
+ MOption m_option;
+ void (*test)(const TestData *data);
+};
+
+static void test_machine(gconstpointer opaque)
+{
+ TestData *s = (TestData *)opaque;
+ char *args = g_strdup_printf("%s", s->args);
+
+ if (s->m_option.size) {
+ char *old = args;
+ args = g_strdup_printf("%s -m %s", args, s->m_option.size);
+ g_free(old);
+ }
+
+ if (s->m_option.slots) {
+ char *old = args;
+ args = g_strdup_printf("%s -m slots=%s", args, s->m_option.slots);
+ g_free(old);
+ }
+
+ if (s->m_option.maxmem) {
+ char *old = args;
+ args = g_strdup_printf("%s -m maxmem=%s", args, s->m_option.maxmem);
+ g_free(old);
+ }
+
+ qtest_start(args);
+ s->test(s);
+ qtest_end();
+ g_free(args);
+}
+
+#define DEFARGS "-net none -display none -machine accel=qtest "
+
+#define ADD_COMMON(name, cmdline, sz, slots_nr, max_mem, func) \
+ { \
+ static const TestData d = { \
+ .args = DEFARGS cmdline, \
+ .m_option.size = sz, \
+ .m_option.slots = slots_nr, \
+ .m_option.maxmem = max_mem, \
+ .test = func}; \
+ char *path; \
+ path = g_strdup_printf("/memhp/%s/[%s %s%s%s%s%s%s]", name, cmdline, \
+ d.m_option.size ? " -m size=" : "", \
+ d.m_option.size ? d.m_option.size : "", \
+ d.m_option.slots ? " -m slots=" : "", \
+ d.m_option.slots ? d.m_option.slots : "", \
+ d.m_option.maxmem ? " -m maxmem=" : "", \
+ d.m_option.maxmem ? d.m_option.maxmem : ""); \
+ g_test_add_data_func(path, &d, test_machine); \
+ g_free(path); \
+ }
+
+#define ADD_X86_COMMON(name, cmdline, sz, slots_nr, max_mem, func) \
+ if (strcmp(qtest_get_arch(), "i386") == 0 || \
+ strcmp(qtest_get_arch(), "x86_64") == 0) { \
+ ADD_COMMON(name, cmdline, sz, slots_nr, max_mem, func) \
+ }
+#define ADD_440FX_TEST(name, cmdline, sz, slots_nr, max_mem, func) \
+ ADD_X86_COMMON(name "/pc", cmdline "-M pc", sz, slots_nr, max_mem, func)
+
+#define ADD_Q35_TEST(name, cmdline, sz, slots_nr, max_mem, func) \
+ ADD_X86_COMMON(name "/q35" , cmdline "-M q35", sz, slots_nr, max_mem, func)
+
+#define ADD_TESTS(name, cmdline, sz, slots_nr, max_mem, func) \
+ { \
+ ADD_440FX_TEST(name, cmdline, sz, slots_nr, max_mem, func); \
+ ADD_Q35_TEST(name, cmdline, sz, slots_nr, max_mem, func); \
+ }
+
+static void test_num_prop_value(const char *path, const char *prop,
+ const char *value)
+{
+ QDict *response;
+ uint64_t ret, num_value;
+
+ response = qmp("{ 'execute': 'qom-get',"
+ " 'arguments': { 'path': '%s',"
+ " 'property': '%s' } }",
+ path, prop);
+ /* qom-get may fail but should not, e.g., segfault. */
+ g_assert(qdict_haskey(response, "return"));
+ ret = qdict_get_int(response, "return");
+ QDECREF(response);
+
+ parse_option_size(prop, value, &num_value, &error_abort);
+ g_assert(ret == num_value);
+}
+
+static void test_args(const TestData *data)
+{
+ if (data->m_option.size) {
+ test_num_prop_value("/machine", "memory-size", data->m_option.size);
+ }
+
+ if (data->m_option.slots) {
+ test_num_prop_value("/machine", "memory-slots", data->m_option.slots);
+ }
+
+ if (data->m_option.maxmem) {
+ test_num_prop_value("/machine", "maxmem", data->m_option.maxmem);
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+
+ ADD_TESTS("args", "", "8M", NULL, NULL, test_args);
+ ADD_TESTS("args", "", "8M", "1", "16M", test_args);
+ ADD_TESTS("args", "", "8M", "256", "16M", test_args);
+ ADD_TESTS("args", "", "8M", "1", "1G", test_args);
+ ADD_TESTS("args", "", "8M", "1", "1T", test_args);
+
+ return g_test_run();
+}
--
1.7.1
prev parent reply other threads:[~2014-06-25 11:42 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-25 11:42 [Qemu-devel] [PATCH 0/4] tests for -m option Igor Mammedov
2014-06-25 11:42 ` [Qemu-devel] [PATCH 1/4] switch RAM_ADDR_FMT format specifier to print decimal Igor Mammedov
2014-06-25 11:51 ` Michael S. Tsirkin
2014-06-25 12:14 ` Igor Mammedov
2014-06-25 15:38 ` Michael S. Tsirkin
2014-06-25 17:47 ` Peter Maydell
2014-06-25 11:42 ` [Qemu-devel] [PATCH 2/4] vl.c: use single local_err throughout main() Igor Mammedov
2014-06-25 11:51 ` Michael S. Tsirkin
2014-06-25 12:16 ` Igor Mammedov
2014-06-25 15:42 ` Michael S. Tsirkin
2014-06-25 11:42 ` [Qemu-devel] [PATCH 3/4] machine: convert ram_size, maxram_size, ram_slots to properties Igor Mammedov
2014-06-25 11:54 ` Michael S. Tsirkin
2014-06-25 13:08 ` Igor Mammedov
2014-06-25 15:37 ` Michael S. Tsirkin
2014-06-25 14:09 ` Kirill Batuzov
2014-06-25 14:45 ` Igor Mammedov
2014-06-25 11:42 ` Igor Mammedov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1403696543-2458-5-git-send-email-imammedo@redhat.com \
--to=imammedo@redhat.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=marcel.a@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefano.stabellini@eu.citrix.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).