8 * Desc: Command line version of the sanity check functions found in jack
16 #include "systemtest.h"
21 typedef int (*testfuncPtr
) ();
22 typedef int (*testfuncOpPtr
) (string
);
26 string switchText
; // ie -option
27 string swOptionText
; // option arguments for just this swtich.
28 string descriptionText
; // Help Text on what this does
29 string failureText
; // What to say when this test fails
30 bool hasOption
; // Set true if this switch has option paramters
31 testfuncPtr functionPtr
; // Function to call
32 testfuncOpPtr opFunctionPtr
; // Function with option string to call
33 string optionArg
; // Storage used to hold any options passed in by the user
36 static vector
<testRecord
> gTestSet
;
38 static vector
<string
> gValidSwitchList
;
39 static vector
<string
> gSwitchDescriptionList
;
41 static vector
<string
> gSwitchesReceived
;
48 OK
&= system_user_can_rtprio();
50 if (system_has_frequencyscaling()) {
51 OK
&= !system_uses_frequencyscaling();
54 OK
&= !(system_memlock_amount() == 0);
62 return system_has_group(name
.c_str());
66 IsMemberOfGroup(string name
)
68 return system_user_in_group(name
.c_str());
76 if (system_has_frequencyscaling()) {
77 OK
&= !system_uses_frequencyscaling();
86 return !(system_memlock_amount() == 0);
93 printf(" sanityCheck - A program to verify proper system settings for use with audio applications (Ardour/Jack/Mixbus).\n");
95 printf(" Usage: sanityCheck [OPTIONS]\n");
97 printf(" Options are as follows:\n");
101 vector
<testRecord
>::iterator itr
;
103 for (itr
= gTestSet
.begin(); itr
!= gTestSet
.end(); ++itr
) {
104 printf("%20s %s :\t%s\n", (*itr
).switchText
.c_str(), (*itr
).swOptionText
.c_str(), (*itr
).descriptionText
.c_str());
118 rec
.switchText
= "-a";
119 rec
.swOptionText
= "";
120 rec
.descriptionText
= "Checks for a working RT system. Same as -rt -freqscaling -memlock";
121 rec
.failureText
= "";
122 rec
.hasOption
= false;
123 rec
.functionPtr
= &ExecuteAll
;
125 gTestSet
.push_back(rec
);
127 rec
.switchText
= "-h";
128 rec
.swOptionText
= "";
129 rec
.descriptionText
= "Print usage";
130 rec
.failureText
= "";
131 rec
.hasOption
= false;
132 rec
.functionPtr
= &PrintUsage
;
134 gTestSet
.push_back(rec
);
136 // Switches for various tests that can be performed.
137 rec
.switchText
= "-rt";
138 rec
.swOptionText
= "";
139 rec
.descriptionText
= "Verfiy that the user can run tasks with realtime priority";
140 rec
.failureText
= "";
141 rec
.hasOption
= false;
142 rec
.functionPtr
= &system_user_can_rtprio
;
144 gTestSet
.push_back(rec
);
146 rec
.switchText
= "-hasrtlimits";
147 rec
.swOptionText
= "";
148 rec
.descriptionText
= "Verfiy the system has a limits.conf and the audio group can use realtime";
149 rec
.failureText
= "";
150 rec
.hasOption
= false;
151 rec
.functionPtr
= &system_has_rtprio_limits_conf
;
153 gTestSet
.push_back(rec
);
155 rec
.switchText
= "-hasgroup";
156 rec
.swOptionText
= "<groupname>";
157 rec
.descriptionText
= "Verfiy that the system has a group named <groupname>";
158 rec
.failureText
= "";
159 rec
.hasOption
= true;
160 rec
.opFunctionPtr
= &HasGroup
;
162 gTestSet
.push_back(rec
);
164 rec
.switchText
= "-hasaudiogroup";
165 rec
.swOptionText
= "";
166 rec
.descriptionText
= "Verfiy that the system has an audio group (audio or jackuser) defined";
167 rec
.failureText
= "";
168 rec
.hasOption
= false;
169 rec
.functionPtr
= &system_has_audiogroup
;
171 gTestSet
.push_back(rec
);
173 rec
.switchText
= "-memberofgroup";
174 rec
.swOptionText
= "<groupname>";
175 rec
.descriptionText
= "Verfiy that the user is a member of the group named <groupname>";
176 rec
.failureText
= "";
177 rec
.hasOption
= true;
178 rec
.opFunctionPtr
= &IsMemberOfGroup
;
180 gTestSet
.push_back(rec
);
182 rec
.switchText
= "-memberaudiogroup";
183 rec
.swOptionText
= "";
184 rec
.descriptionText
= "Verfiy that the user is a member of the audio group (audio or jackuser)";
185 rec
.failureText
= "";
186 rec
.hasOption
= false;
187 rec
.functionPtr
= &system_user_in_audiogroup
;
189 gTestSet
.push_back(rec
);
191 rec
.switchText
= "-freqscaling";
192 rec
.swOptionText
= "";
193 rec
.descriptionText
= "Check to see if frequency scaling is being used by the CPU";
194 rec
.failureText
= "";
195 rec
.hasOption
= false;
196 rec
.functionPtr
= &CheckFreqScaling
;
198 gTestSet
.push_back(rec
);
200 rec
.switchText
= "-memlock";
201 rec
.swOptionText
= "";
202 rec
.descriptionText
= "Check to see if the user is able to lock memory";
203 rec
.failureText
= "";
204 rec
.hasOption
= false;
205 rec
.functionPtr
= &CheckMemoryLocking
;
207 gTestSet
.push_back(rec
);
217 vector
<testRecord
>::iterator itr
;
222 gSwitchesReceived
.push_back("-a");
225 for (i
= 1; i
< argc
&& OK
== true; i
++) {
228 for (itr
= gTestSet
.begin(); itr
!= gTestSet
.end(); ++itr
) {
229 if (tmp
== (*itr
).switchText
) {
230 if ((*itr
).hasOption
== true) {
234 // reqiured option for this switch is missing
239 (*itr
).optionArg
= op
;
243 // reqiured option for this switch is missing
253 if (OK
&& itr
!= gTestSet
.end()) {
254 // Known option switch found
255 gSwitchesReceived
.push_back(tmp
);
265 // All switches are at least valid, now check to make sure they are all valid to
268 if (gSwitchesReceived
.size() > 1) {
269 // make sure help is not mixed with other options
270 vector
<string
>::iterator swItr
;
273 swItr
= find(gSwitchesReceived
.begin(), gSwitchesReceived
.end(), tmp
);
275 if (swItr
!= gSwitchesReceived
.end()) {
276 gSwitchesReceived
.clear();
277 gSwitchesReceived
.push_back("-h");
280 // make sure -a is only used by itself
282 swItr
= find(gSwitchesReceived
.begin(), gSwitchesReceived
.end(), tmp
);
284 if (swItr
!= gSwitchesReceived
.end()) {
285 gSwitchesReceived
.clear();
286 gSwitchesReceived
.push_back("-a");
293 fprintf(stderr
, "\n");
294 fprintf(stderr
, "ERROR - Invalid Option: %s\n", (const char *) argv
[--i
]);
295 fprintf(stderr
, "Check syntax\n");
305 vector
<string
>::iterator itr
;
306 vector
<testRecord
>::iterator testItr
;
308 for (itr
= gSwitchesReceived
.begin(); itr
!= gSwitchesReceived
.end(); ++itr
) {
309 for (testItr
= gTestSet
.begin(); testItr
!= gTestSet
.end(); ++testItr
) {
310 if ((*itr
) == (*testItr
).switchText
) {
316 if ((*testItr
).hasOption
) {
317 result
= ((*testItr
).opFunctionPtr((*testItr
).optionArg
) != 0);
320 result
= ((*testItr
).functionPtr() != 0);
324 // Check for a Failure message and print it if found.
325 if (!(*testItr
).failureText
.empty()) {
326 printf("\n%s\n", (*testItr
).failureText
.c_str());
345 if (ParseSwitches(argc
, argv
)) {
346 if (Execute() == false) {
347 printf("\nSanity Check Failed!\n\n");
351 printf("\nSanity Check OK!\n\n");