From 4fbb9c43aa44d9145151bb5f77d302ba01fb7551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Thu, 7 Sep 2023 06:14:59 +0000 Subject: [PATCH] include: Add tests for N2867. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D41735 --- etc/mtree/BSD.tests.dist | 2 ++ tests/Makefile | 1 + tests/include/Makefile | 7 +++++ tests/include/stdckdint_test.c | 52 ++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 tests/include/Makefile create mode 100644 tests/include/stdckdint_test.c diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index fb755b4001ac..04dc24d772c8 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -278,6 +278,8 @@ .. .. .. + include + .. lib atf libatf-c diff --git a/tests/Makefile b/tests/Makefile index bd20d063ca71..09c0fbc62a2e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -9,6 +9,7 @@ KYUAFILE= yes SUBDIR+= etc SUBDIR+= examples +SUBDIR+= include SUBDIR+= sys SUBDIR+= atf_python diff --git a/tests/include/Makefile b/tests/include/Makefile new file mode 100644 index 000000000000..e98d08da1f2b --- /dev/null +++ b/tests/include/Makefile @@ -0,0 +1,7 @@ +.include + +TESTSDIR= ${TESTSBASE}/include + +ATF_TESTS_C+= stdckdint_test + +.include diff --git a/tests/include/stdckdint_test.c b/tests/include/stdckdint_test.c new file mode 100644 index 000000000000..89262bbd5500 --- /dev/null +++ b/tests/include/stdckdint_test.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2023 Dag-Erling Smørgrav + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +#include + +ATF_TC_WITHOUT_HEAD(ckd_add); +ATF_TC_BODY(ckd_add, tc) +{ + int result; + + ATF_CHECK(!ckd_add(&result, INT_MAX, 0)); + ATF_CHECK_EQ(INT_MAX, result); + ATF_CHECK(ckd_add(&result, INT_MAX, 1)); + ATF_CHECK_EQ(INT_MIN, result); +} + +ATF_TC_WITHOUT_HEAD(ckd_sub); +ATF_TC_BODY(ckd_sub, tc) +{ + int result; + + ATF_CHECK(!ckd_sub(&result, INT_MIN, 0)); + ATF_CHECK_EQ(INT_MIN, result); + ATF_CHECK(ckd_sub(&result, INT_MIN, 1)); + ATF_CHECK_EQ(INT_MAX, result); +} + +ATF_TC_WITHOUT_HEAD(ckd_mul); +ATF_TC_BODY(ckd_mul, tc) +{ + int result; + + ATF_CHECK(!ckd_mul(&result, INT_MAX / 2, 2)); + ATF_CHECK_EQ(INT_MAX - 1, result); + ATF_CHECK(ckd_mul(&result, INT_MAX / 2 + 1, 2)); + ATF_CHECK_EQ(INT_MIN, result); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, ckd_add); + ATF_TP_ADD_TC(tp, ckd_sub); + ATF_TP_ADD_TC(tp, ckd_mul); + return (atf_no_error()); + +}