csu/tests: Add tests to verify that errno == 0 upon program startup

Reviewed by:	kib, kevans
Differential Revision:	https://reviews.freebsd.org/D50998
This commit is contained in:
Mark Johnston 2025-06-23 23:54:30 +00:00
parent 09c9cab2c2
commit b5c04c8f96
4 changed files with 44 additions and 0 deletions

View file

@ -318,6 +318,8 @@
..
dynamicpie
..
errno
..
static
..
..

View file

@ -4,6 +4,7 @@ SUBDIR= dso
TESTS_SUBDIRS= dynamic
TESTS_SUBDIRS+= dynamiclib
TESTS_SUBDIRS+= dynamicpie
TESTS_SUBDIRS+= errno
TESTS_SUBDIRS+= static
SUBDIR_DEPEND_dynamiclib=dso

View file

@ -0,0 +1,18 @@
PLAIN_TESTS_C= errno_test \
errno_static_test \
errno_thr_test \
errno_thr_static_test
SRCS.errno_static_test= errno_test.c
LDFLAGS.errno_static_test= -static
SRCS.errno_thr_test= errno_test.c
LIBADD.errno_thr_test= pthread
SRCS.errno_thr_static_test= errno_test.c
LDFLAGS.errno_thr_static_test= -static
LIBADD.errno_thr_static_test= pthread
MK_PIE:= no
.include <bsd.test.mk>

View file

@ -0,0 +1,23 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2025 Mark Johnston <markj@FreeBSD.org>
*/
#include <errno.h>
#include <stdlib.h>
static void __attribute__((constructor))
f(void)
{
errno = 42;
}
int
main(void)
{
/* errno must be zero upon program startup. */
if (errno != 0)
exit(1);
exit(0);
}