diff mbox series

[v1,7/8] tests/tcg: add new threadcount test

Message ID 20200513173200.11830-8-alex.bennee@linaro.org
State Superseded
Headers show
Series plugins/next (cleanup, cpu_index and lockstep) | expand

Commit Message

Alex Bennée May 13, 2020, 5:31 p.m. UTC
Based on the original testcase by Nikolay Igotti.

Message-ID: <CAEme+7GLKg_dNsHizzTKDymX9HyD+Ph2iZ=WKhOw2XG+zhViXg@mail.gmail.com>
Cc: Nikolay Igotti <igotti@gmail.com>
[Nikolay can we have your signed of by to add the testcase?]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 tests/tcg/multiarch/threadcount.c   | 62 +++++++++++++++++++++++++++++
 tests/tcg/multiarch/Makefile.target |  2 +
 2 files changed, 64 insertions(+)
 create mode 100644 tests/tcg/multiarch/threadcount.c

-- 
2.20.1

Comments

Nikolay Igotti May 15, 2020, 7:51 p.m. UTC | #1
Sure, use it for anything.

ср, 13 мая 2020 г. в 20:32, Alex Bennée <alex.bennee@linaro.org>:

> Based on the original testcase by Nikolay Igotti.

>

> Message-ID: <CAEme+7GLKg_dNsHizzTKDymX9HyD+Ph2iZ=

> WKhOw2XG+zhViXg@mail.gmail.com>

> Cc: Nikolay Igotti <igotti@gmail.com>

> [Nikolay can we have your signed of by to add the testcase?]

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> ---

>  tests/tcg/multiarch/threadcount.c   | 62 +++++++++++++++++++++++++++++

>  tests/tcg/multiarch/Makefile.target |  2 +

>  2 files changed, 64 insertions(+)

>  create mode 100644 tests/tcg/multiarch/threadcount.c

>

> diff --git a/tests/tcg/multiarch/threadcount.c

> b/tests/tcg/multiarch/threadcount.c

> new file mode 100644

> index 00000000000..546dd90eeb2

> --- /dev/null

> +++ b/tests/tcg/multiarch/threadcount.c

> @@ -0,0 +1,62 @@

> +/*

> + * Thread Exerciser

> + *

> + * Unlike testthread which is mainly concerned about testing thread

> + * semantics this test is used to exercise the thread creation and

> + * accounting. A version of this test found a problem with clashing

> + * cpu_indexes which caused a break in plugin handling.

> + *

> + * Based on the original test case by Nikolay Igotti.

> + *

> + * Copyright (c) 2020 Linaro Ltd

> + *

> + * SPDX-License-Identifier: GPL-2.0-or-later

> + */

> +

> +#include <stdint.h>

> +#include <stdio.h>

> +#include <stdlib.h>

> +#include <unistd.h>

> +#include <pthread.h>

> +

> +int max_threads = 10;

> +

> +typedef struct {

> +    int delay;

> +} ThreadArg;

> +

> +static void *thread_fn(void* varg)  {

> +    ThreadArg* arg = varg;

> +    usleep(arg->delay);

> +    free(arg);

> +    return NULL;

> +}

> +

> +int main(int argc, char **argv) {

> +    int i;

> +    pthread_t *threads;

> +

> +    if (argc > 1) {

> +        max_threads = atoi(argv[1]);

> +    }

> +    threads = calloc(sizeof(pthread_t), max_threads);

> +

> +    for (i = 0; i < max_threads; i++) {

> +        ThreadArg* arg = calloc(sizeof(ThreadArg), 1);

> +        arg->delay = i * 100;

> +        pthread_create(threads + i, NULL, thread_fn, arg);

> +    }

> +

> +    printf("Created %d threads\n", max_threads);

> +

> +    /* sleep until roughly half the threads have "finished" */

> +    usleep(max_threads * 50);

> +

> +    for (i = 0; i < max_threads; i++) {

> +        pthread_join(threads[i], NULL);

> +    }

> +

> +    printf("Done\n");

> +

> +    return 0;

> +}

> diff --git a/tests/tcg/multiarch/Makefile.target

> b/tests/tcg/multiarch/Makefile.target

> index 51fb75ecfdd..cb49cc9ccb2 100644

> --- a/tests/tcg/multiarch/Makefile.target

> +++ b/tests/tcg/multiarch/Makefile.target

> @@ -28,6 +28,8 @@ run-float_%: float_%

>

>  testthread: LDFLAGS+=-lpthread

>

> +threadcount: LDFLAGS+=-lpthread

> +

>  # We define the runner for test-mmap after the individual

>  # architectures have defined their supported pages sizes. If no

>  # additional page sizes are defined we only run the default test.

> --

> 2.20.1

>

>
<div><div dir="auto">Sure, use it for anything.</div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">ср, 13 мая 2020 г. в 20:32, Alex Bennée &lt;<a href="mailto:alex.bennee@linaro.org">alex.bennee@linaro.org</a>&gt;:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Based on the original testcase by Nikolay Igotti.<br>
<br>
Message-ID: &lt;CAEme+7GLKg_dNsHizzTKDymX9HyD+Ph2iZ=<a href="mailto:WKhOw2XG%2BzhViXg@mail.gmail.com" target="_blank">WKhOw2XG+zhViXg@mail.gmail.com</a>&gt;<br>
Cc: Nikolay Igotti &lt;<a href="mailto:igotti@gmail.com" target="_blank">igotti@gmail.com</a>&gt;<br>
[Nikolay can we have your signed of by to add the testcase?]<br>
Signed-off-by: Alex Bennée &lt;<a href="mailto:alex.bennee@linaro.org" target="_blank">alex.bennee@linaro.org</a>&gt;<br>

---<br>
 tests/tcg/multiarch/threadcount.c   | 62 +++++++++++++++++++++++++++++<br>
 tests/tcg/multiarch/Makefile.target |  2 +<br>
 2 files changed, 64 insertions(+)<br>
 create mode 100644 tests/tcg/multiarch/threadcount.c<br>
<br>
diff --git a/tests/tcg/multiarch/threadcount.c b/tests/tcg/multiarch/threadcount.c<br>
new file mode 100644<br>
index 00000000000..546dd90eeb2<br>
--- /dev/null<br>
+++ b/tests/tcg/multiarch/threadcount.c<br>
@@ -0,0 +1,62 @@<br>
+/*<br>
+ * Thread Exerciser<br>
+ *<br>
+ * Unlike testthread which is mainly concerned about testing thread<br>
+ * semantics this test is used to exercise the thread creation and<br>
+ * accounting. A version of this test found a problem with clashing<br>
+ * cpu_indexes which caused a break in plugin handling.<br>
+ *<br>
+ * Based on the original test case by Nikolay Igotti.<br>
+ *<br>
+ * Copyright (c) 2020 Linaro Ltd<br>
+ *<br>
+ * SPDX-License-Identifier: GPL-2.0-or-later<br>
+ */<br>
+<br>
+#include &lt;stdint.h&gt;<br>
+#include &lt;stdio.h&gt;<br>
+#include &lt;stdlib.h&gt;<br>
+#include &lt;unistd.h&gt;<br>
+#include &lt;pthread.h&gt;<br>
+<br>
+int max_threads = 10;<br>
+<br>
+typedef struct {<br>
+    int delay;<br>
+} ThreadArg;<br>
+<br>
+static void *thread_fn(void* varg)  {<br>
+    ThreadArg* arg = varg;<br>
+    usleep(arg-&gt;delay);<br>
+    free(arg);<br>
+    return NULL;<br>
+}<br>
+<br>
+int main(int argc, char **argv) {<br>
+    int i;<br>
+    pthread_t *threads;<br>
+<br>
+    if (argc &gt; 1) {<br>
+        max_threads = atoi(argv[1]);<br>
+    }<br>
+    threads = calloc(sizeof(pthread_t), max_threads);<br>
+<br>
+    for (i = 0; i &lt; max_threads; i++) {<br>
+        ThreadArg* arg = calloc(sizeof(ThreadArg), 1);<br>
+        arg-&gt;delay = i * 100;<br>
+        pthread_create(threads + i, NULL, thread_fn, arg);<br>
+    }<br>
+<br>
+    printf(&quot;Created %d threads\n&quot;, max_threads);<br>
+<br>
+    /* sleep until roughly half the threads have &quot;finished&quot; */<br>
+    usleep(max_threads * 50);<br>
+<br>
+    for (i = 0; i &lt; max_threads; i++) {<br>
+        pthread_join(threads[i], NULL);<br>
+    }<br>
+<br>
+    printf(&quot;Done\n&quot;);<br>
+<br>
+    return 0;<br>
+}<br>
diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target<br>
index 51fb75ecfdd..cb49cc9ccb2 100644<br>
--- a/tests/tcg/multiarch/Makefile.target<br>
+++ b/tests/tcg/multiarch/Makefile.target<br>
@@ -28,6 +28,8 @@ run-float_%: float_%<br>
<br>
 testthread: LDFLAGS+=-lpthread<br>
<br>
+threadcount: LDFLAGS+=-lpthread<br>
+<br>
 # We define the runner for test-mmap after the individual<br>
 # architectures have defined their supported pages sizes. If no<br>
 # additional page sizes are defined we only run the default test.<br>
-- <br>
2.20.1<br>
<br>
</blockquote></div></div>
Philippe Mathieu-Daudé May 22, 2020, 9:33 a.m. UTC | #2
On 5/13/20 7:31 PM, Alex Bennée wrote:
> Based on the original testcase by Nikolay Igotti.

> 

> Message-ID: <CAEme+7GLKg_dNsHizzTKDymX9HyD+Ph2iZ=WKhOw2XG+zhViXg@mail.gmail.com>

> Cc: Nikolay Igotti <igotti@gmail.com>

> [Nikolay can we have your signed of by to add the testcase?]

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> ---

>   tests/tcg/multiarch/threadcount.c   | 62 +++++++++++++++++++++++++++++

>   tests/tcg/multiarch/Makefile.target |  2 +

>   2 files changed, 64 insertions(+)

>   create mode 100644 tests/tcg/multiarch/threadcount.c

> 

> diff --git a/tests/tcg/multiarch/threadcount.c b/tests/tcg/multiarch/threadcount.c

> new file mode 100644

> index 00000000000..546dd90eeb2

> --- /dev/null

> +++ b/tests/tcg/multiarch/threadcount.c

> @@ -0,0 +1,62 @@

> +/*

> + * Thread Exerciser

> + *

> + * Unlike testthread which is mainly concerned about testing thread

> + * semantics this test is used to exercise the thread creation and

> + * accounting. A version of this test found a problem with clashing

> + * cpu_indexes which caused a break in plugin handling.

> + *

> + * Based on the original test case by Nikolay Igotti.

> + *

> + * Copyright (c) 2020 Linaro Ltd

> + *

> + * SPDX-License-Identifier: GPL-2.0-or-later

> + */

> +

> +#include <stdint.h>

> +#include <stdio.h>

> +#include <stdlib.h>

> +#include <unistd.h>

> +#include <pthread.h>

> +

> +int max_threads = 10;

> +

> +typedef struct {

> +    int delay;

> +} ThreadArg;

> +

> +static void *thread_fn(void* varg)  {

> +    ThreadArg* arg = varg;

> +    usleep(arg->delay);

> +    free(arg);

> +    return NULL;

> +}

> +

> +int main(int argc, char **argv) {

> +    int i;

> +    pthread_t *threads;

> +

> +    if (argc > 1) {

> +        max_threads = atoi(argv[1]);

> +    }

> +    threads = calloc(sizeof(pthread_t), max_threads);

> +

> +    for (i = 0; i < max_threads; i++) {

> +        ThreadArg* arg = calloc(sizeof(ThreadArg), 1);

> +        arg->delay = i * 100;

> +        pthread_create(threads + i, NULL, thread_fn, arg);

> +    }

> +

> +    printf("Created %d threads\n", max_threads);

> +

> +    /* sleep until roughly half the threads have "finished" */

> +    usleep(max_threads * 50);

> +

> +    for (i = 0; i < max_threads; i++) {

> +        pthread_join(threads[i], NULL);

> +    }

> +

> +    printf("Done\n");

> +

> +    return 0;

> +}

> diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target

> index 51fb75ecfdd..cb49cc9ccb2 100644

> --- a/tests/tcg/multiarch/Makefile.target

> +++ b/tests/tcg/multiarch/Makefile.target

> @@ -28,6 +28,8 @@ run-float_%: float_%

>   

>   testthread: LDFLAGS+=-lpthread

>   

> +threadcount: LDFLAGS+=-lpthread

> +

>   # We define the runner for test-mmap after the individual

>   # architectures have defined their supported pages sizes. If no

>   # additional page sizes are defined we only run the default test.

> 


Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
diff mbox series

Patch

diff --git a/tests/tcg/multiarch/threadcount.c b/tests/tcg/multiarch/threadcount.c
new file mode 100644
index 00000000000..546dd90eeb2
--- /dev/null
+++ b/tests/tcg/multiarch/threadcount.c
@@ -0,0 +1,62 @@ 
+/*
+ * Thread Exerciser
+ *
+ * Unlike testthread which is mainly concerned about testing thread
+ * semantics this test is used to exercise the thread creation and
+ * accounting. A version of this test found a problem with clashing
+ * cpu_indexes which caused a break in plugin handling.
+ *
+ * Based on the original test case by Nikolay Igotti.
+ *
+ * Copyright (c) 2020 Linaro Ltd
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pthread.h>
+
+int max_threads = 10;
+
+typedef struct {
+    int delay;
+} ThreadArg;
+
+static void *thread_fn(void* varg)  {
+    ThreadArg* arg = varg;
+    usleep(arg->delay);
+    free(arg);
+    return NULL;
+}
+
+int main(int argc, char **argv) {
+    int i;
+    pthread_t *threads;
+
+    if (argc > 1) {
+        max_threads = atoi(argv[1]);
+    }
+    threads = calloc(sizeof(pthread_t), max_threads);
+
+    for (i = 0; i < max_threads; i++) {
+        ThreadArg* arg = calloc(sizeof(ThreadArg), 1);
+        arg->delay = i * 100;
+        pthread_create(threads + i, NULL, thread_fn, arg);
+    }
+
+    printf("Created %d threads\n", max_threads);
+
+    /* sleep until roughly half the threads have "finished" */
+    usleep(max_threads * 50);
+
+    for (i = 0; i < max_threads; i++) {
+        pthread_join(threads[i], NULL);
+    }
+
+    printf("Done\n");
+
+    return 0;
+}
diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target
index 51fb75ecfdd..cb49cc9ccb2 100644
--- a/tests/tcg/multiarch/Makefile.target
+++ b/tests/tcg/multiarch/Makefile.target
@@ -28,6 +28,8 @@  run-float_%: float_%
 
 testthread: LDFLAGS+=-lpthread
 
+threadcount: LDFLAGS+=-lpthread
+
 # We define the runner for test-mmap after the individual
 # architectures have defined their supported pages sizes. If no
 # additional page sizes are defined we only run the default test.