Module Name:    src
Committed By:   kamil
Date:           Sun Nov 20 16:13:03 UTC 2016

Modified Files:
        src/tests/lib/libpthread_dbg: t_threads.c

Log Message:
Add threads2 and threads3 in tests/lib/libpthread_dbg/t_threads.c

threads2:
Asserts that td_thr_iter() call is executed for each thread once

threads3:
Asserts that for each td_thr_iter() call td_thr_info() is valid

These tests pass correctly.

Sponsored by <The NetBSD Foundation>


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libpthread_dbg/t_threads.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread_dbg/t_threads.c
diff -u src/tests/lib/libpthread_dbg/t_threads.c:1.2 src/tests/lib/libpthread_dbg/t_threads.c:1.3
--- src/tests/lib/libpthread_dbg/t_threads.c:1.2	Sat Nov 19 15:13:46 2016
+++ src/tests/lib/libpthread_dbg/t_threads.c	Sun Nov 20 16:13:03 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_threads.c,v 1.2 2016/11/19 15:13:46 kamil Exp $	*/
+/*	$NetBSD: t_threads.c,v 1.3 2016/11/20 16:13:03 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -28,12 +28,16 @@
 
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_threads.c,v 1.2 2016/11/19 15:13:46 kamil Exp $");
+__RCSID("$NetBSD: t_threads.c,v 1.3 2016/11/20 16:13:03 kamil Exp $");
 
 #include <dlfcn.h>
 #include <pthread.h>
 #include <pthread_dbg.h>
 #include <stdio.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <stdlib.h>
 
 #include <atf-c.h>
 
@@ -47,13 +51,13 @@ ATF_TC_HEAD(threads1, tc)
 	    "Asserts that td_thr_iter() call without extra logic works");
 }
 
-static volatile int exiting;
+static volatile int exiting1;
 
 static void *
 busyFunction1(void *arg)
 {
 
-	while (exiting == 0)
+	while (exiting1 == 0)
 		usleep(50000);
 
 	return NULL;
@@ -92,16 +96,157 @@ ATF_TC_BODY(threads1, tc)
 
 	ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads1, NULL) == TD_ERR_OK);
 
-	exiting = 1;
+	exiting1 = 1;
 
 	printf("Calling td_close(3)\n");
 	ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
 }
 
+ATF_TC(threads2);
+ATF_TC_HEAD(threads2, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr",
+	    "Asserts that td_thr_iter() call is executed for each thread once");
+}
+
+static volatile int exiting2;
+
+static void *
+busyFunction2(void *arg)
+{
+
+	while (exiting2 == 0)
+		usleep(50000);
+
+	return NULL;
+}
+
+static int
+iterateThreads2(td_thread_t *thread, void *arg)
+{
+	int *counter = (int *)arg;
+
+	++(*counter);
+
+	return TD_ERR_OK;
+}
+
+ATF_TC_BODY(threads2, tc)
+{
+	struct td_proc_callbacks_t dummy_callbacks;
+	td_proc_t *main_ta;
+	const size_t max_threads = 10;
+	size_t i;
+	pthread_t threads[max_threads];
+	int count = 0;
+
+	dummy_callbacks.proc_read	= basic_proc_read;
+	dummy_callbacks.proc_write	= basic_proc_write;
+	dummy_callbacks.proc_lookup	= basic_proc_lookup;
+	dummy_callbacks.proc_regsize	= dummy_proc_regsize;
+	dummy_callbacks.proc_getregs	= dummy_proc_getregs;
+	dummy_callbacks.proc_setregs	= dummy_proc_setregs;
+
+
+	for (i = 0; i < max_threads; i++) {
+		printf("Creating thread %zu\n", i);
+		PTHREAD_REQUIRE
+		    (pthread_create(&threads[i], NULL, busyFunction2, NULL));
+	}
+
+	printf("Calling td_open(3)\n");
+	ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
+
+	ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads2, &count) == TD_ERR_OK);
+
+	exiting2 = 1;
+
+	printf("Calling td_close(3)\n");
+	ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
+
+	ATF_REQUIRE_EQ_MSG(count, max_threads + 1,
+	    "counted threads (%d) != expected threads (%d)",
+	    count, max_threads + 1);
+}
+
+ATF_TC(threads3);
+ATF_TC_HEAD(threads3, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr",
+	    "Asserts that for each td_thr_iter() call td_thr_info() is valid");
+}
+
+static volatile int exiting3;
+
+static void *
+busyFunction3(void *arg)
+{
+
+	while (exiting3 == 0)
+		usleep(50000);
+
+	return NULL;
+}
+
+static int
+iterateThreads3(td_thread_t *thread, void *arg)
+{
+	int *counter = (int *)arg;
+	td_thread_info_t info;
+
+	ATF_REQUIRE(td_thr_info(thread, &info) == TD_ERR_OK);
+
+	++(*counter);
+
+	return TD_ERR_OK;
+}
+
+ATF_TC_BODY(threads3, tc)
+{
+	struct td_proc_callbacks_t dummy_callbacks;
+	td_proc_t *main_ta;
+	const size_t max_threads = 10;
+	size_t i;
+	pthread_t threads[max_threads];
+	int count = 0;
+
+	dummy_callbacks.proc_read	= basic_proc_read;
+	dummy_callbacks.proc_write	= basic_proc_write;
+	dummy_callbacks.proc_lookup	= basic_proc_lookup;
+	dummy_callbacks.proc_regsize	= dummy_proc_regsize;
+	dummy_callbacks.proc_getregs	= dummy_proc_getregs;
+	dummy_callbacks.proc_setregs	= dummy_proc_setregs;
+
+
+	for (i = 0; i < max_threads; i++) {
+		printf("Creating thread %zu\n", i);
+		PTHREAD_REQUIRE
+		    (pthread_create(&threads[i], NULL, busyFunction3, NULL));
+	}
+
+	printf("Calling td_open(3)\n");
+	ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
+
+	ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads3, &count) == TD_ERR_OK);
+
+	exiting3 = 1;
+
+	printf("Calling td_close(3)\n");
+	ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
+
+	ATF_REQUIRE_EQ_MSG(count, max_threads + 1,
+	    "counted threads (%d) != expected threads (%d)",
+	    count, max_threads + 1);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
 	ATF_TP_ADD_TC(tp, threads1);
+	ATF_TP_ADD_TC(tp, threads2);
+	ATF_TP_ADD_TC(tp, threads3);
 
 	return atf_no_error();
 }

Reply via email to