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
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>
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
>
>
© 2016 - 2026 Red Hat, Inc.