The branch main has been updated by bapt:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=8093646b0be9731f24eddbcee7dc34e1fd2365b5

commit 8093646b0be9731f24eddbcee7dc34e1fd2365b5
Author:     Baptiste Daroussin <b...@freebsd.org>
AuthorDate: 2023-06-01 21:26:57 +0000
Commit:     Baptiste Daroussin <b...@freebsd.org>
CommitDate: 2023-06-01 21:27:45 +0000

    cpuset(3): Add unit tests
    
    Differential Revision:  https://reviews.freebsd.org/D13046
---
 lib/libutil/tests/Makefile      |  1 +
 lib/libutil/tests/cpuset_test.c | 73 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/lib/libutil/tests/Makefile b/lib/libutil/tests/Makefile
index 5414042762af..fc9a871dd8bc 100644
--- a/lib/libutil/tests/Makefile
+++ b/lib/libutil/tests/Makefile
@@ -6,6 +6,7 @@ TAP_TESTS_C+=   humanize_number_test
 TAP_TESTS_C+=  pidfile_test
 TAP_TESTS_C+=  trimdomain_test
 TAP_TESTS_C+=  trimdomain-nodomain_test
+ATF_TESTS_C+=  cpuset_test
 
 WARNS?=                2
 LIBADD+=       util
diff --git a/lib/libutil/tests/cpuset_test.c b/lib/libutil/tests/cpuset_test.c
new file mode 100644
index 000000000000..ea8eb8d83743
--- /dev/null
+++ b/lib/libutil/tests/cpuset_test.c
@@ -0,0 +1,73 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/cpuset.h>
+
+#include <stdio.h>
+#include <libutil.h>
+#include <atf-c.h>
+
+ATF_TC(invalid);
+ATF_TC_HEAD(invalid, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test invalid cpu");
+}
+
+ATF_TC_BODY(invalid, tc)
+{
+       cpuset_t mask;
+       char testvalue[BUFSIZ];
+
+       snprintf(testvalue, sizeof(testvalue), "%d", CPU_SETSIZE + 1);
+
+       ATF_CHECK_EQ(cpuset_parselist(testvalue,  &mask), 
CPUSET_PARSE_INVALID_CPU);
+}
+
+ATF_TC(invalidchar);
+ATF_TC_HEAD(invalidchar, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test invalid char");
+}
+
+ATF_TC_BODY(invalidchar, tc)
+{
+       cpuset_t mask;
+
+       ATF_CHECK_EQ(cpuset_parselist("1+3",  &mask), CPUSET_PARSE_ERROR);
+}
+
+ATF_TC(all);
+ATF_TC_HEAD(all, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test 'all' special cpu-list");
+}
+
+ATF_TC_BODY(all, tc)
+{
+       cpuset_t mask;
+
+       ATF_CHECK_EQ(cpuset_parselist("all",  &mask), CPUSET_PARSE_OK);
+}
+
+ATF_TC(normalsyntax);
+ATF_TC_HEAD(normalsyntax, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test normal cpu-list syntax");
+}
+
+ATF_TC_BODY(normalsyntax, tc)
+{
+       cpuset_t mask;
+
+       ATF_CHECK_EQ(cpuset_parselist("1-3,6",  &mask), CPUSET_PARSE_OK);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+       ATF_TP_ADD_TC(tp, invalid);
+       ATF_TP_ADD_TC(tp, invalidchar);
+       ATF_TP_ADD_TC(tp, all);
+       ATF_TP_ADD_TC(tp, normalsyntax);
+       return (atf_no_error());
+}

Reply via email to