View | Details | Raw Unified | Return to bug 268521 | Differences between
and this patch

Collapse All | Expand All

(-)b/contrib/netbsd-tests/lib/libc/setjmp/t_setjmp.c (-8 / +47 lines)
Lines 1-4 Link Here
1
/* $NetBSD: t_setjmp.c,v 1.2 2017/01/14 21:08:17 christos Exp $ */
1
/* $NetBSD: t_setjmp.c,v 1.3 2021/03/21 16:36:32 christos Exp $ */
2
2
3
/*-
3
/*-
4
 * Copyright (c) 2008 The NetBSD Foundation, Inc.
4
 * Copyright (c) 2008 The NetBSD Foundation, Inc.
Lines 63-75 Link Here
63
#include <sys/cdefs.h>
63
#include <sys/cdefs.h>
64
__COPYRIGHT("@(#) Copyright (c) 2008\
64
__COPYRIGHT("@(#) Copyright (c) 2008\
65
 The NetBSD Foundation, inc. All rights reserved.");
65
 The NetBSD Foundation, inc. All rights reserved.");
66
__RCSID("$NetBSD: t_setjmp.c,v 1.2 2017/01/14 21:08:17 christos Exp $");
66
__RCSID("$NetBSD: t_setjmp.c,v 1.3 2021/03/21 16:36:32 christos Exp $");
67
67
68
#include <sys/types.h>
68
#include <sys/types.h>
69
69
70
#include <errno.h>
70
#include <errno.h>
71
#include <setjmp.h>
71
#include <setjmp.h>
72
#include <signal.h>
72
#include <signal.h>
73
#include <stdbool.h>
73
#include <stdio.h>
74
#include <stdio.h>
74
#include <stdlib.h>
75
#include <stdlib.h>
75
#include <string.h>
76
#include <string.h>
Lines 83-88 __RCSID("$NetBSD: t_setjmp.c,v 1.2 2017/01/14 21:08:17 christos Exp $"); Link Here
83
#define TEST_U_SETJMP 1
84
#define TEST_U_SETJMP 1
84
#define TEST_SIGSETJMP_SAVE 2
85
#define TEST_SIGSETJMP_SAVE 2
85
#define TEST_SIGSETJMP_NOSAVE 3
86
#define TEST_SIGSETJMP_NOSAVE 3
87
#define TEST_LONGJMP_ZERO 4
88
#define TEST_U_LONGJMP_ZERO 5
86
89
87
static int expectsignal;
90
static int expectsignal;
88
91
Lines 101-112 h_check(int test) Link Here
101
	sigjmp_buf sjb;
104
	sigjmp_buf sjb;
102
	sigset_t ss;
105
	sigset_t ss;
103
	int i, x;
106
	int i, x;
107
	volatile bool did_longjmp;
104
108
105
	i = getpid();
109
	i = getpid();
110
	did_longjmp = false;
106
111
107
	if (test == TEST_SETJMP || test == TEST_SIGSETJMP_SAVE)
112
	if (test == TEST_SETJMP || test == TEST_SIGSETJMP_SAVE ||
113
	    test == TEST_LONGJMP_ZERO)
108
		expectsignal = 0;
114
		expectsignal = 0;
109
	else if (test == TEST_U_SETJMP || test == TEST_SIGSETJMP_NOSAVE)
115
	else if (test == TEST_U_SETJMP || test == TEST_SIGSETJMP_NOSAVE ||
116
	    test == TEST_U_LONGJMP_ZERO)
110
		expectsignal = 1;
117
		expectsignal = 1;
111
	else
118
	else
112
		atf_tc_fail("unknown test");
119
		atf_tc_fail("unknown test");
Lines 119-144 h_check(int test) Link Here
119
	REQUIRE_ERRNO(sigaddset(&ss, SIGABRT) != -1);
126
	REQUIRE_ERRNO(sigaddset(&ss, SIGABRT) != -1);
120
	REQUIRE_ERRNO(sigprocmask(SIG_BLOCK, &ss, NULL) != -1);
127
	REQUIRE_ERRNO(sigprocmask(SIG_BLOCK, &ss, NULL) != -1);
121
128
122
	if (test == TEST_SETJMP)
129
	if (test == TEST_SETJMP || test == TEST_LONGJMP_ZERO)
123
		x = setjmp(jb);
130
		x = setjmp(jb);
124
	else if (test == TEST_U_SETJMP)
131
	else if (test == TEST_U_SETJMP || test == TEST_U_LONGJMP_ZERO)
125
		x = _setjmp(jb);
132
		x = _setjmp(jb);
126
	else 
133
	else 
127
		x = sigsetjmp(sjb, !expectsignal);
134
		x = sigsetjmp(sjb, !expectsignal);
128
135
129
	if (x != 0) {
136
	if (x != 0) {
130
		ATF_REQUIRE_MSG(x == i, "setjmp returned wrong value");
137
		if (test == TEST_LONGJMP_ZERO || test == TEST_U_LONGJMP_ZERO)
138
			ATF_REQUIRE_MSG(x == 1, "setjmp returned wrong value");
139
		else
140
			ATF_REQUIRE_MSG(x == i, "setjmp returned wrong value");
141
131
		kill(i, SIGABRT);
142
		kill(i, SIGABRT);
132
		ATF_REQUIRE_MSG(!expectsignal, "kill(SIGABRT) failed");
143
		ATF_REQUIRE_MSG(!expectsignal, "kill(SIGABRT) failed");
133
		atf_tc_pass();
144
		atf_tc_pass();
145
	} else if (did_longjmp) {
146
		atf_tc_fail("setjmp returned zero after longjmp");
134
	}
147
	}
135
148
136
	REQUIRE_ERRNO(sigprocmask(SIG_UNBLOCK, &ss, NULL) != -1);
149
	REQUIRE_ERRNO(sigprocmask(SIG_UNBLOCK, &ss, NULL) != -1);
137
150
151
	did_longjmp = true;
138
	if (test == TEST_SETJMP)
152
	if (test == TEST_SETJMP)
139
		longjmp(jb, i);
153
		longjmp(jb, i);
154
	else if (test == TEST_LONGJMP_ZERO)
155
		longjmp(jb, 0);
140
	else if (test == TEST_U_SETJMP)
156
	else if (test == TEST_U_SETJMP)
141
		_longjmp(jb, i);
157
		_longjmp(jb, i);
158
	else if (test == TEST_U_LONGJMP_ZERO)
159
		_longjmp(jb, 0);
142
	else 
160
	else 
143
		siglongjmp(sjb, i);
161
		siglongjmp(sjb, i);
144
162
Lines 185-196 ATF_TC_BODY(sigsetjmp_nosave, tc) Link Here
185
	h_check(TEST_SIGSETJMP_NOSAVE);
203
	h_check(TEST_SIGSETJMP_NOSAVE);
186
}
204
}
187
205
206
ATF_TC(longjmp_zero);
207
ATF_TC_HEAD(longjmp_zero, tc)
208
{
209
	atf_tc_set_md_var(tc, "descr", "Checks longjmp(3) with a zero value");
210
}
211
ATF_TC_BODY(longjmp_zero, tc)
212
{
213
	h_check(TEST_LONGJMP_ZERO);
214
}
215
216
ATF_TC(_longjmp_zero);
217
ATF_TC_HEAD(_longjmp_zero, tc)
218
{
219
	atf_tc_set_md_var(tc, "descr", "Checks _longjmp(3) with a zero value");
220
}
221
ATF_TC_BODY(_longjmp_zero, tc)
222
{
223
	h_check(TEST_U_LONGJMP_ZERO);
224
}
225
188
ATF_TP_ADD_TCS(tp)
226
ATF_TP_ADD_TCS(tp)
189
{
227
{
190
	ATF_TP_ADD_TC(tp, setjmp);
228
	ATF_TP_ADD_TC(tp, setjmp);
191
	ATF_TP_ADD_TC(tp, _setjmp);
229
	ATF_TP_ADD_TC(tp, _setjmp);
192
	ATF_TP_ADD_TC(tp, sigsetjmp_save);
230
	ATF_TP_ADD_TC(tp, sigsetjmp_save);
193
	ATF_TP_ADD_TC(tp, sigsetjmp_nosave);
231
	ATF_TP_ADD_TC(tp, sigsetjmp_nosave);
232
	ATF_TP_ADD_TC(tp, longjmp_zero);
233
	ATF_TP_ADD_TC(tp, _longjmp_zero);
194
234
195
	return atf_no_error();
235
	return atf_no_error();
196
}
236
}
197
- 

Return to bug 268521