Skip to content
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

Fix #4270: make detailed-0.9 test suites work with dynamic exes #4274

Merged
merged 2 commits into from
Feb 5, 2017

Conversation

bennofs
Copy link
Collaborator

@bennofs bennofs commented Jan 27, 2017

The detailed-0.9 test suite type compiles the test module into a shared library,
so for running the tests, we need to include the directory where the shared
library is stored in LD_LIBRARY_PATH.

@mention-bot
Copy link

@bennofs, thanks for your PR! By analyzing the history of the files in this pull request, we identified @Ericson2314, @ttuegel and @ezyang to be potential reviewers.

@ttuegel
Copy link
Member

ttuegel commented Jan 27, 2017

Do we need to do the same thing for exitcode-stdio-1.0 tests?

@23Skidoo
Copy link
Member

@ttuegel Mayhaps. Does the fix look good to you?

@bennofs Can you please add a regression test?

@bennofs
Copy link
Collaborator Author

bennofs commented Jan 27, 2017

@ttuegel I believe not since a normal executable component will not build any shared library that needs to be linked against

@ttuegel
Copy link
Member

ttuegel commented Jan 27, 2017

I believe not since a normal executable component will not build any shared library that needs to be linked against

@bennofs What if it links against the package's library component?

@ezyang
Copy link
Contributor

ezyang commented Jan 27, 2017

From AppVeyor failure, test needs to be disabled on platforms that don't support dynamic linking e.g. Windows. Use skipUnless =<< hasSharedLibraries

ezyang
ezyang previously requested changes Jan 27, 2017
else return shellEnv
print shellEnv'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you wanted to keep this

@@ -94,8 +94,10 @@ runTest pkg_descr lbi clbi flags suite = do
let (Platform _ os) = LBI.hostPlatform lbi
paths <- LBI.depLibraryPaths
True False lbi clbi
return (addLibraryPath os paths shellEnv)
cpath <- canonicalizePath $ LBI.componentBuildDir lbi clbi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you want canonicalizePath and not makeAbsolute?

@bennofs
Copy link
Collaborator Author

bennofs commented Jan 27, 2017

@ttuegel That is already handled correctly, since we do add the library dirs for all dependencies. The LibV09 case just wasn't handled correctly because for this particular case, we need the libdir of the current component as well (since that contains the shared lib that is loaded by the test stub), not just of the dependencies.

I (hopefully) addressed the remaining review comments (thanks for that!). Tell me if you'd like me to squash the commits.

@bennofs
Copy link
Collaborator Author

bennofs commented Jan 28, 2017

Should hasSharedLibraries be false when the Cabal library itself is not build with shared libraries? This is the reason why it's failing on travis right now: for some build configs on travis, we only build the static Cabal library so the test cannot run.

@ezyang
Copy link
Contributor

ezyang commented Jan 28, 2017

@bennofs You're right! So I guess we also need a "has Cabal shared library" parameter. Unfortunately, I don't actually know how to test for this... maybe do a ./configure style probe? (Don't do it on every test, only when requested; see withDelay for an example of how we've been coding this sort of thing.)

@bennofs
Copy link
Collaborator Author

bennofs commented Jan 28, 2017

This PR actually seems to be a duplicate of #3527

@bennofs
Copy link
Collaborator Author

bennofs commented Jan 31, 2017

@ezyang I was looking at the test code, and found a function called hasCabalGorGhc in Prelude.hs. What's that function for?

@ezyang
Copy link
Contributor

ezyang commented Jan 31, 2017

hasCabalForGhc is a different function, related to what we do when we test the Cabal library, passing --with-ghc for a different version of GHC. In this situation, we can't use certain features like detailed test suites, because the version of GHC we are compiling the test with doesn't have the new version of Cabal.

bennofs added a commit to bennofs/cabal that referenced this pull request Feb 1, 2017
The detailed-0.9 test suite type compiles the test module into a shared library,
so for running the tests, we need to include the directory where the shared
library is stored in LD_LIBRARY_PATH.
@bennofs
Copy link
Collaborator Author

bennofs commented Feb 1, 2017

I squashed some of the commits, travis build should be fine now.

@ezyang ezyang dismissed their stale review February 3, 2017 22:16

new changes

-- An example where this is needed is if you want to dynamically link
-- detailed-0.9 test suites, since those depend on the Cabal library unde rtest.
hasCabalShared :: TestM Bool
hasCabalShared = do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting implementation of hasCabalShared. At the very least, I would add a note that it is a relatively expensive check, because it involves banging on GHC, so you really only want to call this once, if at all possible.

Assuming that this is the best way to go about doing this, I have some comments:

  • First, are you sure that runProgramM ghcProgram isn't enough to invoke GHC? I believe that GHC should already be configured in testProgramDb; the configuration was done in Test/Cabal/Monad.hs so I don't think we should have to do it again. If this doesn't work, there is probably a different bug somewhere. Is the problem that runM calls requireSuccess whereas you need to get a boolean out instead? Maybe we can refactor those functions so you get a version that raises exceptions, and one that doesn't. This is related to cabal-testsuite: check return code of runghc Setup.hs #4292 where we wanted to handle fails more systematically.

  • Second, the invocation of GHC doesn't attempt to control what packages are in scope, which means that you could end up in a situation where there are two Cabal packages in scope. I guess GHC is preferring the latest version so it's working correctly in this case, but it would be more robust to explicitly specify which Cabal library we want to use, and the test would stop working the moment someone uses a GHC that comes with a newer version of Cabal.

Is this check the way we want to go about it? I'll admit, I can't think of very many other good choices. One possibility is to look at the LocalBuildInfo when we mkScriptEnv and check if dynamic compilation was enabled (adding a new field to ScriptEnv saying if we were building with dynamic or not.) This seems a lot simpler and efficient!

@ezyang
Copy link
Contributor

ezyang commented Feb 3, 2017

Sorry about the yak shaving on hasCabalShared; I know I'm the one who suggested the configure style check, but I only just realized that maybe the LBI has the info we want. If that method works, I think it's my preferred choice. But even if it doesn't, I hope we can simplify the code in hasCabalShared a bit.

@bennofs
Copy link
Collaborator Author

bennofs commented Feb 3, 2017

Using the LocalBuildInfo sounds like a good idea indeed, I will have to try that.

@bennofs
Copy link
Collaborator Author

bennofs commented Feb 4, 2017

Windows build failure is due to #4005

@bennofs
Copy link
Collaborator Author

bennofs commented Feb 4, 2017

@ezyang using the LocalBuildInfo was a really good idea, there's now much less code.

@ezyang
Copy link
Contributor

ezyang commented Feb 4, 2017

@bennofs Good! I restarted the Windows build, if it passes let's ship it!

@ezyang
Copy link
Contributor

ezyang commented Feb 4, 2017

Failing -Werror; import changes need to be undone.

@bennofs
Copy link
Collaborator Author

bennofs commented Feb 5, 2017

@ezyang fixed that and squashed the changes into the add-regression-test commit.

@ezyang ezyang merged commit a1d9e88 into haskell:master Feb 5, 2017
@ezyang
Copy link
Contributor

ezyang commented Feb 5, 2017

Good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants