[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 3/9] tests/x86: Refactor hot unplug hd-geo-test
From: |
Michael Labiuk |
Subject: |
[PATCH v5 3/9] tests/x86: Refactor hot unplug hd-geo-test |
Date: |
Fri, 30 Sep 2022 01:35:41 +0300 |
Moving common code to function.
Signed-off-by: Michael Labiuk <michael.labiuk@virtuozzo.com>
---
tests/qtest/hd-geo-test.c | 144 +++++++++++++++-----------------------
1 file changed, 57 insertions(+), 87 deletions(-)
diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index ba772f4d7a..61f4c24b81 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -691,7 +691,8 @@ static void add_virtio_disk(TestArgs *args,
args->n_virtio_disks++;
}
-static void test_override(TestArgs *args, CHSResult expected[])
+static void test_override(TestArgs *args, const char *arch,
+ CHSResult expected[])
{
QTestState *qts;
char *joined_args;
@@ -700,7 +701,7 @@ static void test_override(TestArgs *args, CHSResult
expected[])
joined_args = g_strjoinv(" ", args->argv);
- qts = qtest_initf("-machine pc %s", joined_args);
+ qts = qtest_initf("-machine %s %s", arch, joined_args);
fw_cfg = pc_fw_cfg_init(qts);
read_bootdevices(fw_cfg, expected);
@@ -737,7 +738,7 @@ static void test_override_ide(void)
add_ide_disk(args, 1, 0, 1, 9000, 120, 30);
add_ide_disk(args, 2, 1, 0, 0, 1, 1);
add_ide_disk(args, 3, 1, 1, 1, 0, 0);
- test_override(args, expected);
+ test_override(args, "pc", expected);
}
static void test_override_scsi(void)
@@ -759,7 +760,7 @@ static void test_override_scsi(void)
add_scsi_disk(args, 1, 0, 0, 1, 0, 9000, 120, 30);
add_scsi_disk(args, 2, 0, 0, 2, 0, 1, 0, 0);
add_scsi_disk(args, 3, 0, 0, 3, 0, 0, 1, 0);
- test_override(args, expected);
+ test_override(args, "pc", expected);
}
static void test_override_scsi_2_controllers(void)
@@ -782,7 +783,7 @@ static void test_override_scsi_2_controllers(void)
add_scsi_disk(args, 1, 0, 0, 1, 0, 9000, 120, 30);
add_scsi_disk(args, 2, 1, 0, 0, 1, 1, 0, 0);
add_scsi_disk(args, 3, 1, 0, 1, 2, 0, 1, 0);
- test_override(args, expected);
+ test_override(args, "pc", expected);
}
static void test_override_virtio_blk(void)
@@ -797,7 +798,7 @@ static void test_override_virtio_blk(void)
add_drive_with_mbr(args, empty_mbr, 1);
add_virtio_disk(args, 0, "pci.0", 3, 10000, 120, 30);
add_virtio_disk(args, 1, "pci.0", 4, 9000, 120, 30);
- test_override(args, expected);
+ test_override(args, "pc", expected);
}
static void test_override_zero_chs(void)
@@ -808,16 +809,54 @@ static void test_override_zero_chs(void)
};
add_drive_with_mbr(args, empty_mbr, 1);
add_ide_disk(args, 0, 1, 1, 0, 0, 0);
- test_override(args, expected);
+ test_override(args, "pc", expected);
+}
+
+static void test_override_hot_unplug(TestArgs *args, const char *devid,
+ CHSResult expected[], CHSResult
expected2[])
+{
+ QTestState *qts;
+ char *joined_args;
+ QFWCFG *fw_cfg;
+ QDict *response;
+ int i;
+
+ joined_args = g_strjoinv(" ", args->argv);
+
+ qts = qtest_initf("%s", joined_args);
+ fw_cfg = pc_fw_cfg_init(qts);
+
+ read_bootdevices(fw_cfg, expected);
+
+ /* unplug device an restart */
+ qtest_qmp_device_del_send(qts, devid);
+
+ response = qtest_qmp(qts,
+ "{ 'execute': 'system_reset', 'arguments': { }}");
+ g_assert(response);
+ g_assert(!qdict_haskey(response, "error"));
+ qobject_unref(response);
+
+ qtest_qmp_eventwait(qts, "RESET");
+
+ read_bootdevices(fw_cfg, expected2);
+
+ g_free(joined_args);
+ qtest_quit(qts);
+
+ g_free(fw_cfg);
+
+ for (i = 0; i < args->n_drives; i++) {
+ unlink(args->drives[i]);
+ g_free(args->drives[i]);
+ }
+ g_free(args->drives);
+ g_strfreev(args->argv);
+ g_free(args);
}
static void test_override_scsi_hot_unplug(void)
{
- QTestState *qts;
- char *joined_args;
- QFWCFG *fw_cfg;
- QDict *response;
- int i;
TestArgs *args = create_args();
CHSResult expected[] = {
{"/pci@i0cf8/scsi@2/channel@0/disk@0,0", {10000, 120, 30} },
@@ -834,51 +873,14 @@ static void test_override_scsi_hot_unplug(void)
add_scsi_disk(args, 0, 0, 0, 0, 0, 10000, 120, 30);
add_scsi_disk(args, 1, 0, 0, 1, 0, 20, 20, 20);
- joined_args = g_strjoinv(" ", args->argv);
+ args->argc = append_arg(args->argc, args->argv, ARGV_SIZE,
+ g_strdup("-machine pc"));
- qts = qtest_initf("-machine pc %s", joined_args);
- fw_cfg = pc_fw_cfg_init(qts);
-
- read_bootdevices(fw_cfg, expected);
-
- /* unplug device an restart */
- response = qtest_qmp(qts,
- "{ 'execute': 'device_del',"
- " 'arguments': {'id': 'scsi-disk0' }}");
- g_assert(response);
- g_assert(!qdict_haskey(response, "error"));
- qobject_unref(response);
- response = qtest_qmp(qts,
- "{ 'execute': 'system_reset', 'arguments': { }}");
- g_assert(response);
- g_assert(!qdict_haskey(response, "error"));
- qobject_unref(response);
-
- qtest_qmp_eventwait(qts, "RESET");
-
- read_bootdevices(fw_cfg, expected2);
-
- g_free(joined_args);
- qtest_quit(qts);
-
- g_free(fw_cfg);
-
- for (i = 0; i < args->n_drives; i++) {
- unlink(args->drives[i]);
- g_free(args->drives[i]);
- }
- g_free(args->drives);
- g_strfreev(args->argv);
- g_free(args);
+ test_override_hot_unplug(args, "scsi-disk0", expected, expected2);
}
static void test_override_virtio_hot_unplug(void)
{
- QTestState *qts;
- char *joined_args;
- QFWCFG *fw_cfg;
- QDict *response;
- int i;
TestArgs *args = create_args();
CHSResult expected[] = {
{"/pci@i0cf8/scsi@2/disk@0,0", {10000, 120, 30} },
@@ -894,42 +896,10 @@ static void test_override_virtio_hot_unplug(void)
add_virtio_disk(args, 0, "pci.0", 2, 10000, 120, 30);
add_virtio_disk(args, 1, "pci.0", 3, 20, 20, 20);
- joined_args = g_strjoinv(" ", args->argv);
+ args->argc = append_arg(args->argc, args->argv, ARGV_SIZE,
+ g_strdup("-machine pc"));
- qts = qtest_initf("-machine pc %s", joined_args);
- fw_cfg = pc_fw_cfg_init(qts);
-
- read_bootdevices(fw_cfg, expected);
-
- /* unplug device an restart */
- response = qtest_qmp(qts,
- "{ 'execute': 'device_del',"
- " 'arguments': {'id': 'virtio-disk0' }}");
- g_assert(response);
- g_assert(!qdict_haskey(response, "error"));
- qobject_unref(response);
- response = qtest_qmp(qts,
- "{ 'execute': 'system_reset', 'arguments': { }}");
- g_assert(response);
- g_assert(!qdict_haskey(response, "error"));
- qobject_unref(response);
-
- qtest_qmp_eventwait(qts, "RESET");
-
- read_bootdevices(fw_cfg, expected2);
-
- g_free(joined_args);
- qtest_quit(qts);
-
- g_free(fw_cfg);
-
- for (i = 0; i < args->n_drives; i++) {
- unlink(args->drives[i]);
- g_free(args->drives[i]);
- }
- g_free(args->drives);
- g_strfreev(args->argv);
- g_free(args);
+ test_override_hot_unplug(args, "virtio-disk0", expected, expected2);
}
int main(int argc, char **argv)
--
2.34.1
- [PATCH v5 0/9] Add 'q35' machine type to hotplug tests, Michael Labiuk, 2022/09/29
- [PATCH v5 9/9] tests/x86: Add 'q35' machine type to ivshmem-test, Michael Labiuk, 2022/09/29
- [PATCH v5 5/9] tests/x86: Add 'q35' machine type to hotplug hd-geo-test, Michael Labiuk, 2022/09/29
- [PATCH v5 3/9] tests/x86: Refactor hot unplug hd-geo-test,
Michael Labiuk <=
- [PATCH v5 8/9] tests/x86: Add 'q35' machine type to drive_del-test, Michael Labiuk, 2022/09/29
- [PATCH v5 2/9] tests/x86: Add subtest with 'q35' machine type to device-plug-test, Michael Labiuk, 2022/09/29
- [PATCH v5 7/9] tests/x86: replace snprint() by g_strdup_printf() in drive_del-test, Michael Labiuk, 2022/09/29
- [PATCH v5 6/9] tests/x86: Fix comment typo in drive_del-test, Michael Labiuk, 2022/09/29
- [PATCH v5 1/9] tests/x86: add helper qtest_qmp_device_del_send(), Michael Labiuk, 2022/09/29
- [PATCH v5 4/9] tests/x86: Add 'q35' machine type to override-tests in hd-geo-test, Michael Labiuk, 2022/09/29