Skip to content

Commit e682cf7

Browse files
Bodigrimsjakobi
andauthored
CI: add big-endian job (#436)
* Run less UTF-8 tests so that tests in emulated environment take reasonable time * Wrap certain tests into Sqrt to reduce memory pressure * CI: add s390x and ppc64le emulated jobs Co-authored-by: Simon Jakobi <[email protected]>
1 parent 731418d commit e682cf7

File tree

4 files changed

+55
-10
lines changed

4 files changed

+55
-10
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
branches:
55
- master
66
- bytestring-0.11
7-
pull_request: {}
7+
pull_request: {} # Validate all PRs
88

99
defaults:
1010
run:
@@ -60,3 +60,31 @@ jobs:
6060
run: |
6161
cd bytestring-*/
6262
cabal haddock
63+
64+
# Emulation is incredibly slow and memory demanding. It seems that any
65+
# executable with GHC RTS takes at least 7-8 Gb of RAM, so we can run
66+
# `cabal` or `ghc` on their own, but cannot run them both at the same time,
67+
# striking out `cabal test`. Instead we rely on system packages and invoke
68+
# `ghc --make` manually, and even so `ghc -O` is prohibitively expensive.
69+
emulated:
70+
needs: build
71+
runs-on: ubuntu-latest
72+
strategy:
73+
fail-fast: true
74+
matrix:
75+
arch: ['s390x', 'ppc64le']
76+
steps:
77+
- uses: actions/checkout@v2
78+
- uses: uraimo/[email protected]
79+
timeout-minutes: 60
80+
with:
81+
arch: ${{ matrix.arch }}
82+
distro: ubuntu20.04
83+
githubToken: ${{ github.token }}
84+
install: |
85+
apt-get update -y
86+
apt-get install -y ghc libghc-tasty-quickcheck-dev
87+
run: |
88+
ghc --version
89+
ghc --make -Iinclude -itests:tests/builder -o Main cbits/*.c tests/Main.hs +RTS -s
90+
./Main +RTS -s

tests/IsValidUtf8.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ testSuite = testGroup "UTF-8 validation" $ [
2929
goInvalid = forAll arbitrary $
3030
\inv -> (B.isValidUtf8 . toByteString $ inv) === False
3131
testCount :: QuickCheckTests
32-
testCount = 100000
32+
testCount = 1000
3333

3434
checkRegressions :: [TestTree]
3535
checkRegressions = [

tests/Properties/ByteString.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ tests =
141141
B.unpack mempty === []
142142

143143
, testProperty "concat" $
144-
\xs -> B.unpack (B.concat xs) === concat (map B.unpack xs)
144+
\(Sqrt xs) -> B.unpack (B.concat xs) === concat (map B.unpack xs)
145145
, testProperty "concat [x,x]" $
146146
\x -> B.unpack (B.concat [x, x]) === concat [B.unpack x, B.unpack x]
147147
, testProperty "concat [x,[]]" $
148148
\x -> B.unpack (B.concat [x, B.empty]) === concat [B.unpack x, []]
149149
, testProperty "mconcat" $
150-
\xs -> B.unpack (mconcat xs) === mconcat (map B.unpack xs)
150+
\(Sqrt xs) -> B.unpack (mconcat xs) === mconcat (map B.unpack xs)
151151
, testProperty "mconcat [x,x]" $
152152
\x -> B.unpack (mconcat [x, x]) === mconcat [B.unpack x, B.unpack x]
153153
, testProperty "mconcat [x,[]]" $
@@ -186,7 +186,7 @@ tests =
186186
, testProperty "<>" $
187187
\x y -> B.unpack (x <> y) === B.unpack x <> B.unpack y
188188
, testProperty "stimes" $
189-
\(NonNegative n) x -> stimes (n :: Int) (x :: B.ByteString) === mtimesDefault n x
189+
\(Sqrt (NonNegative n)) (Sqrt x) -> stimes (n :: Int) (x :: B.ByteString) === mtimesDefault n x
190190

191191
, testProperty "break" $
192192
\f x -> (B.unpack *** B.unpack) (B.break f x) === break f (B.unpack x)
@@ -434,10 +434,10 @@ tests =
434434
, testProperty "foldr cons" $
435435
\x -> B.foldr B.cons B.empty x === x
436436
, testProperty "foldl special" $
437-
\x (toElem -> c) -> B.unpack (B.foldl (\acc t -> if t == c then acc else B.cons t acc) B.empty x) ===
437+
\(Sqrt x) (toElem -> c) -> B.unpack (B.foldl (\acc t -> if t == c then acc else B.cons t acc) B.empty x) ===
438438
foldl (\acc t -> if t == c then acc else t : acc) [] (B.unpack x)
439439
, testProperty "foldr special" $
440-
\x (toElem -> c) -> B.unpack (B.foldr (\t acc -> if t == c then acc else B.cons t acc) B.empty x) ===
440+
\(Sqrt x) (toElem -> c) -> B.unpack (B.foldr (\t acc -> if t == c then acc else B.cons t acc) B.empty x) ===
441441
foldr (\t acc -> if t == c then acc else t : acc) [] (B.unpack x)
442442

443443
, testProperty "foldl1" $
@@ -486,7 +486,7 @@ tests =
486486
, testProperty "intersperse" $
487487
\(toElem -> c) x -> B.unpack (B.intersperse c x) === List.intersperse c (B.unpack x)
488488
, testProperty "intercalate" $
489-
\x ys -> B.unpack (B.intercalate x ys) === List.intercalate (B.unpack x) (map B.unpack ys)
489+
\(Sqrt x) (Sqrt ys) -> B.unpack (B.intercalate x ys) === List.intercalate (B.unpack x) (map B.unpack ys)
490490
, testProperty "intercalate 'c' [x,y]" $
491491
\(toElem -> c) x y -> B.unpack (B.intercalate (B.singleton c) [x, y]) === List.intercalate [c] [B.unpack x, B.unpack y]
492492
, testProperty "intercalate split" $

tests/QuickCheckUtils.hs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
{-# LANGUAGE FlexibleInstances, FlexibleContexts #-}
1+
{-# LANGUAGE FlexibleContexts #-}
2+
{-# LANGUAGE FlexibleInstances #-}
3+
{-# LANGUAGE TypeApplications #-}
24

3-
module QuickCheckUtils (Char8(..), String8(..), CByteString(..)) where
5+
module QuickCheckUtils
6+
( Char8(..)
7+
, String8(..)
8+
, CByteString(..)
9+
, Sqrt(..)
10+
) where
411

512
import Test.Tasty.QuickCheck
613
import Text.Show.Functions
@@ -84,3 +91,13 @@ instance Arbitrary String8 where
8491
toChar :: Word8 -> Char
8592
toChar = toEnum . fromIntegral
8693
shrink (String8 xs) = fmap String8 (shrink xs)
94+
95+
-- | If a test takes O(n^2) time or memory, it's useful to wrap its inputs
96+
-- into 'Sqrt' so that increasing number of tests affects run time linearly.
97+
newtype Sqrt a = Sqrt { unSqrt :: a }
98+
deriving (Eq, Show)
99+
100+
instance Arbitrary a => Arbitrary (Sqrt a) where
101+
arbitrary = Sqrt <$> sized
102+
(\n -> resize (round @Double $ sqrt $ fromIntegral @Int n) arbitrary)
103+
shrink = map Sqrt . shrink . unSqrt

0 commit comments

Comments
 (0)