1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-20 11:11:24 +00:00

cpuset(3): Add unit tests

Differential Revision:	https://reviews.freebsd.org/D13046
This commit is contained in:
Baptiste Daroussin 2023-06-01 23:26:57 +02:00
parent aee3ee66a1
commit 8093646b0b
2 changed files with 74 additions and 0 deletions

View File

@ -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

View File

@ -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());
}