From d218bd4aa01d20cc544249d1922e7e27c3eb6153 Mon Sep 17 00:00:00 2001 From: Kayvan Memarian Date: Sun, 15 Sep 2024 00:52:06 +0100 Subject: [PATCH] CHERI: adding ci tests for the new elaboration of readonly objects --- tests/cheri-ci/0337-CHERI_const1.undef.c | 7 +++++++ tests/cheri-ci/0338-CHERI_const2.undef.c | 10 ++++++++++ tests/cheri-ci/0339-CHERI_const3.undef.c | 10 ++++++++++ tests/cheri-ci/0340-CHERI_string-literal.undef.c | 6 ++++++ .../expected/0337-CHERI_const1.undef.c.expected | 1 + .../expected/0338-CHERI_const2.undef.c.expected | 1 + .../expected/0339-CHERI_const3.undef.c.expected | 1 + .../0340-CHERI_string-literal.undef.c.expected | 1 + ...-misaligned_pointer_implicit_conversion.undef.c | 14 ++++++++++++++ tests/tests-cheri.sh | 4 ++++ 10 files changed, 55 insertions(+) create mode 100644 tests/cheri-ci/0337-CHERI_const1.undef.c create mode 100644 tests/cheri-ci/0338-CHERI_const2.undef.c create mode 100644 tests/cheri-ci/0339-CHERI_const3.undef.c create mode 100644 tests/cheri-ci/0340-CHERI_string-literal.undef.c create mode 100644 tests/cheri-ci/expected/0337-CHERI_const1.undef.c.expected create mode 100644 tests/cheri-ci/expected/0338-CHERI_const2.undef.c.expected create mode 100644 tests/cheri-ci/expected/0339-CHERI_const3.undef.c.expected create mode 100644 tests/cheri-ci/expected/0340-CHERI_string-literal.undef.c.expected create mode 100644 tests/ci/0341-misaligned_pointer_implicit_conversion.undef.c diff --git a/tests/cheri-ci/0337-CHERI_const1.undef.c b/tests/cheri-ci/0337-CHERI_const1.undef.c new file mode 100644 index 000000000..d0fb82d32 --- /dev/null +++ b/tests/cheri-ci/0337-CHERI_const1.undef.c @@ -0,0 +1,7 @@ +int main(void) +{ + const int xxx = 42; + int *p = (int*)&xxx; + xxx; + *p = 100; // undefined +} \ No newline at end of file diff --git a/tests/cheri-ci/0338-CHERI_const2.undef.c b/tests/cheri-ci/0338-CHERI_const2.undef.c new file mode 100644 index 000000000..3d4b92609 --- /dev/null +++ b/tests/cheri-ci/0338-CHERI_const2.undef.c @@ -0,0 +1,10 @@ +int aux(int *p) +{ + return p?(*p = 10):10; +} + +int main(void) +{ + const int xxx = (aux((int*)&xxx), xxx); // the store in aux() is undefined + aux((int*)&xxx); // the store in aux() is undefined +} \ No newline at end of file diff --git a/tests/cheri-ci/0339-CHERI_const3.undef.c b/tests/cheri-ci/0339-CHERI_const3.undef.c new file mode 100644 index 000000000..f78e7988b --- /dev/null +++ b/tests/cheri-ci/0339-CHERI_const3.undef.c @@ -0,0 +1,10 @@ +int aux(int *p) +{ + return p?(*p = 10):10; +} + +int main(void) +{ + const int xxx = (aux(0), xxx); + aux((int*)&xxx); // the store in aux() is undefined +} \ No newline at end of file diff --git a/tests/cheri-ci/0340-CHERI_string-literal.undef.c b/tests/cheri-ci/0340-CHERI_string-literal.undef.c new file mode 100644 index 000000000..e23db1802 --- /dev/null +++ b/tests/cheri-ci/0340-CHERI_string-literal.undef.c @@ -0,0 +1,6 @@ +int main(void) +{ + char *str = "string"; + str[0]; + str[0] = 'S'; // undefined +} diff --git a/tests/cheri-ci/expected/0337-CHERI_const1.undef.c.expected b/tests/cheri-ci/expected/0337-CHERI_const1.undef.c.expected new file mode 100644 index 000000000..eaa9763cd --- /dev/null +++ b/tests/cheri-ci/expected/0337-CHERI_const1.undef.c.expected @@ -0,0 +1 @@ +Undefined {ub: "UB064_modifying_const", stderr: "", loc: "<6:3--6:11>"} diff --git a/tests/cheri-ci/expected/0338-CHERI_const2.undef.c.expected b/tests/cheri-ci/expected/0338-CHERI_const2.undef.c.expected new file mode 100644 index 000000000..18d92ac9e --- /dev/null +++ b/tests/cheri-ci/expected/0338-CHERI_const2.undef.c.expected @@ -0,0 +1 @@ +Undefined {ub: "UB_CHERI_InsufficientPermissions", stderr: "", loc: "<3:12--3:21>"} diff --git a/tests/cheri-ci/expected/0339-CHERI_const3.undef.c.expected b/tests/cheri-ci/expected/0339-CHERI_const3.undef.c.expected new file mode 100644 index 000000000..1178b6458 --- /dev/null +++ b/tests/cheri-ci/expected/0339-CHERI_const3.undef.c.expected @@ -0,0 +1 @@ +Undefined {ub: "UB064_modifying_const", stderr: "", loc: "<3:12--3:21>"} diff --git a/tests/cheri-ci/expected/0340-CHERI_string-literal.undef.c.expected b/tests/cheri-ci/expected/0340-CHERI_string-literal.undef.c.expected new file mode 100644 index 000000000..ce8520a5d --- /dev/null +++ b/tests/cheri-ci/expected/0340-CHERI_string-literal.undef.c.expected @@ -0,0 +1 @@ +Undefined {ub: "UB033_modifying_string_literal", stderr: "", loc: "<5:3--5:15>"} diff --git a/tests/ci/0341-misaligned_pointer_implicit_conversion.undef.c b/tests/ci/0341-misaligned_pointer_implicit_conversion.undef.c new file mode 100644 index 000000000..9c18c6dd7 --- /dev/null +++ b/tests/ci/0341-misaligned_pointer_implicit_conversion.undef.c @@ -0,0 +1,14 @@ +#include + +void func(void *p0) +{ + int **p1 = p0; // undef +} + +int main(void) +{ + char *p = malloc(sizeof(int*)+1); + void *p0 = (void*)(p+1); + + func(p0); +} \ No newline at end of file diff --git a/tests/tests-cheri.sh b/tests/tests-cheri.sh index 3bdb88759..4979a146c 100644 --- a/tests/tests-cheri.sh +++ b/tests/tests-cheri.sh @@ -198,6 +198,10 @@ citests=( 0332-rvalue-temporary-lifetime-pointer-zap.c 0333-shifts_non_representable.undef.c 0336-memcpy-ovelap.undef.c + 0337-CHERI_const1.undef.c + 0338-CHERI_const2.undef.c + 0339-CHERI_const3.undef.c + 0340-CHERI_string-literal.undef.c ) # TESTS THAT ARE KNOW TO FAIL (for example .error test for which we need to improve the message)