Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libpthread_dbg Add threads2 and threads3 in tests/...



details:   https://anonhg.NetBSD.org/src/rev/1b5565d09f5f
branches:  trunk
changeset: 819160:1b5565d09f5f
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sun Nov 20 16:13:03 2016 +0000

description:
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>

diffstat:

 tests/lib/libpthread_dbg/t_threads.c |  155 +++++++++++++++++++++++++++++++++-
 1 files changed, 150 insertions(+), 5 deletions(-)

diffs (202 lines):

diff -r 576a5349c2f7 -r 1b5565d09f5f tests/lib/libpthread_dbg/t_threads.c
--- a/tests/lib/libpthread_dbg/t_threads.c      Sun Nov 20 15:55:31 2016 +0000
+++ b/tests/lib/libpthread_dbg/t_threads.c      Sun Nov 20 16:13:03 2016 +0000
@@ -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 @@
            "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_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();
 }



Home | Main Index | Thread Index | Old Index