public List<String> launchLocal() { List<String> result = new ArrayList<>(); if (LLVMOptions.isDebug()) { System.out.println("current file: " + originalFile); } try { int retValue = LLVM.executeMain(bitCodeFile); result.add("exit " + retValue); } catch (Throwable t) { recordError(tuple, t); result.add("exit -1"); } return result; }
@Parameterized.Parameters public static List<TestCaseFiles[]> getTestFiles() throws IOException { File configFile = LLVMPaths.LLVM_TEST_SUITE_CONFIG; File testSuite = LLVMPaths.LLVM_TEST_SUITE; String discoveryPath = LLVMOptions.getLLVMTestDiscoveryPath(); return getTestCasesFromConfigFile( configFile, testSuite, discoveryPath, new TestCaseGenerator() { public List<TestCaseFiles> getCompiledTestCaseFiles(File toBeCompiled) { String expectedOutputName = PathUtil.replaceExtension( toBeCompiled.getAbsolutePath(), LLVM_REFERENCE_OUTPUT_EXTENSION); File expectedOutputFile = new File(expectedOutputName); File dest = TestHelper.getTempLLFile(toBeCompiled, "_main"); try { TestCaseFiles result = TestHelper.compileToLLVMIRWithClang(toBeCompiled, dest, expectedOutputFile); return Arrays.asList(result); } catch (Exception e) { return Collections.emptyList(); } } public TestCaseFiles getBitCodeTestCaseFiles(File bitCodeFile) { String expectedOutputName = PathUtil.replaceExtension( bitCodeFile.getAbsolutePath(), LLVM_REFERENCE_OUTPUT_EXTENSION); File expectedOutputFile = new File(expectedOutputName); TestCaseFiles testCaseFiles; if (expectedOutputFile.exists()) { testCaseFiles = TestCaseFiles.createFromBitCodeFile(bitCodeFile, expectedOutputFile); } else { testCaseFiles = TestCaseFiles.createFromBitCodeFile(bitCodeFile); } return testCaseFiles; } public ProgrammingLanguage[] getSupportedLanguages() { return Clang.getSupportedLanguages(); } }); }
@Test(timeout = TEST_TIMEOUT_TIME) public void test() throws IOException { if (LLVMOptions.isDebug()) { System.out.println("current file: " + originalFile); } List<String> expectedLines; int expectedReturnValue; try { expectedLines = Files.readAllLines(Paths.get(expectedFile.getAbsolutePath())); expectedReturnValue = parseAndRemoveReturnValue(expectedLines); } catch (Exception e) { expectedLines = new ArrayList<>(); expectedReturnValue = 0; } List<String> actualLines = launchRemote(bitCodeFile); // launchLocal(); int actualReturnValue = parseAndRemoveReturnValue(actualLines); boolean pass = expectedLines.equals(actualLines) && expectedReturnValue == actualReturnValue; recordTestCase(tuple, pass); assertEquals(bitCodeFile.getAbsolutePath(), expectedLines, actualLines); assertEquals(bitCodeFile.getAbsolutePath(), expectedReturnValue, actualReturnValue); }