haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.62k stars 691 forks source link

Running cabal-install unit-tests fails due to Hpc failure #7384

Closed fendor closed 3 years ago

fendor commented 3 years ago

Describe the bug Executing the test-suite via cabal run unit-tests in cabal-install sub-directory works fine on the first run. After changing the test-suite, followed by executing the tests again the following error is thrown:

Hpc failure: module mismatch with .tix/.mix file hash number
(perhaps remove unit-tests.tix file?)

To Reproduce Steps to reproduce the behavior:

$ cd cabal-install
$ cabal v2-run unit-tests -- -p "forkPackages"
$ # Modify test-suite slightly
$ cabal v2-run unit-tests -- -p "forkPackages" # Fails

Expected behavior Should not crash

System information

emilypi commented 3 years ago

Pinging @hvr. Historically, when I brought this fact up, it was brushed off as "Not Cabal's Problem", because it is primarily due to the way HPC produces garbage and doesn't clean up after itself. I tend to agree, but I think until HPC gets its ducks in a row, Cabal should handle the cleanup and teardown when it creates coverage reports.

I would welcome PR's that help with this, and PR's that improve the general state of Coverage as Cabal handles it in general.

fendor commented 3 years ago

Sounds like hpc needs some love.

emilypi commented 3 years ago

It really does. It has no owner currently, and it's becoming bitrotten as a result. If you know anyone with free bandwidth to spare, hit up @bgamari or someone else on the GHC team and perhaps they can bring that person up to speed.

ezyang commented 3 years ago

I feel it is even worse than reported here; in particular, I can induce this problem without any reference to profiling, e.g., cabal run cabal-testsuite:cabal-tests -- --with-cabal $(cabal list-bin cabal-install:cabal) cabal-testsuite/PackageTests/Backpack/T6385/cabal.test.hs, rebuild cabal-install, and then run it again.

Mikolaj commented 3 years ago

Now I understand why README.md say to use cabal install --project-file=cabal.project.release cabal-install. But requiring all cabal devs to specify the project file on each command is definitely too much.

fendor commented 3 years ago

Is fixed (or work-arounded) by #7421

BinderDavid commented 1 year ago

This is due to an (in my opinion) anti-feature of hpc: At program startup it tries to read in the .tix file and accumulates coverage information across multiple runs. This behaviour is documented in the hpc user guide:

The program may be run multiple times (e.g. with different test data), and the coverage data from the separate runs is accumulated in the .tix file. To reset the coverage data and start again, just remove the .tix file. You can control where the .tix file is generated using the environment variable HPCTIXFILE.

I just stumbled upon this problem myself. See https://gitlab.haskell.org/ghc/ghc/-/issues/23955