tests/tcg/s390x: Test overflow conditions
PATCH v2 1/1 tests/tcg/s390x: Test overflow conditions
Add a test to check for overflow conditions in s390x. This patch is based on the following patches :
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=5a2e67a691501
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=fc6e0d0f2db51
---
Changes since v1:
- Corrected the "long" data type to "long long"
- Changed local variable name in overflow function to "res"
tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/overflow.c | 58 +++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 tests/tcg/s390x/overflow.c
tests/tcg/s390x/Makefile.target +1 -0
@@ -16,6 +16,7 @@ TESTS+=shift TESTS+=trap TESTS+=signals-s390x TESTS+=branch-relative-long +TESTS+=overflow VECTOR_TESTS=vxeh2_vs VECTOR_TESTS+=vxeh2_vcvt
tests/tcg/s390x/overflow.c new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 6 lines · Gautam Agrawal
Add a test to check for overflow conditions in s390x. This patch is based on the following patches :
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=5a2e67a691501
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=fc6e0d0f2db51Signed-off-by Gautam Agrawal <[email protected]>
Signature · 3 lines
Thanks, David / dhildenb
Quoted 7 lines · Gautam Agrawal
Add a test to check for overflow conditions in s390x. This patch is based on the following patches :
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=5a2e67a691501
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=fc6e0d0f2db51Signed-off-by Gautam Agrawal <[email protected]>---
Thank you very much, queued to my s390x-next branch now:
https://gitlab.com/thuth/qemu/-/commits/s390x-next/
Thomas
Quoted 82 lines · Gautam Agrawal
Add a test to check for overflow conditions in s390x. This patch is based on the following patches :
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=5a2e67a691501
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=fc6e0d0f2db51Signed-off-by Gautam Agrawal <[email protected]>---
Changes since v1:
- Corrected the "long" data type to "long long"
- Changed local variable name in overflow function to "res"tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/overflow.c | 58 +++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)create mode 100644
tests/tcg/s390x/overflow.ctests/tcg/s390x/Makefile.target +1
-0@@ -16,6 +16,7 @@ TESTS+=shift TESTS+=trap TESTS+=signals-s390x TESTS+=branch-relative-long +TESTS+=overflow VECTOR_TESTS=vxeh2_vs VECTOR_TESTS+=vxeh2_vcvttests/tcg/s390x/overflow.c new file +48
-0@@ -0,0 +1,58 @@ +#include <stdio.h> + +int overflow_add_32 (int x,int y) +{ +int res; +return __builtin_add_overflow (x, y, &res); +} + +int overflow_add_64 (long long x,long long y) +{ +long long res; +return __builtin_add_overflow (x, y, &res); +} + +int overflow_sub_32 (int x,int y) +{ +int res; +return __builtin_sub_overflow (x, y, &res); +} + +int overflow_sub_64 (long long x,long long y) +{ +long long res; +return __builtin_sub_overflow (x, y, &res); +} + +int a1_add =-2147483648 ; +int b1_add =-2147483648 ; +long long a2_add =-9223372036854775808ULL ; +long long b2_add =-9223372036854775808ULL ; + +int a1_sub; +int b1_sub =-2147483648 ; +long long a2_sub =0L ; +long long b2_sub =-9223372036854775808ULL ; + +int main () +{ +int ret =0 ; + +if (!overflow_add_32 (a1_add, b1_add)) { +fprintf (stderr,"data overflow while adding 32 bits\n" ); + ret =1 ; + } +if (!overflow_add_64 (a2_add, b2_add)) { +fprintf (stderr,"data overflow while adding 64 bits\n" ); + ret =1 ; + }
tests/tcg/s390x/overflow.c line 58
Quoted 10 lines
tests/tcg/s390x/overflow.c new file +10
-0+if (!overflow_sub_32 (a1_sub, b1_sub)) { +fprintf (stderr,"data overflow while subtracting 32 bits\n" ); + ret =1 ; + } +if (!overflow_sub_64 (a2_sub, b2_sub)) { +fprintf (stderr,"data overflow while subtracting 64 bits\n" ); + ret =1 ; + } +return ret; +}
Thinking a little bit more about this, there is nothing specific to s390x in here, so I think we could even move this test to tests/tcg/multiarch/ so that other architectures benefit from this test as well...
Alex, would that be OK for you?
Thomas