Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libc/setjmp PR/56066: Jessica Clarke: Add tests fo...
details: https://anonhg.NetBSD.org/src/rev/dc1db146d9d9
branches: trunk
changeset: 960581:dc1db146d9d9
user: christos <christos%NetBSD.org@localhost>
date: Sun Mar 21 16:36:32 2021 +0000
description:
PR/56066: Jessica Clarke: Add tests for calling {_,}longjmp with a zero value.
diffstat:
tests/lib/libc/setjmp/t_setjmp.c | 54 ++++++++++++++++++++++++++++++++++-----
1 files changed, 47 insertions(+), 7 deletions(-)
diffs (129 lines):
diff -r 83654d01fc63 -r dc1db146d9d9 tests/lib/libc/setjmp/t_setjmp.c
--- a/tests/lib/libc/setjmp/t_setjmp.c Sun Mar 21 16:21:35 2021 +0000
+++ b/tests/lib/libc/setjmp/t_setjmp.c Sun Mar 21 16:36:32 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_setjmp.c,v 1.2 2017/01/14 21:08:17 christos Exp $ */
+/* $NetBSD: t_setjmp.c,v 1.3 2021/03/21 16:36:32 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -63,13 +63,14 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_setjmp.c,v 1.2 2017/01/14 21:08:17 christos Exp $");
+__RCSID("$NetBSD: t_setjmp.c,v 1.3 2021/03/21 16:36:32 christos Exp $");
#include <sys/types.h>
#include <errno.h>
#include <setjmp.h>
#include <signal.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -83,6 +84,8 @@
#define TEST_U_SETJMP 1
#define TEST_SIGSETJMP_SAVE 2
#define TEST_SIGSETJMP_NOSAVE 3
+#define TEST_LONGJMP_ZERO 4
+#define TEST_U_LONGJMP_ZERO 5
static int expectsignal;
@@ -101,12 +104,16 @@
sigjmp_buf sjb;
sigset_t ss;
int i, x;
+ volatile bool did_longjmp;
i = getpid();
+ did_longjmp = false;
- if (test == TEST_SETJMP || test == TEST_SIGSETJMP_SAVE)
+ if (test == TEST_SETJMP || test == TEST_SIGSETJMP_SAVE ||
+ test == TEST_LONGJMP_ZERO)
expectsignal = 0;
- else if (test == TEST_U_SETJMP || test == TEST_SIGSETJMP_NOSAVE)
+ else if (test == TEST_U_SETJMP || test == TEST_SIGSETJMP_NOSAVE ||
+ test == TEST_U_LONGJMP_ZERO)
expectsignal = 1;
else
atf_tc_fail("unknown test");
@@ -119,26 +126,37 @@
REQUIRE_ERRNO(sigaddset(&ss, SIGABRT) != -1);
REQUIRE_ERRNO(sigprocmask(SIG_BLOCK, &ss, NULL) != -1);
- if (test == TEST_SETJMP)
+ if (test == TEST_SETJMP || test == TEST_LONGJMP_ZERO)
x = setjmp(jb);
- else if (test == TEST_U_SETJMP)
+ else if (test == TEST_U_SETJMP || test == TEST_U_LONGJMP_ZERO)
x = _setjmp(jb);
else
x = sigsetjmp(sjb, !expectsignal);
if (x != 0) {
- ATF_REQUIRE_MSG(x == i, "setjmp returned wrong value");
+ if (test == TEST_LONGJMP_ZERO || test == TEST_U_LONGJMP_ZERO)
+ ATF_REQUIRE_MSG(x == 1, "setjmp returned wrong value");
+ else
+ ATF_REQUIRE_MSG(x == i, "setjmp returned wrong value");
+
kill(i, SIGABRT);
ATF_REQUIRE_MSG(!expectsignal, "kill(SIGABRT) failed");
atf_tc_pass();
+ } else if (did_longjmp) {
+ atf_tc_fail("setjmp returned zero after longjmp");
}
REQUIRE_ERRNO(sigprocmask(SIG_UNBLOCK, &ss, NULL) != -1);
+ did_longjmp = true;
if (test == TEST_SETJMP)
longjmp(jb, i);
+ else if (test == TEST_LONGJMP_ZERO)
+ longjmp(jb, 0);
else if (test == TEST_U_SETJMP)
_longjmp(jb, i);
+ else if (test == TEST_U_LONGJMP_ZERO)
+ _longjmp(jb, 0);
else
siglongjmp(sjb, i);
@@ -185,12 +203,34 @@
h_check(TEST_SIGSETJMP_NOSAVE);
}
+ATF_TC(longjmp_zero);
+ATF_TC_HEAD(longjmp_zero, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks longjmp(3) with a zero value");
+}
+ATF_TC_BODY(longjmp_zero, tc)
+{
+ h_check(TEST_LONGJMP_ZERO);
+}
+
+ATF_TC(_longjmp_zero);
+ATF_TC_HEAD(_longjmp_zero, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks _longjmp(3) with a zero value");
+}
+ATF_TC_BODY(_longjmp_zero, tc)
+{
+ h_check(TEST_U_LONGJMP_ZERO);
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, setjmp);
ATF_TP_ADD_TC(tp, _setjmp);
ATF_TP_ADD_TC(tp, sigsetjmp_save);
ATF_TP_ADD_TC(tp, sigsetjmp_nosave);
+ ATF_TP_ADD_TC(tp, longjmp_zero);
+ ATF_TP_ADD_TC(tp, _longjmp_zero);
return atf_no_error();
}
Home |
Main Index |
Thread Index |
Old Index