RunTest.hs 8.05 KB
Newer Older
1 2
module Settings.Builders.RunTest (runTestBuilderArgs) where

3
import CommandLine (TestArgs(..), defaultTestArgs, TestSpeed(..))
4
import Flavour
5
import GHC
6
import Hadrian.Utilities
7
import Oracles.Setting (setting)
8 9 10
import Rules.Test
import Settings.Builders.Common

11 12 13 14
oneZero :: String -> Bool -> String
oneZero lbl False = lbl ++ "=0"
oneZero lbl True = lbl ++ "=1"

15
-- Arguments to send to the runtest.py script.
16 17
--
-- A lot of this mirrors what's achieved at testsuite/mk/test.mk.
18 19 20 21 22 23 24
runTestBuilderArgs :: Args
runTestBuilderArgs = builder RunTest ? do
    pkgs     <- expr $ stagePackages Stage1
    libTests <- expr $ filterM doesDirectoryExist $ concat
            [ [ pkgPath pkg -/- "tests", pkgPath pkg -/- "tests-ghc" ]
            | pkg <- pkgs, isLibrary pkg, pkg /= rts, pkg /= libffi ]

25 26 27 28 29 30
    flav <- expr flavour
    rtsways <- rtsWays flav
    libways <- libraryWays flav
    let hasRtsWay w = elem w rtsways
        hasLibWay w = elem w libways
        debugged = ghcDebugged flav
31 32 33

    withNativeCodeGen <- expr ghcWithNativeCodeGen
    withInterpreter   <- expr ghcWithInterpreter
Andrey Mokhov's avatar
Andrey Mokhov committed
34
    unregisterised    <- getFlag GhcUnregisterised
35 36 37 38 39
    withSMP           <- expr ghcWithSMP

    windows  <- expr windowsHost
    darwin   <- expr osxHost
    threads  <- shakeThreads <$> expr getShakeOptions
40 41 42
    os       <- expr $ setting TargetOs
    arch     <- expr $ setting TargetArch
    platform <- expr $ setting TargetPlatform
43 44 45 46
    top      <- expr topDirectory
    ghcFlags    <- expr runTestGhcFlags
    timeoutProg <- expr buildRoot <&> (-/- timeoutProgPath)

47 48
    -- TODO: set CABAL_MINIMAL_BUILD/CABAL_PLUGIN_BUILD

49 50 51 52 53 54 55 56 57 58
    mconcat [ arg $ "testsuite/driver/runtests.py"
            , arg $ "--rootdir=" ++ ("testsuite" -/- "tests")
            , pure ["--rootdir=" ++ test | test <- libTests]
            , arg "-e", arg $ "windows=" ++ show windows
            , arg "-e", arg $ "darwin=" ++ show darwin
            , arg "-e", arg $ "config.speed=2"                        -- Use default value in GHC's test.mk
            , arg "-e", arg $ "config.local=True"
            , arg "-e", arg $ "config.cleanup=False"                  -- Don't clean up.
            , arg "-e", arg $ "config.compiler_debugged=" ++ quote (yesNo debugged)
            , arg "-e", arg $ "ghc_debugged=" ++ quote (yesNo debugged)
59
            , arg "-e", arg $ oneZero "ghc_with_native_codegen" withNativeCodeGen
60 61 62 63 64

            , arg "-e", arg $ "config.have_interp=" ++ show withInterpreter
            , arg "-e", arg $ "config.unregisterised=" ++ show unregisterised

            , arg "-e", arg $ "ghc_compiler_always_flags=" ++ quote ghcFlags
65 66 67 68 69 70
            , arg "-e", arg $ oneZero "ghc_with_dynamic_rts" (hasRtsWay dynamic)
            , arg "-e", arg $ oneZero "ghc_with_threaded_rts" (hasRtsWay threaded)
            , arg "-e", arg $ oneZero "config.have_vanilla" (hasLibWay vanilla)
            , arg "-e", arg $ oneZero "config.have_dynamic" (hasLibWay dynamic)
            , arg "-e", arg $ oneZero "config.have_profiling" (hasLibWay profiling)
            , arg "-e", arg $ oneZero "ghc_with_smp" withSMP
71 72 73 74 75 76
            , arg "-e", arg $ "ghc_with_llvm=0"                       -- TODO: support LLVM

            , arg "-e", arg $ "config.ghc_dynamic_by_default=False"   -- TODO: support dynamic
            , arg "-e", arg $ "config.ghc_dynamic=False"              -- TODO: support dynamic

            , arg "-e", arg $ "config.in_tree_compiler=True"          -- Use default value, see https://github.com/ghc/ghc/blob/master/testsuite/mk/boilerplate.mk
77 78 79 80
            , arg "-e", arg $ "config.top=" ++ show (top -/- "testsuite")
            , arg "-e", arg $ "config.wordsize=\"64\""
            , arg "-e", arg $ "config.os="       ++ show os
            , arg "-e", arg $ "config.arch="     ++ show arch
Andrey Mokhov's avatar
Andrey Mokhov committed
81 82
            , arg "-e", arg $ "config.platform=" ++ show platform

83 84 85 86 87 88 89 90 91
            , arg "--config", arg $ "gs=gs"                           -- Use the default value as in test.mk
            , arg "--config", arg $ "timeout_prog=" ++ show (top -/- timeoutProg)
            , arg $ "--threads=" ++ show threads
            , getTestArgs -- User-provided arguments from command line.
            ]

-- | Prepare the command-line arguments to run GHC's test script.
getTestArgs :: Args
getTestArgs = do
92 93 94 95
    args            <- expr $ userSetting defaultTestArgs
    bindir          <- expr $ setBinaryDirectory (testCompiler args)
    compiler        <- expr $ setCompiler (testCompiler args)
    globalVerbosity <- shakeVerbosity <$> expr getShakeOptions 
96 97
    let configFileArg= ["--config-file=" ++ (testConfigFile args)]
        testOnlyArg  = case testOnly args of
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
                           Just cases -> map ("--only=" ++) (words cases)
                           Nothing -> []
        onlyPerfArg  = if testOnlyPerf args
                           then Just "--only-perf-tests"
                           else Nothing
        skipPerfArg  = if testSkipPerf args
                           then Just "--skip-perf-tests"
                           else Nothing
        speedArg     = ["-e", "config.speed=" ++ setTestSpeed (testSpeed args)]
        summaryArg   = case testSummary args of
                           Just filepath -> Just $ "--summary-file" ++ quote filepath
                           Nothing -> Just $ "--summary-file=testsuite_summary.txt"
        junitArg     = case testJUnit args of
                           Just filepath -> Just $ "--junit " ++ quote filepath
                           Nothing -> Nothing
        configArgs   = concat [["-e", configArg] | configArg <- testConfigs args]
114
        verbosityArg = case testVerbosity args of
115 116 117 118 119 120 121 122
                           Nothing -> Just $ "--verbose=" ++ show (fromEnum globalVerbosity)
                           Just verbosity -> Just $ "--verbose=" ++ verbosity
        wayArgs      = map ("--way=" ++) (testWays args) 
        compilerArg  = ["--config", "compiler=" ++ show (compiler)]
        ghcPkgArg    = ["--config", "ghc_pkg=" ++ show (bindir -/- "ghc-pkg")]
        haddockArg   = ["--config", "haddock=" ++ show (bindir -/- "haddock")]
        hp2psArg     = ["--config", "hp2ps=" ++ show (bindir -/- "hp2ps")]
        hpcArg       = ["--config", "hpc=" ++ show (bindir -/- "hpc")]   
123
    pure $  configFileArg ++ testOnlyArg ++ speedArg 
124
         ++ catMaybes [ onlyPerfArg, skipPerfArg, summaryArg
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
                      , junitArg, verbosityArg  ] 
         ++ configArgs ++ wayArgs ++  compilerArg ++ ghcPkgArg
         ++ haddockArg ++ hp2psArg ++ hpcArg

-- | Directory to look for Binaries
-- | We assume that required programs are present in the same binary directory 
-- | in which ghc is stored and that they have their conventional name.
-- | QUESTION : packages can be named different from their conventional names.
-- | For example, ghc-pkg can be named as ghc-pkg-version. In such cases, it will
-- | be impossible to search the binary. Only possible way will be to take user 
-- | inputs for these directory also. boilerplate soes not account for this 
-- | problem, but simply returns an error. How should we handle such cases?
setBinaryDirectory :: String -> Action FilePath
setBinaryDirectory "stage0" = setting InstallBinDir
setBinaryDirectory "stage1" = liftM2 (-/-) topDirectory (stageBinPath Stage0) 
setBinaryDirectory "stage2" = liftM2 (-/-) topDirectory (stageBinPath Stage1) 
setBinaryDirectory compiler = pure $ parentPath compiler

-- | Set Test Compiler
setCompiler :: String -> Action FilePath
setCompiler "stage0" = setting SystemGhc
setCompiler "stage1" = liftM2 (-/-) topDirectory (fullpath Stage0 ghc)
setCompiler "stage2" = liftM2 (-/-) topDirectory (fullpath Stage1 ghc)
setCompiler compiler = pure compiler 
149 150 151 152 153 154

-- | Set speed for test
setTestSpeed :: TestSpeed -> String
setTestSpeed Fast    = "2"
setTestSpeed Average = "1"
setTestSpeed Slow    = "0"
155

156 157 158 159 160 161 162 163 164 165
-- | Returns parent path of test compiler 
-- | TODO : Is there a simpler way to find parent directory?
parentPath :: String -> String
parentPath path = let upPath = init $ splitOn "/" path
                  in  intercalate "/" upPath

-- | TODO: move to hadrian utilities.
fullpath :: Stage -> Package -> Action FilePath
fullpath stage pkg = programPath =<< programContext stage pkg