From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Richard Henderson <richard.henderson@linaro.org>
Cc: qemu-s390x@nongnu.org, Gautam Agrawal <gautamnagrawal@gmail.com>
Subject: [PULL 05/12] tests/tcg: Test overflow conditions
Date: Fri, 3 Jun 2022 08:58:58 +0200 [thread overview]
Message-ID: <20220603065905.23805-6-thuth@redhat.com> (raw)
In-Reply-To: <20220603065905.23805-1-thuth@redhat.com>
From: Gautam Agrawal <gautamnagrawal@gmail.com>
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
Signed-off-by: Gautam Agrawal <gautamnagrawal@gmail.com>
Message-Id: <20220531183524.40948-1-gautamnagrawal@gmail.com>
[thuth: Move overflow.c to tests/tcg/multiarch/ to make it generic]
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/tcg/multiarch/overflow.c | 58 ++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
create mode 100644 tests/tcg/multiarch/overflow.c
diff --git a/tests/tcg/multiarch/overflow.c b/tests/tcg/multiarch/overflow.c
new file mode 100644
index 0000000000..1c59c2cb70
--- /dev/null
+++ b/tests/tcg/multiarch/overflow.c
@@ -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;
+ }
+ 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;
+}
--
2.31.1
next prev parent reply other threads:[~2022-06-03 7:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-03 6:58 [PULL 00/12] s390x and misc patches Thomas Huth
2022-06-03 6:58 ` [PULL 01/12] s390: Typo fix FLOATING_POINT_SUPPPORT_ENH Thomas Huth
2022-06-03 6:58 ` [PULL 02/12] hw/s390x/s390-virtio-ccw: Improve the machine description string Thomas Huth
2022-06-03 6:58 ` [PULL 03/12] target/s390x: kvm: Honor storage keys during emulation Thomas Huth
2022-06-03 6:58 ` [PULL 04/12] MAINTAINERS: Update s390 vhost entries Thomas Huth
2022-06-03 6:58 ` Thomas Huth [this message]
2022-06-03 6:58 ` [PULL 06/12] MAINTAINERS: Change my email address Thomas Huth
2022-06-03 6:59 ` [PULL 07/12] MAINTAINERS: Update maintainers for Guest x86 HAXM CPUs Thomas Huth
2022-06-03 6:59 ` [PULL 08/12] qtest/npcm7xx_pwm-test: Fix memory leak in mft_qom_set Thomas Huth
2022-06-03 6:59 ` [PULL 09/12] tests/qtest: use g_autofree for test_server_create_chr Thomas Huth
2022-06-03 6:59 ` [PULL 10/12] ui: Remove deprecated parameters of the "-display sdl" option Thomas Huth
2022-06-03 6:59 ` [PULL 11/12] ui: Switch "-display sdl" to use the QAPI parser Thomas Huth
2022-06-03 6:59 ` [PULL 12/12] ui: Remove deprecated options "-sdl" and "-curses" Thomas Huth
2022-06-03 15:16 ` [PULL 00/12] s390x and misc patches Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220603065905.23805-6-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=gautamnagrawal@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).