Abdullah Alamoudi | ac683db | 2016-02-23 00:59:31 +0300 | [diff] [blame] | 1 | ###################################################################### |
| 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 | ###################################################################### |
| 15 | test-lexer-one-token 123 LEX_INTEGER_VALUE |
| 16 | test-lexer-one-token 123.456 LEX_REAL_VALUE |
| 17 | test-lexer-one-token true LEX_BOOLEAN_VALUE |
| 18 | test-lexer-one-token false LEX_BOOLEAN_VALUE |
| 19 | test-lexer-one-token "blah" LEX_STRING_VALUE |
| 20 | test-lexer-one-token "new\nline" LEX_STRING_VALUE |
| 21 | test-lexer-one-token "blue bibs be big" LEX_STRING_VALUE |
| 22 | test-lexer-one-token blah LEX_IDENTIFIER |
| 23 | test-lexer-one-token __ LEX_IDENTIFIER |
| 24 | test-lexer-one-token undefined LEX_UNDEFINED_VALUE |
| 25 | test-lexer-one-token error LEX_ERROR_VALUE |
| 26 | test-lexer-one-token . LEX_SELECTION |
| 27 | test-lexer-one-token * LEX_MULTIPLY |
| 28 | test-lexer-one-token / LEX_DIVIDE |
| 29 | test-lexer-one-token % LEX_MODULUS |
| 30 | test-lexer-one-token + LEX_PLUS |
| 31 | test-lexer-one-token - LEX_MINUS |
| 32 | test-lexer-one-token & LEX_BITWISE_AND |
| 33 | test-lexer-one-token | LEX_BITWISE_OR |
| 34 | test-lexer-one-token ~ LEX_BITWISE_NOT |
| 35 | test-lexer-one-token ^ LEX_BITWISE_XOR |
| 36 | test-lexer-one-token << LEX_LEFT_SHIFT |
| 37 | test-lexer-one-token >> LEX_RIGHT_SHIFT |
| 38 | test-lexer-one-token >>> LEX_URIGHT_SHIFT |
| 39 | test-lexer-one-token && LEX_LOGICAL_AND |
| 40 | test-lexer-one-token || LEX_LOGICAL_OR |
| 41 | test-lexer-one-token ! LEX_LOGICAL_NOT |
| 42 | test-lexer-one-token < LEX_LESS_THAN |
| 43 | test-lexer-one-token <= LEX_LESS_OR_EQUAL |
| 44 | test-lexer-one-token > LEX_GREATER_THAN |
| 45 | test-lexer-one-token >= LEX_GREATER_OR_EQUAL |
| 46 | test-lexer-one-token == LEX_EQUAL |
| 47 | test-lexer-one-token != LEX_NOT_EQUAL |
| 48 | test-lexer-one-token is LEX_META_EQUAL |
| 49 | test-lexer-one-token isnt LEX_META_NOT_EQUAL |
| 50 | test-lexer-one-token = LEX_BOUND_TO |
| 51 | test-lexer-one-token ? LEX_QMARK |
| 52 | test-lexer-one-token : LEX_COLON |
| 53 | test-lexer-one-token ; LEX_SEMICOLON |
| 54 | test-lexer-one-token , LEX_COMMA |
| 55 | test-lexer-one-token [ LEX_OPEN_BOX |
| 56 | test-lexer-one-token ] LEX_CLOSE_BOX |
| 57 | test-lexer-one-token ( LEX_OPEN_PAREN |
| 58 | test-lexer-one-token ) LEX_CLOSE_PAREN |
| 59 | test-lexer-one-token { LEX_OPEN_BRACE |
| 60 | test-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. |
| 64 | test-lexer-one-token \ LEX_TOKEN_ERROR |
| 65 | |
| 66 | ###################################################################### |
| 67 | # |
| 68 | # ClassAds |
| 69 | # |
| 70 | ###################################################################### |
| 71 | begin-classad Job-1 |
| 72 | [ |
| 73 | Requirements = (other.Type == "Machine" && other.memory >= 4000); |
| 74 | Type = "Job"; |
| 75 | Memoryused = 6000; |
| 76 | ] |
| 77 | end-classad |
| 78 | |
| 79 | begin-classad Machine-1 |
| 80 | [ |
| 81 | Type = "machine"; |
| 82 | Requirements = (other.Type == "job" && other.memoryused < 8000); |
| 83 | Memory = 5000; |
| 84 | ] |
| 85 | end-classad |
| 86 | |
| 87 | begin-classad Machine-2 |
| 88 | [ |
| 89 | Type = "Machine"; |
| 90 | Requirements = other.mytype == "Job"; |
| 91 | Memory = 3000 |
| 92 | ] |
| 93 | end-classad |
| 94 | |
| 95 | begin-classad Machine-3 |
| 96 | [ |
| 97 | Type = "Machine"; |
| 98 | Requirements = other.mytype == "Job"; |
| 99 | Memory = 6000 |
| 100 | ] |
| 101 | end-classad |
| 102 | |
| 103 | begin-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 | ] |
| 147 | end-classad |
| 148 | |
| 149 | begin-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 | ] |
| 191 | end-classad |
| 192 | |
| 193 | evaluate Motherboard job_enclosure.job.Requirements |
| 194 | evaluate Motherboard machine_enclosure.job.Requirements |
| 195 | evaluate Motherboard storage_enclosure.storage.Requirements |
| 196 | evaluate Motherboard have_match |
| 197 | |
| 198 | ###################################################################### |
| 199 | # |
| 200 | # Basic Evaluation Tests |
| 201 | # |
| 202 | ###################################################################### |
| 203 | evaluate Job-1 TestTernary |
| 204 | evaluate Misc Self.rank |
| 205 | evaluate Machine-1 memory |
| 206 | evaluate Misc Set |
| 207 | evaluate Misc Sum |
| 208 | evaluate Misc Average |
| 209 | evaluate Misc Min |
| 210 | evaluate Misc Max |
| 211 | evaluate Misc AllSmall |
| 212 | evaluate Misc AllBig |
| 213 | evaluate Misc AnyTwo |
| 214 | evaluate Misc AllTwo |
| 215 | evaluate Misc ClassAds.b |
| 216 | evaluate Misc ClassAds.c |
| 217 | evaluate Misc All_Undefined |
| 218 | evaluate Misc Any_Undefined |
| 219 | evaluate Misc A |
| 220 | evaluate Misc B |
| 221 | evaluate Misc C |
| 222 | evaluate Misc D |
| 223 | evaluate Misc SizeSet; |
| 224 | evaluate Misc SizeZero; |
| 225 | evaluate Misc SizeOne; |
| 226 | evaluate Misc SizeTwo; |
| 227 | evaluate Misc R1; |
| 228 | evaluate Misc R2; |
| 229 | evaluate Misc R3; |
| 230 | evaluate Misc R4; |
| 231 | evaluate Misc R5; |
| 232 | evaluate Misc R6; |
| 233 | |
| 234 | ###################################################################### |
| 235 | # |
| 236 | # Matching tests |
| 237 | # |
| 238 | ###################################################################### |
| 239 | test-match symmetricMatch Job-1 Machine-1 ExpectMatch |
| 240 | test-match leftMatchesRight Job-1 Machine-1 ExpectMatch |
| 241 | test-match rightMatchesLeft Job-1 Machine-1 ExpectMatch |
| 242 | test-match symmetricMatch Job-1 Machine-2 ExpectDontMatch |
| 243 | |
| 244 | ###################################################################### |
| 245 | # |
| 246 | # Collections |
| 247 | # |
| 248 | ###################################################################### |
| 249 | #make-collection Machines machines-log |
| 250 | make-collection Machines |
| 251 | add-to-collection Machines Machine-1 |
| 252 | add-to-collection Machines Machine-2 |
| 253 | add-to-collection Machines Machine-3 |
| 254 | |
| 255 | create-subview Machines root Machine-View (other.Memory >= 4000) |
| 256 | check-in-view Machines Machine-View Machine-1 ExpectIn |
| 257 | check-in-view Machines Machine-View Machine-2 ExpectNotIn |
| 258 | check-in-view Machines Machine-View Machine-3 ExpectIn |
| 259 | |
| 260 | create-subview Machines Machine-View BigMachine-View (other.Memory > 5000) |
| 261 | check-in-view Machines BigMachine-View Machine-1 ExpectNotIn |
| 262 | check-in-view Machines BigMachine-View Machine-2 ExpectNotIn |
| 263 | check-in-view Machines BigMachine-View Machine-3 ExpectIn |
| 264 | |
| 265 | #truncate-log Machines |
| 266 | |
| 267 | begin-classad Group-1 |
| 268 | [ |
| 269 | Type = "Group"; |
| 270 | Users = {"Alain", "Peter"}; |
| 271 | ] |
| 272 | end-classad |
| 273 | |
| 274 | begin-classad Group-2 |
| 275 | [ |
| 276 | Type = "Group"; |
| 277 | Users = {"Annalisa", "David"}; |
| 278 | ] |
| 279 | end-classad |
| 280 | |
| 281 | #make-collection Groups groups-log |
| 282 | make-collection Groups groups-log |
| 283 | add-to-collection Groups Group-1 |
| 284 | add-to-collection Groups Group-2 |
| 285 | |
| 286 | begin-classad List-Eval |
| 287 | [ a = { x }; x = 1 ] |
| 288 | end-classad |
| 289 | |
| 290 | evaluate Misc SizeOne; |
| 291 | evaluate Misc SizeTwo; |
| 292 | evaluate List-Eval a[0] |
| 293 | |
| 294 | begin-classad Lexer-Fault |
| 295 | [ a=!b; b=true; ] |
| 296 | end-classad |
| 297 | evaluate Lexer-Fault b |
| 298 | evaluate Lexer-Fault a |
| 299 | |
| 300 | begin-classad Octal |
| 301 | [ a = "\101\044\44\1"; /* Should be A(( */ ] |
| 302 | end-classad |
| 303 | evaluate Octal a |
| 304 | |
| 305 | begin-classad Floats |
| 306 | [a = 0.7 * 4.5; ] |
| 307 | end-classad |
| 308 | |
| 309 | begin-classad Quoted-Names |
| 310 | [ |
| 311 | 'a' = 4; |
| 312 | 'b.##$%' = 5; |
| 313 | ] |
| 314 | end-classad |
| 315 | |
| 316 | begin-classad Times |
| 317 | [ |
| 318 | Abs1 = absTime("2003-09-03T"); |
| 319 | Rel1 = relTime("2+25:14:16.123"); |
| 320 | ] |
| 321 | end-classad |
| 322 | |
| 323 | begin-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 | ] |
| 331 | end-classad |
| 332 | |
| 333 | print-classad Floats |
| 334 | print-classad Quoted-Names |
| 335 | print-classad Times |
| 336 | print-classad Numbers |
| 337 | print-classad-xml Numbers |
| 338 | |
| 339 | begin-classad Loop |
| 340 | [ |
| 341 | attr = a//b |
| 342 | ] |
| 343 | end-classad |
| 344 | |
| 345 | #begin-classad Crash |
| 346 | #[ |
| 347 | # attr = a<b> |
| 348 | #] |
| 349 | #end-classad |
| 350 | |
| 351 | begin-classad policy |
| 352 | [ |
| 353 | type = 'machine'; |
| 354 | access_times = |
| 355 | [ |
| 356 | globus = [start = 1900; end = 2100;]; |
| 357 | condor = [start = 100; end = 500;]; |
| 358 | ] |
| 359 | ] |
| 360 | end-classad |
| 361 | |
| 362 | evaluate policy access_times |
| 363 | evaluate policy access_times["globus"] |
| 364 | evaluate policy access_times["globus"].start |
| 365 | |