Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 1 | /* |
Thomas Huth | 152e039 | 2017-10-06 12:13:51 +0200 | [diff] [blame] | 2 | * QTest testcase for CPU plugging |
Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 2015 SUSE Linux GmbH |
| 5 | * |
| 6 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 7 | * See the COPYING file in the top-level directory. |
| 8 | */ |
| 9 | |
Peter Maydell | 681c28a | 2016-02-08 18:08:51 +0000 | [diff] [blame] | 10 | #include "qemu/osdep.h" |
Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 11 | |
Thomas Huth | dd21074 | 2019-09-03 07:50:26 +0200 | [diff] [blame] | 12 | #include "libqtest-single.h" |
Markus Armbruster | 452fcdb | 2018-02-01 12:18:39 +0100 | [diff] [blame] | 13 | #include "qapi/qmp/qdict.h" |
Igor Mammedov | 021a007 | 2019-08-30 07:07:23 -0400 | [diff] [blame] | 14 | #include "qapi/qmp/qlist.h" |
Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 15 | |
Thomas Huth | 152e039 | 2017-10-06 12:13:51 +0200 | [diff] [blame] | 16 | struct PlugTestData { |
Marc-André Lureau | 34e46f6 | 2016-07-18 14:56:51 +0400 | [diff] [blame] | 17 | char *machine; |
Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 18 | const char *cpu_model; |
Thomas Huth | 80b8c0b | 2017-10-06 13:32:13 +0200 | [diff] [blame] | 19 | char *device_model; |
Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 20 | unsigned sockets; |
| 21 | unsigned cores; |
| 22 | unsigned threads; |
| 23 | unsigned maxcpus; |
| 24 | }; |
Thomas Huth | 152e039 | 2017-10-06 12:13:51 +0200 | [diff] [blame] | 25 | typedef struct PlugTestData PlugTestData; |
Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 26 | |
Igor Mammedov | 021a007 | 2019-08-30 07:07:23 -0400 | [diff] [blame] | 27 | static void test_plug_with_device_add(gconstpointer data) |
Thomas Huth | 80b8c0b | 2017-10-06 13:32:13 +0200 | [diff] [blame] | 28 | { |
| 29 | const PlugTestData *td = data; |
| 30 | char *args; |
Thomas Huth | e5758de | 2019-07-22 17:10:55 +0200 | [diff] [blame] | 31 | QTestState *qts; |
Igor Mammedov | 021a007 | 2019-08-30 07:07:23 -0400 | [diff] [blame] | 32 | QDict *resp; |
| 33 | QList *cpus; |
| 34 | QObject *e; |
| 35 | int hotplugged = 0; |
Thomas Huth | 80b8c0b | 2017-10-06 13:32:13 +0200 | [diff] [blame] | 36 | |
| 37 | args = g_strdup_printf("-machine %s -cpu %s " |
Igor Mammedov | bc1fb85 | 2018-09-13 13:06:01 +0200 | [diff] [blame] | 38 | "-smp 1,sockets=%u,cores=%u,threads=%u,maxcpus=%u", |
Thomas Huth | 80b8c0b | 2017-10-06 13:32:13 +0200 | [diff] [blame] | 39 | td->machine, td->cpu_model, |
| 40 | td->sockets, td->cores, td->threads, td->maxcpus); |
Thomas Huth | e5758de | 2019-07-22 17:10:55 +0200 | [diff] [blame] | 41 | qts = qtest_init(args); |
Thomas Huth | 80b8c0b | 2017-10-06 13:32:13 +0200 | [diff] [blame] | 42 | |
Igor Mammedov | 021a007 | 2019-08-30 07:07:23 -0400 | [diff] [blame] | 43 | resp = qtest_qmp(qts, "{ 'execute': 'query-hotpluggable-cpus'}"); |
| 44 | g_assert(qdict_haskey(resp, "return")); |
| 45 | cpus = qdict_get_qlist(resp, "return"); |
| 46 | g_assert(cpus); |
| 47 | |
| 48 | while ((e = qlist_pop(cpus))) { |
| 49 | const QDict *cpu, *props; |
| 50 | |
| 51 | cpu = qobject_to(QDict, e); |
| 52 | if (qdict_haskey(cpu, "qom-path")) { |
Marc-André Lureau | 7413091 | 2019-11-07 23:27:31 +0400 | [diff] [blame] | 53 | qobject_unref(e); |
Igor Mammedov | 021a007 | 2019-08-30 07:07:23 -0400 | [diff] [blame] | 54 | continue; |
Thomas Huth | 80b8c0b | 2017-10-06 13:32:13 +0200 | [diff] [blame] | 55 | } |
Igor Mammedov | 021a007 | 2019-08-30 07:07:23 -0400 | [diff] [blame] | 56 | |
| 57 | g_assert(qdict_haskey(cpu, "props")); |
| 58 | props = qdict_get_qdict(cpu, "props"); |
| 59 | |
| 60 | qtest_qmp_device_add_qdict(qts, td->device_model, props); |
| 61 | hotplugged++; |
Marc-André Lureau | 7413091 | 2019-11-07 23:27:31 +0400 | [diff] [blame] | 62 | qobject_unref(e); |
Thomas Huth | 80b8c0b | 2017-10-06 13:32:13 +0200 | [diff] [blame] | 63 | } |
| 64 | |
Igor Mammedov | 021a007 | 2019-08-30 07:07:23 -0400 | [diff] [blame] | 65 | /* make sure that there were hotplugged CPUs */ |
| 66 | g_assert(hotplugged); |
| 67 | qobject_unref(resp); |
Thomas Huth | e5758de | 2019-07-22 17:10:55 +0200 | [diff] [blame] | 68 | qtest_quit(qts); |
Thomas Huth | 73a7d31 | 2017-10-06 15:53:19 +0200 | [diff] [blame] | 69 | g_free(args); |
| 70 | } |
| 71 | |
Marc-André Lureau | 34e46f6 | 2016-07-18 14:56:51 +0400 | [diff] [blame] | 72 | static void test_data_free(gpointer data) |
| 73 | { |
Thomas Huth | 152e039 | 2017-10-06 12:13:51 +0200 | [diff] [blame] | 74 | PlugTestData *pc = data; |
Marc-André Lureau | 34e46f6 | 2016-07-18 14:56:51 +0400 | [diff] [blame] | 75 | |
| 76 | g_free(pc->machine); |
Thomas Huth | 80b8c0b | 2017-10-06 13:32:13 +0200 | [diff] [blame] | 77 | g_free(pc->device_model); |
Marc-André Lureau | 34e46f6 | 2016-07-18 14:56:51 +0400 | [diff] [blame] | 78 | g_free(pc); |
| 79 | } |
| 80 | |
Thomas Huth | 02ef6e8 | 2017-03-30 09:50:06 +0200 | [diff] [blame] | 81 | static void add_pc_test_case(const char *mname) |
Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 82 | { |
Marc-André Lureau | 34e46f6 | 2016-07-18 14:56:51 +0400 | [diff] [blame] | 83 | char *path; |
Thomas Huth | 152e039 | 2017-10-06 12:13:51 +0200 | [diff] [blame] | 84 | PlugTestData *data; |
Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 85 | |
Thomas Huth | 02ef6e8 | 2017-03-30 09:50:06 +0200 | [diff] [blame] | 86 | if (!g_str_has_prefix(mname, "pc-")) { |
| 87 | return; |
Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 88 | } |
Thomas Huth | 152e039 | 2017-10-06 12:13:51 +0200 | [diff] [blame] | 89 | data = g_new(PlugTestData, 1); |
Thomas Huth | 02ef6e8 | 2017-03-30 09:50:06 +0200 | [diff] [blame] | 90 | data->machine = g_strdup(mname); |
| 91 | data->cpu_model = "Haswell"; /* 1.3+ theoretically */ |
Thomas Huth | 80b8c0b | 2017-10-06 13:32:13 +0200 | [diff] [blame] | 92 | data->device_model = g_strdup_printf("%s-%s-cpu", data->cpu_model, |
| 93 | qtest_get_arch()); |
Thomas Huth | 02ef6e8 | 2017-03-30 09:50:06 +0200 | [diff] [blame] | 94 | data->sockets = 1; |
| 95 | data->cores = 3; |
| 96 | data->threads = 2; |
Igor Mammedov | bc1fb85 | 2018-09-13 13:06:01 +0200 | [diff] [blame] | 97 | data->maxcpus = data->sockets * data->cores * data->threads; |
Thomas Huth | 80b8c0b | 2017-10-06 13:32:13 +0200 | [diff] [blame] | 98 | |
Igor Mammedov | 63e7983 | 2020-09-15 08:04:03 -0400 | [diff] [blame] | 99 | path = g_strdup_printf("cpu-plug/%s/device-add/%ux%ux%u&maxcpus=%u", |
| 100 | mname, data->sockets, data->cores, |
| 101 | data->threads, data->maxcpus); |
| 102 | qtest_add_data_func_full(path, data, test_plug_with_device_add, |
| 103 | test_data_free); |
| 104 | g_free(path); |
Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Thomas Huth | 73a7d31 | 2017-10-06 15:53:19 +0200 | [diff] [blame] | 107 | static void add_pseries_test_case(const char *mname) |
| 108 | { |
| 109 | char *path; |
| 110 | PlugTestData *data; |
| 111 | |
| 112 | if (!g_str_has_prefix(mname, "pseries-") || |
| 113 | (g_str_has_prefix(mname, "pseries-2.") && atoi(&mname[10]) < 7)) { |
| 114 | return; |
| 115 | } |
| 116 | data = g_new(PlugTestData, 1); |
| 117 | data->machine = g_strdup(mname); |
| 118 | data->cpu_model = "power8_v2.0"; |
| 119 | data->device_model = g_strdup("power8_v2.0-spapr-cpu-core"); |
| 120 | data->sockets = 2; |
| 121 | data->cores = 3; |
| 122 | data->threads = 1; |
Igor Mammedov | bc1fb85 | 2018-09-13 13:06:01 +0200 | [diff] [blame] | 123 | data->maxcpus = data->sockets * data->cores * data->threads; |
Thomas Huth | 73a7d31 | 2017-10-06 15:53:19 +0200 | [diff] [blame] | 124 | |
| 125 | path = g_strdup_printf("cpu-plug/%s/device-add/%ux%ux%u&maxcpus=%u", |
| 126 | mname, data->sockets, data->cores, |
| 127 | data->threads, data->maxcpus); |
Igor Mammedov | 021a007 | 2019-08-30 07:07:23 -0400 | [diff] [blame] | 128 | qtest_add_data_func_full(path, data, test_plug_with_device_add, |
Thomas Huth | 73a7d31 | 2017-10-06 15:53:19 +0200 | [diff] [blame] | 129 | test_data_free); |
| 130 | g_free(path); |
| 131 | } |
| 132 | |
Thomas Huth | 7d8b00f | 2017-10-17 13:39:15 +0200 | [diff] [blame] | 133 | static void add_s390x_test_case(const char *mname) |
| 134 | { |
| 135 | char *path; |
Igor Mammedov | 63e7983 | 2020-09-15 08:04:03 -0400 | [diff] [blame] | 136 | PlugTestData *data; |
Thomas Huth | 7d8b00f | 2017-10-17 13:39:15 +0200 | [diff] [blame] | 137 | |
| 138 | if (!g_str_has_prefix(mname, "s390-ccw-virtio-")) { |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | data = g_new(PlugTestData, 1); |
| 143 | data->machine = g_strdup(mname); |
| 144 | data->cpu_model = "qemu"; |
| 145 | data->device_model = g_strdup("qemu-s390x-cpu"); |
| 146 | data->sockets = 1; |
| 147 | data->cores = 3; |
| 148 | data->threads = 1; |
Igor Mammedov | bc1fb85 | 2018-09-13 13:06:01 +0200 | [diff] [blame] | 149 | data->maxcpus = data->sockets * data->cores * data->threads; |
Thomas Huth | 7d8b00f | 2017-10-17 13:39:15 +0200 | [diff] [blame] | 150 | |
Igor Mammedov | 63e7983 | 2020-09-15 08:04:03 -0400 | [diff] [blame] | 151 | path = g_strdup_printf("cpu-plug/%s/device-add/%ux%ux%u&maxcpus=%u", |
Thomas Huth | 7d8b00f | 2017-10-17 13:39:15 +0200 | [diff] [blame] | 152 | mname, data->sockets, data->cores, |
| 153 | data->threads, data->maxcpus); |
Igor Mammedov | 63e7983 | 2020-09-15 08:04:03 -0400 | [diff] [blame] | 154 | qtest_add_data_func_full(path, data, test_plug_with_device_add, |
Thomas Huth | 7d8b00f | 2017-10-17 13:39:15 +0200 | [diff] [blame] | 155 | test_data_free); |
| 156 | g_free(path); |
| 157 | } |
| 158 | |
Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 159 | int main(int argc, char **argv) |
| 160 | { |
| 161 | const char *arch = qtest_get_arch(); |
| 162 | |
| 163 | g_test_init(&argc, &argv, NULL); |
| 164 | |
| 165 | if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { |
Thomas Huth | 1f4a0d8 | 2018-08-16 13:35:55 +0200 | [diff] [blame] | 166 | qtest_cb_for_every_machine(add_pc_test_case, g_test_quick()); |
Thomas Huth | 73a7d31 | 2017-10-06 15:53:19 +0200 | [diff] [blame] | 167 | } else if (g_str_equal(arch, "ppc64")) { |
Thomas Huth | 1f4a0d8 | 2018-08-16 13:35:55 +0200 | [diff] [blame] | 168 | qtest_cb_for_every_machine(add_pseries_test_case, g_test_quick()); |
Thomas Huth | 7d8b00f | 2017-10-17 13:39:15 +0200 | [diff] [blame] | 169 | } else if (g_str_equal(arch, "s390x")) { |
Thomas Huth | 1f4a0d8 | 2018-08-16 13:35:55 +0200 | [diff] [blame] | 170 | qtest_cb_for_every_machine(add_s390x_test_case, g_test_quick()); |
Andreas Färber | 7fe55c3 | 2015-03-13 17:21:11 +0100 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | return g_test_run(); |
| 174 | } |