From: Olivier Dion via lttng-dev <lttng-dev@lists.lttng.org>
To: lttng-dev@lists.lttng.org
Cc: Olivier Dion <odion@efficios.com>, Tony Finch <dot@dotat.at>,
"Paul E. McKenney" <paulmck@kernel.org>
Subject: [lttng-dev] [PATCH v2 12/12] tests: Add tests for checking race conditions
Date: Wed, 7 Jun 2023 14:53:59 -0400 [thread overview]
Message-ID: <20230607185359.8125-13-odion@efficios.com> (raw)
In-Reply-To: <20230515201718.9809-1-odion@efficios.com>
These tests do nothing useful except of stress testing a
single-consumer, multiple-producers program on various data structures.
These tests are only meaningful when compiling liburcu with TSAN.
Change-Id: If22b27ed0fb95bf890947fc4e75f923edb5ada8f
Signed-off-by: Olivier Dion <odion@efficios.com>
---
tests/unit/test_lfstack.c | 90 ++++++++++++++++++++++++++++
tests/unit/test_wfcqueue.c | 119 +++++++++++++++++++++++++++++++++++++
tests/unit/test_wfqueue.c | 91 ++++++++++++++++++++++++++++
tests/unit/test_wfstack.c | 90 ++++++++++++++++++++++++++++
4 files changed, 390 insertions(+)
create mode 100644 tests/unit/test_lfstack.c
create mode 100644 tests/unit/test_wfcqueue.c
create mode 100644 tests/unit/test_wfqueue.c
create mode 100644 tests/unit/test_wfstack.c
diff --git a/tests/unit/test_lfstack.c b/tests/unit/test_lfstack.c
new file mode 100644
index 0000000..a1f99f0
--- /dev/null
+++ b/tests/unit/test_lfstack.c
@@ -0,0 +1,90 @@
+/*
+ * test_lfstack.c
+ *
+ * Userspace RCU library - test wftack race conditions
+ *
+ * Copyright 2023 - Olivier Dion <odion@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define _LGPL_SOURCE
+
+#include <stdlib.h>
+
+#include <pthread.h>
+
+#include <urcu/lfstack.h>
+
+#include "tap.h"
+
+#define NR_TESTS 1
+#define NR_PRODUCERS 4
+#define LOOP 100
+
+static void async_run(struct cds_lfs_stack *queue)
+{
+ struct cds_lfs_node *node = malloc(sizeof(*node));
+
+ cds_lfs_node_init(node);
+
+ cds_lfs_push(queue, node);
+}
+
+static void *async_loop(void *queue)
+{
+ size_t k = 0;
+
+ while (k < LOOP * NR_PRODUCERS) {
+ free(cds_lfs_pop_blocking(queue));
+ ++k;
+ }
+
+ return NULL;
+}
+
+static void *spawn_jobs(void *queue)
+{
+ for (size_t k = 0; k < LOOP; ++k) {
+ async_run(queue);
+ }
+
+ return 0;
+}
+
+int main(void)
+{
+ pthread_t consumer;
+ pthread_t producers[NR_PRODUCERS];
+ struct cds_lfs_stack queue;
+
+ plan_tests(NR_TESTS);
+
+ cds_lfs_init(&queue);
+ pthread_create(&consumer, NULL, async_loop, &queue);
+
+ for (size_t k = 0; k < NR_PRODUCERS; ++k) {
+ pthread_create(&producers[k], NULL, spawn_jobs, &queue);
+ }
+
+ pthread_join(consumer, NULL);
+ for (size_t k = 0; k < NR_PRODUCERS; ++k) {
+ pthread_join(producers[k], NULL);
+ }
+
+ ok1("No race conditions");
+
+ return exit_status();
+}
diff --git a/tests/unit/test_wfcqueue.c b/tests/unit/test_wfcqueue.c
new file mode 100644
index 0000000..338aa07
--- /dev/null
+++ b/tests/unit/test_wfcqueue.c
@@ -0,0 +1,119 @@
+/*
+ * test_wfcqueue.c
+ *
+ * Userspace RCU library - test wfcqueue race conditions
+ *
+ * Copyright 2023 - Olivier Dion <odion@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define _LGPL_SOURCE
+
+#include <stdlib.h>
+
+#include <pthread.h>
+
+#include <urcu/wfcqueue.h>
+
+#include "tap.h"
+
+#define NR_TESTS 1
+#define NR_PRODUCERS 4
+#define LOOP 100
+
+struct queue {
+ struct cds_wfcq_head head;
+ struct cds_wfcq_tail tail;
+};
+
+static void async_run(struct queue *queue)
+{
+ struct cds_wfcq_node *node = malloc(sizeof(*node));
+
+ cds_wfcq_node_init(node);
+
+ cds_wfcq_enqueue(&queue->head, &queue->tail, node);
+}
+static void do_async_loop(size_t *k, struct queue *queue)
+{
+ struct queue my_queue;
+ enum cds_wfcq_ret state;
+ struct cds_wfcq_node *node, *next;
+
+ cds_wfcq_init(&my_queue.head, &my_queue.tail);
+
+ state = cds_wfcq_splice_blocking(&my_queue.head,
+ &my_queue.tail,
+ &queue->head,
+ &queue->tail);
+
+ if (state == CDS_WFCQ_RET_SRC_EMPTY) {
+ return;
+ }
+
+ __cds_wfcq_for_each_blocking_safe(&my_queue.head,
+ &my_queue.tail,
+ node, next) {
+ free(node);
+ (*k)++;
+ }
+}
+
+static void *async_loop(void *queue)
+{
+ size_t k = 0;
+
+ while (k < LOOP * NR_PRODUCERS) {
+ (void) poll(NULL, 0, 10);
+ do_async_loop(&k, queue);
+ }
+
+ return NULL;
+}
+
+static void *spawn_jobs(void *queue)
+{
+ for (size_t k = 0; k < LOOP; ++k) {
+ async_run(queue);
+ }
+
+ return 0;
+}
+
+int main(void)
+{
+ pthread_t consumer;
+ pthread_t producers[NR_PRODUCERS];
+ struct queue queue;
+
+ plan_tests(NR_TESTS);
+
+ cds_wfcq_init(&queue.head, &queue.tail);
+ pthread_create(&consumer, NULL, async_loop, &queue);
+
+ for (size_t k = 0; k < NR_PRODUCERS; ++k) {
+ pthread_create(&producers[k], NULL, spawn_jobs, &queue);
+ }
+
+ pthread_join(consumer, NULL);
+ for (size_t k = 0; k < NR_PRODUCERS; ++k) {
+ pthread_join(producers[k], NULL);
+ }
+
+ ok1("No race conditions");
+
+ return exit_status();
+}
diff --git a/tests/unit/test_wfqueue.c b/tests/unit/test_wfqueue.c
new file mode 100644
index 0000000..57afaba
--- /dev/null
+++ b/tests/unit/test_wfqueue.c
@@ -0,0 +1,91 @@
+/*
+ * test_wfqueue.c
+ *
+ * Userspace RCU library - test wfqueue race conditions
+ *
+ * Copyright 2023 - Olivier Dion <odion@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define _LGPL_SOURCE
+
+#include <stdlib.h>
+
+#include <pthread.h>
+
+#define CDS_WFQ_DEPRECATED
+#include <urcu/wfqueue.h>
+
+#include "tap.h"
+
+#define NR_TESTS 1
+#define NR_PRODUCERS 4
+#define LOOP 100
+
+static void async_run(struct cds_wfq_queue *queue)
+{
+ struct cds_wfq_node *node = malloc(sizeof(*node));
+
+ cds_wfq_node_init(node);
+
+ cds_wfq_enqueue(queue, node);
+}
+
+static void *async_loop(void *queue)
+{
+ size_t k = 0;
+
+ while (k < LOOP * NR_PRODUCERS) {
+ free(cds_wfq_dequeue_blocking(queue));
+ ++k;
+ }
+
+ return NULL;
+}
+
+static void *spawn_jobs(void *queue)
+{
+ for (size_t k = 0; k < LOOP; ++k) {
+ async_run(queue);
+ }
+
+ return 0;
+}
+
+int main(void)
+{
+ pthread_t consumer;
+ pthread_t producers[NR_PRODUCERS];
+ struct cds_wfq_queue queue;
+
+ plan_tests(NR_TESTS);
+
+ cds_wfq_init(&queue);
+ pthread_create(&consumer, NULL, async_loop, &queue);
+
+ for (size_t k = 0; k < NR_PRODUCERS; ++k) {
+ pthread_create(&producers[k], NULL, spawn_jobs, &queue);
+ }
+
+ pthread_join(consumer, NULL);
+ for (size_t k = 0; k < NR_PRODUCERS; ++k) {
+ pthread_join(producers[k], NULL);
+ }
+
+ ok1("No race conditions");
+
+ return exit_status();
+}
diff --git a/tests/unit/test_wfstack.c b/tests/unit/test_wfstack.c
new file mode 100644
index 0000000..578ae92
--- /dev/null
+++ b/tests/unit/test_wfstack.c
@@ -0,0 +1,90 @@
+/*
+ * test_wfstack.c
+ *
+ * Userspace RCU library - test wftack race conditions
+ *
+ * Copyright 2023 - Olivier Dion <odion@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define _LGPL_SOURCE
+
+#include <stdlib.h>
+
+#include <pthread.h>
+
+#include <urcu/wfstack.h>
+
+#include "tap.h"
+
+#define NR_TESTS 1
+#define NR_PRODUCERS 4
+#define LOOP 100
+
+static void async_run(struct cds_wfs_stack *queue)
+{
+ struct cds_wfs_node *node = malloc(sizeof(*node));
+
+ cds_wfs_node_init(node);
+
+ cds_wfs_push(queue, node);
+}
+
+static void *async_loop(void *queue)
+{
+ size_t k = 0;
+
+ while (k < LOOP * NR_PRODUCERS) {
+ free(cds_wfs_pop_blocking(queue));
+ ++k;
+ }
+
+ return NULL;
+}
+
+static void *spawn_jobs(void *queue)
+{
+ for (size_t k = 0; k < LOOP; ++k) {
+ async_run(queue);
+ }
+
+ return 0;
+}
+
+int main(void)
+{
+ pthread_t consumer;
+ pthread_t producers[NR_PRODUCERS];
+ struct cds_wfs_stack queue;
+
+ plan_tests(NR_TESTS);
+
+ cds_wfs_init(&queue);
+ pthread_create(&consumer, NULL, async_loop, &queue);
+
+ for (size_t k = 0; k < NR_PRODUCERS; ++k) {
+ pthread_create(&producers[k], NULL, spawn_jobs, &queue);
+ }
+
+ pthread_join(consumer, NULL);
+ for (size_t k = 0; k < NR_PRODUCERS; ++k) {
+ pthread_join(producers[k], NULL);
+ }
+
+ ok1("No race conditions");
+
+ return exit_status();
+}
--
2.40.1
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
prev parent reply other threads:[~2023-06-07 18:55 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-15 20:17 [lttng-dev] [PATCH 00/11] Add support for TSAN to liburcu Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 01/11] configure: Add --disable-atomic-builtins option Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 02/11] urcu/uatomic: Use atomic builtins if configured Olivier Dion via lttng-dev
2023-06-21 23:19 ` Paul E. McKenney via lttng-dev
2023-06-22 15:55 ` Mathieu Desnoyers via lttng-dev
2023-06-22 18:32 ` Paul E. McKenney via lttng-dev
2023-06-22 19:53 ` Olivier Dion via lttng-dev
2023-06-22 19:56 ` Mathieu Desnoyers via lttng-dev
2023-06-22 20:10 ` Olivier Dion via lttng-dev
2023-06-22 20:11 ` Paul E. McKenney via lttng-dev
2023-06-22 19:54 ` Mathieu Desnoyers via lttng-dev
2023-06-29 17:22 ` Olivier Dion via lttng-dev
2023-06-29 17:27 ` Olivier Dion via lttng-dev
2023-06-29 18:33 ` Mathieu Desnoyers via lttng-dev
2023-06-29 18:29 ` Mathieu Desnoyers via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 03/11] urcu/compiler: " Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 04/11] urcu/arch/generic: " Olivier Dion via lttng-dev
2023-06-21 23:22 ` Paul E. McKenney via lttng-dev
2023-06-22 0:53 ` Olivier Dion via lttng-dev
2023-06-22 1:48 ` Mathieu Desnoyers via lttng-dev
2023-06-22 3:44 ` Paul E. McKenney via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 05/11] urcu/system: " Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 06/11] urcu/uatomic: Add CMM memory model Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 07/11] urcu-wait: Fix wait state load/store Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 08/11] tests: Use uatomic for accessing global states Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 09/11] benchmark: " Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 10/11] tests/unit/test_build: Quiet unused return value Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 11/11] urcu/annotate: Add CMM annotation Olivier Dion via lttng-dev
2023-05-16 15:57 ` Olivier Dion via lttng-dev
2023-05-16 8:18 ` [lttng-dev] [PATCH 00/11] Add support for TSAN to liburcu Dmitry Vyukov via lttng-dev
2023-05-16 15:47 ` Olivier Dion via lttng-dev
2023-05-17 10:21 ` Dmitry Vyukov via lttng-dev
2023-05-17 10:57 ` Dmitry Vyukov via lttng-dev
2023-05-17 14:44 ` Olivier Dion via lttng-dev
2023-05-23 16:05 ` Olivier Dion via lttng-dev
2023-05-24 8:14 ` Dmitry Vyukov via lttng-dev
2023-05-26 5:33 ` Ondřej Surý via lttng-dev
2023-05-26 6:08 ` Dmitry Vyukov via lttng-dev
2023-05-26 6:10 ` Dmitry Vyukov via lttng-dev
2023-05-26 10:06 ` Ondřej Surý via lttng-dev
2023-05-26 10:08 ` Dmitry Vyukov via lttng-dev
2023-05-26 14:20 ` Olivier Dion via lttng-dev
2023-05-26 15:15 ` Olivier Dion via lttng-dev
2023-05-17 14:44 ` Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 00/12] " Olivier Dion via lttng-dev
2023-06-07 19:04 ` Ondřej Surý via lttng-dev
2023-06-07 19:20 ` Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 01/12] configure: Add --disable-atomic-builtins option Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 02/12] urcu/compiler: Use atomic builtins if configured Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 03/12] urcu/arch/generic: " Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 04/12] urcu/system: " Olivier Dion via lttng-dev
2023-06-21 23:23 ` Paul E. McKenney via lttng-dev
2023-07-04 14:43 ` Olivier Dion via lttng-dev
2023-07-05 18:48 ` Paul E. McKenney via lttng-dev
2023-07-05 19:03 ` Olivier Dion via lttng-dev
2023-07-05 19:28 ` Paul E. McKenney via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 05/12] urcu/uatomic: Add CMM memory model Olivier Dion via lttng-dev
2023-06-21 23:28 ` Paul E. McKenney via lttng-dev
2023-06-29 16:49 ` Olivier Dion via lttng-dev
2023-06-29 18:40 ` Paul E. McKenney via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 06/12] urcu-wait: Fix wait state load/store Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 07/12] tests: Use uatomic for accessing global states Olivier Dion via lttng-dev
2023-06-21 23:37 ` Paul E. McKenney via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 08/12] benchmark: " Olivier Dion via lttng-dev
2023-06-21 23:38 ` Paul E. McKenney via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 09/12] tests/unit/test_build: Quiet unused return value Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 10/12] urcu/annotate: Add CMM annotation Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 11/12] Add cmm_emit_legacy_smp_mb() Olivier Dion via lttng-dev
2023-06-07 18:53 ` Olivier Dion via lttng-dev [this message]
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=20230607185359.8125-13-odion@efficios.com \
--to=lttng-dev@lists.lttng.org \
--cc=dot@dotat.at \
--cc=odion@efficios.com \
--cc=paulmck@kernel.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