git: 3eafe0188410 - main - rtld-elf: add some tests for parse_integer()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 14 Jun 2026 01:02:35 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=3eafe0188410dcccb21c28a4c2e8f19c68861c76
commit 3eafe0188410dcccb21c28a4c2e8f19c68861c76
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-06-13 00:51:53 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-06-14 01:02:00 +0000
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
---
libexec/rtld-elf/tests/Makefile | 10 +++++++++
libexec/rtld-elf/tests/parse_integer_test.c | 35 +++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/libexec/rtld-elf/tests/Makefile b/libexec/rtld-elf/tests/Makefile
index 4fbc32d87615..b61cf67227bb 100644
--- a/libexec/rtld-elf/tests/Makefile
+++ b/libexec/rtld-elf/tests/Makefile
@@ -1,3 +1,5 @@
+#include <src.opts.mk>
+
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 <bsd.test.mk>
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 000000000000..9f99b02c7d3c
--- /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 <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());
+}