Module Name: src Committed By: kamil Date: Fri Nov 18 22:50:20 UTC 2016
Modified Files: src/distrib/sets/lists/debug: mi src/distrib/sets/lists/tests: mi src/tests/lib/libpthread_dbg: Makefile t_dummy.c Added Files: src/tests/lib/libpthread_dbg: h_common.h t_threads.c Log Message: Add new test file lib/libpthread_dbg/t_threads This test contains threads1 test that: Asserts that td_thr_iter() call without extra logic works This tests fails and is linked with gnats: PR lib/51635: td_thr_iter in <pthread_dbg.h> seems broken Sponsored by <The NetBSD Foundation> To generate a diff of this commit: cvs rdiff -u -r1.178 -r1.179 src/distrib/sets/lists/debug/mi cvs rdiff -u -r1.701 -r1.702 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread_dbg/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/libpthread_dbg/h_common.h \ src/tests/lib/libpthread_dbg/t_threads.c cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libpthread_dbg/t_dummy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/debug/mi diff -u src/distrib/sets/lists/debug/mi:1.178 src/distrib/sets/lists/debug/mi:1.179 --- src/distrib/sets/lists/debug/mi:1.178 Wed Nov 16 21:36:22 2016 +++ src/distrib/sets/lists/debug/mi Fri Nov 18 22:50:19 2016 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.178 2016/11/16 21:36:22 kamil Exp $ +# $NetBSD: mi,v 1.179 2016/11/18 22:50:19 kamil Exp $ ./etc/mtree/set.debug comp-sys-root ./usr/lib comp-sys-usr compatdir ./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib,compatfile @@ -2174,6 +2174,7 @@ ./usr/libdata/debug/usr/tests/lib/libpthread/t_swapcontext.debug tests-lib-tests debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libpthread/t_timedmutex.debug tests-lib-tests debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libpthread_dbg/t_dummy.debug tests-lib-tests debug,atf,compattestfile +./usr/libdata/debug/usr/tests/lib/libpthread_dbg/t_threads.debug tests-lib-tests debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/librt/t_sched.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/librt/t_sem.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/librefuse/t_refuse_opt.debug tests-lib-debug debug,atf,compattestfile Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.701 src/distrib/sets/lists/tests/mi:1.702 --- src/distrib/sets/lists/tests/mi:1.701 Wed Nov 16 21:36:23 2016 +++ src/distrib/sets/lists/tests/mi Fri Nov 18 22:50:19 2016 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.701 2016/11/16 21:36:23 kamil Exp $ +# $NetBSD: mi,v 1.702 2016/11/18 22:50:19 kamil Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -3020,6 +3020,7 @@ ./usr/tests/lib/libpthread_dbg/Atffile tests-lib-tests compattestfile,atf ./usr/tests/lib/libpthread_dbg/Kyuafile tests-lib-tests compattestfile,atf,kyua ./usr/tests/lib/libpthread_dbg/t_dummy tests-lib-tests compattestfile,atf +./usr/tests/lib/libpthread_dbg/t_threads tests-lib-tests compattestfile,atf ./usr/tests/lib/librt tests-lib-tests compattestfile,atf ./usr/tests/lib/librt/Atffile tests-lib-tests compattestfile,atf ./usr/tests/lib/librt/Kyuafile tests-lib-tests compattestfile,atf,kyua Index: src/tests/lib/libpthread_dbg/Makefile diff -u src/tests/lib/libpthread_dbg/Makefile:1.1 src/tests/lib/libpthread_dbg/Makefile:1.2 --- src/tests/lib/libpthread_dbg/Makefile:1.1 Wed Nov 16 21:36:23 2016 +++ src/tests/lib/libpthread_dbg/Makefile Fri Nov 18 22:50:19 2016 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.1 2016/11/16 21:36:23 kamil Exp $ +# $NetBSD: Makefile,v 1.2 2016/11/18 22:50:19 kamil Exp $ NOMAN= # defined @@ -9,5 +9,6 @@ LDADD+= -lpthread LDADD+= -lpthread_dbg TESTS_C+= t_dummy +TESTS_C+= t_threads .include <bsd.test.mk> Index: src/tests/lib/libpthread_dbg/t_dummy.c diff -u src/tests/lib/libpthread_dbg/t_dummy.c:1.4 src/tests/lib/libpthread_dbg/t_dummy.c:1.5 --- src/tests/lib/libpthread_dbg/t_dummy.c:1.4 Thu Nov 17 17:30:22 2016 +++ src/tests/lib/libpthread_dbg/t_dummy.c Fri Nov 18 22:50:19 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: t_dummy.c,v 1.4 2016/11/17 17:30:22 kamil Exp $ */ +/* $NetBSD: t_dummy.c,v 1.5 2016/11/18 22:50:19 kamil Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -28,91 +28,14 @@ #include <sys/cdefs.h> -__RCSID("$NetBSD: t_dummy.c,v 1.4 2016/11/17 17:30:22 kamil Exp $"); +__RCSID("$NetBSD: t_dummy.c,v 1.5 2016/11/18 22:50:19 kamil Exp $"); -#include <dlfcn.h> -#include <pthread.h> +#include "h_common.h" #include <pthread_dbg.h> #include <stdio.h> #include <atf-c.h> -static int -dummy_proc_read(void *arg, caddr_t addr, void *buf, size_t size) -{ - return TD_ERR_ERR; -} - -static int -dummy_proc_write(void *arg, caddr_t addr, void *buf, size_t size) -{ - return TD_ERR_ERR; -} - -static int -dummy_proc_lookup(void *arg, const char *sym, caddr_t *addr) -{ - return TD_ERR_ERR; -} - -static int -dummy_proc_regsize(void *arg, int regset, size_t *size) -{ - return TD_ERR_ERR; -} - -static int -dummy_proc_getregs(void *arg, int regset, int lwp, void *buf) -{ - return TD_ERR_ERR; -} - -static int -dummy_proc_setregs(void *arg, int regset, int lwp, void *buf) -{ - return TD_ERR_ERR; -} - -/* Minimalistic basic implementation */ - -static int -basic_proc_read(void *arg, caddr_t addr, void *buf, size_t size) -{ - memcpy(addr, buf, size); - - return TD_ERR_OK; -} - -static int -basic_proc_write(void *arg, caddr_t addr, void *buf, size_t size) -{ - memcpy(addr, buf, size); - - return TD_ERR_OK; -} - -static int -basic_proc_lookup(void *arg, const char *sym, caddr_t *addr) -{ - void *handle; - void *symbol; - - ATF_REQUIRE_MSG((handle = dlopen(NULL, RTLD_LOCAL | RTLD_LAZY)) - != NULL, "dlopen(3) failed: %s", dlerror()); - - symbol = dlsym(handle, sym); - - ATF_REQUIRE_MSG(dlclose(handle) == 0, "dlclose(3) failed: %s", - dlerror()); - - if (!symbol) - return TD_ERR_NOSYM; - - *addr = (caddr_t)(uintptr_t)symbol; - - return TD_ERR_OK; -} - ATF_TC(dummy1); ATF_TC_HEAD(dummy1, tc) Added files: Index: src/tests/lib/libpthread_dbg/h_common.h diff -u /dev/null src/tests/lib/libpthread_dbg/h_common.h:1.1 --- /dev/null Fri Nov 18 22:50:20 2016 +++ src/tests/lib/libpthread_dbg/h_common.h Fri Nov 18 22:50:19 2016 @@ -0,0 +1,128 @@ +/* $NetBSD: h_common.h,v 1.1 2016/11/18 22:50:19 kamil Exp $ */ + +/*- + * Copyright (c) 2016 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef H_COMMON_H +#define H_COMMON_H + +#include <sys/cdefs.h> +#include <dlfcn.h> +#include <pthread_dbg.h> +#include <string.h> + +#include <atf-c.h> + +#define PTHREAD_REQUIRE(x) \ + do { \ + int ret = (x); \ + ATF_REQUIRE_MSG(ret == 0, "%s: %s", #x, strerror(ret)); \ + } while (0) + +#define PTHREAD_REQUIRE_STATUS(x, v) \ + do { \ + int ret = (x); \ + ATF_REQUIRE_MSG(ret == (v), "%s: %s", #x, strerror(ret)); \ + } while (0) + +static int __used +dummy_proc_read(void *arg, caddr_t addr, void *buf, size_t size) +{ + return TD_ERR_ERR; +} + +static int __used +dummy_proc_write(void *arg, caddr_t addr, void *buf, size_t size) +{ + return TD_ERR_ERR; +} + +static int __used +dummy_proc_lookup(void *arg, const char *sym, caddr_t *addr) +{ + return TD_ERR_ERR; +} + +static int __used +dummy_proc_regsize(void *arg, int regset, size_t *size) +{ + return TD_ERR_ERR; +} + +static int __used +dummy_proc_getregs(void *arg, int regset, int lwp, void *buf) +{ + return TD_ERR_ERR; +} + +static int __used +dummy_proc_setregs(void *arg, int regset, int lwp, void *buf) +{ + return TD_ERR_ERR; +} + +/* Minimalistic basic implementation */ + +static int __used +basic_proc_read(void *arg, caddr_t addr, void *buf, size_t size) +{ + memcpy(addr, buf, size); + + return TD_ERR_OK; +} + +static int __used +basic_proc_write(void *arg, caddr_t addr, void *buf, size_t size) +{ + memcpy(addr, buf, size); + + return TD_ERR_OK; +} + +static int __used +basic_proc_lookup(void *arg, const char *sym, caddr_t *addr) +{ + void *handle; + void *symbol; + + ATF_REQUIRE_MSG((handle = dlopen(NULL, RTLD_LOCAL | RTLD_LAZY)) + != NULL, "dlopen(3) failed: %s", dlerror()); + + symbol = dlsym(handle, sym); + + ATF_REQUIRE_MSG(dlclose(handle) == 0, "dlclose(3) failed: %s", + dlerror()); + + if (!symbol) + return TD_ERR_NOSYM; + + *addr = (caddr_t)(uintptr_t)symbol; + + return TD_ERR_OK; +} + +#endif // H_COMMON_H Index: src/tests/lib/libpthread_dbg/t_threads.c diff -u /dev/null src/tests/lib/libpthread_dbg/t_threads.c:1.1 --- /dev/null Fri Nov 18 22:50:20 2016 +++ src/tests/lib/libpthread_dbg/t_threads.c Fri Nov 18 22:50:19 2016 @@ -0,0 +1,110 @@ +/* $NetBSD: t_threads.c,v 1.1 2016/11/18 22:50:19 kamil Exp $ */ + +/*- + * Copyright (c) 2016 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_threads.c,v 1.1 2016/11/18 22:50:19 kamil Exp $"); + +#include <dlfcn.h> +#include <pthread.h> +#include <pthread_dbg.h> +#include <stdio.h> + +#include <atf-c.h> + +#include "h_common.h" + +ATF_TC(threads1); +ATF_TC_HEAD(threads1, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that td_thr_iter() call without extra logic works"); +} + +static volatile int exiting; + +static void * +busyFunction1(void *arg) +{ + + while (exiting == 0) + usleep(50000); + + return NULL; +} + +static int +iterateThreads1(td_thread_t *thread, void *arg) +{ + + return TD_ERR_OK; +} + +ATF_TC_BODY(threads1, 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]; + + /* td_thr_iter in <pthread_dbg.h> seems broken */ + atf_tc_expect_fail("PR lib/51635"); + + 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, busyFunction1, 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, iterateThreads1, NULL) == TD_ERR_OK); + + exiting = 1; + + printf("Calling td_close(3)\n"); + ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, threads1); + + return atf_no_error(); +}