99package org .sosy_lab .java_smt .test ;
1010
1111import static com .google .common .truth .Truth .assertThat ;
12- import static com . google . common . truth . TruthJUnit . assume ;
12+ import static org . junit . Assert . assertThrows ;
1313
1414import com .google .common .collect .ImmutableList ;
1515import com .google .common .collect .ImmutableSet ;
@@ -34,21 +34,6 @@ private BooleanFormula makeStarAll(List<BooleanFormula> formulas) {
3434 return formulas .stream ().reduce (slmgr ::makeStar ).orElse (bmgr .makeTrue ());
3535 }
3636
37- protected void requireSepNil () {
38- assume ()
39- .withMessage ("Java bindings for solver %s do not support SEP_NIL" , solverToUse ())
40- .that (solverToUse ())
41- .isNotEqualTo (Solvers .CVC4 );
42- }
43-
44- protected void requireMultipleHeapSorts () {
45- assume ()
46- .withMessage (
47- "Java bindings for solver %s do not support multiple heap sorts" , solverToUse ())
48- .that (solverToUse ())
49- .isNotEqualTo (Solvers .CVC4 );
50- }
51-
5237 @ Before
5338 public void setup () {
5439 requireSeparationLogic ();
@@ -70,24 +55,52 @@ public void testMakeEmp() throws InterruptedException, SolverException {
7055 }
7156
7257 @ Test
73- public void testMakeEmptoP2 () throws InterruptedException , SolverException {
74- requireMultipleHeapSorts ();
58+ public void testMakeEmpWithMultipleSorts () throws InterruptedException , SolverException {
7559 // Actually, no solver supports multiple heap sorts. However, our bindings for CVC5
76- // apply non-incremental mode for SL and use distinct solver instances for distinct queries .
60+ // can not detect the heap sort for EMP, so we use a dummy sort (Int->Int) instead .
7761
7862 BooleanFormula emptyHeapInt =
7963 slmgr .makeEmptyHeap (FormulaType .RationalType , FormulaType .BooleanType );
8064 BooleanFormula emptyHeapRat =
8165 slmgr .makeEmptyHeap (FormulaType .IntegerType , FormulaType .IntegerType );
8266 BooleanFormula query = bmgr .and (emptyHeapInt , emptyHeapRat );
8367
84- assertThatFormula (query ).isSatisfiable (ProverOptions .ENABLE_SEPARATION_LOGIC );
68+ try (ProverEnvironment prover =
69+ context .newProverEnvironment (ProverOptions .ENABLE_SEPARATION_LOGIC )) {
70+ prover .push (query );
71+ if (solverToUse () == Solvers .CVC5 ) {
72+ assertThatEnvironment (prover ).isSatisfiable ();
73+ } else {
74+ assertThrows (Exception .class , () -> prover .isUnsat ());
75+ }
76+ prover .pop ();
77+ }
8578 }
8679
8780 @ Test
88- public void testNotNilPtoNil () throws InterruptedException , SolverException {
89- requireSepNil ();
81+ public void testMakeEmpWithMultipleSortsInDistinctQueries ()
82+ throws InterruptedException , SolverException {
83+ // Actually, no solver supports multiple heap sorts. However, our bindings for CVC5
84+ // apply non-incremental mode for SL and use distinct solver instances for distinct queries.
85+
86+ BooleanFormula emptyHeapInt =
87+ slmgr .makeEmptyHeap (FormulaType .RationalType , FormulaType .BooleanType );
88+ BooleanFormula emptyHeapRat =
89+ slmgr .makeEmptyHeap (FormulaType .IntegerType , FormulaType .IntegerType );
90+
91+ try (ProverEnvironment prover =
92+ context .newProverEnvironment (ProverOptions .ENABLE_SEPARATION_LOGIC )) {
93+ prover .push (emptyHeapInt );
94+ assertThatEnvironment (prover ).isSatisfiable ();
95+ prover .pop ();
96+ prover .push (emptyHeapRat );
97+ assertThatEnvironment (prover ).isSatisfiable ();
98+ prover .pop ();
99+ }
100+ }
90101
102+ @ Test
103+ public void testNotNilPtoNil () throws InterruptedException , SolverException {
91104 IntegerFormula nil = slmgr .makeNilElement (FormulaType .IntegerType );
92105 BooleanFormula nilPtoNil = slmgr .makePointsTo (nil , nil );
93106
@@ -96,8 +109,6 @@ public void testNotNilPtoNil() throws InterruptedException, SolverException {
96109
97110 @ Test
98111 public void testNilPtoValue () throws InterruptedException , SolverException {
99- requireSepNil ();
100-
101112 IntegerFormula nil = slmgr .makeNilElement (FormulaType .IntegerType );
102113 IntegerFormula value = imgr .makeNumber (42 );
103114 BooleanFormula nilPtoValue = slmgr .makePointsTo (nil , value );
@@ -107,8 +118,6 @@ public void testNilPtoValue() throws InterruptedException, SolverException {
107118
108119 @ Test
109120 public void testXPtoNil () throws InterruptedException , SolverException {
110- requireSepNil ();
111-
112121 IntegerFormula ptr = imgr .makeVariable ("p" );
113122 IntegerFormula nil = slmgr .makeNilElement (FormulaType .IntegerType );
114123 BooleanFormula ptoNil = slmgr .makePointsTo (ptr , nil );
@@ -127,8 +136,6 @@ public void testXPtoValue() throws InterruptedException, SolverException {
127136
128137 @ Test
129138 public void testPPtoNilThenPPtoNil () throws SolverException , InterruptedException {
130- requireSepNil ();
131-
132139 IntegerFormula ptr = imgr .makeVariable ("p" );
133140 IntegerFormula nil = slmgr .makeNilElement (FormulaType .IntegerType );
134141 BooleanFormula ptoNil = slmgr .makePointsTo (ptr , nil );
@@ -141,14 +148,14 @@ public void testPPtoNilThenPPtoNil() throws SolverException, InterruptedExceptio
141148 prover .push (ptoNil );
142149 assertThatEnvironment (prover ).isSatisfiable ();
143150 assertThatEnvironment (prover ).isSatisfiable ();
151+ assertThatEnvironment (prover ).isSatisfiable ();
152+ assertThatEnvironment (prover ).isSatisfiable ();
144153 prover .pop ();
145154 }
146155 }
147156
148157 @ Test
149158 public void testPtoNilThenPPto42 () throws SolverException , InterruptedException {
150- requireSepNil ();
151-
152159 IntegerFormula ptr = imgr .makeVariable ("p" );
153160 IntegerFormula nil = slmgr .makeNilElement (FormulaType .IntegerType );
154161 IntegerFormula value = imgr .makeNumber (42 );
@@ -210,8 +217,6 @@ public void testStar() throws InterruptedException, SolverException {
210217
211218 @ Test
212219 public void testSimpleTreeValid () throws InterruptedException , SolverException {
213- requireSepNil ();
214-
215220 // lets build a tree:
216221 // - each node consists of two integers: left and right
217222 // - each node pointer points to the left integer, the right integer is at pointer+1
@@ -250,8 +255,6 @@ public void testSimpleTreeValid() throws InterruptedException, SolverException {
250255
251256 @ Test
252257 public void testSimpleTreeInvalid () throws InterruptedException , SolverException {
253- requireSepNil ();
254-
255258 IntegerFormula nil = slmgr .makeNilElement (FormulaType .IntegerType );
256259 IntegerFormula root = imgr .makeVariable ("root" );
257260 IntegerFormula left = imgr .makeVariable ("left" );
@@ -271,8 +274,6 @@ public void testSimpleTreeInvalid() throws InterruptedException, SolverException
271274
272275 @ Test
273276 public void testListValid () throws InterruptedException , SolverException {
274- requireSepNil ();
275-
276277 IntegerFormula nil = slmgr .makeNilElement (FormulaType .IntegerType );
277278 List <IntegerFormula > nodes = new ArrayList <>();
278279 for (int i = 0 ; i <= 10 ; i ++) {
0 commit comments