3 // Copyright (C) 2004 Enrico Scholz <ensc@delenn.intern.sigma-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "lib_internal/coreassert.h"
30 #define TEST_T2F_C(X,Y,Z) assert(vc_text2cflag_compat(X,Y)==Z)
31 #define TEST_F2T_C(Y,X) { \
32 char const *x=vc_hicflag2text_compat(X); \
33 assert((x==0 && Y==0) || (x!=0 && Y!=0)); \
34 if (x!=0 && Y!=0) assert(strcmp(x, Y ? Y : "")==0); \
37 #define TEST_LIST_C(STR,LEN,EXP,ERR_POS,ERR_LEN) { \
38 struct vc_err_listparser err; \
41 res = vc_list2cflag_compat(buf, LEN, &err); \
43 assert(err.len==ERR_LEN); \
44 if (ERR_POS==-1) assert(err.ptr==0); \
45 else assert(err.ptr==buf+(ERR_POS)); \
50 #define TEST_T2F(X,Y,Z) assert(vc_text2cflag(X,Y)==Z)
51 #define TEST_F2T(Y,X) { \
52 uint_least64_t x = (X); \
53 char const *rc=vc_locflag2text(&x); \
54 assert((rc==0 && Y==0) || (rc!=0 && Y!=0)); \
55 if (rc!=0 && Y!=0) assert(strcmp(rc, Y ? Y : "")==0); \
57 #define TEST_LIST(STR,LEN,EXP_RES,EXP_FLAG,EXP_MASK,ERR_POS,ERR_LEN) { \
58 struct vc_err_listparser err; \
61 struct vc_ctx_flags flags = {0,0}; \
62 res = vc_list2cflag(buf, LEN, &err, &flags); \
63 assert(res==(EXP_RES)); \
64 assert(flags.flagword==(uint_least64_t)(EXP_FLAG)); \
65 assert(flags.mask ==(uint_least64_t)(EXP_MASK)); \
66 assert(err.len==ERR_LEN); \
67 if (ERR_POS==-1) assert(err.ptr==0); \
68 else assert(err.ptr==buf+(ERR_POS)); \
71 #define ALL64 (~(uint_least64_t)(0))
75 TEST_T2F_C("lock", 0, S_CTX_INFO_LOCK);
76 TEST_T2F_C("lockXXXX", 4, S_CTX_INFO_LOCK);
77 TEST_T2F_C("locXXXXX", 3, 0);
78 TEST_T2F_C("sched", 0, S_CTX_INFO_SCHED);
79 TEST_T2F_C("nproc", 0, S_CTX_INFO_NPROC);
80 TEST_T2F_C("private", 0, S_CTX_INFO_PRIVATE);
81 TEST_T2F_C("fakeinit", 0, S_CTX_INFO_INIT);
82 TEST_T2F_C("hideinfo", 0, S_CTX_INFO_HIDEINFO);
83 TEST_T2F_C("ulimit", 0, S_CTX_INFO_ULIMIT);
84 TEST_T2F_C("XXX", 0, 0);
87 TEST_F2T_C("lock", S_CTX_INFO_LOCK);
88 TEST_F2T_C("sched", S_CTX_INFO_SCHED);
89 TEST_F2T_C("nproc", S_CTX_INFO_NPROC);
90 TEST_F2T_C("private", S_CTX_INFO_PRIVATE);
91 TEST_F2T_C("fakeinit", S_CTX_INFO_INIT);
92 TEST_F2T_C("hideinfo", S_CTX_INFO_HIDEINFO);
93 TEST_F2T_C("ulimit", S_CTX_INFO_ULIMIT);
95 TEST_F2T_C("ulimit", 64 | 128 | 23 );
96 TEST_F2T_C("fakeinit", 23);
98 TEST_LIST_C("lock", 0, S_CTX_INFO_LOCK, -1,0);
99 TEST_LIST_C("lock,sched,", 0, S_CTX_INFO_LOCK|S_CTX_INFO_SCHED, -1,0);
100 TEST_LIST_C("lock,XXX", 0, S_CTX_INFO_LOCK, 5,3);
101 TEST_LIST_C("", 0, 0, -1,0);
102 TEST_LIST_C("X", 0, 0, 0,1);
103 TEST_LIST_C("lock,sched,", 10, S_CTX_INFO_LOCK|S_CTX_INFO_SCHED, -1,0);
107 TEST_T2F("fakeinit", 0, VC_VXF_INFO_INIT);
108 TEST_T2F("XXX", 0, 0);
111 TEST_F2T("fakeinit", VC_VXF_INFO_INIT);
114 TEST_LIST("fakeinit", 0, 0, VC_VXF_INFO_INIT, VC_VXF_INFO_INIT,-1,0);
115 TEST_LIST("FaKeInIt", 0, 0, VC_VXF_INFO_INIT, VC_VXF_INFO_INIT,-1,0);
116 TEST_LIST("~fakeinit", 0, 0, 0, VC_VXF_INFO_INIT,-1,0);
117 TEST_LIST("!fakeinit", 0, 0, 0, VC_VXF_INFO_INIT,-1,0);
118 TEST_LIST("fakeinit,XXX", 0, -1, VC_VXF_INFO_INIT, VC_VXF_INFO_INIT, 9,3);
119 TEST_LIST("", 0, 0, 0, 0, -1,0);
120 TEST_LIST("0", 0, 0, 0, 0, -1,0);
121 TEST_LIST("00", 0, 0, 0, 0, -1,0);
122 TEST_LIST("X", 0, -1, 0, 0, 0,1);
123 TEST_LIST("all", 0, 0, ALL64, ALL64, -1,0);
124 TEST_LIST("ALL", 0, 0, ALL64, ALL64, -1,0);
125 TEST_LIST("any", 0, 0, ALL64, ALL64, -1,0);
126 TEST_LIST("ANY", 0, 0, ALL64, ALL64, -1,0);
127 TEST_LIST("~all", 0, 0, 0, ALL64, -1,0);
128 TEST_LIST("~ALL", 0, 0, 0, ALL64, -1,0);
129 TEST_LIST("none", 0, 0, 0, 0, -1,0);
130 TEST_LIST("NONE", 0, 0, 0, 0, -1,0);
131 TEST_LIST("~none", 0, 0, 0, 0, -1,0);
132 TEST_LIST("~NONE", 0, 0, 0, 0, -1,0);
133 TEST_LIST("all,~fakeinit",0, 0, ~VC_VXF_INFO_INIT,ALL64, -1,0);
134 TEST_LIST("~all,fakeinit",0, 0, VC_VXF_INFO_INIT, ALL64, -1,0);
135 TEST_LIST("fakeinit,~all",0, 0, 0, ALL64, -1,0);
136 TEST_LIST("none,~lock", 0, 0, 0, VC_VXF_INFO_LOCK,-1,0);
137 TEST_LIST("~none,lock", 0, 0, VC_VXF_INFO_LOCK,VC_VXF_INFO_LOCK,-1,0);
138 TEST_LIST("lock,none", 0, 0, VC_VXF_INFO_LOCK,VC_VXF_INFO_LOCK,-1,0);
139 TEST_LIST("lock,~none", 0, 0, VC_VXF_INFO_LOCK,VC_VXF_INFO_LOCK,-1,0);
140 TEST_LIST("~", 0, -1, 0, 0, 1,0);
141 TEST_LIST("~~", 0, -1, 0, 0, 2,0);
142 TEST_LIST("!", 0, -1, 0, 0, 1,0);
143 TEST_LIST("^", 0, -1, 0, 0, 1,0);
144 TEST_LIST("fakeinit,~", 0, -1, VC_VXF_INFO_INIT, VC_VXF_INFO_INIT,10,0);
145 TEST_LIST("1", 0, 0, 1, 1, -1,0);
146 TEST_LIST("1,23,42", 0, 0, 1|23|42, 1|23|42, -1,0);
147 TEST_LIST("~1", 0, 0, 0, 1, -1,0);
148 TEST_LIST("!1", 0, 0, 0, 1, -1,0);
149 TEST_LIST("~~1", 0, 0, 1, 1, -1,0);
150 TEST_LIST("~~~1", 0, 0, 0, 1, -1,0);
151 TEST_LIST("~!~1", 0, 0, 0, 1, -1,0);
152 TEST_LIST("42,fakeinit", 0, 0, VC_VXF_INFO_INIT|42, VC_VXF_INFO_INIT|42, -1,0);
153 TEST_LIST("42x,1", 0, -1, 0, 0, 0,3);
155 TEST_LIST("^4,~^2", 0, 0, 0x10, 0x14, -1,0);
156 TEST_LIST("^4,~~^2", 0, 0, 0x14, 0x14, -1,0);
157 TEST_LIST("^4,~~~^2", 0, 0, 0x10, 0x14, -1,0);
158 TEST_LIST("~^2,^4", 0, 0, 0x10, 0x14, -1,0);
159 TEST_LIST("1,^1,~^2,8", 0, 0, 0x0b, 0x0f, -1,0);
161 TEST_LIST("lock,nproc,private,fakeinit,hideinfo,ulimit,namespace,"
162 "sched_hard,sched_prio,sched_pause,"
163 "virt_mem,virt_uptime,virt_cpu,virt_load,"
164 "hide_mount,hide_netif,state_setup,state_init,"
165 "fork_rss,prolific,igneg_nice",
167 VC_VXF_INFO_LOCK|VC_VXF_INFO_NPROC|VC_VXF_INFO_PRIVATE|VC_VXF_INFO_INIT|
168 VC_VXF_INFO_HIDEINFO|VC_VXF_INFO_ULIMIT|VC_VXF_INFO_NAMESPACE|
169 VC_VXF_SCHED_HARD|VC_VXF_SCHED_PRIO|VC_VXF_SCHED_PAUSE|
170 VC_VXF_VIRT_MEM|VC_VXF_VIRT_UPTIME|VC_VXF_VIRT_CPU|VC_VXF_VIRT_LOAD|
171 VC_VXF_HIDE_MOUNT|VC_VXF_HIDE_NETIF|
172 VC_VXF_STATE_SETUP|VC_VXF_STATE_INIT|
173 VC_VXF_FORK_RSS|VC_VXF_PROLIFIC|VC_VXF_IGNEG_NICE,
175 VC_VXF_INFO_LOCK|VC_VXF_INFO_NPROC|VC_VXF_INFO_PRIVATE|VC_VXF_INFO_INIT|
176 VC_VXF_INFO_HIDEINFO|VC_VXF_INFO_ULIMIT|VC_VXF_INFO_NAMESPACE|
177 VC_VXF_SCHED_HARD|VC_VXF_SCHED_PRIO|VC_VXF_SCHED_PAUSE|
178 VC_VXF_VIRT_MEM|VC_VXF_VIRT_UPTIME|VC_VXF_VIRT_CPU|VC_VXF_VIRT_LOAD|
179 VC_VXF_HIDE_MOUNT|VC_VXF_HIDE_NETIF|
180 VC_VXF_STATE_SETUP|VC_VXF_STATE_INIT|
181 VC_VXF_FORK_RSS|VC_VXF_PROLIFIC|VC_VXF_IGNEG_NICE,
185 TEST_LIST("~lock,~nproc,~private,~fakeinit,~hideinfo,~ulimit,~namespace,"
186 "~sched_hard,~sched_prio,~sched_pause,"
187 "~virt_mem,~virt_uptime,~virt_cpu,~virt_load,"
188 "~hide_mount,~hide_netif,~state_setup,~state_init,"
189 "~fork_rss,~prolific,~igneg_nice",
192 VC_VXF_INFO_LOCK|VC_VXF_INFO_NPROC|VC_VXF_INFO_PRIVATE|VC_VXF_INFO_INIT|
193 VC_VXF_INFO_HIDEINFO|VC_VXF_INFO_ULIMIT|VC_VXF_INFO_NAMESPACE|
194 VC_VXF_SCHED_HARD|VC_VXF_SCHED_PRIO|VC_VXF_SCHED_PAUSE|
195 VC_VXF_VIRT_MEM|VC_VXF_VIRT_UPTIME|VC_VXF_VIRT_CPU|VC_VXF_VIRT_LOAD|
196 VC_VXF_HIDE_MOUNT|VC_VXF_HIDE_NETIF|
197 VC_VXF_STATE_SETUP|VC_VXF_STATE_INIT|
198 VC_VXF_FORK_RSS|VC_VXF_PROLIFIC|VC_VXF_IGNEG_NICE,