@@ -7,7 +7,56 @@ import UnitTests.Distribution.Solver.Modular.DSL
77import UnitTests.Distribution.Solver.Modular.DSL.TestCaseUtils
88
99tests :: [TestTree ]
10- tests = [runTest $ issue2899 " issue #2899" ]
10+ tests = [
11+ runTest $ basicTest " basic space leak test"
12+ , runTest $ flagsTest " package with many flags"
13+ , runTest $ issue2899 " issue #2899"
14+ ]
15+
16+ -- | This test solves for n packages that each have two versions. Backjumping
17+ -- is disabled, so the solver must explore a search tree of size 2^n. It should
18+ -- fail if memory usage is proportional to the size of the tree.
19+ basicTest :: String -> SolverTest
20+ basicTest name =
21+ disableBackjumping $ mkTest pkgs name [" target" ] anySolverFailure
22+ where
23+ n :: Int
24+ n = 18
25+
26+ pkgs :: ExampleDb
27+ pkgs = map Right $
28+ [ exAv " target" 1 [ExAny $ pkgName 1 ]]
29+ ++ [ exAv (pkgName i) v [ExAny $ pkgName (i + 1 )]
30+ | i <- [1 .. n], v <- [1 , 2 ]]
31+
32+ pkgName :: Int -> ExamplePkgName
33+ pkgName x = " pkg-" ++ show x
34+
35+ -- | This test is similar to 'basicTest', except that it has one package with n
36+ -- flags, flag-1 through flag-n. The solver assigns flags in order, so it
37+ -- doesn't discover the unknown dependencies under flag-n until it has assigned
38+ -- all of the flags. It has to explore the whole search tree.
39+ flagsTest :: String -> SolverTest
40+ flagsTest name =
41+ disableBackjumping $
42+ goalOrder orderedFlags $ mkTest pkgs name [" pkg" ] anySolverFailure
43+ where
44+ n :: Int
45+ n = 16
46+
47+ pkgs :: ExampleDb
48+ pkgs = [Right $ exAv " pkg" 1 $
49+ [exFlag (flagName n) [ExAny " unknown1" ] [ExAny " unknown2" ]]
50+
51+ -- The remaining flags have no effect:
52+ ++ [exFlag (flagName i) [] [] | i <- [1 .. n - 1 ]]
53+ ]
54+
55+ flagName :: Int -> ExampleFlagName
56+ flagName x = " flag-" ++ show x
57+
58+ orderedFlags :: [ExampleVar ]
59+ orderedFlags = [F None " pkg" (flagName i) | i <- [1 .. n]]
1160
1261-- | Test for a space leak caused by sharing of search trees under packages with
1362-- link choices (issue #2899).
0 commit comments