Skip to content

Commit

Permalink
Auto-retry tests failing due to GHC #19421
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnbastiaan committed Feb 10, 2025
1 parent f838d01 commit 30ae972
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 17 additions & 2 deletions tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ module Main (main) where

import qualified Clash.Util.Interpolate as I

import Control.Retry (RetryAction(ConsultPolicy, DontRetry), RetryPolicyM, RetryStatus)
import Clash.Annotations.Primitive (HDL(..))
import qualified Data.Text as Text
import Data.Default (def)
import Data.List ((\\), intercalate)
import Data.List ((\\), intercalate, isInfixOf)
import Data.List.Extra (trim)
import Data.Version (versionBranch)
import System.Directory
Expand All @@ -22,7 +23,9 @@ import GHC.IO.Unsafe (unsafePerformIO)
import Text.Printf (printf)

import Test.Tasty
import Test.Tasty.Flaky (flakyTestWithRetryAction, limitRetries)
import Test.Tasty.Common
import Test.Tasty.Providers (Result)
import Test.Tasty.Clash

-- | GHC version as major.minor.patch1. For example: 8.10.2.
Expand Down Expand Up @@ -127,8 +130,20 @@ clashTestGroup testName testTrees =
testGroup testName $
zipWith ($) testTrees (repeat (testName : parentNames))

-- | Auto-retry failures caused by GHC bug #19421. See clash-compiler PR #2444.
workaroundMmapCrash :: TestTree -> TestTree
workaroundMmapCrash = flakyTestWithRetryAction retryAction retryPolicy
where
retryAction :: RetryStatus -> Result -> IO RetryAction
retryAction _ result
| "m32_allocator_init: Failed to map" `isInfixOf` show result = pure ConsultPolicy
| otherwise = pure DontRetry

retryPolicy :: RetryPolicyM IO
retryPolicy = limitRetries 5

runClashTest :: IO ()
runClashTest = defaultMain $ clashTestRoot
runClashTest = defaultMain $ workaroundMmapCrash $ clashTestRoot
[ clashTestGroup "examples"
[ runTest "ALU" def{hdlSim=[]}
, let _opts = def { hdlSim=[]
Expand Down
3 changes: 2 additions & 1 deletion tests/clash-testsuite.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ executable clash-testsuite
clash-ghc:clash

build-depends:
containers,
clash-testsuite,
containers,
extra,
retry,

if impl(ghc >= 9.0.0)
build-depends:
Expand Down

0 comments on commit 30ae972

Please sign in to comment.