testsuite: Ensure T5423 flushes C output buffer
authorBen Gamari <ben@smart-cactus.org>
Tue, 11 Jun 2019 16:48:32 +0000 (12:48 -0400)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Sun, 16 Jun 2019 10:26:38 +0000 (06:26 -0400)
Previously T5423 would fail to flush the printf output buffer.
Consequently it was platform-dependent whether the C or Haskell print
output would be emitted first.

testsuite/tests/rts/Makefile
testsuite/tests/rts/T5423.hs
testsuite/tests/rts/T5423.stdout
testsuite/tests/rts/T5423_c.c [new file with mode: 0644]

index 32c2b17..51f2746 100644 (file)
@@ -37,7 +37,8 @@ T5423:
        $(RM) T5423_cmm.o T5423.o T5423.hi T5423$(exeext)
        "$(TEST_HC)" $(TEST_HC_OPTS) -v0 -c T5423_cmm.cmm
        "$(TEST_HC)" $(TEST_HC_OPTS) -v0 -c T5423.hs
-       "$(TEST_HC)" $(TEST_HC_OPTS) -v0 T5423.o T5423_cmm.o -o T5423$(exeext)
+       "$(TEST_HC)" $(TEST_HC_OPTS) -v0 -c T5423_c.c
+       "$(TEST_HC)" $(TEST_HC_OPTS) -v0 T5423.o T5423_cmm.o T5423_c.o -o T5423$(exeext)
        ./T5423
 
 .PHONY: T9405
index 2565c3f..cda8704 100644 (file)
@@ -7,8 +7,13 @@ foreign import prim "test" test :: Int# -> Int# -> Int# -> Int# -> Int#
                                 -> Int# -> Int# -> Int# -> Int# -> Int#
                                 -> Int#
 
+foreign import ccall "flush_stdout" flush_stdout :: IO ()
+
 v :: Int
 v = I# (test 111# 112# 113# 114# 115# 116# 117# 118# 119# 120#)
 
 main :: IO ()
-main = print v
+main = do
+  n <- return $! v
+  flush_stdout -- Ensure that libc output buffer is flushed
+  print n
index 478bb27..fc92992 100644 (file)
@@ -1,2 +1,2 @@
-120
 111  112  113  114  115  116  117  118  119  120
+120
diff --git a/testsuite/tests/rts/T5423_c.c b/testsuite/tests/rts/T5423_c.c
new file mode 100644 (file)
index 0000000..efc9c84
--- /dev/null
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void flush_stdout(void)
+{
+    fflush(stdout);
+}