[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 6/7] tests/x86: Refactor hot unplug hd-geo-test
From: |
Michael Labiuk |
Subject: |
[PATCH v4 6/7] tests/x86: Refactor hot unplug hd-geo-test |
Date: |
Tue, 20 Sep 2022 13:48:41 +0300 |
Moving common code to function.
Signed-off-by: Michael Labiuk <michael.labiuk@virtuozzo.com>
---
tests/qtest/hd-geo-test.c | 133 +++++++++++++++-----------------------
1 file changed, 53 insertions(+), 80 deletions(-)
diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index 58b1107d64..d488ad9ac0 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -898,13 +898,55 @@ static void test_override_zero_chs_q35(void)
test_override(args, "q35", 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 */
+ response = qtest_qmp(qts,
+ "{ 'execute': 'device_del',"
+ " 'arguments': {'id': %s }}", devid);
+ 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]);
+ 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} },
@@ -921,51 +963,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]);
- 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} },
@@ -981,42 +986,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]);
- 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 v4 0/7] Add 'q35' machine type to hotplug tests, Michael Labiuk, 2022/09/20
- [PATCH v4 7/7] tests/x86: Add 'q35' machine type to hotplug hd-geo-test, Michael Labiuk, 2022/09/20
- [PATCH v4 6/7] tests/x86: Refactor hot unplug hd-geo-test,
Michael Labiuk <=
- [PATCH v4 4/7] tests/x86: Add 'q35' machine type to drive_del-test, Michael Labiuk, 2022/09/20
- [PATCH v4 2/7] tests/x86: Add subtest with 'q35' machine type to device-plug-test, Michael Labiuk, 2022/09/20
- [PATCH v4 3/7] tests/x86: Add 'q35' machine type to ivshmem-test, Michael Labiuk, 2022/09/20
- [PATCH v4 5/7] tests/x86: Add 'q35' machine type to override-tests in hd-geo-test, Michael Labiuk, 2022/09/20