rtld-elf: add some tests for parse_integer()

Reviewed by:	des, dim
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D57549
This commit is contained in:
Konstantin Belousov
2026-06-13 03:51:53 +03:00
parent 4249a9bc09
commit 3eafe01884
2 changed files with 45 additions and 0 deletions
+10
View File
@@ -1,3 +1,5 @@
#include <src.opts.mk>
SUBDIR+= libpythagoras libdeep libval libval2 target SUBDIR+= libpythagoras libdeep libval libval2 target
TESTS_SUBDIRS+= rtld_deepbind TESTS_SUBDIRS+= rtld_deepbind
@@ -16,6 +18,14 @@ SRCS.$t= $t.c common.c
ATF_TESTS_C+= dlopen_test ATF_TESTS_C+= dlopen_test
ATF_TESTS_C+= dlopen_hash_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 WARNS?= 3
.include <bsd.test.mk> .include <bsd.test.mk>
@@ -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 <limits.h>
#include <atf-c.h>
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());
}