public class MainTest { private static final File programs_location = FileUtils.absoluteResourcePath("syntax"); private static final File programs_c_location = FileUtils.absoluteResourcePath("c"); private static final File bad_programs_location = new File(programs_location, "bad"); private static final File mini_programs_location = new File(programs_c_location, "mini_bnc"); private static final File nec_programs_location = new File(programs_c_location, "nec_bnc"); private static final File nec_inline_programs_location = new File(programs_c_location, "nec_inline_bnc"); private static final File sv_programs_location = new File(System.getProperty("user.dir"), "../../benchmarks/sv_bnc"); private static final FilenameFilter cFileFilter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".c"); } }; private static final FilenameFilter iFileFilter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".i"); } }; private static final FilenameFilter falseDerefFileFilter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith("_false-valid-deref.c"); } }; private static final FilenameFilter falseFreeFileFilter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith("_false-valid-free.c"); } }; private static final FilenameFilter falseMemtrackFileFilter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith("_false-valid-memtrack.c"); } }; private static final FilenameFilter falseAssertFileFilter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith("_false-valid-assert.c"); } }; private static final FilenameFilter propFileFilter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".properties"); } }; private void runCascade(final String... args) throws Exception { System.out.println("runCascade: " + Joiner.on(";").join(args)); TestUtils.callMayExit( new Callable<Void>() { @Override public Void call() throws Exception { Preferences.clearAll(); Main main = getInjector().getInstance(Main.class); main.init(); List<String> files = main.processCommandLine(args); main.setOutStream(IOUtils.NULL_PRINT_STREAM); main.setErrStream(System.err); main.setStatsStream(System.err); main.run(files); return null; } }); } private void runCascadeTO(final String... args) throws Exception { System.out.println("runCascade with timeout " + "20s: " + Joiner.on(";").join(args)); TestUtils.callWithTimeout( new Runnable() { @Override public void run() { Preferences.clearAll(); try { Main main = getInjector().getInstance(Main.class); main.init(); List<String> files = main.processCommandLine(args); main.setOutStream(System.out); main.setErrStream(IOUtils.NULL_PRINT_STREAM); IOUtils.enableOut(); main.run(files); } catch (TheoremProverException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } } }, 20); } private TestUtils.Tester<File> parserTest(final String... args) { return new TestUtils.Tester<File>() { @Override public void runTest(File f) { try { List<String> argList = Lists.newArrayList(args); argList.add(f.toString()); runCascade(argList.toArray(new String[0])); } catch (ParseException e) { throw new AssertionError(e); } catch (Throwable e) { throw new RuntimeException(e); } } }; } private TestUtils.Tester<File> parserTestTimeout(final String... args) { return new TestUtils.Tester<File>() { @Override public void runTest(File f) { try { List<String> argList = Lists.newArrayList(args); argList.add(f.toString()); runCascadeTO(argList.toArray(new String[0])); } catch (Throwable e) { throw new RuntimeException(e); } } }; } @Test(expected = ExitException.class) public void testHelp() throws Exception { runCascade(new String[] {"--help"}); } @Test(expected = ExitException.class) public void testVersion() throws Exception { runCascade(new String[] {"--version"}); } @Test public void testPrograms() { TestUtils.checkDirectory(programs_location, cFileFilter, parserTest("--parsec"), false); } @Test public void testProgramsNoThreads() { TestUtils.checkDirectory( programs_location, cFileFilter, parserTest("--parsec", "--no-threads"), false); } @Test public void testBadPrograms() { TestUtils.checkDirectory(bad_programs_location, cFileFilter, parserTest("--parsec"), true); } @Test public void testBadProgramsNoThreads() { TestUtils.checkDirectory( bad_programs_location, cFileFilter, parserTest("--parsec", "--no-threads"), true); } @Test public void testProperties() { TestUtils.checkDirectory(bad_programs_location, propFileFilter, parserTest("--prop"), true); } @Test public void testDryRun() { TestUtils.checkDirectory(programs_location, cFileFilter, parserTest("--dry-run"), false); TestUtils.checkDirectoryRec( mini_programs_location, cFileFilter, parserTest("--dry-run", "--iter-times", "1"), false); TestUtils.checkDirectoryRec( mini_programs_location, cFileFilter, parserTest("--dry-run", "--iter-times", "1", "--lambda"), false); TestUtils.checkDirectoryRec( mini_programs_location, cFileFilter, parserTest("--dry-run", "--multi-cell", "--iter-times", "1"), false); TestUtils.checkDirectoryRec( mini_programs_location, cFileFilter, parserTest("--dry-run", "--multi-cell", "--iter-times", "1", "--lambda"), false); } @Test @Ignore public void testFieldSensitive() { File invalid_programs_location = new File(mini_programs_location, "invalid"); File valid_programs_location = new File(mini_programs_location, "valid"); Tester<File> tester = parserTestTimeout( "--inline-anno", "--iter-times", "10", "--vari-cell", "--lambda", "--memory-check", "--hoare", "--fs", "-m32"); TestUtils.checkDirectoryRec(invalid_programs_location, cFileFilter, tester, false); TestUtils.checkDirectoryRec(valid_programs_location, cFileFilter, tester, false); } @Test @Ignore public void testReachability() { File bv_programs_location = new File(sv_programs_location, "bitvector"); File bv_reg_programs_location = new File(sv_programs_location, "bitvector-regression"); TestUtils.checkDirectoryRec( bv_programs_location, iFileFilter, parserTestTimeout( "-r", "ERROR", "--multi-cell", "--iter-times", "10", "--function-inline", "2"), false); TestUtils.checkDirectoryRec( bv_reg_programs_location, iFileFilter, parserTestTimeout( "-r", "ERROR", "--multi-cell", "--iter-times", "10", "--function-inline", "2"), false); } @Test @Ignore public void testMemorySafety() { File memsafety_programs_location = new File(sv_programs_location, "memsafety"); TestUtils.checkDirectoryRec( memsafety_programs_location, iFileFilter, parserTestTimeout( "--memory-check", "--lambda", "--hoare", "--multi-cell", "--iter-times", "10", "--function-inline", "2"), false); } @Test @Ignore public void testNecBenchmarkDry() { final Tester<File> SoundTester = parserTestTimeout("--dry-run"); TestUtils.checkDirectoryRec(nec_programs_location, cFileFilter, SoundTester, false); } @Test // @Ignore public void testCFSMiniBenchmark() { final Tester<File> SoundTester = parserTestTimeout( "--inline-anno", "--iter-times", "10", "-m32", "--vari-cell", "--lambda", "--memory-check", "--hoare", "-cfs"); File invalid_location = new File(mini_programs_location, "invalid"); File valid_location = new File(mini_programs_location, "valid"); TestUtils.checkDirectoryRec(invalid_location, falseDerefFileFilter, SoundTester, false); TestUtils.checkDirectoryRec(invalid_location, falseFreeFileFilter, SoundTester, false); TestUtils.checkDirectoryRec(invalid_location, falseMemtrackFileFilter, SoundTester, false); TestUtils.checkDirectoryRec(invalid_location, falseAssertFileFilter, SoundTester, false); TestUtils.checkDirectoryRec(valid_location, cFileFilter, SoundTester, false); } @Test // @Ignore public void testCFSCSMiniBenchmark() { final Tester<File> SoundTester = parserTestTimeout( "--inline-anno", "--iter-times", "10", "-m32", "--vari-cell", "--lambda", "--memory-check", "--hoare", "-cfscs"); File invalid_location = new File(mini_programs_location, "invalid"); File valid_location = new File(mini_programs_location, "valid"); TestUtils.checkDirectoryRec(invalid_location, falseDerefFileFilter, SoundTester, false); TestUtils.checkDirectoryRec(invalid_location, falseFreeFileFilter, SoundTester, false); TestUtils.checkDirectoryRec(invalid_location, falseMemtrackFileFilter, SoundTester, false); TestUtils.checkDirectoryRec(invalid_location, falseAssertFileFilter, SoundTester, false); TestUtils.checkDirectoryRec(valid_location, cFileFilter, SoundTester, false); } @Test @Ignore public void testNecInlineBenchmarkDry() { final Tester<File> SoundTester = parserTestTimeout("--dry-run", "--inline-anno"); TestUtils.checkDirectoryRec(nec_inline_programs_location, cFileFilter, SoundTester, false); } }
public class ControlFileTest { public static final File programs_location = FileUtils.absoluteResourcePath("syntax"); public static final File bad_programs_location = FileUtils.filePath(programs_location, "bad"); private void checkPosition(Position p) { assertNotNull("No File for Position", p.getFile()); assertNotNull("No LineNum for Position", p.getLine()); List<Command> cmds = p.getCommands(); for (Command c : cmds) { assertNotNull("No CascadeFunction for Command", c.getCascadeFunction()); assertNotNull("No Argument for Command", c.getArgument()); } } /** * Try to parse the program, given a filename * * @param file */ private void parseFromFile(File file) { // System.out.print("Parsing " + file + " ... "); try { ControlFile cf = ControlFile.fromXml(file); /* * Validate that the ControlFile object has the expected fields populated: * 1) At least one source File 2) At least one Run. 4) At least one * Start/End Position for each Run 5) A File and LineNum for each * Position. */ List<File> sfs = cf.getSourceFiles(); assertFalse("No source files in control file.", sfs == null || sfs.isEmpty()); for (File sf : sfs) { assertNotNull(sf); assertTrue("file " + sf.getAbsolutePath() + " does not exist", sf.exists()); } // for( TheoryId theory : cf.getTheories() ) { TheoryId theory = cf.getTheoryId(); if (theory != null) { // assertNotNull( theory ); try { Class.forName(theory.getQname()); } catch (ClassNotFoundException e) { fail("Theory definition not found: " + theory.getQname()); } } List<Run> runs = cf.getRuns(); assertFalse("No runs in control file.", runs == null || runs.isEmpty()); for (Run run : runs) { assertNotNull("null Run found in control file", run); Position sp = run.getStartPosition(); Position ep = run.getEndPosition(); assertNotNull("No start position for Run", sp); assertNotNull("No end position for Run", ep); checkPosition(sp); checkPosition(ep); for (Position wp : run.getWayPoints()) { checkPosition(wp); } } } catch (ControlFileException e) { fail(e.getMessage()); // fail(x.toString()); } } @Test public void testPProgram() { // Make the control file filter FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".ctrl"); } }; TestUtils.Tester<File> tester = new TestUtils.Tester<File>() { @Override public void runTest(File f) { parseFromFile(f); } }; TestUtils.checkDirectory(programs_location, filter, tester, false); TestUtils.checkDirectory(bad_programs_location, filter, tester, true); } }