-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added witness test, fixed witness printing
- Loading branch information
1 parent
7b0d21c
commit 113f274
Showing
7 changed files
with
141 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliWitnessTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2023 Budapest University of Technology and Economics | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package hu.bme.mit.theta.xcfa.cli | ||
|
||
import hu.bme.mit.theta.xcfa.cli.XcfaCli.Companion.main | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.Arguments | ||
import org.junit.jupiter.params.provider.MethodSource | ||
import java.util.stream.Stream | ||
import kotlin.io.path.absolutePathString | ||
import kotlin.io.path.createTempDirectory | ||
import kotlin.io.path.exists | ||
|
||
data class WitnessEdge( | ||
val startlineRange: Pair<Int, Int>?, | ||
val endlineRange: Pair<Int, Int>?, | ||
val startoffsetRange: Pair<Int, Int>?, | ||
val endoffsetRange: Pair<Int, Int>?, | ||
val assumption: Regex?, | ||
) | ||
|
||
class XcfaCliWitnessTest { | ||
companion object { | ||
|
||
@JvmStatic | ||
fun cFiles(): Stream<Arguments> { | ||
return Stream.of( | ||
Arguments.of("/c/litmustest/singlethread/witness_test.c", listOf( | ||
WitnessEdge( | ||
startlineRange = Pair(5, 5), | ||
endlineRange = Pair(5, 5), | ||
startoffsetRange = Pair(79, 91), | ||
endoffsetRange = Pair(110, 115), | ||
assumption = Regex("i *== *-1"), | ||
), | ||
)), | ||
) | ||
} | ||
|
||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("cFiles") | ||
fun testCWitness(filePath: String, expectedWitnessEdges: List<WitnessEdge>) { | ||
val temp = createTempDirectory() | ||
val params = arrayOf( | ||
"--input-type", "C", | ||
"--input", javaClass.getResource(filePath)!!.path, | ||
"--stacktrace", | ||
"--output-results", | ||
"--output-directory", temp.absolutePathString(), | ||
"--debug", | ||
) | ||
main(params) | ||
Assertions.assertTrue(temp.resolve("witness.graphml").exists()) | ||
val witnessContents = temp.resolve("witness.graphml").toFile().readText() | ||
val edges = mutableListOf<Map<String, String>>() | ||
val edgeMatcher = Regex("(?s)<edge.*?</edge") | ||
for(match in edgeMatcher.findAll(witnessContents)) { | ||
val dataMatcher = Regex("<data key=\"(.*)\">(.*)</data>") | ||
val data = mutableMapOf<String, String>() | ||
for(dataMatch in dataMatcher.findAll(match.value)) { | ||
val (key, value) = dataMatch.destructured | ||
data.put(key, value) | ||
} | ||
edges.add(data) | ||
} | ||
for (expectedWitnessEdge in expectedWitnessEdges) { | ||
Assertions.assertFalse( | ||
edges.none { edge -> | ||
val startline = expectedWitnessEdge.startlineRange?.let {edge["startline"]?.let{v -> Pair(it, Integer.parseInt(v)) } }?.let { it.first.first <= it.second && it.second <= it.first.second } ?: false | ||
val endline = expectedWitnessEdge.endlineRange?.let {edge["endline"]?.let{v -> Pair(it, Integer.parseInt(v)) } }?.let { it.first.first <= it.second && it.second <= it.first.second } ?: false | ||
val startoffset = expectedWitnessEdge.startoffsetRange?.let {edge["startoffset"]?.let{v -> Pair(it, Integer.parseInt(v)) } }?.let { it.first.first <= it.second && it.second <= it.first.second } ?: false | ||
val endoffset = expectedWitnessEdge.endoffsetRange?.let {edge["endoffset"]?.let{v -> Pair(it, Integer.parseInt(v)) } }?.let { it.first.first <= it.second && it.second <= it.first.second } ?: false | ||
val assumption = expectedWitnessEdge.assumption?.let {edge["assumption"]?.let{v -> Pair(it, v) } }?.let { it.first.matches(it.second) } ?: false | ||
startline && endline && startoffset && endoffset && assumption | ||
}, | ||
"Expected witness edge not found: $expectedWitnessEdge" | ||
) | ||
} | ||
temp.toFile().deleteRecursively() | ||
} | ||
|
||
|
||
} |
9 changes: 9 additions & 0 deletions
9
subprojects/xcfa/xcfa-cli/src/test/resources/c/litmustest/singlethread/witness_test.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
extern void reach_error(); | ||
extern int __VERIFIER_nondet_int(void); | ||
|
||
int main() { | ||
int i = __VERIFIER_nondet_int(); | ||
|
||
if(i + 1 == 0) reach_error(); | ||
|
||
} |