Skip to content

Commit b73c4b5

Browse files
committed
Add support for --cc in tests
Add an opt-in --cc={compiler} which is threaded throughout all compiler invocations.
1 parent 52a8741 commit b73c4b5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

gibbon-compiler/tests/TestRunner.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE LambdaCase #-}
66
module TestRunner where
77

8+
import Control.Applicative ((<|>), optional)
89
import Control.Monad
910
import Data.Maybe ( catMaybes )
1011
import Data.Foldable
@@ -212,6 +213,9 @@ modeExeFlags Interp1 = error "Cannot compile in Interp1 mode."
212213
modeExeFlags Gibbon1 = ["--to-exe", "--packed", "--gibbon1"]
213214
modeExeFlags MPL = ["--mpl-exe"]
214215

216+
ccFlags :: TestConfig -> [String]
217+
ccFlags tc = maybe [] (\cc -> ["--cc=" ++ cc]) (ccOverride tc)
218+
215219
modeFileSuffix :: Mode -> String
216220
modeFileSuffix Colobus1 = "_colobus1"
217221
modeFileSuffix Colobus2 = "_colobus2"
@@ -347,6 +351,7 @@ data TestConfig = TestConfig
347351
-- It's a global parameter i.e it affects ALL tests.
348352
-- However, if a corresponding parameter is specified
349353
-- for a particular test, that has higher precedence.
354+
, ccOverride :: Maybe String -- ^ If set, pass --cc=<value> to all gibbon invocations.
350355
, checkPerf :: Bool -- ^ Should we also run the performance tests ?
351356
, onlyPerf :: Bool -- ^ If true, only run the benchmarks.
352357
, recordBenchmarks :: Bool -- ^ If true, record the results of running fresh benchmarks. Used via BenchRunner.
@@ -361,6 +366,7 @@ defaultTestConfig = TestConfig
361366
, testSummaryFile = "gibbon-test-summary.txt"
362367
, tempdir = "examples/build_tmp"
363368
, gRunModes = []
369+
, ccOverride = Nothing
364370
, checkPerf = False
365371
, onlyPerf = False
366372
, recordBenchmarks = False
@@ -374,6 +380,7 @@ instance FromJSON TestConfig where
374380
o .:? "test-summary-file" .!= (testSummaryFile defaultTestConfig) <*>
375381
o .:? "tempdir" .!= (tempdir defaultTestConfig) <*>
376382
o .:? "run-modes" .!= (gRunModes defaultTestConfig) <*>
383+
o .:? "cc" .!= (ccOverride defaultTestConfig) <*>
377384
o .:? "check-perf" .!= (checkPerf defaultTestConfig) <*>
378385
o .:? "only-perf" .!= (onlyPerf defaultTestConfig) <*>
379386
o .:? "run-benchmarks" .!= (recordBenchmarks defaultTestConfig) <*>
@@ -402,6 +409,9 @@ configParser dtc = TestConfig
402409
<*> option readM_modes (long "run-modes" <>
403410
help "Only run the tests in these modes" <>
404411
value (gRunModes dtc))
412+
<*> fmap (\mb -> mb <|> ccOverride dtc)
413+
(optional (strOption (long "cc" <>
414+
help "C compiler to use for all tests")))
405415
<*> switch (long "check-perf" <>
406416
help "Run performance tests." <>
407417
showDefault)
@@ -529,7 +539,7 @@ runTest tc Test{name,dir,expectedResults,runModes,mb_anspath,test_flags} = do
529539
exepath = replaceExtension basename ".exe"
530540
cmd = "gibbon"
531541
-- The order of (++) is important. The PATH to the test file must always be at the end.
532-
cmd_flags = modeRunFlags mode ++ test_flags ++
542+
cmd_flags = modeRunFlags mode ++ ccFlags tc ++ test_flags ++
533543
[ "--cfile=" ++ cpath ,
534544
"--exefile=" ++ exepath ,
535545
compiler_dir </> dir </> name ]
@@ -602,7 +612,7 @@ doNTrials tc mode t@Test{name,dir,numTrials,sizeParam,moreIters,isMegaBench,benc
602612

603613

604614
-- The order of (++) is important. The PATH to the test file must always be at the end.
605-
cmd_flags = modeExeFlags mode ++ test_flags ++
615+
cmd_flags = modeExeFlags mode ++ ccFlags tc ++ test_flags ++
606616
[ "--cfile=" ++ cpath ,
607617
"--exefile=" ++ exepath ,
608618
compiler_dir </> dir </> name ]

0 commit comments

Comments
 (0)