diff options
author | Ben Gamari <ben@smart-cactus.org> | 2021-07-25 18:27:55 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-08-02 04:13:15 -0400 |
commit | 2de8f031e7f81745c23656f6a8cfb43199ce337c (patch) | |
tree | 1ae0a41628b9841e89b36324ef0c6cd4169003d4 | |
parent | 022c794564bf81a20bfe4dc3329090aa8ca7ad63 (diff) | |
download | haskell-2de8f031e7f81745c23656f6a8cfb43199ce337c.tar.gz |
testsuite: Add test for #20137
5 files changed, 118 insertions, 0 deletions
diff --git a/testsuite/tests/codeGen/should_run/T20137/T20137.hs b/testsuite/tests/codeGen/should_run/T20137/T20137.hs new file mode 100644 index 0000000000..4786e27778 --- /dev/null +++ b/testsuite/tests/codeGen/should_run/T20137/T20137.hs @@ -0,0 +1,57 @@ +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE CApiFFI #-} + +module Main where + +import Data.List +import Data.Bits +import GHC.Ptr +import Foreign.Ptr +import Foreign.C.Types + +type FD = CInt +type CString = Ptr CChar + +foreign import ccall unsafe "runInteractiveProcess" + c_runInteractiveProcess + :: Ptr CString + -> CString + -> Ptr CString + -> FD + -> FD + -> FD + -> Ptr FD + -> Ptr FD + -> Ptr FD + -> Ptr CInt + -> Ptr CInt + -> CInt -- flags + -> Ptr CString + -> IO CInt + +main = do + c_runInteractiveProcess + (f 0x1) + (f 0x2) + (f 0x3) + + 0x4 0x5 0x6 + + (f 0x7) + (f 0x8) + (f 0x9) + + (f 0xa) + (f 0xb) + + 0xcccccccc + + (f 0xd) + +-- | Fill a word with a nibble. +-- e.g. @f 1 == 0x1111111111111111@. +f :: Int -> Ptr a +f n = intPtrToPtr $ fromIntegral $ foldl' (.|.) 0 (map (n `shiftL`) [0,4..60]) + diff --git a/testsuite/tests/codeGen/should_run/T20137/T20137.stdout-ws-32 b/testsuite/tests/codeGen/should_run/T20137/T20137.stdout-ws-32 new file mode 100644 index 0000000000..85408b75a5 --- /dev/null +++ b/testsuite/tests/codeGen/should_run/T20137/T20137.stdout-ws-32 @@ -0,0 +1,13 @@ +11111111 +22222222 +33333333 +4 +5 +6 +77777777 +ffffffff88888888 +ffffffff99999999 +ffffffffaaaaaaaa +ffffffffbbbbbbbb +cccccccc +ffffffffdddddddd diff --git a/testsuite/tests/codeGen/should_run/T20137/T20137.stdout-ws-64 b/testsuite/tests/codeGen/should_run/T20137/T20137.stdout-ws-64 new file mode 100644 index 0000000000..f76acf4ae5 --- /dev/null +++ b/testsuite/tests/codeGen/should_run/T20137/T20137.stdout-ws-64 @@ -0,0 +1,13 @@ +1111111111111111 +2222222222222222 +3333333333333333 +4 +5 +6 +7777777777777777 +8888888888888888 +9999999999999999 +aaaaaaaaaaaaaaaa +bbbbbbbbbbbbbbbb +cccccccc +dddddddddddddddd diff --git a/testsuite/tests/codeGen/should_run/T20137/T20137C.c b/testsuite/tests/codeGen/should_run/T20137/T20137C.c new file mode 100644 index 0000000000..f68d88a054 --- /dev/null +++ b/testsuite/tests/codeGen/should_run/T20137/T20137C.c @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <stdint.h> +#include <inttypes.h> + +int +runInteractiveProcess (char *const * args, + char *workingDirectory, char **environment, + // handles to use for the standard handles. -1 indicates + // create pipe, -2 indicates close. + int fdStdIn, int fdStdOut, int fdStdErr, + // output arguments to return created pipe handle to caller + int *pfdStdInput, int *pfdStdOutput, int *pfdStdError, + int *childGroup, int *childUser, + int flags, + char **failed_doing) +{ + // N.B. We don't use %p here since the rendering of this varies across + // libc implementations + printf("%" PRIx64 "\n", (uint64_t) args); + printf("%" PRIx64 "\n", (uint64_t) workingDirectory); + printf("%" PRIx64 "\n", (uint64_t) environment); + printf("%x\n", fdStdIn); + printf("%x\n", fdStdOut); + printf("%x\n", fdStdErr); + printf("%" PRIx64 "\n", (uint64_t) pfdStdInput); + printf("%" PRIx64 "\n", (uint64_t) pfdStdOutput); + printf("%" PRIx64 "\n", (uint64_t) pfdStdError); + printf("%" PRIx64 "\n", (uint64_t) childGroup); + printf("%" PRIx64 "\n", (uint64_t) childUser); + printf("%x\n", flags); + printf("%" PRIx64 "\n", (uint64_t) failed_doing); + return 0; +} + diff --git a/testsuite/tests/codeGen/should_run/T20137/all.T b/testsuite/tests/codeGen/should_run/T20137/all.T new file mode 100644 index 0000000000..33e1975bbb --- /dev/null +++ b/testsuite/tests/codeGen/should_run/T20137/all.T @@ -0,0 +1 @@ +test('T20137', normal, compile_and_run, ['T20137C.c']) |