The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b5c04c8f96f6b51edb767e37aba0ea13b172723a
commit b5c04c8f96f6b51edb767e37aba0ea13b172723a Author: Mark Johnston <ma...@freebsd.org> AuthorDate: 2025-06-23 23:54:30 +0000 Commit: Mark Johnston <ma...@freebsd.org> CommitDate: 2025-06-24 01:24:04 +0000 csu/tests: Add tests to verify that errno == 0 upon program startup Reviewed by: kib, kevans Differential Revision: https://reviews.freebsd.org/D50998 --- etc/mtree/BSD.tests.dist | 2 ++ lib/csu/tests/Makefile | 1 + lib/csu/tests/errno/Makefile | 18 ++++++++++++++++++ lib/csu/tests/errno/errno_test.c | 23 +++++++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 7d21dcbd2cbf..183c88038742 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -318,6 +318,8 @@ .. dynamicpie .. + errno + .. static .. .. diff --git a/lib/csu/tests/Makefile b/lib/csu/tests/Makefile index c9a0e6eff5da..b76ef590c88f 100644 --- a/lib/csu/tests/Makefile +++ b/lib/csu/tests/Makefile @@ -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 diff --git a/lib/csu/tests/errno/Makefile b/lib/csu/tests/errno/Makefile new file mode 100644 index 000000000000..eae54a936294 --- /dev/null +++ b/lib/csu/tests/errno/Makefile @@ -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> diff --git a/lib/csu/tests/errno/errno_test.c b/lib/csu/tests/errno/errno_test.c new file mode 100644 index 000000000000..d190c7fd2959 --- /dev/null +++ b/lib/csu/tests/errno/errno_test.c @@ -0,0 +1,23 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2025 Mark Johnston <ma...@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); +}