diff mbox

[v2,24/24] tests: check -numa node, cpu=props_list usecase

Message ID 1493816238-33120-25-git-send-email-imammedo@redhat.com
State New
Headers show

Commit Message

Igor Mammedov May 3, 2017, 12:57 p.m. UTC
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 tests/numa-test.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 151 insertions(+)

Comments

David Gibson May 8, 2017, 6:35 a.m. UTC | #1
On Wed, May 03, 2017 at 02:57:18PM +0200, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  tests/numa-test.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 151 insertions(+)
> 
> diff --git a/tests/numa-test.c b/tests/numa-test.c
> index 2722687..c3475d6 100644
> --- a/tests/numa-test.c
> +++ b/tests/numa-test.c
> @@ -131,6 +131,144 @@ static void test_query_cpus(const void *data)
>      g_free(cli);
>  }
>  
> +static void pc_numa_cpu(const void *data)
> +{
> +    char *cli;
> +    QDict *resp;
> +    QList *cpus;
> +    const QObject *e;
> +
> +    cli = make_cli(data, "-cpu pentium -smp 8,sockets=2,cores=2,threads=2 "
> +        "-numa node,nodeid=0 -numa node,nodeid=1 "
> +        "-numa cpu,node-id=1,socket-id=0 "
> +        "-numa cpu,node-id=0,socket-id=1,core-id=0 "
> +        "-numa cpu,node-id=0,socket-id=1,core-id=1,thread-id=0 "
> +        "-numa cpu,node-id=1,socket-id=1,core-id=1,thread-id=1");
> +    qtest_start(cli);
> +    cpus = get_cpus(&resp);
> +    g_assert(cpus);
> +
> +    while ((e = qlist_pop(cpus))) {
> +        QDict *cpu, *props;
> +        int64_t socket, core, thread, node;
> +
> +        cpu = qobject_to_qdict(e);
> +        g_assert(qdict_haskey(cpu, "props"));
> +        props = qdict_get_qdict(cpu, "props");
> +
> +        g_assert(qdict_haskey(props, "node-id"));
> +        node = qdict_get_int(props, "node-id");
> +        g_assert(qdict_haskey(props, "socket-id"));
> +        socket = qdict_get_int(props, "socket-id");
> +        g_assert(qdict_haskey(props, "core-id"));
> +        core = qdict_get_int(props, "core-id");
> +        g_assert(qdict_haskey(props, "thread-id"));
> +        thread = qdict_get_int(props, "thread-id");
> +
> +        if (socket == 0) {
> +            g_assert_cmpint(node, ==, 1);
> +        } else if (socket == 1 && core == 0) {
> +            g_assert_cmpint(node, ==, 0);
> +        } else if (socket == 1 && core == 1 && thread == 0) {
> +            g_assert_cmpint(node, ==, 0);
> +        } else if (socket == 1 && core == 1 && thread == 1) {
> +            g_assert_cmpint(node, ==, 1);
> +        } else {
> +            g_assert(false);
> +        }
> +    }
> +
> +    QDECREF(resp);
> +    qtest_end();
> +    g_free(cli);
> +}
> +
> +static void spapr_numa_cpu(const void *data)
> +{
> +    char *cli;
> +    QDict *resp;
> +    QList *cpus;
> +    const QObject *e;
> +
> +    cli = make_cli(data, "-smp 4,cores=4 "
> +        "-numa node,nodeid=0 -numa node,nodeid=1 "
> +        "-numa cpu,node-id=0,core-id=0 "
> +        "-numa cpu,node-id=0,core-id=1 "
> +        "-numa cpu,node-id=0,core-id=2 "
> +        "-numa cpu,node-id=1,core-id=3");
> +    qtest_start(cli);
> +    cpus = get_cpus(&resp);
> +    g_assert(cpus);
> +
> +    while ((e = qlist_pop(cpus))) {
> +        QDict *cpu, *props;
> +        int64_t core, node;
> +
> +        cpu = qobject_to_qdict(e);
> +        g_assert(qdict_haskey(cpu, "props"));
> +        props = qdict_get_qdict(cpu, "props");
> +
> +        g_assert(qdict_haskey(props, "node-id"));
> +        node = qdict_get_int(props, "node-id");
> +        g_assert(qdict_haskey(props, "core-id"));
> +        core = qdict_get_int(props, "core-id");
> +
> +        if (core >= 0 && core < 3) {
> +            g_assert_cmpint(node, ==, 0);
> +        } else if (core == 3) {
> +            g_assert_cmpint(node, ==, 1);
> +        } else {
> +            g_assert(false);
> +        }
> +    }
> +
> +    QDECREF(resp);
> +    qtest_end();
> +    g_free(cli);
> +}
> +
> +static void aarch64_numa_cpu(const void *data)
> +{
> +    char *cli;
> +    QDict *resp;
> +    QList *cpus;
> +    const QObject *e;
> +
> +    cli = make_cli(data, "-smp 2 "
> +        "-numa node,nodeid=0 -numa node,nodeid=1 "
> +        "-numa cpu,node-id=1,thread-id=0 "
> +        "-numa cpu,node-id=0,thread-id=1");
> +    qtest_start(cli);
> +    cpus = get_cpus(&resp);
> +    g_assert(cpus);
> +
> +    while ((e = qlist_pop(cpus))) {
> +        QDict *cpu, *props;
> +        int64_t thread, node;
> +
> +        cpu = qobject_to_qdict(e);
> +        g_assert(qdict_haskey(cpu, "props"));
> +        props = qdict_get_qdict(cpu, "props");
> +
> +        g_assert(qdict_haskey(props, "node-id"));
> +        node = qdict_get_int(props, "node-id");
> +        g_assert(qdict_haskey(props, "thread-id"));
> +        thread = qdict_get_int(props, "thread-id");
> +
> +        if (thread == 0) {
> +            g_assert_cmpint(node, ==, 1);
> +        } else if (thread == 1) {
> +            g_assert_cmpint(node, ==, 0);
> +        } else {
> +            g_assert(false);
> +        }
> +    }
> +
> +    QDECREF(resp);
> +    qtest_end();
> +    g_free(cli);
> +}
> +
>  int main(int argc, char **argv)
>  {
>      const char *args = NULL;
> @@ -147,5 +285,18 @@ int main(int argc, char **argv)
>      qtest_add_data_func("/numa/mon/cpus/partial", args, test_mon_partial);
>      qtest_add_data_func("/numa/qmp/cpus/query-cpus", args, test_query_cpus);
>  
> +    if (!strcmp(arch, "i386") || !strcmp(arch, "x86_64")) {
> +        qtest_add_data_func("/numa/pc/cpu/explicit", args, pc_numa_cpu);
> +    }
> +
> +    if (!strcmp(arch, "ppc64")) {
> +        qtest_add_data_func("/numa/spapr/cpu/explicit", args, spapr_numa_cpu);
> +    }
> +
> +    if (!strcmp(arch, "aarch64")) {
> +        qtest_add_data_func("/numa/aarch64/cpu/explicit", args,
> +                            aarch64_numa_cpu);
> +    }
> +
>      return g_test_run();
>  }
diff mbox

Patch

diff --git a/tests/numa-test.c b/tests/numa-test.c
index 2722687..c3475d6 100644
--- a/tests/numa-test.c
+++ b/tests/numa-test.c
@@ -131,6 +131,144 @@  static void test_query_cpus(const void *data)
     g_free(cli);
 }
 
+static void pc_numa_cpu(const void *data)
+{
+    char *cli;
+    QDict *resp;
+    QList *cpus;
+    const QObject *e;
+
+    cli = make_cli(data, "-cpu pentium -smp 8,sockets=2,cores=2,threads=2 "
+        "-numa node,nodeid=0 -numa node,nodeid=1 "
+        "-numa cpu,node-id=1,socket-id=0 "
+        "-numa cpu,node-id=0,socket-id=1,core-id=0 "
+        "-numa cpu,node-id=0,socket-id=1,core-id=1,thread-id=0 "
+        "-numa cpu,node-id=1,socket-id=1,core-id=1,thread-id=1");
+    qtest_start(cli);
+    cpus = get_cpus(&resp);
+    g_assert(cpus);
+
+    while ((e = qlist_pop(cpus))) {
+        QDict *cpu, *props;
+        int64_t socket, core, thread, node;
+
+        cpu = qobject_to_qdict(e);
+        g_assert(qdict_haskey(cpu, "props"));
+        props = qdict_get_qdict(cpu, "props");
+
+        g_assert(qdict_haskey(props, "node-id"));
+        node = qdict_get_int(props, "node-id");
+        g_assert(qdict_haskey(props, "socket-id"));
+        socket = qdict_get_int(props, "socket-id");
+        g_assert(qdict_haskey(props, "core-id"));
+        core = qdict_get_int(props, "core-id");
+        g_assert(qdict_haskey(props, "thread-id"));
+        thread = qdict_get_int(props, "thread-id");
+
+        if (socket == 0) {
+            g_assert_cmpint(node, ==, 1);
+        } else if (socket == 1 && core == 0) {
+            g_assert_cmpint(node, ==, 0);
+        } else if (socket == 1 && core == 1 && thread == 0) {
+            g_assert_cmpint(node, ==, 0);
+        } else if (socket == 1 && core == 1 && thread == 1) {
+            g_assert_cmpint(node, ==, 1);
+        } else {
+            g_assert(false);
+        }
+    }
+
+    QDECREF(resp);
+    qtest_end();
+    g_free(cli);
+}
+
+static void spapr_numa_cpu(const void *data)
+{
+    char *cli;
+    QDict *resp;
+    QList *cpus;
+    const QObject *e;
+
+    cli = make_cli(data, "-smp 4,cores=4 "
+        "-numa node,nodeid=0 -numa node,nodeid=1 "
+        "-numa cpu,node-id=0,core-id=0 "
+        "-numa cpu,node-id=0,core-id=1 "
+        "-numa cpu,node-id=0,core-id=2 "
+        "-numa cpu,node-id=1,core-id=3");
+    qtest_start(cli);
+    cpus = get_cpus(&resp);
+    g_assert(cpus);
+
+    while ((e = qlist_pop(cpus))) {
+        QDict *cpu, *props;
+        int64_t core, node;
+
+        cpu = qobject_to_qdict(e);
+        g_assert(qdict_haskey(cpu, "props"));
+        props = qdict_get_qdict(cpu, "props");
+
+        g_assert(qdict_haskey(props, "node-id"));
+        node = qdict_get_int(props, "node-id");
+        g_assert(qdict_haskey(props, "core-id"));
+        core = qdict_get_int(props, "core-id");
+
+        if (core >= 0 && core < 3) {
+            g_assert_cmpint(node, ==, 0);
+        } else if (core == 3) {
+            g_assert_cmpint(node, ==, 1);
+        } else {
+            g_assert(false);
+        }
+    }
+
+    QDECREF(resp);
+    qtest_end();
+    g_free(cli);
+}
+
+static void aarch64_numa_cpu(const void *data)
+{
+    char *cli;
+    QDict *resp;
+    QList *cpus;
+    const QObject *e;
+
+    cli = make_cli(data, "-smp 2 "
+        "-numa node,nodeid=0 -numa node,nodeid=1 "
+        "-numa cpu,node-id=1,thread-id=0 "
+        "-numa cpu,node-id=0,thread-id=1");
+    qtest_start(cli);
+    cpus = get_cpus(&resp);
+    g_assert(cpus);
+
+    while ((e = qlist_pop(cpus))) {
+        QDict *cpu, *props;
+        int64_t thread, node;
+
+        cpu = qobject_to_qdict(e);
+        g_assert(qdict_haskey(cpu, "props"));
+        props = qdict_get_qdict(cpu, "props");
+
+        g_assert(qdict_haskey(props, "node-id"));
+        node = qdict_get_int(props, "node-id");
+        g_assert(qdict_haskey(props, "thread-id"));
+        thread = qdict_get_int(props, "thread-id");
+
+        if (thread == 0) {
+            g_assert_cmpint(node, ==, 1);
+        } else if (thread == 1) {
+            g_assert_cmpint(node, ==, 0);
+        } else {
+            g_assert(false);
+        }
+    }
+
+    QDECREF(resp);
+    qtest_end();
+    g_free(cli);
+}
+
 int main(int argc, char **argv)
 {
     const char *args = NULL;
@@ -147,5 +285,18 @@  int main(int argc, char **argv)
     qtest_add_data_func("/numa/mon/cpus/partial", args, test_mon_partial);
     qtest_add_data_func("/numa/qmp/cpus/query-cpus", args, test_query_cpus);
 
+    if (!strcmp(arch, "i386") || !strcmp(arch, "x86_64")) {
+        qtest_add_data_func("/numa/pc/cpu/explicit", args, pc_numa_cpu);
+    }
+
+    if (!strcmp(arch, "ppc64")) {
+        qtest_add_data_func("/numa/spapr/cpu/explicit", args, spapr_numa_cpu);
+    }
+
+    if (!strcmp(arch, "aarch64")) {
+        qtest_add_data_func("/numa/aarch64/cpu/explicit", args,
+                            aarch64_numa_cpu);
+    }
+
     return g_test_run();
 }