-
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.
- Loading branch information
1 parent
db55149
commit 4963dbb
Showing
4 changed files
with
120 additions
and
6 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
112 changes: 112 additions & 0 deletions
112
subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaStateTest.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,112 @@ | ||
/* | ||
* 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.analysis | ||
|
||
import hu.bme.mit.theta.analysis.expl.ExplState | ||
import hu.bme.mit.theta.core.type.inttype.IntExprs | ||
import hu.bme.mit.theta.xcfa.model.* | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
import java.util.* | ||
import java.util.function.Predicate | ||
|
||
class XcfaStateTest { | ||
|
||
@Test | ||
fun testApply1() { | ||
val actionOrder: MutableList<XcfaAction> = ArrayList() | ||
val expectations: MutableList<Predicate<XcfaState<ExplState>>> = ArrayList() | ||
lateinit var initState: XcfaState<ExplState> | ||
lateinit var xcfa: XCFA | ||
|
||
val edges: MutableList<XcfaEdge> = ArrayList() | ||
xcfa = xcfa("example") { | ||
val proc1 = procedure("proc1") { | ||
val a = "a" type IntExprs.Int() direction ParamDirection.IN | ||
val b = "b" type IntExprs.Int() direction ParamDirection.OUT | ||
|
||
edges.add((init to final) { | ||
b assign a.ref | ||
}) | ||
} | ||
val main = procedure("main") { | ||
val tmp = "tmp" type IntExprs.Int() | ||
edges.add((init to "L1") { | ||
proc1("1", tmp.ref) | ||
}) | ||
edges.add(("L1" to "L2") { | ||
tmp.start(proc1, tmp.ref) | ||
}) | ||
edges.add(("L2" to final) { | ||
tmp.join() | ||
}) | ||
} | ||
|
||
main.start() | ||
} | ||
initState = XcfaState( | ||
xcfa, | ||
mapOf( | ||
Pair(0, | ||
XcfaProcessState( | ||
locs = LinkedList(listOf(edges[1].source)), | ||
varLookup = LinkedList() | ||
) | ||
) | ||
), | ||
ExplState.bottom() | ||
) | ||
|
||
actionOrder.add(XcfaAction(0, edges[1])) | ||
expectations.add { it.processes[0]!!.locs.size == 2 && it.processes[0]!!.locs.peek() == edges[0].source } | ||
|
||
actionOrder.add(XcfaAction(0, edges[0])) | ||
expectations.add { it.processes[0]!!.locs.size == 2 && it.processes[0]!!.locs.peek() == edges[0].target } | ||
|
||
actionOrder.add(XcfaAction(0, XcfaEdge(edges[0].target, edges[0].target, ReturnLabel(NopLabel)))) | ||
expectations.add { it.processes[0]!!.locs.size == 1 && it.processes[0]!!.locs.peek() == edges[1].target } | ||
|
||
actionOrder.add(XcfaAction(0, edges[2])) | ||
expectations.add { | ||
it.processes.size == 2 && | ||
it.processes[0]!!.locs.size == 1 && it.processes[0]!!.locs.peek() == edges[2].target && | ||
it.processes[1]!!.locs.size == 1 && it.processes[1]!!.locs.peek() == edges[0].source | ||
} | ||
|
||
actionOrder.add(XcfaAction(1, edges[0])) | ||
expectations.add { | ||
it.processes.size == 2 && | ||
it.processes[0]!!.locs.size == 1 && it.processes[0]!!.locs.peek() == edges[2].target && | ||
it.processes[1]!!.locs.size == 1 && it.processes[1]!!.locs.peek() == edges[0].target | ||
} | ||
|
||
actionOrder.add(XcfaAction(1, XcfaEdge(edges[0].target, edges[0].target, ReturnLabel(NopLabel)))) | ||
expectations.add { it.processes.size == 1 && it.processes[0]!!.locs.size == 1 && it.processes[0]!!.locs.peek() == edges[2].target } | ||
|
||
actionOrder.add(XcfaAction(0, edges[3])) | ||
expectations.add { it.processes[0]!!.locs.size == 1 && it.processes[0]!!.locs.peek() == edges[3].target } | ||
|
||
var state = initState | ||
for ((index, xcfaAction) in actionOrder.withIndex()) { | ||
println("Test $index: $xcfaAction") | ||
val newState = state.apply(xcfaAction) | ||
assertTrue(expectations[index].test(newState.first)) | ||
state = newState.first | ||
println("Test $index OK") | ||
} | ||
} | ||
} |
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