Skip to content

Commit

Permalink
Try more tests, problems with ContextProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
KuechA committed Mar 14, 2024
1 parent aac8bbc commit 28bc31e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,51 @@ class DFGFunctionSummariesTest {
assertEquals(jsonSummaries.functionToDFGEntryMap, yamlSummaries.functionToDFGEntryMap)
}

@Test
fun testMatching() {
val code =
GraphExamples.testFrontend(
TranslationConfiguration.builder()
.defaultPasses()
.registerLanguage(TestLanguage("."))
.registerFunctionSummary(File("src/test/resources/function-dfg2.yml"))
.inferenceConfiguration(
InferenceConfiguration.builder()
.inferDfgForUnresolvedCalls(true)
.inferFunctions(true)
.build()
)
.build()
)
.build {
translationResult {
translationUnit("DfgInferredCall.c") {
function("main", t("int")) {
body {
declare {
variable("a", t("test.List")) { construct("test.List") }
}
memberCall("addAll", ref("a", t("test.List"))) {
literal(1, t("int"))
construct("test.Object")
}

returnStmt { ref("a") }
}
}
}
}
}

val methodAddAllTwoArgs = code.methods["addAll"]
assertNotNull(methodAddAllTwoArgs)
assertEquals(2, methodAddAllTwoArgs.parameters.size)
assertEquals(
setOf<Node>(methodAddAllTwoArgs.receiver!!),
methodAddAllTwoArgs.parameters[1].nextDFG
)
}

@Test
fun testPropagateArguments() {
val dfgTest = getDfgInferredCall()
Expand Down
36 changes: 36 additions & 0 deletions cpg-core/src/test/resources/function-dfg2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- functionDeclaration:
language: de.fraunhofer.aisec.cpg.frontends.TestLanguage
methodName: test.List.addAll
signature:
- int
- test.Object
dataFlows:
- from: param1
to: base
dfgType: full

- functionDeclaration:
language: de.fraunhofer.aisec.cpg.frontends.TestLanguage
methodName: test.List.addAll
signature:
- test.Object
dataFlows:
- from: param0
to: base
dfgType: full

- functionDeclaration:
language: de.fraunhofer.aisec.cpg.frontends.TestLanguage
methodName: test.List.add
dataFlows:
- from: param0
to: base
dfgType: full

- functionDeclaration:
language: de.fraunhofer.aisec.cpg.frontends.TestLanguage
methodName: memcpy
dataFlows:
- from: param1
to: param0
dfgType: full

0 comments on commit 28bc31e

Please sign in to comment.