Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report AlwaysFalseConstraints as CF errors #341

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions testdata/ostrusted-unsat-test/Unsat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ostrusted.qual.OsUntrusted;
import ostrusted.qual.OsTrusted;

class Unsat {
d367wang marked this conversation as resolved.
Show resolved Hide resolved

void foo(@OsTrusted String s) {}

@OsUntrusted
String bar() { return ""; }
d367wang marked this conversation as resolved.
Show resolved Hide resolved

void m() {
String s = bar();
// :: error: (argument.type.incompatible)
foo(s);
}
}
31 changes: 31 additions & 0 deletions tests/checkers/inference/OsTrustedUnsatTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package checkers.inference;

import checkers.inference.solver.SolverEngine;
import checkers.inference.test.CFInferenceUnsatTest;
import org.checkerframework.framework.test.TestUtilities;
import org.checkerframework.javacutil.Pair;
import org.junit.runners.Parameterized;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class OsTrustedUnsatTest extends CFInferenceUnsatTest {

public OsTrustedUnsatTest(File testFile) {
super(testFile, ostrusted.OsTrustedChecker.class, "ostrusted",
"-Anomsgtext", "-Astubs=src/ostrusted/jdk.astub", "-d", "tests/build/outputdir");
}

@Override
public Pair<String, List<String>> getSolverNameAndOptions() {
return Pair.<String, List<String>>of(SolverEngine.class.getCanonicalName(), new ArrayList<String>());
}

@Parameterized.Parameters
public static List<File> getTestFiles(){
List<File> testfiles = new ArrayList<>();//InferenceTestUtilities.findAllSystemTests();
testfiles.addAll(TestUtilities.findRelativeNestedJavaFiles("testdata", "ostrusted-unsat-test"));
return testfiles;
}
}
4 changes: 4 additions & 0 deletions tests/checkers/inference/test/CFInferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ testFile, testDataDir, checkerName, checkerOptions, getAdditionalInferenceOption
solverArgs.second, useHacks(), shouldEmitDebugInfo, getPathToAfuScripts(), getPathToInferenceScript());

InferenceTestResult testResult = new InferenceTestExecutor().runTest(config);
postProcessResult(testResult);
}

protected void postProcessResult(InferenceTestResult testResult) {
d367wang marked this conversation as resolved.
Show resolved Hide resolved
InferenceTestUtilities.assertResultsAreValid(testResult);
}
}
33 changes: 33 additions & 0 deletions tests/checkers/inference/test/CFInferenceUnsatTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package checkers.inference.test;

import org.checkerframework.javacutil.SystemUtil;

import javax.annotation.processing.AbstractProcessor;
import java.io.File;

/**
* This test suite runs inference individually on target files that are unsatisfiable. This means each
* test case is expected to pass the initial check phase while fail at the inference phase and terminate.
d367wang marked this conversation as resolved.
Show resolved Hide resolved
*
* The use of this class is the same as {@link CFInferenceTest}. Note that the target directory of the test
* cases can only contain unsatisfiable cases.
*/
public abstract class CFInferenceUnsatTest extends CFInferenceTest{
public CFInferenceUnsatTest(File testFile, Class<? extends AbstractProcessor> checker,
String testDir, String... checkerOptions) {
super(testFile, checker, testDir, checkerOptions);
}

@Override
protected void postProcessResult(InferenceTestResult testResult) {
final InferenceTestPhase lastPhaseRun = testResult.getLastPhaseRun();
if (lastPhaseRun == InferenceTestPhase.INITIAL_TYPECHECK) {
InferenceTestUtilities.assertResultsAreValid(testResult);

} else if (lastPhaseRun == InferenceTestPhase.FINAL_TYPECHECK) {
String summary = "Inference is expected to fail, but succeeded on source files: \n"
+ SystemUtil.join("\n", testResult.getConfiguration().getInitialTypecheckConfig().getTestSourceFiles()) + "\n\n";
InferenceTestUtilities.assertFail(InferenceTestPhase.INFER, summary);
}
}
}