]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add testcases for CU24. Part of fixing #289839.
authorFlorian Krohm <florian@eich-krohm.de>
Sat, 21 Jul 2012 17:42:54 +0000 (17:42 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sat, 21 Jul 2012 17:42:54 +0000 (17:42 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12771

docs/internals/s390-opcodes.csv
none/tests/s390x/Makefile.am
none/tests/s390x/cu24.c [new file with mode: 0644]
none/tests/s390x/cu24.stderr.exp [new file with mode: 0644]
none/tests/s390x/cu24.stdout.exp [new file with mode: 0644]
none/tests/s390x/cu24.vgtest [new file with mode: 0644]
none/tests/s390x/cu24_1.c [new symlink]
none/tests/s390x/cu24_1.stderr.exp [new file with mode: 0644]
none/tests/s390x/cu24_1.stdout.exp [new file with mode: 0644]
none/tests/s390x/cu24_1.vgtest [new file with mode: 0644]

index 82fe33418476cfc22a69dd11a69cdf90351c615d..3767b701f708736b61b220f0b0cd215d39407fa2 100644 (file)
@@ -665,7 +665,7 @@ stfle,"store facility list extended",implemented,
 stckf,"store clock fast",implemented,
 mvcos,"move with optional specifications",N/A,"privileged instruction"
 lptea,"load page-table-entry address",N/A,"privileged instruction"
-cu24,"convert utf-16 to utf-32","not implemented","open bugzilla"
+cu24,"convert utf-16 to utf-32",implemented
 cu21,"convert utf-16 to utf-8",implemented
 cu42,"convert utf-32 to utf-16","not implemented","open bugzilla"
 cu41,"convert utf-32 to utf-8","not implemented","open bugzilla"
index 62cfc83e0a5adbbef94bc10be954d81aa94ff351..d3e7ca02818f4cd310542d36ec4cabb6c6d8d4fe 100644 (file)
@@ -7,7 +7,7 @@ INSN_TESTS = clc clcle cvb cvd icm lpr tcxb lam_stam xc mvst add sub mul \
              and_EI or_EI xor_EI insert_EI mul_GE add_GE condloadstore \
              op_exception fgx stck stckf stcke stfle cksm mvcl clcl troo \
              trto trot trtt tr tre cij cgij clij clgij crj cgrj clrj clgrj \
-             cs csg cds cdsg cu21 cu21_1
+             cs csg cds cdsg cu21 cu21_1 cu24 cu24_1
 
 check_PROGRAMS = $(INSN_TESTS) \
                 allexec \
@@ -34,3 +34,4 @@ allexec_CFLAGS   = $(AM_CFLAGS) @FLAG_W_NO_NONNULL@
 ex_clone_LDFLAGS = -lpthread
 tcxb_CFLAGS      = $(AM_CFLAGS) -std=gnu99
 cu21_1_CFLAGS    = $(AM_CFLAGS) -DM3=1
+cu24_1_CFLAGS    = $(AM_CFLAGS) -DM3=1
diff --git a/none/tests/s390x/cu24.c b/none/tests/s390x/cu24.c
new file mode 100644 (file)
index 0000000..2cd8828
--- /dev/null
@@ -0,0 +1,183 @@
+#include <stdint.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "opcodes.h"
+
+#ifndef M3
+#define M3 0
+#endif
+
+/* The abstracted result of an CU24 insn */
+typedef struct {
+   uint64_t addr1;  // target
+   uint64_t len1;
+   uint64_t addr2;  // source
+   uint64_t len2;
+   uint32_t cc;
+} cu24_t;
+
+/* Define various input buffers. */
+
+/* Single UTF-16 value */
+uint16_t pattern1[] = {
+   0x0000, 0xd7ff,    /* [0000 ... d7ff]  corner cases */
+   0xdc00, 0xffff,    /* [dc00 ... ffff]  corner cases */
+   0x0047, 0x0156, 0x1245, 0xa021, 0xfffe /* misc */
+};
+
+/* UTF-16 surrogate pair */
+uint16_t pattern2[] = {
+   0xd800, 0xdc00,    /* left  corner case */
+   0xdbff, 0xdfff,    /* right corner case */
+   0xdada, 0xdddd, 0xdeaf, 0xdcdc  /* misc */
+};
+
+/* Invalid low surrogate */
+uint16_t invalid[] = { 0xd801, 0x0098 };
+
+/* Mixed bytes */
+uint16_t mixed[] = {
+   0x0078,
+   0x0200,
+   0xffff,
+   0xd800, 0xdc01,
+   0xde00, 0xdd00,
+   0xc0c0
+};
+
+/* This is the buffer for the converted bytes. */
+uint32_t buff[1000];  /* Large so we con'don't have to worry about it */
+
+
+static cu24_t
+do_cu24(uint32_t *dst, uint64_t dst_len, uint16_t *src, uint64_t src_len)
+{
+   int cc = 42;
+   cu24_t regs;
+
+   /* build up the register pairs */
+   register uint16_t *source     asm("4") = src;
+   register uint64_t  source_len asm("5") = src_len;
+   register uint32_t *dest       asm("2") = dst;
+   register uint64_t  dest_len   asm("3") = dst_len;
+
+   asm volatile(
+                CU24(M3,2,4)
+                "ipm %2\n\t"
+                "srl %2,28\n\t"
+                : "+d"(dest), "+d"(source), "=d"(cc),
+                  "+d"(source_len), "+d"(dest_len)
+                :
+                : "memory", "cc");
+
+   /* Capture register contents at end of cu24 */
+   regs.addr1 = (uint64_t)dest;
+   regs.len1  = dest_len;
+   regs.addr2 = (uint64_t)source;
+   regs.len2  = source_len;
+   regs.cc = cc;
+   
+   return regs;
+}
+
+void
+run_test(uint32_t *dst, uint64_t dst_len, uint16_t *src, uint64_t src_len)
+{
+   int i;
+   cu24_t result;
+
+   result = do_cu24(dst, dst_len, src, src_len);
+
+   // Write out the converted byte, if any
+   printf("UTF32: ");
+   if (dst_len - result.len1 == 0)
+      printf(" <none>");
+   else {
+      uint64_t num_bytes = dst_len - result.len1;
+
+      /* The number of bytes that were written must be divisible by 4 */
+      if (num_bytes % 4 != 0)
+         fprintf(stderr, "*** number of bytes is not a multiple of 4\n");
+
+      for (i = 0; i < num_bytes / 4; i++) {
+         printf(" %02x", dst[i]);
+      }
+   }
+   printf("\n");
+
+   printf("  cc = %d\n", result.cc);
+   if (dst != NULL)
+      printf("  dst address difference: %"PRId64, result.addr1 - (uint64_t)dst);
+   printf("  dst len: %"PRId64"\n", result.len1);
+
+   if (src != NULL)
+      printf("  src address difference: %"PRId64, result.addr2 - (uint64_t)src);
+   printf("  src len: %"PRId64"\n", result.len2);
+}
+
+int main()
+{
+   /* Length == 0, no memory should be read or written */
+   printf("\n------------- test1 ----------------\n");
+   run_test(NULL, 0, NULL, 0);
+
+   /* Test exhaustion of source length (source bytes are valid) */
+   printf("\n------------- test2.1 ----------------\n");
+
+   /* No character will be written to BUFF, i.e. loop in jitted code
+      is not iterated */
+   run_test(buff, sizeof buff, NULL,     1);
+   run_test(buff, sizeof buff, pattern1, 1);
+   run_test(buff, sizeof buff, pattern2, 1);
+   run_test(buff, sizeof buff, pattern2, 2);
+   run_test(buff, sizeof buff, pattern2, 3);
+
+   printf("\n------------- test2.2 ----------------\n");
+   /* At least one character will be written to BUFF, i.e. loop in jitted
+      code is iterated */
+   run_test(buff, sizeof buff, pattern1, 3);
+   run_test(buff, sizeof buff, pattern1, 5);
+   run_test(buff, sizeof buff, pattern2, 2);
+   run_test(buff, sizeof buff, pattern2, 5);
+   run_test(buff, sizeof buff, pattern2, 7);
+
+   /* Test exhaustion of destination length (source bytes are valid) */
+   printf("\n------------- test3.1 ----------------\n");
+
+   /* No character will be written to BUFF, i.e. loop in jitted code
+      is not iterated */
+
+   /* Want to write 4 bytes at a time */
+   run_test(NULL, 0, pattern1, sizeof pattern1);
+   run_test(NULL, 1, pattern1, sizeof pattern1);
+   run_test(NULL, 2, pattern1, sizeof pattern1);
+   run_test(NULL, 3, pattern1, sizeof pattern1);
+
+   printf("\n------------- test3.2 ----------------\n");
+   /* At least one character will be written to BUFF, i.e. loop in jitted
+      code is iterated */
+   run_test(buff, 4, pattern1, sizeof pattern1);
+   run_test(buff, 5, pattern1, sizeof pattern1);
+   run_test(buff, 6, pattern1, sizeof pattern1);
+   run_test(buff, 7, pattern1, sizeof pattern1);
+
+   /* When both operands are exhausted, cc=0 takes precedence.
+      (test1 tests this for len == 0) */
+   printf("\n------------- test4 ----------------\n");
+   run_test(buff, 4, pattern1, 2);   // no iteration
+   run_test(buff, 8, pattern1, 4);   // iteration
+
+   /* Input has invalid low surrogate. */
+   printf("\n------------- test5 ----------------\n");
+   run_test(buff, sizeof buff, invalid, sizeof invalid);
+   run_test(buff, 0, invalid, sizeof invalid);
+
+   /* Convert all pattern buffers */
+   printf("\n------------- test6 ----------------\n");
+   run_test(buff, sizeof buff, pattern1, sizeof pattern1);
+   run_test(buff, sizeof buff, pattern2, sizeof pattern2);
+
+   return 0;
+}
diff --git a/none/tests/s390x/cu24.stderr.exp b/none/tests/s390x/cu24.stderr.exp
new file mode 100644 (file)
index 0000000..139597f
--- /dev/null
@@ -0,0 +1,2 @@
+
+
diff --git a/none/tests/s390x/cu24.stdout.exp b/none/tests/s390x/cu24.stdout.exp
new file mode 100644 (file)
index 0000000..d29f4dd
--- /dev/null
@@ -0,0 +1,116 @@
+
+------------- test1 ----------------
+UTF32:  <none>
+  cc = 0
+  dst len: 0
+  src len: 0
+
+------------- test2.1 ----------------
+UTF32:  <none>
+  cc = 0
+  dst address difference: 0  dst len: 4000
+  src len: 1
+UTF32:  <none>
+  cc = 0
+  dst address difference: 0  dst len: 4000
+  src address difference: 0  src len: 1
+UTF32:  <none>
+  cc = 0
+  dst address difference: 0  dst len: 4000
+  src address difference: 0  src len: 1
+UTF32:  <none>
+  cc = 0
+  dst address difference: 0  dst len: 4000
+  src address difference: 0  src len: 2
+UTF32:  <none>
+  cc = 0
+  dst address difference: 0  dst len: 4000
+  src address difference: 0  src len: 3
+
+------------- test2.2 ----------------
+UTF32:  00
+  cc = 0
+  dst address difference: 4  dst len: 3996
+  src address difference: 2  src len: 1
+UTF32:  00 d7ff
+  cc = 0
+  dst address difference: 8  dst len: 3992
+  src address difference: 4  src len: 1
+UTF32:  <none>
+  cc = 0
+  dst address difference: 0  dst len: 4000
+  src address difference: 0  src len: 2
+UTF32:  10000
+  cc = 0
+  dst address difference: 4  dst len: 3996
+  src address difference: 4  src len: 1
+UTF32:  10000
+  cc = 0
+  dst address difference: 4  dst len: 3996
+  src address difference: 4  src len: 3
+
+------------- test3.1 ----------------
+UTF32:  <none>
+  cc = 1
+  dst len: 0
+  src address difference: 0  src len: 18
+UTF32:  <none>
+  cc = 1
+  dst len: 1
+  src address difference: 0  src len: 18
+UTF32:  <none>
+  cc = 1
+  dst len: 2
+  src address difference: 0  src len: 18
+UTF32:  <none>
+  cc = 1
+  dst len: 3
+  src address difference: 0  src len: 18
+
+------------- test3.2 ----------------
+UTF32:  00
+  cc = 1
+  dst address difference: 4  dst len: 0
+  src address difference: 2  src len: 16
+UTF32:  00
+  cc = 1
+  dst address difference: 4  dst len: 1
+  src address difference: 2  src len: 16
+UTF32:  00
+  cc = 1
+  dst address difference: 4  dst len: 2
+  src address difference: 2  src len: 16
+UTF32:  00
+  cc = 1
+  dst address difference: 4  dst len: 3
+  src address difference: 2  src len: 16
+
+------------- test4 ----------------
+UTF32:  00
+  cc = 0
+  dst address difference: 4  dst len: 0
+  src address difference: 2  src len: 0
+UTF32:  00 d7ff
+  cc = 0
+  dst address difference: 8  dst len: 0
+  src address difference: 4  src len: 0
+
+------------- test5 ----------------
+UTF32:  10498
+  cc = 0
+  dst address difference: 4  dst len: 3996
+  src address difference: 4  src len: 0
+UTF32:  <none>
+  cc = 1
+  dst address difference: 0  dst len: 0
+  src address difference: 0  src len: 4
+
+------------- test6 ----------------
+UTF32:  00 d7ff dc00 ffff 47 156 1245 a021 fffe
+  cc = 0
+  dst address difference: 36  dst len: 3964
+  src address difference: 18  src len: 0
+UTF32:  10000 10ffff c69dd deaf dcdc
+  cc = 0
+  dst address difference: 20  dst len: 3980
+  src address difference: 16  src len: 0
diff --git a/none/tests/s390x/cu24.vgtest b/none/tests/s390x/cu24.vgtest
new file mode 100644 (file)
index 0000000..a130e91
--- /dev/null
@@ -0,0 +1 @@
+prog: cu24
diff --git a/none/tests/s390x/cu24_1.c b/none/tests/s390x/cu24_1.c
new file mode 120000 (symlink)
index 0000000..85676fa
--- /dev/null
@@ -0,0 +1 @@
+cu24.c
\ No newline at end of file
diff --git a/none/tests/s390x/cu24_1.stderr.exp b/none/tests/s390x/cu24_1.stderr.exp
new file mode 100644 (file)
index 0000000..139597f
--- /dev/null
@@ -0,0 +1,2 @@
+
+
diff --git a/none/tests/s390x/cu24_1.stdout.exp b/none/tests/s390x/cu24_1.stdout.exp
new file mode 100644 (file)
index 0000000..c6e22d5
--- /dev/null
@@ -0,0 +1,116 @@
+
+------------- test1 ----------------
+UTF32:  <none>
+  cc = 0
+  dst len: 0
+  src len: 0
+
+------------- test2.1 ----------------
+UTF32:  <none>
+  cc = 0
+  dst address difference: 0  dst len: 4000
+  src len: 1
+UTF32:  <none>
+  cc = 0
+  dst address difference: 0  dst len: 4000
+  src address difference: 0  src len: 1
+UTF32:  <none>
+  cc = 0
+  dst address difference: 0  dst len: 4000
+  src address difference: 0  src len: 1
+UTF32:  <none>
+  cc = 0
+  dst address difference: 0  dst len: 4000
+  src address difference: 0  src len: 2
+UTF32:  <none>
+  cc = 0
+  dst address difference: 0  dst len: 4000
+  src address difference: 0  src len: 3
+
+------------- test2.2 ----------------
+UTF32:  00
+  cc = 0
+  dst address difference: 4  dst len: 3996
+  src address difference: 2  src len: 1
+UTF32:  00 d7ff
+  cc = 0
+  dst address difference: 8  dst len: 3992
+  src address difference: 4  src len: 1
+UTF32:  <none>
+  cc = 0
+  dst address difference: 0  dst len: 4000
+  src address difference: 0  src len: 2
+UTF32:  10000
+  cc = 0
+  dst address difference: 4  dst len: 3996
+  src address difference: 4  src len: 1
+UTF32:  10000
+  cc = 0
+  dst address difference: 4  dst len: 3996
+  src address difference: 4  src len: 3
+
+------------- test3.1 ----------------
+UTF32:  <none>
+  cc = 1
+  dst len: 0
+  src address difference: 0  src len: 18
+UTF32:  <none>
+  cc = 1
+  dst len: 1
+  src address difference: 0  src len: 18
+UTF32:  <none>
+  cc = 1
+  dst len: 2
+  src address difference: 0  src len: 18
+UTF32:  <none>
+  cc = 1
+  dst len: 3
+  src address difference: 0  src len: 18
+
+------------- test3.2 ----------------
+UTF32:  00
+  cc = 1
+  dst address difference: 4  dst len: 0
+  src address difference: 2  src len: 16
+UTF32:  00
+  cc = 1
+  dst address difference: 4  dst len: 1
+  src address difference: 2  src len: 16
+UTF32:  00
+  cc = 1
+  dst address difference: 4  dst len: 2
+  src address difference: 2  src len: 16
+UTF32:  00
+  cc = 1
+  dst address difference: 4  dst len: 3
+  src address difference: 2  src len: 16
+
+------------- test4 ----------------
+UTF32:  00
+  cc = 0
+  dst address difference: 4  dst len: 0
+  src address difference: 2  src len: 0
+UTF32:  00 d7ff
+  cc = 0
+  dst address difference: 8  dst len: 0
+  src address difference: 4  src len: 0
+
+------------- test5 ----------------
+UTF32:  <none>
+  cc = 2
+  dst address difference: 0  dst len: 4000
+  src address difference: 0  src len: 4
+UTF32:  <none>
+  cc = 2
+  dst address difference: 0  dst len: 0
+  src address difference: 0  src len: 4
+
+------------- test6 ----------------
+UTF32:  00 d7ff dc00 ffff 47 156 1245 a021 fffe
+  cc = 0
+  dst address difference: 36  dst len: 3964
+  src address difference: 18  src len: 0
+UTF32:  10000 10ffff c69dd deaf dcdc
+  cc = 0
+  dst address difference: 20  dst len: 3980
+  src address difference: 16  src len: 0
diff --git a/none/tests/s390x/cu24_1.vgtest b/none/tests/s390x/cu24_1.vgtest
new file mode 100644 (file)
index 0000000..84372fb
--- /dev/null
@@ -0,0 +1 @@
+prog: cu24_1