From 08d6ff7f6a861a087e52d691fdaabd71344dbf8f Mon Sep 17 00:00:00 2001 From: Maximilian Kaul Date: Tue, 12 Oct 2021 16:07:50 +0200 Subject: [PATCH] new test case --- .../aisec/codyze/crymlin/WpdsTest.kt | 32 +++++++++++++++++++ .../resources/unittests/WPDS_c_cpp_style.mark | 30 +++++++++++++++++ .../resources/unittests/wpds_cppstyle1.cpp | 7 ++++ .../resources/unittests/wpds_cppstyle2.cpp | 7 ++++ src/test/resources/unittests/wpds_cstyle1.c | 7 ++++ src/test/resources/unittests/wpds_cstyle2.c | 7 ++++ 6 files changed, 90 insertions(+) create mode 100644 src/test/resources/unittests/WPDS_c_cpp_style.mark create mode 100644 src/test/resources/unittests/wpds_cppstyle1.cpp create mode 100644 src/test/resources/unittests/wpds_cppstyle2.cpp create mode 100644 src/test/resources/unittests/wpds_cstyle1.c create mode 100644 src/test/resources/unittests/wpds_cstyle2.c diff --git a/src/test/java/de/fraunhofer/aisec/codyze/crymlin/WpdsTest.kt b/src/test/java/de/fraunhofer/aisec/codyze/crymlin/WpdsTest.kt index 621464a06..7738048b6 100644 --- a/src/test/java/de/fraunhofer/aisec/codyze/crymlin/WpdsTest.kt +++ b/src/test/java/de/fraunhofer/aisec/codyze/crymlin/WpdsTest.kt @@ -510,6 +510,38 @@ internal class WpdsTest : AbstractMarkTest() { assertFalse(startLineNumbers[18]!!) // EVP_EncryptFinal } + @Test + @Throws(Exception::class) + fun testWPDSCStyle1() { + val findings = performTest("unittests/wpds_cstyle1.c", "unittests/WPDS_c_cpp_style.mark") + + assertTrue { findings.all { !it.isProblem } } + } + @Test + @Throws(Exception::class) + fun testWPDSCppStyle1() { + val findings = performTest("unittests/wpds_cppstyle1.cpp", "unittests/WPDS_c_cpp_style.mark") + + assertTrue { findings.all { !it.isProblem } } + } + + @Test + @Throws(Exception::class) + fun testWPDSCStyle2() { + // missing call to "finish()" + val findings = performTest("unittests/wpds_cstyle2.c", "unittests/WPDS_c_cpp_style.mark") + + assertFalse { findings.all { !it.isProblem } } + } + @Test + @Throws(Exception::class) + fun testWPDSCppStyle2() { + // missing call to "finish()" + val findings = performTest("unittests/wpds_cppstyle2.cpp", "unittests/WPDS_c_cpp_style.mark") + + assertFalse { findings.all { !it.isProblem } } + } + init { // Using WPDS instead of NFA tsMode = TypestateMode.WPDS diff --git a/src/test/resources/unittests/WPDS_c_cpp_style.mark b/src/test/resources/unittests/WPDS_c_cpp_style.mark new file mode 100644 index 000000000..3f11de9c1 --- /dev/null +++ b/src/test/resources/unittests/WPDS_c_cpp_style.mark @@ -0,0 +1,30 @@ +entity Foo { + op new { + this = Foo_new(); + } + + op init { + Foo_init(this); + Foo::init(); + } + + op work { + Foo_work(this, _); + Foo::work(_); + } + + op finish { + Foo_finish(this); + Foo::finish(); + } +} + +rule FooOrder { + using Foo as foo + ensure order + foo.new()?, // only c style + foo.init(), + foo.work()+, + foo.finish() + warn +} diff --git a/src/test/resources/unittests/wpds_cppstyle1.cpp b/src/test/resources/unittests/wpds_cppstyle1.cpp new file mode 100644 index 000000000..2b0244c9a --- /dev/null +++ b/src/test/resources/unittests/wpds_cppstyle1.cpp @@ -0,0 +1,7 @@ +int somefunc () { + Foo f = new Foo(); + f.init(); + f.work(null); + f.finish(); + return 0; +} diff --git a/src/test/resources/unittests/wpds_cppstyle2.cpp b/src/test/resources/unittests/wpds_cppstyle2.cpp new file mode 100644 index 000000000..554759eb7 --- /dev/null +++ b/src/test/resources/unittests/wpds_cppstyle2.cpp @@ -0,0 +1,7 @@ +int somefunc () { + Foo f = new Foo(); + f.init(); + f.work(null); + //f.finish(); + return 0; +} diff --git a/src/test/resources/unittests/wpds_cstyle1.c b/src/test/resources/unittests/wpds_cstyle1.c new file mode 100644 index 000000000..874e6b0dd --- /dev/null +++ b/src/test/resources/unittests/wpds_cstyle1.c @@ -0,0 +1,7 @@ +int somefunc () { + Foo f = Foo_new(); + Foo_init(f); + Foo_work(f, null); + Foo_finish(f); + return 0; +} diff --git a/src/test/resources/unittests/wpds_cstyle2.c b/src/test/resources/unittests/wpds_cstyle2.c new file mode 100644 index 000000000..d6523d0f4 --- /dev/null +++ b/src/test/resources/unittests/wpds_cstyle2.c @@ -0,0 +1,7 @@ +int somefunc () { + Foo f = Foo_new(); + Foo_init(f); + Foo_work(f, null); + //Foo_finish(f); + return 0; +}