Skip to content

Commit d36e3be

Browse files
committed
Enable support for multiple parameter values in a candidate file.
The candidate file (root, exp, or associated) may have multiple possible values for a parameter in the case that the candidate file is valid for those multiple parameter values. This updates the tasty-sugar to properly recognize and utilize those candidate files.
1 parent f75a609 commit d36e3be

File tree

4 files changed

+165
-25
lines changed

4 files changed

+165
-25
lines changed

src/internal/Test/Tasty/Sugar/ExpectCheck.hs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,28 @@ expectedSearch rootN rootPrefix rootPVMatches seps params expSuffix
139139
$ filter expMatch allNames
140140
guard $ isCompatible pvals efile
141141

142-
let onlyOneOfEach (p,v) r = case lookup p r of
143-
Nothing -> (p,v) : r
144-
Just _ -> r
145-
rAndeMatches <- return (foldr onlyOneOfEach rmatch (candidatePMatch efile))
142+
let onlyOneOfEach r c@(p,v) =
143+
-- Note: there may be multiple c with same p and different v because
144+
-- the candidate file has multiple specifications for a particular
145+
-- parameter. Here, we want the one that matches what is in pvals or
146+
-- if there is not a match just take the first one.
147+
let matchesP = (p ==) . fst
148+
rootVals = filter matchesP pvals
149+
in case L.find (maybe False (`paramMatchVal` v) . snd) rootVals of
150+
Just _ ->
151+
-- matches rootVal, so use it and discard any others
152+
return $ c : filter (not . matchesP) r
153+
Nothing -> case lookup p r of
154+
Nothing -> return $ c : r -- first p, so use it
155+
Just _ -> return r
156+
rAndeMatches <- (foldM onlyOneOfEach rmatch (candidatePMatch $ efile))
146157
<|> (if null unconstrained
147158
then mzero
148159
else let unConstr = (`elem` unconstrained) . fst
149160
rm = filter (not . unConstr) (candidatePMatch efile)
150161
in if null rm
151162
then mzero
152-
else return (foldr onlyOneOfEach rmatch rm)
163+
else foldM onlyOneOfEach rmatch rm
153164
)
154165

155166
let pmatch = namedPMatches rAndeMatches pvals

src/internal/Test/Tasty/Sugar/ParamCheck.hs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,17 @@ pmatchMax f a b = case pmatchCmp (f a) (f b) of
9999
-- file is compatible with the provided parameters and chosen parameter values.
100100
-- One principle compatibility check is ensuring that there is no *other*
101101
-- parameter value in the filename that conflicts with a chosen parameter value.
102+
--
103+
-- Note that a particular candidate file may have multiple matching values for a
104+
-- parameter.
102105
isCompatible :: [(String, Maybe String)]
103106
-> CandidateFile
104107
-> Bool
105-
isCompatible pvals fname =
106-
let isCompatParam (n,v) = case DL.lookup n pvals of
107-
Nothing -> True
108-
Just Nothing -> True
109-
Just (Just cv) -> paramMatchVal cv v
110-
in all isCompatParam $ candidatePMatch fname
108+
isCompatible pvals candidatFile =
109+
let isCompatParamV v = \case
110+
Nothing -> True
111+
(Just cv) -> paramMatchVal cv v
112+
isCompatParam (n,mbv) =
113+
let nps = filter ((n ==) . fst) $ candidatePMatch candidatFile
114+
in null nps || any ((`isCompatParamV` mbv) . snd) nps
115+
in all isCompatParam pvals

test/TestLLVMRange.hs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ files2 cube = makeCandidate cube testInpPath []
5252
, "T847-fail2.clang12+.z3.good"
5353
, "T847-fail2.z3.good"
5454
, "T972-fail.c"
55-
, "T972-fail.clang12+.z3.good"
56-
, "T972-fail.clang14+.z3.good"
55+
, "T972-fail.clang12+.clang14+.z3.good"
5756
, "T972-fail.z3.good"
5857
, "abd-test-file-32.c"
5958
, "abd-test-file-32.config"
@@ -641,9 +640,9 @@ mkTest2 mode matchClang sweet exp =
641640
case mode of
642641
"direct" ->
643642
[ expA "T972-fail.z3.good" "z3" "older-clang"
644-
, expE "T972-fail.clang14+.z3.good" "z3" "clang14+"
643+
, expE "T972-fail.clang12+.clang14+.z3.good" "z3" "clang14+"
645644
, expA "T972-fail.z3.good" "z3" "clang13+"
646-
, expE "T972-fail.clang12+.z3.good" "z3" "clang12+"
645+
, expE "T972-fail.clang12+.clang14+.z3.good" "z3" "clang12+"
647646
, expA "T972-fail.z3.good" "z3" "clang11+"
648647
]
649648
"ranged" ->
@@ -657,16 +656,16 @@ mkTest2 mode matchClang sweet exp =
657656
[ expA "T972-fail.z3.good" "z3" "clang11+"
658657
]
659658
Just 12 ->
660-
[ expE "T972-fail.clang12+.z3.good" "z3" "clang12+"
659+
[ expE "T972-fail.clang12+.clang14+.z3.good" "z3" "clang12+"
661660
]
662661
Just 13 ->
663-
[ expE "T972-fail.clang12+.z3.good" "z3" "clang12+"
662+
[ expE "T972-fail.clang12+.clang14+.z3.good" "z3" "clang12+"
664663
]
665664
Just 14 ->
666-
[ expE "T972-fail.clang14+.z3.good" "z3" "clang14+"
665+
[ expE "T972-fail.clang12+.clang14+.z3.good" "z3" "clang14+"
667666
]
668667
Just 16 ->
669-
[ expE "T972-fail.clang14+.z3.good" "z3" "clang14+"
668+
[ expE "T972-fail.clang12+.clang14+.z3.good" "z3" "clang14+"
670669
]
671670
Nothing -> []
672671

test/internals/test-internals.hs

Lines changed: 131 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
module Main where
22

3-
import Control.Monad ( unless )
3+
import Control.Monad ( unless )
44
import qualified Data.List as L
5-
import Test.Tasty
6-
import Test.Tasty.HUnit
7-
import Text.Show.Pretty
5+
import Test.Tasty
6+
import Test.Tasty.HUnit
7+
import Text.Show.Pretty
88

9-
import Test.Tasty.Sugar.Types
10-
import Test.Tasty.Sugar.ExpectCheck
9+
import Test.Tasty.Sugar.Candidates
10+
import Test.Tasty.Sugar.ExpectCheck
11+
import Test.Tasty.Sugar.ParamCheck
12+
import Test.Tasty.Sugar.Types
1113

1214

1315
main = defaultMain $
@@ -180,6 +182,129 @@ main = defaultMain $
180182
in mapM test (L.permutations $ adding <> sample)
181183
>> return ()
182184

185+
, testCase "multi-val-param matching" $
186+
let cand = CandidateFile { candidateDir = "testdir"
187+
, candidateSubdirs = []
188+
, candidateFile = "file.clang12+.clang14+.z3.exp"
189+
, candidatePMatch =
190+
[ ("clangtgt", Explicit "clang12+")
191+
, ("clangtgt", Explicit "clang14+")
192+
, ("solver", Explicit "z3")
193+
]
194+
, candidateMatchIdx = 99
195+
}
196+
pvals1 = [ ("clangtgt", Just "clang12+"), ("solver", Just "z3") ]
197+
pvals2 = [ ("clangtgt", Just "clang14+"), ("solver", Just "z3") ]
198+
pvals3 = [ ("clangtgt", Just "clang12"), ("solver", Just "z3") ]
199+
in do isCompatible pvals1 cand @? "first multival"
200+
isCompatible pvals2 cand @? "second multival"
201+
not (isCompatible pvals3 cand) @? "no multival"
202+
203+
, testCase "collation of expectations" $
204+
let exp1 = Expectation
205+
{ expectedFile = "test/data/llvm1/T972-fail.z3.good"
206+
, expParamsMatch = [("clang-range",Assumed "clang11+")
207+
,("solver",Explicit "z3")]
208+
, associated = []
209+
}
210+
exp2 = Expectation
211+
{ expectedFile = "test/data/llvm1/T972-fail.clang12+.clang14+.z3.good"
212+
, expParamsMatch = [("clang-range",Explicit "clang12+")
213+
,("solver",Explicit "z3")]
214+
, associated = []
215+
}
216+
exp3 = Expectation
217+
{ expectedFile = "test/data/llvm1/T972-fail.z3.good"
218+
, expParamsMatch = [("clang-range",Assumed "clang12+")
219+
,("solver",Explicit "z3")]
220+
, associated = []
221+
}
222+
exp4 = Expectation
223+
{ expectedFile = "test/data/llvm1/T972-fail.z3.good"
224+
, expParamsMatch = [("clang-range",Assumed "clang13+")
225+
,("solver",Explicit "z3")]
226+
, associated = []
227+
}
228+
exp5 = Expectation
229+
{ expectedFile = "test/data/llvm1/T972-fail.clang12+.clang14+.z3.good"
230+
, expParamsMatch = [("clang-range",Explicit "clang14+")
231+
,("solver",Explicit "z3")]
232+
, associated = []
233+
}
234+
exp6 = Expectation
235+
{ expectedFile = "test/data/llvm1/T972-fail.z3.good"
236+
, expParamsMatch = [("clang-range",Assumed "clang14+")
237+
,("solver",Explicit "z3")]
238+
, associated = []
239+
}
240+
exp7 = Expectation
241+
{ expectedFile = "test/data/llvm1/T972-fail.z3.good"
242+
, expParamsMatch = [("clang-range",Assumed "older-clang")
243+
,("solver",Explicit "z3")]
244+
, associated = []
245+
}
246+
allExps = [exp1, exp2, exp3, exp4, exp5, exp6, exp7]
247+
in collateExpectations allExps @?= [exp7, exp5, exp4, exp2, exp1]
248+
-- ^ order of collateExpectations results doesn't really matter, so
249+
-- feel free to re-order this as needed.
250+
251+
, testCase "matchStrength" $
252+
let cand1 = CandidateFile { candidateDir = "testdir"
253+
, candidateSubdirs = []
254+
, candidateFile = "file.clang12+.clang14+.z3.exp"
255+
, candidatePMatch =
256+
[ ("clangtgt", Explicit "clang12+")
257+
, ("clangtgt", Explicit "clang14+")
258+
, ("solver", Explicit "z3")
259+
]
260+
, candidateMatchIdx = 99
261+
}
262+
cand2 = CandidateFile { candidateDir = "testdir"
263+
, candidateSubdirs = []
264+
, candidateFile = "file.z3.exp"
265+
, candidatePMatch =
266+
[ ("solver", Explicit "z3")
267+
]
268+
, candidateMatchIdx = 99
269+
}
270+
strength1 = matchStrength (snd <$> (candidatePMatch cand1))
271+
strength2 = matchStrength (snd <$> (candidatePMatch cand2))
272+
in strength1 > strength2 @?
273+
("candidate 1 strength of " <> show strength1
274+
<> " is not greater than candidate 2 strength of "
275+
<> show strength2)
276+
277+
, testCase "candidateMatchPrefix" $
278+
let seps = "."
279+
rootPrefix = CandidateFile { candidateDir = "testdir"
280+
, candidateSubdirs = []
281+
, candidateFile = "file"
282+
, candidatePMatch = []
283+
, candidateMatchIdx = 5
284+
}
285+
expSuffix = "exp"
286+
cand1 = CandidateFile { candidateDir = "testdir"
287+
, candidateSubdirs = []
288+
, candidateFile = "file.clang12+.clang14+.z3.exp"
289+
, candidatePMatch =
290+
[ ("clangtgt", Explicit "clang12+")
291+
, ("clangtgt", Explicit "clang14+")
292+
, ("solver", Explicit "z3")
293+
]
294+
, candidateMatchIdx = 5
295+
}
296+
cand2 = CandidateFile { candidateDir = "testdir"
297+
, candidateSubdirs = []
298+
, candidateFile = "file.z3.exp"
299+
, candidatePMatch =
300+
[ ("solver", Explicit "z3")
301+
]
302+
, candidateMatchIdx = 5
303+
}
304+
in do candidateMatchPrefix seps rootPrefix cand1 @? "cand1 pfx match"
305+
candidateMatchPrefix seps rootPrefix cand2 @? "cand2 pfx match"
306+
candidateMatchSuffix seps "exp" rootPrefix cand1 @? "cand1 sfx match"
307+
candidateMatchSuffix seps "exp" rootPrefix cand2 @? "cand2 sfx match"
183308
]
184309

185310

0 commit comments

Comments
 (0)