-
Notifications
You must be signed in to change notification settings - Fork 724
Add test suite with two basic tests for solver space leaks. #4122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
153ea8c
Add test suite with two basic tests for solver space leaks.
sebright 41cd786
Fix space leak in conflict counting.
sebright 42ae270
Run memory usage tests in CI.
sebright 4b1a31c
Fix space leak caused by a bug in DeriveFunctor in GHC 7.6.3.
sebright 22480db
Simplify conflict counting.
sebright 1129ad3
Limit stack size in memory usage tests.
sebright File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| module Main where | ||
|
|
||
| import Test.Tasty | ||
|
|
||
| import qualified UnitTests.Distribution.Solver.Modular.MemoryUsage | ||
|
|
||
| tests :: TestTree | ||
| tests = | ||
| testGroup "Memory Usage" | ||
| [ testGroup "UnitTests.Distribution.Solver.Modular.MemoryUsage" | ||
| UnitTests.Distribution.Solver.Modular.MemoryUsage.tests | ||
| ] | ||
|
|
||
| main :: IO () | ||
| main = defaultMain tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
cabal-install/tests/UnitTests/Distribution/Solver/Modular/MemoryUsage.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| -- | Tests for detecting space leaks in the dependency solver. | ||
| module UnitTests.Distribution.Solver.Modular.MemoryUsage (tests) where | ||
|
|
||
| import Test.Tasty (TestTree) | ||
|
|
||
| import UnitTests.Distribution.Solver.Modular.DSL | ||
| import UnitTests.Distribution.Solver.Modular.DSL.TestCaseUtils | ||
|
|
||
| tests :: [TestTree] | ||
| tests = [ | ||
| runTest $ basicTest "basic space leak test" | ||
| , runTest $ flagsTest "package with many flags" | ||
| ] | ||
|
|
||
| -- | This test solves for n packages that each have two versions. Backjumping | ||
| -- is disabled, so the solver must explore a search tree of size 2^n. It should | ||
| -- fail if memory usage is proportional to the size of the tree. | ||
| basicTest :: String -> SolverTest | ||
| basicTest name = | ||
| disableBackjumping $ mkTest pkgs name ["target"] anySolverFailure | ||
| where | ||
| n :: Int | ||
| n = 18 | ||
|
|
||
| pkgs :: ExampleDb | ||
| pkgs = map Right $ | ||
| [ exAv "target" 1 [ExAny $ pkgName 1]] | ||
| ++ [ exAv (pkgName i) v [ExAny $ pkgName (i + 1)] | ||
| | i <- [1..n], v <- [1, 2]] | ||
|
|
||
| pkgName :: Int -> ExamplePkgName | ||
| pkgName x = "pkg-" ++ show x | ||
|
|
||
| -- | This test is similar to 'basicTest', except that it has one package with n | ||
| -- flags, flag-1 through flag-n. The solver assigns flags in order, so it | ||
| -- doesn't discover the unknown dependencies under flag-n until it has assigned | ||
| -- all of the flags. It has to explore the whole search tree. | ||
| flagsTest :: String -> SolverTest | ||
| flagsTest name = | ||
| disableBackjumping $ | ||
| goalOrder orderedFlags $ mkTest pkgs name ["pkg"] anySolverFailure | ||
| where | ||
| n :: Int | ||
| n = 16 | ||
|
|
||
| pkgs :: ExampleDb | ||
| pkgs = [Right $ exAv "pkg" 1 $ | ||
| [exFlag (flagName n) [ExAny "unknown1"] [ExAny "unknown2"]] | ||
|
|
||
| -- The remaining flags have no effect: | ||
| ++ [exFlag (flagName i) [] [] | i <- [1..n - 1]] | ||
| ] | ||
|
|
||
| flagName :: Int -> ExampleFlagName | ||
| flagName x = "flag-" ++ show x | ||
|
|
||
| orderedFlags :: [ExampleVar] | ||
| orderedFlags = [F None "pkg" (flagName i) | i <- [1..n]] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider a bang pattern instead of
seqfor readability.Also, in
exploreLogbelow thecmis only updated when conflict counting is enabled, while it is always updated here. As you suggested in #3960, I think theif countConflicts…would make sense here as well. (Or, if you think thatseqingcmis already sufficient, remove theif countConflictsinexploreLogas well, which would IMHO improve readability).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
I just made a minimal change to avoid conflicts with your PR, but you're right: it's simpler to always update the map.