From af77114815ad9052261898c830171e49fbed5160 Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Fri, 3 Nov 2023 17:50:43 +0000
Subject: [PATCH] testsuite: fix optasm tests for wasm32

---
 testsuite/tests/cmm/should_compile/all.T                     | 5 ++++-
 testsuite/tests/regalloc/all.T                               | 2 ++
 testsuite/tests/rts/T5644/all.T                              | 5 +++--
 testsuite/tests/rts/all.T                                    | 4 ++++
 .../{simplCore.oneShot.stderr => simplCore-oneShot.stderr}   | 0
 .../{simplCore.oneShot.stdout => simplCore-oneShot.stdout}   | 0
 testsuite/tests/simplCore/prog003/test.T                     | 2 +-
 testsuite/tests/simplCore/should_run/all.T                   | 3 ++-
 8 files changed, 16 insertions(+), 5 deletions(-)
 rename testsuite/tests/simplCore/prog003/{simplCore.oneShot.stderr => simplCore-oneShot.stderr} (100%)
 rename testsuite/tests/simplCore/prog003/{simplCore.oneShot.stdout => simplCore-oneShot.stdout} (100%)

diff --git a/testsuite/tests/cmm/should_compile/all.T b/testsuite/tests/cmm/should_compile/all.T
index 512e2bf6f8ed..45f0b50fcbce 100644
--- a/testsuite/tests/cmm/should_compile/all.T
+++ b/testsuite/tests/cmm/should_compile/all.T
@@ -3,7 +3,10 @@ setTestOpts(
   ])
 
 test('selfloop', [cmm_src], compile, ['-no-hs-main'])
-test('cmm_sink_sp', [ only_ways(['optasm']), grep_errmsg(r'(\[Sp.*\]).*(=).*(\[.*R1.*\]).*;',[1,2,3]), cmm_src], compile, ['-no-hs-main -ddump-cmm -dsuppress-uniques -O'])
+test('cmm_sink_sp', [ only_ways(['optasm']),
+                      when(arch('wasm32'), fragile(24152)),
+                      grep_errmsg(r'(\[Sp.*\]).*(=).*(\[.*R1.*\]).*;',[1,2,3]),
+                      cmm_src], compile, ['-no-hs-main -ddump-cmm -dsuppress-uniques -O'])
 
 test('T16930', normal, makefile_test, ['T16930'])
 test('T17442', normal, compile, [''])
diff --git a/testsuite/tests/regalloc/all.T b/testsuite/tests/regalloc/all.T
index 022c04025c3b..8dd68bc3f36a 100644
--- a/testsuite/tests/regalloc/all.T
+++ b/testsuite/tests/regalloc/all.T
@@ -1,6 +1,8 @@
 test('regalloc_unit_tests',
      [ when(unregisterised(), skip), extra_files(['no_spills.cmm']),
        when(not have_ncg(), skip),
+       # no regalloc business on wasm32
+       when(arch('wasm32'), expect_fail),
        [ignore_stderr, only_ways(['normal'])], extra_run_opts('"' + config.libdir + '"') ],
      compile_and_run,
      ['-package ghc'])
diff --git a/testsuite/tests/rts/T5644/all.T b/testsuite/tests/rts/T5644/all.T
index 7dd120d575ea..4f621937223e 100644
--- a/testsuite/tests/rts/T5644/all.T
+++ b/testsuite/tests/rts/T5644/all.T
@@ -1,8 +1,9 @@
 test('T5644', [extra_files(['Conf.hs', 'ManyQueue.hs', 'Util.hs', 'heap-overflow.hs']),
-               
+
                 only_ways(['optasm','threaded1','threaded2']),
                 extra_run_opts('+RTS -M20m -RTS'),
-                exit_code(251) # RTS exit code for "out of memory"
+                exit_code(251), # RTS exit code for "out of memory"
+                when(arch('wasm32'), [ignore_stderr, exit_code(1)])
               ],
               multimod_compile_and_run,
               ['heap-overflow.hs','-O'])
diff --git a/testsuite/tests/rts/all.T b/testsuite/tests/rts/all.T
index 74465d6e57b3..eb0f0b81d134 100644
--- a/testsuite/tests/rts/all.T
+++ b/testsuite/tests/rts/all.T
@@ -44,6 +44,8 @@ test('derefnull',
       when(opsys('mingw32'), [ignore_stderr, exit_code(11)]),
       when(opsys('mingw32'), [fragile(18548)]),
       when(arch('javascript'), [ignore_stderr, exit_code(1)]),
+      # On wasm32, 0x0 is a valid linear memory address
+      when(arch('wasm32'), [ignore_stdout, ignore_stderr, exit_code(0)]),
       # ThreadSanitizer changes the output
       when(have_thread_sanitizer(), skip),
       # since these test are supposed to crash the
@@ -82,6 +84,8 @@ test('divbyzero',
       when(platform('x86_64-apple-darwin'), [ignore_stderr, exit_code(136)]),
       # ThreadSanitizer changes the output
       when(have_thread_sanitizer(), skip),
+      # wasmtime returns sigabrt error code upon wasm traps
+      when(arch('wasm32'), [ignore_stdout, ignore_stderr, exit_code(134)]),
       # since these test are supposed to crash the
       # profile report will be empty always.
       # so disable the check for profiling
diff --git a/testsuite/tests/simplCore/prog003/simplCore.oneShot.stderr b/testsuite/tests/simplCore/prog003/simplCore-oneShot.stderr
similarity index 100%
rename from testsuite/tests/simplCore/prog003/simplCore.oneShot.stderr
rename to testsuite/tests/simplCore/prog003/simplCore-oneShot.stderr
diff --git a/testsuite/tests/simplCore/prog003/simplCore.oneShot.stdout b/testsuite/tests/simplCore/prog003/simplCore-oneShot.stdout
similarity index 100%
rename from testsuite/tests/simplCore/prog003/simplCore.oneShot.stdout
rename to testsuite/tests/simplCore/prog003/simplCore-oneShot.stdout
diff --git a/testsuite/tests/simplCore/prog003/test.T b/testsuite/tests/simplCore/prog003/test.T
index d5c81e9960ef..1c8d8961604b 100644
--- a/testsuite/tests/simplCore/prog003/test.T
+++ b/testsuite/tests/simplCore/prog003/test.T
@@ -1,3 +1,3 @@
-test('simplCore.oneShot', [extra_files(['OneShot1.hs', 'OneShot2.hs']),
+test('simplCore-oneShot', [extra_files(['OneShot1.hs', 'OneShot2.hs']),
                            only_ways(['optasm'])], multimod_compile_and_run,
      ['OneShot2', '-v0'])
diff --git a/testsuite/tests/simplCore/should_run/all.T b/testsuite/tests/simplCore/should_run/all.T
index 58b956e2d543..e7e33c539619 100644
--- a/testsuite/tests/simplCore/should_run/all.T
+++ b/testsuite/tests/simplCore/should_run/all.T
@@ -19,7 +19,8 @@ test('simplrun007', normal, compile_and_run, [''])
 test('simplrun008', normal, compile_and_run, [''])
 test('simplrun009', normal, compile_and_run, [''])
 test('simplrun010', [extra_run_opts('24 16 8 +RTS -M10m -RTS'),
-                     exit_code(251)]
+                     exit_code(251),
+                     when(arch('wasm32'), [ignore_stderr, exit_code(1)])]
                   , compile_and_run, [''])
 test('simplrun011', normal, compile_and_run, ['-fno-worker-wrapper'])
 
-- 
GitLab