diff --git a/libexec/rtld-elf/tests/Makefile b/libexec/rtld-elf/tests/Makefile index 4fbc32d8761..b61cf67227b 100644 --- a/libexec/rtld-elf/tests/Makefile +++ b/libexec/rtld-elf/tests/Makefile @@ -1,3 +1,5 @@ +#include + SUBDIR+= libpythagoras libdeep libval libval2 target TESTS_SUBDIRS+= rtld_deepbind @@ -16,6 +18,14 @@ SRCS.$t= $t.c common.c ATF_TESTS_C+= dlopen_test ATF_TESTS_C+= dlopen_hash_test +ATF_TESTS_C+= parse_integer_test +parse_integer_test.c: parse_integer_func.c +CFLAGS.parse_integer_test.c+= -I${.OBJDIR} +parse_integer_func.c: ${SRCTOP}/libexec/rtld-elf/rtld.c + sed -ne '/^parse_integer/,/^\}/p' ${SRCTOP}/libexec/rtld-elf/rtld.c \ + >parse_integer_func.c +CLEANFILES+= parse_integer_func.c + WARNS?= 3 .include diff --git a/libexec/rtld-elf/tests/parse_integer_test.c b/libexec/rtld-elf/tests/parse_integer_test.c new file mode 100644 index 00000000000..9f99b02c7d3 --- /dev/null +++ b/libexec/rtld-elf/tests/parse_integer_test.c @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2026 The FreeBSD Foundation + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + */ + +#include +#include + +static int +#include "parse_integer_func.c" + +ATF_TC_WITHOUT_HEAD(integers); +ATF_TC_BODY(integers, tc) +{ + ATF_REQUIRE_EQ(parse_integer("0"), 0); + ATF_REQUIRE_EQ(parse_integer("10"), 10); + ATF_REQUIRE_EQ(parse_integer("10001"), 10001); + ATF_REQUIRE_EQ(parse_integer("0b101"), 0b101); + ATF_REQUIRE_EQ(parse_integer("0x10"), 0x10); + ATF_REQUIRE_EQ(parse_integer("020"), 020); + ATF_REQUIRE_EQ(parse_integer("090"), -1); + /* This test assumes some value for INT_MAX */ + ATF_REQUIRE_EQ(parse_integer("1111111111111111111111111111"), -1); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, integers); + return (atf_no_error()); +}