xref: /freebsd/contrib/netbsd-tests/lib/libpthread_dbg/t_dummy.c (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
1 /*	$NetBSD: t_dummy.c,v 1.6 2016/11/19 15:13:46 kamil Exp $	*/
2 
3 /*-
4  * Copyright (c) 2016 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #include <sys/cdefs.h>
31 __RCSID("$NetBSD: t_dummy.c,v 1.6 2016/11/19 15:13:46 kamil Exp $");
32 
33 #include "h_common.h"
34 #include <pthread_dbg.h>
35 #include <stdio.h>
36 
37 #include <atf-c.h>
38 
39 
40 ATF_TC(dummy1);
41 ATF_TC_HEAD(dummy1, tc)
42 {
43 
44 	atf_tc_set_md_var(tc, "descr",
45 	    "Asserts that dummy lookup functions stop td_open() with failure");
46 }
47 
48 ATF_TC_BODY(dummy1, tc)
49 {
50 
51 	struct td_proc_callbacks_t dummy_callbacks;
52 	td_proc_t *main_ta;
53 
54 	dummy_callbacks.proc_read	= dummy_proc_read;
55 	dummy_callbacks.proc_write	= dummy_proc_write;
56 	dummy_callbacks.proc_lookup	= dummy_proc_lookup;
57 	dummy_callbacks.proc_regsize	= dummy_proc_regsize;
58 	dummy_callbacks.proc_getregs	= dummy_proc_getregs;
59 	dummy_callbacks.proc_setregs	= dummy_proc_setregs;
60 
61 	ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_ERR);
62 }
63 
64 ATF_TC(dummy2);
65 ATF_TC_HEAD(dummy2, tc)
66 {
67 
68 	atf_tc_set_md_var(tc, "descr",
69 	    "Asserts that td_open() for basic proc_{read,write,lookup} works");
70 }
71 
72 ATF_TC_BODY(dummy2, tc)
73 {
74 	struct td_proc_callbacks_t dummy_callbacks;
75 	td_proc_t *main_ta;
76 
77 	dummy_callbacks.proc_read	= basic_proc_read;
78 	dummy_callbacks.proc_write	= basic_proc_write;
79 	dummy_callbacks.proc_lookup	= basic_proc_lookup;
80 	dummy_callbacks.proc_regsize	= dummy_proc_regsize;
81 	dummy_callbacks.proc_getregs	= dummy_proc_getregs;
82 	dummy_callbacks.proc_setregs	= dummy_proc_setregs;
83 
84 	printf("Calling td_open(3)\n");
85 	ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
86 
87 	printf("Calling td_close(3)\n");
88 	ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
89 }
90 
91 ATF_TC(dummy3);
92 ATF_TC_HEAD(dummy3, tc)
93 {
94 
95 	atf_tc_set_md_var(tc, "descr",
96 	    "Asserts that calling twice td_open() for the same process fails");
97 }
98 
99 ATF_TC_BODY(dummy3, tc)
100 {
101 	struct td_proc_callbacks_t dummy_callbacks;
102 	td_proc_t *main_ta1;
103 	td_proc_t *main_ta2;
104 
105 	dummy_callbacks.proc_read	= basic_proc_read;
106 	dummy_callbacks.proc_write	= basic_proc_write;
107 	dummy_callbacks.proc_lookup	= basic_proc_lookup;
108 	dummy_callbacks.proc_regsize	= dummy_proc_regsize;
109 	dummy_callbacks.proc_getregs	= dummy_proc_getregs;
110 	dummy_callbacks.proc_setregs	= dummy_proc_setregs;
111 
112 	printf("Calling td_open(3) for the first time - expecting success\n");
113 	ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta1) == TD_ERR_OK);
114 
115 	printf("Calling td_open(3) for the first time - expecting in-use\n");
116 	ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta2) ==
117 	    TD_ERR_INUSE);
118 
119 	printf("Calling td_close(3) for the first successful call\n");
120 	ATF_REQUIRE(td_close(main_ta1) == TD_ERR_OK);
121 }
122 
123 ATF_TP_ADD_TCS(tp)
124 {
125 
126 	ATF_TP_ADD_TC(tp, dummy1);
127 	ATF_TP_ADD_TC(tp, dummy2);
128 	ATF_TP_ADD_TC(tp, dummy3);
129 
130 	return atf_no_error();
131 }
132