Skip to content

Commit

Permalink
Fix casm test failures due to concurrent calls to setCurrentDir (#2706)
Browse files Browse the repository at this point in the history
See test failure:
https://github.com/anoma/juvix/actions/runs/8466758094/job/23196216342

```
          Test030: Ackermann function (higher-order definition):                           FAIL (7.40s)
            Translate to JuvixCore                     (6.92s)
            Translate to CASM                          (0.06s)
            Pretty print                               (0.15s)
            Interpret                                  (0.12s)
            Compare expected and actual program output
            Check run_cairo_vm.sh is on path
            Serialize to Cairo bytecode
            Run Cairo VM                               (0.14s)
              /tmp/tmp-60ba562ca9d8f9b5: changeWorkingDirectory: does not exist (No such file or directory)
            
            Use -p '/Juvix to CASM positive tests (no optimization).Test030: Ackermann function (higher-order definition)/' to rerun this test only.
```

`setCurrentDir` cannot be used because tests are run at the same time on
different threads.

This PR removes `setCurrentDir` and instead passes the CWD directly to
the `proc` call.
  • Loading branch information
paulcadman authored Mar 28, 2024
1 parent 90b35b3 commit cd5a43a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 1 addition & 4 deletions test/Casm/Run/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import Runtime.Base qualified as R

casmRunVM' :: Path Abs Dir -> Path Abs File -> IO Text
casmRunVM' dirPath outputFile = do
dir <- getCurrentDir
setCurrentDir dirPath
out0 <- R.readProcess "run_cairo_vm.sh" [toFilePath outputFile] ""
setCurrentDir dir
out0 <- R.readProcessCwd (toFilePath dirPath) "run_cairo_vm.sh" [toFilePath outputFile] ""
return $ fromString $ unlines $ drop 1 $ lines (fromText out0)

casmRunVM :: LabelInfo -> Code -> Path Abs File -> (String -> IO ()) -> Assertion
Expand Down
11 changes: 9 additions & 2 deletions test/Runtime/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ clangCompile mkClangArgs inputFile outputFile execute step =
-- | The same as `P.readProcess` but instead of inheriting `stderr` redirects it
-- to the child's `stdout`.
readProcess :: FilePath -> [String] -> Text -> IO Text
readProcess cmd args stdinText =
readProcess = readProcessCwd' Nothing

readProcessCwd :: FilePath -> FilePath -> [String] -> Text -> IO Text
readProcessCwd cwd = readProcessCwd' (Just cwd)

readProcessCwd' :: Maybe FilePath -> FilePath -> [String] -> Text -> IO Text
readProcessCwd' mcwd cmd args stdinText =
withTempDir'
( \dirPath -> do
(_, hin) <- openTempFile dirPath "stdin"
Expand All @@ -39,7 +45,8 @@ readProcess cmd args stdinText =
(P.proc cmd args)
{ P.std_in = P.UseHandle hin,
P.std_out = P.UseHandle hout,
P.std_err = P.UseHandle hout
P.std_err = P.UseHandle hout,
P.cwd = mcwd
}
P.waitForProcess ph
hSeek hout AbsoluteSeek 0
Expand Down

0 comments on commit cd5a43a

Please sign in to comment.