1 #include <sys/cdefs.h>
2 #include <sys/types.h>
3 #include <sys/cpuset.h>
4
5 #include <stdio.h>
6 #include <libutil.h>
7 #include <atf-c.h>
8
9 ATF_TC(invalid);
ATF_TC_HEAD(invalid,tc)10 ATF_TC_HEAD(invalid, tc)
11 {
12 atf_tc_set_md_var(tc, "descr", "Test invalid cpu");
13 }
14
ATF_TC_BODY(invalid,tc)15 ATF_TC_BODY(invalid, tc)
16 {
17 cpuset_t mask;
18 char testvalue[BUFSIZ];
19
20 snprintf(testvalue, sizeof(testvalue), "%d", CPU_SETSIZE + 1);
21
22 ATF_CHECK_EQ(cpuset_parselist(testvalue, &mask), CPUSET_PARSE_INVALID_CPU);
23 }
24
25 ATF_TC(invalidchar);
ATF_TC_HEAD(invalidchar,tc)26 ATF_TC_HEAD(invalidchar, tc)
27 {
28 atf_tc_set_md_var(tc, "descr", "Test invalid char");
29 }
30
ATF_TC_BODY(invalidchar,tc)31 ATF_TC_BODY(invalidchar, tc)
32 {
33 cpuset_t mask;
34
35 ATF_CHECK_EQ(cpuset_parselist("1+3", &mask), CPUSET_PARSE_ERROR);
36 }
37
38 ATF_TC(all);
ATF_TC_HEAD(all,tc)39 ATF_TC_HEAD(all, tc)
40 {
41 atf_tc_set_md_var(tc, "descr", "Test 'all' special cpu-list");
42 }
43
ATF_TC_BODY(all,tc)44 ATF_TC_BODY(all, tc)
45 {
46 cpuset_t mask;
47
48 ATF_CHECK_EQ(cpuset_parselist("all", &mask), CPUSET_PARSE_OK);
49 }
50
51 ATF_TC(normalsyntax);
ATF_TC_HEAD(normalsyntax,tc)52 ATF_TC_HEAD(normalsyntax, tc)
53 {
54 atf_tc_set_md_var(tc, "descr", "Test normal cpu-list syntax");
55 }
56
ATF_TC_BODY(normalsyntax,tc)57 ATF_TC_BODY(normalsyntax, tc)
58 {
59 cpuset_t mask;
60
61 ATF_CHECK_EQ(cpuset_parselist("1-3,6", &mask), CPUSET_PARSE_OK);
62 }
63
ATF_TP_ADD_TCS(tp)64 ATF_TP_ADD_TCS(tp)
65 {
66 ATF_TP_ADD_TC(tp, invalid);
67 ATF_TP_ADD_TC(tp, invalidchar);
68 ATF_TP_ADD_TC(tp, all);
69 ATF_TP_ADD_TC(tp, normalsyntax);
70 return (atf_no_error());
71 }
72