| 1 | package felix.test; |
| 2 | |
| 3 | import static org.junit.Assert.*; |
| 4 | |
| 5 | import java.util.ArrayList; |
| 6 | import java.util.HashMap; |
| 7 | import java.util.HashSet; |
| 8 | |
| 9 | |
| 10 | import org.junit.BeforeClass; |
| 11 | import org.junit.Test; |
| 12 | |
| 13 | import tuffy.util.Config; |
| 14 | import tuffy.util.Timer; |
| 15 | import tuffy.util.UIMan; |
| 16 | |
| 17 | import felix.compiler.StaticAnalyzer; |
| 18 | import felix.dstruct.ConcurrentOperatorsBucket; |
| 19 | import felix.dstruct.ExecutionPlan; |
| 20 | import felix.dstruct.FelixPredicate; |
| 21 | import felix.dstruct.FelixPredicate.FPProperty; |
| 22 | import felix.dstruct.StatOperator.OPType; |
| 23 | import felix.dstruct.OperatorBucketGraph; |
| 24 | import felix.dstruct.StatOperator; |
| 25 | import felix.executor.Executor; |
| 26 | import felix.main.Felix; |
| 27 | import felix.optimizer.Scheduler; |
| 28 | import felix.parser.FelixCommandOptions; |
| 29 | import felix.util.FelixConfig; |
| 30 | import felix.util.FelixUIMan; |
| 31 | |
| 32 | /** |
| 33 | * Test the compiler. |
| 34 | * @author Ce Zhang |
| 35 | * |
| 36 | */ |
| 37 | public class StaticAnalyzerTest extends Felix{ |
| 38 | |
| 39 | //this.parseKeyConstraintRelation(); |
| 40 | //this.parseReflexiveRelation(); |
| 41 | //this.parseSymmetricRelation(); |
| 42 | //this.parseTransitiveRelation(); |
| 43 | //this.parseChainRecursiveRelation(); |
| 44 | //this.parseNonRecursiveRelation(); |
| 45 | //this.parseOtherRecursiveRelation(); |
| 46 | //this.parseSpecialPredicate(); |
| 47 | //this.parseEmbededWeightRule(); |
| 48 | |
| 49 | /** |
| 50 | * Test the parser for CRF operator. |
| 51 | */ |
| 52 | @Test |
| 53 | public final void test_parseKeyConstraintRelation() { |
| 54 | try{ |
| 55 | String[] args = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
| 56 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db"}; |
| 57 | |
| 58 | FelixConfig.overrideID(); |
| 59 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 60 | |
| 61 | Timer.start("Felix-Timer"); |
| 62 | this.options = options; |
| 63 | resetACoupleAuxDataStructures(); |
| 64 | |
| 65 | fq = this.parseFelixQuery(); |
| 66 | |
| 67 | sa = new StaticAnalyzer(this.fq, options); |
| 68 | |
| 69 | sa.parseKeyConstraintRelation(); |
| 70 | |
| 71 | int ct = 0; |
| 72 | for(FelixPredicate fp : this.fq.getAllPred()){ |
| 73 | |
| 74 | if(fp.getName().equals("lrPred1")){ |
| 75 | ct++; |
| 76 | assertTrue(fp.hasProperty(FPProperty.KEY_CONSTRAINT)); |
| 77 | assertTrue(fp.getLabelPositions().size() == 1); |
| 78 | assertTrue(fp.getKeyPositions().size() == 5); |
| 79 | assertTrue(fp.getLabelFieldsArgs().size() == 1); |
| 80 | assertTrue(fp.getKeyFieldsArgs().size() == 5); |
| 81 | |
| 82 | assertTrue(fp.getLabelPositions().iterator().next() == 4); |
| 83 | |
| 84 | }else if(fp.getName().equals("lrPred2")){ |
| 85 | ct++; |
| 86 | assertTrue(fp.hasProperty(FPProperty.KEY_CONSTRAINT)); |
| 87 | assertTrue(fp.getLabelPositions().size() == 1); |
| 88 | assertTrue(fp.getKeyPositions().size() == 5); |
| 89 | assertTrue(fp.getLabelFieldsArgs().size() == 1); |
| 90 | assertTrue(fp.getKeyFieldsArgs().size() == 5); |
| 91 | |
| 92 | assertTrue(fp.getLabelPositions().iterator().next() == 4); |
| 93 | |
| 94 | }else if(fp.getName().equals("crfPred")){ |
| 95 | ct++; |
| 96 | assertTrue(fp.hasProperty(FPProperty.KEY_CONSTRAINT)); |
| 97 | assertTrue(fp.getLabelPositions().size() == 1); |
| 98 | assertTrue(fp.getKeyPositions().size() == 5); |
| 99 | assertTrue(fp.getLabelFieldsArgs().size() == 1); |
| 100 | assertTrue(fp.getKeyFieldsArgs().size() == 5); |
| 101 | |
| 102 | assertTrue(fp.getLabelPositions().iterator().next() == 4); |
| 103 | |
| 104 | }else if(fp.getName().equals("notCrfPred")){ |
| 105 | ct++; |
| 106 | assertTrue(fp.hasProperty(FPProperty.KEY_CONSTRAINT)); |
| 107 | assertTrue(fp.getLabelPositions().size() == 1); |
| 108 | assertTrue(fp.getKeyPositions().size() == 5); |
| 109 | assertTrue(fp.getLabelFieldsArgs().size() == 1); |
| 110 | assertTrue(fp.getKeyFieldsArgs().size() == 5); |
| 111 | |
| 112 | assertTrue(fp.getLabelPositions().iterator().next() == 4); |
| 113 | |
| 114 | }else{ |
| 115 | assertFalse(fp.hasProperty(FPProperty.KEY_CONSTRAINT)); |
| 116 | assertTrue(fp.getKeyPositions().size() == 2); |
| 117 | assertTrue(fp.getKeyFieldsArgs().size() == 2); |
| 118 | assertTrue(fp.getLabelFieldsArgs().size() == 0); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | assertTrue(ct == 4); |
| 123 | |
| 124 | }catch(Exception e){ |
| 125 | e.printStackTrace(); |
| 126 | } |
| 127 | |
| 128 | } |
| 129 | |
| 130 | |
| 131 | @Test |
| 132 | public final void test_parseChainRecursiveRelation() { |
| 133 | try{ |
| 134 | String[] args = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
| 135 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db"}; |
| 136 | |
| 137 | FelixConfig.overrideID(); |
| 138 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 139 | |
| 140 | Timer.start("Felix-Timer"); |
| 141 | this.options = options; |
| 142 | resetACoupleAuxDataStructures(); |
| 143 | |
| 144 | fq = this.parseFelixQuery(); |
| 145 | |
| 146 | sa = new StaticAnalyzer(this.fq, options); |
| 147 | |
| 148 | sa.parseKeyConstraintRelation(); |
| 149 | sa.parseChainRecursiveRelation(); |
| 150 | |
| 151 | int ct = 0; |
| 152 | for(FelixPredicate fp : this.fq.getAllPred()){ |
| 153 | |
| 154 | if(fp.getName().equals("crfPred")){ |
| 155 | ct++; |
| 156 | assertTrue(fp.hasProperty(FPProperty.CHAIN_RECUR)); |
| 157 | assertTrue(fp.getPropertyClauses(FPProperty.CHAIN_RECUR).size() == 1); |
| 158 | assertTrue(fp.getPropertyClauses(FPProperty.CHAIN_RECUR).iterator().next().getWeight() == -3.14); |
| 159 | |
| 160 | }else{ |
| 161 | assertFalse(fp.hasProperty(FPProperty.CHAIN_RECUR)); |
| 162 | assertTrue(fp.getPropertyClauses(FPProperty.CHAIN_RECUR).size() == 0); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | assertTrue(ct == 1); |
| 167 | |
| 168 | }catch(Exception e){ |
| 169 | e.printStackTrace(); |
| 170 | } |
| 171 | |
| 172 | } |
| 173 | |
| 174 | @Test |
| 175 | public final void test_parseEmbededWeightRule() { |
| 176 | try{ |
| 177 | String[] args = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
| 178 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db"}; |
| 179 | |
| 180 | FelixConfig.overrideID(); |
| 181 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 182 | |
| 183 | Timer.start("Felix-Timer"); |
| 184 | this.options = options; |
| 185 | resetACoupleAuxDataStructures(); |
| 186 | |
| 187 | fq = this.parseFelixQuery(); |
| 188 | |
| 189 | sa = new StaticAnalyzer(this.fq, options); |
| 190 | |
| 191 | sa.parseEmbededWeightRule(); |
| 192 | |
| 193 | int ct = 0; |
| 194 | for(FelixPredicate fp : this.fq.getAllPred()){ |
| 195 | |
| 196 | if(fp.getName().equals("lrPred2")){ |
| 197 | ct++; |
| 198 | assertTrue(fp.hasProperty(FPProperty.EMBED_WEIGHT_RULE)); |
| 199 | assertTrue(fp.getPropertyClauses(FPProperty.EMBED_WEIGHT_RULE).size() == 2); |
| 200 | |
| 201 | }else if(fp.getName().equals("notCorefPred")){ |
| 202 | ct++; |
| 203 | assertTrue(fp.hasProperty(FPProperty.EMBED_WEIGHT_RULE)); |
| 204 | assertTrue(fp.getPropertyClauses(FPProperty.EMBED_WEIGHT_RULE).size() == 1); |
| 205 | |
| 206 | }else{ |
| 207 | assertFalse(fp.hasProperty(FPProperty.CHAIN_RECUR)); |
| 208 | assertTrue(fp.getPropertyClauses(FPProperty.CHAIN_RECUR).size() == 0); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | assertTrue(ct == 2); |
| 213 | |
| 214 | }catch(Exception e){ |
| 215 | e.printStackTrace(); |
| 216 | } |
| 217 | |
| 218 | } |
| 219 | |
| 220 | |
| 221 | @Test |
| 222 | public final void test_parseNonRecursiveRelation() { |
| 223 | try{ |
| 224 | String[] args = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
| 225 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db"}; |
| 226 | |
| 227 | FelixConfig.overrideID(); |
| 228 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 229 | |
| 230 | Timer.start("Felix-Timer"); |
| 231 | this.options = options; |
| 232 | resetACoupleAuxDataStructures(); |
| 233 | |
| 234 | fq = this.parseFelixQuery(); |
| 235 | |
| 236 | sa = new StaticAnalyzer(this.fq, options); |
| 237 | |
| 238 | sa.parseNonRecursiveRelation(); |
| 239 | |
| 240 | int ct = 0; |
| 241 | for(FelixPredicate fp : this.fq.getAllPred()){ |
| 242 | |
| 243 | if(fp.getName().equals("crfPred")){ |
| 244 | ct++; |
| 245 | assertFalse(fp.hasProperty(FPProperty.NON_RECUR)); |
| 246 | assertTrue(fp.getPropertyClauses(FPProperty.NON_RECUR).size() == 0); |
| 247 | |
| 248 | }else if(fp.getName().equals("notCrfPred")){ |
| 249 | ct++; |
| 250 | assertFalse(fp.hasProperty(FPProperty.NON_RECUR)); |
| 251 | assertTrue(fp.getPropertyClauses(FPProperty.NON_RECUR).size() == 0); |
| 252 | |
| 253 | }else{ |
| 254 | if(fp.isClosedWorld()){ |
| 255 | continue; |
| 256 | } |
| 257 | assertTrue(fp.hasProperty(FPProperty.NON_RECUR)); |
| 258 | assertTrue(fp.getPropertyClauses(FPProperty.NON_RECUR).size() > 0); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | assertTrue(ct == 2); |
| 263 | |
| 264 | }catch(Exception e){ |
| 265 | e.printStackTrace(); |
| 266 | } |
| 267 | |
| 268 | } |
| 269 | |
| 270 | @Test |
| 271 | public final void test_parseOtherRecursiveRelation() { |
| 272 | try{ |
| 273 | String[] args = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
| 274 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db"}; |
| 275 | |
| 276 | FelixConfig.overrideID(); |
| 277 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 278 | |
| 279 | Timer.start("Felix-Timer"); |
| 280 | this.options = options; |
| 281 | resetACoupleAuxDataStructures(); |
| 282 | |
| 283 | fq = this.parseFelixQuery(); |
| 284 | |
| 285 | sa = new StaticAnalyzer(this.fq, options); |
| 286 | |
| 287 | sa.parseKeyConstraintRelation(); |
| 288 | sa.parseReflexiveRelation(); |
| 289 | sa.parseSymmetricRelation(); |
| 290 | sa.parseTransitiveRelation(); |
| 291 | sa.parseNonRecursiveRelation(); |
| 292 | sa.parseChainRecursiveRelation(); |
| 293 | sa.parseOtherRecursiveRelation(); |
| 294 | |
| 295 | int ct = 0; |
| 296 | for(FelixPredicate fp : this.fq.getAllPred()){ |
| 297 | |
| 298 | if(fp.getName().equals("notCrfPred")){ |
| 299 | ct++; |
| 300 | assertTrue(fp.hasProperty(FPProperty.OTHER_RECUR)); |
| 301 | assertTrue(fp.getPropertyClauses(FPProperty.OTHER_RECUR).size() == 1); |
| 302 | |
| 303 | }else{ |
| 304 | System.out.println(fp.getName()); |
| 305 | assertFalse(fp.hasProperty(FPProperty.OTHER_RECUR)); |
| 306 | assertTrue(fp.getPropertyClauses(FPProperty.OTHER_RECUR).size() == 0); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | assertTrue(ct == 1); |
| 311 | |
| 312 | }catch(Exception e){ |
| 313 | e.printStackTrace(); |
| 314 | } |
| 315 | |
| 316 | } |
| 317 | |
| 318 | @Test |
| 319 | public final void test_parseReflexiveRelation() { |
| 320 | try{ |
| 321 | String[] args = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
| 322 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db"}; |
| 323 | |
| 324 | FelixConfig.overrideID(); |
| 325 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 326 | |
| 327 | Timer.start("Felix-Timer"); |
| 328 | this.options = options; |
| 329 | resetACoupleAuxDataStructures(); |
| 330 | |
| 331 | fq = this.parseFelixQuery(); |
| 332 | |
| 333 | sa = new StaticAnalyzer(this.fq, options); |
| 334 | |
| 335 | sa.parseKeyConstraintRelation(); |
| 336 | sa.parseReflexiveRelation(); |
| 337 | |
| 338 | int ct = 0; |
| 339 | for(FelixPredicate fp : this.fq.getAllPred()){ |
| 340 | |
| 341 | if(fp.getName().equals("corefPred1")){ |
| 342 | ct++; |
| 343 | assertTrue(fp.hasProperty(FPProperty.REFLEX)); |
| 344 | assertTrue(fp.getPropertyClauses(FPProperty.REFLEX).size() == 1); |
| 345 | |
| 346 | }else if(fp.getName().equals("corefPred2")){ |
| 347 | ct++; |
| 348 | assertTrue(fp.hasProperty(FPProperty.REFLEX)); |
| 349 | assertTrue(fp.getPropertyClauses(FPProperty.REFLEX).size() == 1); |
| 350 | |
| 351 | }else if(fp.getName().equals("notCorefPred")){ |
| 352 | ct++; |
| 353 | assertTrue(fp.hasProperty(FPProperty.REFLEX)); |
| 354 | assertTrue(fp.getPropertyClauses(FPProperty.REFLEX).size() == 1); |
| 355 | |
| 356 | }else{ |
| 357 | assertFalse(fp.hasProperty(FPProperty.REFLEX)); |
| 358 | assertTrue(fp.getPropertyClauses(FPProperty.REFLEX).size() == 0); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | assertTrue(ct == 3); |
| 363 | |
| 364 | }catch(Exception e){ |
| 365 | e.printStackTrace(); |
| 366 | } |
| 367 | |
| 368 | } |
| 369 | |
| 370 | @Test |
| 371 | public final void test_parseSymmetricRelation() { |
| 372 | try{ |
| 373 | String[] args = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
| 374 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db"}; |
| 375 | |
| 376 | FelixConfig.overrideID(); |
| 377 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 378 | |
| 379 | Timer.start("Felix-Timer"); |
| 380 | this.options = options; |
| 381 | resetACoupleAuxDataStructures(); |
| 382 | |
| 383 | fq = this.parseFelixQuery(); |
| 384 | |
| 385 | sa = new StaticAnalyzer(this.fq, options); |
| 386 | |
| 387 | sa.parseKeyConstraintRelation(); |
| 388 | sa.parseSymmetricRelation(); |
| 389 | |
| 390 | int ct = 0; |
| 391 | for(FelixPredicate fp : this.fq.getAllPred()){ |
| 392 | |
| 393 | if(fp.getName().equals("corefPred1")){ |
| 394 | ct++; |
| 395 | assertTrue(fp.hasProperty(FPProperty.SYMM)); |
| 396 | assertTrue(fp.getPropertyClauses(FPProperty.SYMM).size() == 1); |
| 397 | |
| 398 | }else if(fp.getName().equals("corefPred2")){ |
| 399 | ct++; |
| 400 | assertTrue(fp.hasProperty(FPProperty.SYMM)); |
| 401 | assertTrue(fp.getPropertyClauses(FPProperty.SYMM).size() == 2); |
| 402 | |
| 403 | }else if(fp.getName().equals("notCorefPred")){ |
| 404 | ct++; |
| 405 | assertTrue(fp.hasProperty(FPProperty.SYMM)); |
| 406 | assertTrue(fp.getPropertyClauses(FPProperty.SYMM).size() == 1); |
| 407 | |
| 408 | }else{ |
| 409 | assertFalse(fp.hasProperty(FPProperty.SYMM)); |
| 410 | assertTrue(fp.getPropertyClauses(FPProperty.SYMM).size() == 0); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | assertTrue(ct == 3); |
| 415 | |
| 416 | }catch(Exception e){ |
| 417 | e.printStackTrace(); |
| 418 | } |
| 419 | |
| 420 | } |
| 421 | |
| 422 | @Test |
| 423 | public final void test_parseTransitiveRelation() { |
| 424 | try{ |
| 425 | String[] args = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
| 426 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db"}; |
| 427 | |
| 428 | FelixConfig.overrideID(); |
| 429 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 430 | |
| 431 | Timer.start("Felix-Timer"); |
| 432 | this.options = options; |
| 433 | resetACoupleAuxDataStructures(); |
| 434 | |
| 435 | fq = this.parseFelixQuery(); |
| 436 | |
| 437 | sa = new StaticAnalyzer(this.fq, options); |
| 438 | |
| 439 | sa.parseKeyConstraintRelation(); |
| 440 | sa.parseTransitiveRelation(); |
| 441 | |
| 442 | int ct = 0; |
| 443 | for(FelixPredicate fp : this.fq.getAllPred()){ |
| 444 | |
| 445 | if(fp.getName().equals("corefPred1")){ |
| 446 | ct++; |
| 447 | assertTrue(fp.hasProperty(FPProperty.TRANS)); |
| 448 | assertTrue(fp.getPropertyClauses(FPProperty.TRANS).size() == 1); |
| 449 | |
| 450 | }else if(fp.getName().equals("corefPred2")){ |
| 451 | ct++; |
| 452 | assertTrue(fp.hasProperty(FPProperty.TRANS)); |
| 453 | assertTrue(fp.getPropertyClauses(FPProperty.TRANS).size() == 1); |
| 454 | |
| 455 | }else if(fp.getName().equals("notCorefPred")){ |
| 456 | ct++; |
| 457 | assertTrue(fp.hasProperty(FPProperty.TRANS)); |
| 458 | assertTrue(fp.getPropertyClauses(FPProperty.TRANS).size() == 1); |
| 459 | |
| 460 | }else{ |
| 461 | assertFalse(fp.hasProperty(FPProperty.TRANS)); |
| 462 | assertTrue(fp.getPropertyClauses(FPProperty.TRANS).size() == 0); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | assertTrue(ct == 3); |
| 467 | |
| 468 | }catch(Exception e){ |
| 469 | e.printStackTrace(); |
| 470 | } |
| 471 | |
| 472 | } |
| 473 | |
| 474 | @Test |
| 475 | public final void test_parseSpecialPredicate() { |
| 476 | try{ |
| 477 | String[] args = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
| 478 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db"}; |
| 479 | |
| 480 | FelixConfig.overrideID(); |
| 481 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 482 | |
| 483 | Timer.start("Felix-Timer"); |
| 484 | this.options = options; |
| 485 | resetACoupleAuxDataStructures(); |
| 486 | |
| 487 | fq = this.parseFelixQuery(); |
| 488 | |
| 489 | sa = new StaticAnalyzer(this.fq, options); |
| 490 | |
| 491 | sa.parseKeyConstraintRelation(); |
| 492 | sa.parseReflexiveRelation(); |
| 493 | sa.parseSymmetricRelation(); |
| 494 | sa.parseTransitiveRelation(); |
| 495 | sa.parseChainRecursiveRelation(); |
| 496 | sa.parseNonRecursiveRelation(); |
| 497 | sa.parseOtherRecursiveRelation(); |
| 498 | sa.parseSpecialPredicate(); |
| 499 | |
| 500 | int ct = 0; |
| 501 | for(FelixPredicate fp : this.fq.getAllPred()){ |
| 502 | |
| 503 | if(fp.getName().equals("corefPred1_map")){ |
| 504 | ct++; |
| 505 | assertTrue(fp.isCorefMapPredicate == true); |
| 506 | }else{ |
| 507 | assertFalse(fp.isCorefMapPredicate == true); |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | assertTrue(ct == 1); |
| 512 | |
| 513 | }catch(Exception e){ |
| 514 | e.printStackTrace(); |
| 515 | } |
| 516 | |
| 517 | } |
| 518 | |
| 519 | |
| 520 | /** |
| 521 | * Run Felix on a very simple program. |
| 522 | */ |
| 523 | @Test |
| 524 | public final void naiveRun(){ |
| 525 | try{ |
| 526 | String[] args = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
| 527 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db", "-threads", "1"}; |
| 528 | FelixConfig.overrideID(); |
| 529 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 530 | new Felix().run(options); |
| 531 | |
| 532 | String[] args1 = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
| 533 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db", "-marginal", "-threads", "1"}; |
| 534 | FelixConfig.overrideID(); |
| 535 | options = FelixUIMan.parseCommand(args); |
| 536 | new Felix().run(options); |
| 537 | |
| 538 | }catch(Exception e){ |
| 539 | e.printStackTrace(); |
| 540 | assertTrue(false); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * Test whether the parser and og graph can deal with dependency correctly. |
| 546 | */ |
| 547 | @Test |
| 548 | public final void testParse() { |
| 549 | try{ |
| 550 | String[] args = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
| 551 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db"}; |
| 552 | FelixConfig.overrideID(); |
| 553 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 554 | |
| 555 | |
| 556 | Timer.start("Felix-Timer"); |
| 557 | this.options = options; |
| 558 | resetACoupleAuxDataStructures(); |
| 559 | |
| 560 | fq = this.parseFelixQuery(); |
| 561 | |
| 562 | sa = new StaticAnalyzer(this.fq, options); |
| 563 | sa.parse(); |
| 564 | |
| 565 | Scheduler sc = new Scheduler(this, this.fq, options); |
| 566 | ExecutionPlan ep = sc.schedule(); |
| 567 | |
| 568 | int ncrf = 0; |
| 569 | int nlr = 0; |
| 570 | int ncoref = 0; |
| 571 | int ntuffy = 0; |
| 572 | OperatorBucketGraph og = sc.getOperatorBucketGraph(); |
| 573 | |
| 574 | for(ConcurrentOperatorsBucket cob : sc.getOperatorBucketGraph().getOperators()){ |
| 575 | for(StatOperator sop : cob.getOperators()){ |
| 576 | if(sop.type == OPType.TUFFY){ |
| 577 | assertTrue(og.getDownStreamOperator(cob).size() == 0); |
| 578 | assertTrue(og.getUpStreamOperator(cob).size() == 2); |
| 579 | //assertTrue(og.getDownStreamOperator(cob).iterator().next().type == OPType.COREF); |
| 580 | assertTrue(og.getUpStreamOperator(cob).iterator().next().type == OPType.COREF); |
| 581 | //assertTrue(sop.folClauses.size() == 7); |
| 582 | ntuffy ++; |
| 583 | } |
| 584 | if(sop.type == OPType.COREF){ |
| 585 | assertTrue(og.getDownStreamOperator(cob).size() == 1 || og.getDownStreamOperator(cob).size() == 0); |
| 586 | assertTrue(og.getUpStreamOperator(cob).size() == 1 || og.getUpStreamOperator(cob).size() == 0); |
| 587 | |
| 588 | if(og.getUpStreamOperator(cob).size() == 1){ |
| 589 | assertTrue(og.getDownStreamOperator(cob).iterator().next().type == OPType.TUFFY); |
| 590 | assertTrue(og.getUpStreamOperator(cob).iterator().next().type == OPType.TUFFY); |
| 591 | } |
| 592 | |
| 593 | ncoref ++; |
| 594 | } |
| 595 | if(sop.type == OPType.LR){ |
| 596 | assertTrue(og.getDownStreamOperator(cob).size() == 0 && og.getDownStreamOperator(cob).size() == 0); |
| 597 | nlr ++; |
| 598 | } |
| 599 | if(sop.type == OPType.CRF){ |
| 600 | assertTrue(og.getDownStreamOperator(cob).size() == 0 && og.getDownStreamOperator(cob).size() == 0); |
| 601 | ncrf ++; |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | assertTrue(nlr == 2 * (Config.getNumThreads()-1)); |
| 607 | assertTrue(ncrf == 1 * (Config.getNumThreads()-1)); |
| 608 | assertTrue(ncoref == 3); |
| 609 | assertTrue(ntuffy == 1); |
| 610 | |
| 611 | |
| 612 | }catch(Exception e){ |
| 613 | e.printStackTrace(); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | } |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |