From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
"Nikolay Igotti" <igotti@gmail.com>
Subject: [PATCH v1 14/15] tests/tcg: add new threadcount test
Date: Wed, 20 May 2020 15:05:40 +0100 [thread overview]
Message-ID: <20200520140541.30256-15-alex.bennee@linaro.org> (raw)
In-Reply-To: <20200520140541.30256-1-alex.bennee@linaro.org>
Based on the original testcase by Nikolay Igotti.
Message-ID: <CAEme+7GLKg_dNsHizzTKDymX9HyD+Ph2iZ=WKhOw2XG+zhViXg@mail.gmail.com>
Signed-off-by: Nikolay Igotti <igotti@gmail.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
v2
- add Nikolay's s-o-b
- checkpatch fixes
---
tests/tcg/multiarch/threadcount.c | 64 +++++++++++++++++++++++++++++
tests/tcg/multiarch/Makefile.target | 2 +
2 files changed, 66 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..545a1c81466
--- /dev/null
+++ b/tests/tcg/multiarch/threadcount.c
@@ -0,0 +1,64 @@
+/*
+ * 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
next prev parent reply other threads:[~2020-05-20 14:15 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-20 14:05 [PATCH v1 00/15] testing and plugin updates Alex Bennée
2020-05-20 14:05 ` [PATCH v1 01/15] configure: add alternate binary for genisoimage Alex Bennée
2020-05-20 14:05 ` [PATCH v1 02/15] tests/vm: pass --genisoimage to basevm script Alex Bennée
2020-05-20 14:05 ` [PATCH v1 03/15] travis.yml: Use clang++ in the Clang tests Alex Bennée
2020-05-20 14:05 ` [PATCH v1 04/15] tests/tcg: fix invocation of the memory record/replay tests Alex Bennée
2020-05-20 14:05 ` [PATCH v1 05/15] tests/fp: enable extf80_le_quite tests Alex Bennée
2020-05-22 2:59 ` Richard Henderson
2020-05-20 14:05 ` [PATCH v1 06/15] tests/fp: split and audit the conversion tests Alex Bennée
2020-05-22 3:00 ` Richard Henderson
2020-05-20 14:05 ` [PATCH v1 07/15] tests/tcg: better detect confused gdb which can't connect Alex Bennée
2020-05-22 3:01 ` Richard Henderson
2020-05-20 14:05 ` [PATCH v1 08/15] tests/docker: bump fedora to 32 Alex Bennée
2020-05-22 3:01 ` Richard Henderson
2020-05-20 14:05 ` [PATCH v1 09/15] tests/docker: add debian11 base image Alex Bennée
2020-05-22 3:01 ` Richard Henderson
2020-05-20 14:05 ` [PATCH v1 10/15] tests/docker: use a gcc-10 based image for arm64 tests Alex Bennée
2020-05-22 3:02 ` Richard Henderson
2020-05-20 14:05 ` [PATCH v1 11/15] tests/tcg/aarch64: Add bti smoke test Alex Bennée
2020-05-22 3:05 ` Richard Henderson
2020-05-20 14:05 ` [PATCH v1 12/15] cpus-common: ensure auto-assigned cpu_indexes don't clash Alex Bennée
2020-05-22 3:20 ` Richard Henderson
2020-05-20 14:05 ` [PATCH v1 13/15] linux-user: properly "unrealize" vCPU object Alex Bennée
2020-05-20 14:05 ` Alex Bennée [this message]
2020-05-20 14:05 ` [PATCH v1 15/15] plugins: new lockstep plugin for debugging TCG changes Alex Bennée
2020-05-20 16:37 ` [PATCH v1 00/15] testing and plugin updates no-reply
2020-05-20 16:38 ` no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200520140541.30256-15-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=igotti@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).