blob: cc82b6edf9fa3d9bcc87800fb5229abe5c28f07f [file] [log] [blame]
Abdullah Alamoudiac683db2016-02-23 00:59:31 +03001######################################################################
2#
3# File: tests.txt
4# Purpose: This is a series of tests for the ClassAd library.
5# Currently there is no good documentation for how to write
6# tests, you'll just have to look in test_classads.C
7#
8######################################################################
9
10######################################################################
11#
12# Test the lexer
13#
14######################################################################
15test-lexer-one-token 123 LEX_INTEGER_VALUE
16test-lexer-one-token 123.456 LEX_REAL_VALUE
17test-lexer-one-token true LEX_BOOLEAN_VALUE
18test-lexer-one-token false LEX_BOOLEAN_VALUE
19test-lexer-one-token "blah" LEX_STRING_VALUE
20test-lexer-one-token "new\nline" LEX_STRING_VALUE
21test-lexer-one-token "blue bibs be big" LEX_STRING_VALUE
22test-lexer-one-token blah LEX_IDENTIFIER
23test-lexer-one-token __ LEX_IDENTIFIER
24test-lexer-one-token undefined LEX_UNDEFINED_VALUE
25test-lexer-one-token error LEX_ERROR_VALUE
26test-lexer-one-token . LEX_SELECTION
27test-lexer-one-token * LEX_MULTIPLY
28test-lexer-one-token / LEX_DIVIDE
29test-lexer-one-token % LEX_MODULUS
30test-lexer-one-token + LEX_PLUS
31test-lexer-one-token - LEX_MINUS
32test-lexer-one-token & LEX_BITWISE_AND
33test-lexer-one-token | LEX_BITWISE_OR
34test-lexer-one-token ~ LEX_BITWISE_NOT
35test-lexer-one-token ^ LEX_BITWISE_XOR
36test-lexer-one-token << LEX_LEFT_SHIFT
37test-lexer-one-token >> LEX_RIGHT_SHIFT
38test-lexer-one-token >>> LEX_URIGHT_SHIFT
39test-lexer-one-token && LEX_LOGICAL_AND
40test-lexer-one-token || LEX_LOGICAL_OR
41test-lexer-one-token ! LEX_LOGICAL_NOT
42test-lexer-one-token < LEX_LESS_THAN
43test-lexer-one-token <= LEX_LESS_OR_EQUAL
44test-lexer-one-token > LEX_GREATER_THAN
45test-lexer-one-token >= LEX_GREATER_OR_EQUAL
46test-lexer-one-token == LEX_EQUAL
47test-lexer-one-token != LEX_NOT_EQUAL
48test-lexer-one-token is LEX_META_EQUAL
49test-lexer-one-token isnt LEX_META_NOT_EQUAL
50test-lexer-one-token = LEX_BOUND_TO
51test-lexer-one-token ? LEX_QMARK
52test-lexer-one-token : LEX_COLON
53test-lexer-one-token ; LEX_SEMICOLON
54test-lexer-one-token , LEX_COMMA
55test-lexer-one-token [ LEX_OPEN_BOX
56test-lexer-one-token ] LEX_CLOSE_BOX
57test-lexer-one-token ( LEX_OPEN_PAREN
58test-lexer-one-token ) LEX_CLOSE_PAREN
59test-lexer-one-token { LEX_OPEN_BRACE
60test-lexer-one-token } LEX_CLOSE_BRACE
61
62# I think this should evaluate to LEX_BACKSLASH. Apparently
63# it's not actually used anywhere, so it's an error instead.
64test-lexer-one-token \ LEX_TOKEN_ERROR
65
66######################################################################
67#
68# ClassAds
69#
70######################################################################
71begin-classad Job-1
72[
73 Requirements = (other.Type == "Machine" && other.memory >= 4000);
74 Type = "Job";
75 Memoryused = 6000;
76]
77end-classad
78
79begin-classad Machine-1
80[
81 Type = "machine";
82 Requirements = (other.Type == "job" && other.memoryused < 8000);
83 Memory = 5000;
84]
85end-classad
86
87begin-classad Machine-2
88[
89 Type = "Machine";
90 Requirements = other.mytype == "Job";
91 Memory = 3000
92]
93end-classad
94
95begin-classad Machine-3
96[
97 Type = "Machine";
98 Requirements = other.mytype == "Job";
99 Memory = 6000
100]
101end-classad
102
103begin-classad Misc
104[
105 Type = "Misc";
106 Self = [
107 one = "foo";
108 two = "bar";
109 rank = Other[StrCat(one, two)];
110 ];
111 Other = [
112 one = 1;
113 two = 2;
114 foobar = 15
115 ];
116 Buddha = [
117 which = Self.which;
118 ];
119 ClassAds = { [a = 1], [a = 2], [a = 3] };
120 Set = ClassAds.a;
121 SizeSet = size(Set);
122 SizeZero = size({});
123 SizeOne = size({1});
124 SizeTwo = size({1, 2});
125 Sum = sum(Set);
126 Average = avg(Set);
127 Min = min(Set);
128 Max = max(Set);
129 AllSmall = allcompare("<", Set, 100);
130 AllBig = allcompare(">", Set, 100);
131 AnyTwo = anycompare("==", Set, 2);
132 AllTwo = allcompare("==", Set, 2);
133 A = 1;
134 B = true;
135 C = !A;
136 D = !B;
137 R1 = regexp(".*\.cs\.uchicago\.edu", "gargoyle.cs1uchicago.edu");
138 R2 = regexp(".*\.cs\.wisc\.edu", "beak.cs.wisc.edu");
139 R3 = regexp(".*\.cs\.uchicago\.edu", "beak.cs.wisc.edu");
140 R4 = regexp(".*\.cs\.wisc\.edu", "gargoyle.cs.uchicago.edu");
141 R5 = regexp(".*\.cs\.wisc\.edu|.*\.cs\.uchicago\.edu",
142 "gargoyle\.cs\.uchicago.edu");
143 R6 = regexp(".*\.cs\.wisc\.edu|.*\.cs\.uchicago\.edu",
144 "beak.cs.wisc\.edu");
145
146]
147end-classad
148
149begin-classad Motherboard
150[
151 have_match = machine_enclosure.machine.Requirements
152 && job_enclosure.job.Requirements
153 && storage_enclosure.storage.Requirements;
154
155 machine_enclosure =
156 [
157 job = job_enclosure.job;
158 storage = storage_enclosure.storage;
159 machine = [
160 Type="Machine";
161 RAM=6000;
162 Requirements = (job.MemoryNeeded <= RAM);
163 ];
164 ];
165
166 job_enclosure =
167 [
168 machine = machine_enclosure.machine;
169 storage = storage_enclosure.storage;
170 job = [
171 Type="Job";
172 MemoryNeeded = 6000;
173 DiskSpaceNeeded = 8000;
174 Requirements = (machine.RAM >= MemoryNeeded
175 && storage.FreeDiskSpace > DiskSpaceNeeded)
176 ];
177 ];
178
179 storage_enclosure =
180 [
181 job = job_enclosure.job;
182 machine = machine_enclosure.machine;
183 storage = [
184 Type = "Storage";
185 FreeDiskSpace = 10000;
186 Requirements = job.DiskSpaceNeeded < FreeDiskSpace;
187 ];
188
189 ];
190]
191end-classad
192
193evaluate Motherboard job_enclosure.job.Requirements
194evaluate Motherboard machine_enclosure.job.Requirements
195evaluate Motherboard storage_enclosure.storage.Requirements
196evaluate Motherboard have_match
197
198######################################################################
199#
200# Basic Evaluation Tests
201#
202######################################################################
203evaluate Job-1 TestTernary
204evaluate Misc Self.rank
205evaluate Machine-1 memory
206evaluate Misc Set
207evaluate Misc Sum
208evaluate Misc Average
209evaluate Misc Min
210evaluate Misc Max
211evaluate Misc AllSmall
212evaluate Misc AllBig
213evaluate Misc AnyTwo
214evaluate Misc AllTwo
215evaluate Misc ClassAds.b
216evaluate Misc ClassAds.c
217evaluate Misc All_Undefined
218evaluate Misc Any_Undefined
219evaluate Misc A
220evaluate Misc B
221evaluate Misc C
222evaluate Misc D
223evaluate Misc SizeSet;
224evaluate Misc SizeZero;
225evaluate Misc SizeOne;
226evaluate Misc SizeTwo;
227evaluate Misc R1;
228evaluate Misc R2;
229evaluate Misc R3;
230evaluate Misc R4;
231evaluate Misc R5;
232evaluate Misc R6;
233
234######################################################################
235#
236# Matching tests
237#
238######################################################################
239test-match symmetricMatch Job-1 Machine-1 ExpectMatch
240test-match leftMatchesRight Job-1 Machine-1 ExpectMatch
241test-match rightMatchesLeft Job-1 Machine-1 ExpectMatch
242test-match symmetricMatch Job-1 Machine-2 ExpectDontMatch
243
244######################################################################
245#
246# Collections
247#
248######################################################################
249#make-collection Machines machines-log
250make-collection Machines
251add-to-collection Machines Machine-1
252add-to-collection Machines Machine-2
253add-to-collection Machines Machine-3
254
255create-subview Machines root Machine-View (other.Memory >= 4000)
256check-in-view Machines Machine-View Machine-1 ExpectIn
257check-in-view Machines Machine-View Machine-2 ExpectNotIn
258check-in-view Machines Machine-View Machine-3 ExpectIn
259
260create-subview Machines Machine-View BigMachine-View (other.Memory > 5000)
261check-in-view Machines BigMachine-View Machine-1 ExpectNotIn
262check-in-view Machines BigMachine-View Machine-2 ExpectNotIn
263check-in-view Machines BigMachine-View Machine-3 ExpectIn
264
265#truncate-log Machines
266
267begin-classad Group-1
268[
269 Type = "Group";
270 Users = {"Alain", "Peter"};
271]
272end-classad
273
274begin-classad Group-2
275[
276 Type = "Group";
277 Users = {"Annalisa", "David"};
278]
279end-classad
280
281#make-collection Groups groups-log
282make-collection Groups groups-log
283add-to-collection Groups Group-1
284add-to-collection Groups Group-2
285
286begin-classad List-Eval
287[ a = { x }; x = 1 ]
288end-classad
289
290evaluate Misc SizeOne;
291evaluate Misc SizeTwo;
292evaluate List-Eval a[0]
293
294begin-classad Lexer-Fault
295[ a=!b; b=true; ]
296end-classad
297evaluate Lexer-Fault b
298evaluate Lexer-Fault a
299
300begin-classad Octal
301[ a = "\101\044\44\1"; /* Should be A(( */ ]
302end-classad
303evaluate Octal a
304
305begin-classad Floats
306[a = 0.7 * 4.5; ]
307end-classad
308
309begin-classad Quoted-Names
310[
311 'a' = 4;
312 'b.##$%' = 5;
313]
314end-classad
315
316begin-classad Times
317[
318 Abs1 = absTime("2003-09-03T");
319 Rel1 = relTime("2+25:14:16.123");
320]
321end-classad
322
323begin-classad Numbers
324[
325 X = 4.3;
326 Y = real("4.3");
327 Not = real("NaN");
328 Infinite = real("INF");
329 Negative_Infinite = real("-INF");
330]
331end-classad
332
333print-classad Floats
334print-classad Quoted-Names
335print-classad Times
336print-classad Numbers
337print-classad-xml Numbers
338
339begin-classad Loop
340[
341 attr = a//b
342]
343end-classad
344
345#begin-classad Crash
346#[
347# attr = a<b>
348#]
349#end-classad
350
351begin-classad policy
352[
353 type = 'machine';
354 access_times =
355 [
356 globus = [start = 1900; end = 2100;];
357 condor = [start = 100; end = 500;];
358 ]
359]
360end-classad
361
362evaluate policy access_times
363evaluate policy access_times["globus"]
364evaluate policy access_times["globus"].start
365