Skip to content

Commit

Permalink
tests: output into tmp2 directory
Browse files Browse the repository at this point in the history
This restores the execution time for running
'stack test' with VSCode running to the same
time as running 'stack test' without it.

The problem turned out to be the MS C/C++ IntelliSense
plugin and file watching. Our tests output C files in
the test directory at a rapid pace which causes
IntelliSense to react to the new files and use the CPU
for non-test related activities.

The best case scenario would be to output our tests into
a temporary directory somewhere but this is the minimal
fix that I can get sane performance with. I still have
this in my settings.json:

    "files.watcherExclude": {
        "**/.git": true,
        "**/.DS_Store": true,
        "**/tmp" : true,
        "**/tmp2" : true,
        "**/.stack-work" : true,
    },
    "files.exclude": {
        "**/.git": true,
        "tmp" : true,
        "tmp2" : true,
        ".stack-work" : true,
    },
  • Loading branch information
pjonsson committed Aug 18, 2020
1 parent 22fec0e commit 0d48b28
Show file tree
Hide file tree
Showing 34 changed files with 124 additions and 123 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@ cabal.sandbox.config
.stack-work/
src/Onnx.hs

tests/*.[hc]
tests/*.txt
tests/gold/ep-*.[hc]
tests/gold/*_build_test.[hc]
tmp
tmp2
3 changes: 2 additions & 1 deletion feldspar-language.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ test-suite regression
feldspar-language,
mtl,
base,
filepath,
bytestring >= 0.9 && < 0.11,
directory,
filepath,
random >= 1.0 && < 1.2,
stringsearch >= 0.3,
tasty >= 0.3,
Expand Down
53 changes: 28 additions & 25 deletions tests/RegressionTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import Data.Monoid ((<>))
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy as LB
import qualified Data.ByteString.Lazy.Search as LB
import System.Directory (createDirectoryIfMissing)
import System.Exit (ExitCode)
import System.FilePath ((</>), (<.>))
import Text.Printf
Expand Down Expand Up @@ -381,29 +382,29 @@ tests = testGroup "RegressionTests" $
decorationTests :: TestTree
decorationTests = testGroup "DecorationTests"
[ goldenVsFile "example9"
(goldDir "example9.txt") (testDir "example9.txt")
$ writeFile (testDir "example9.txt") $ showDecor example9
(goldDir "example9.txt") (tmpDir "example9.txt")
$ writeFile (tmpDir "example9.txt") $ showDecor example9
, goldenVsFile "topLevelConsts"
(goldDir "topLevelConsts.txt") (testDir "topLevelConsts.txt")
$ writeFile (testDir "topLevelConsts.txt") $ showDecor topLevelConsts
(goldDir "topLevelConsts.txt") (tmpDir "topLevelConsts.txt")
$ writeFile (tmpDir "topLevelConsts.txt") $ showDecor topLevelConsts
, goldenVsFile "monadicSharing"
(goldDir "monadicSharing.txt") (testDir "monadicSharing.txt")
$ writeFile (testDir "monadicSharing.txt") $ showDecor monadicSharing
(goldDir "monadicSharing.txt") (tmpDir "monadicSharing.txt")
$ writeFile (tmpDir "monadicSharing.txt") $ showDecor monadicSharing
, goldenVsFile "trickySharing"
(goldDir "trickySharing.txt") (testDir "trickySharing.txt")
$ writeFile (testDir "trickySharing.txt") $ showDecor trickySharing
(goldDir "trickySharing.txt") (tmpDir "trickySharing.txt")
$ writeFile (tmpDir "trickySharing.txt") $ showDecor trickySharing
, goldenVsFile "noshareT"
(goldDir "noshareT.txt") (testDir "noshareT.txt")
$ writeFile (testDir "noshareT.txt") $ showDecor noshareT
(goldDir "noshareT.txt") (tmpDir "noshareT.txt")
$ writeFile (tmpDir "noshareT.txt") $ showDecor noshareT
, goldenVsFile "shareT"
(goldDir "shareT.txt") (testDir "shareT.txt")
$ writeFile (testDir "shareT.txt") $ showDecor shareT
(goldDir "shareT.txt") (tmpDir "shareT.txt")
$ writeFile (tmpDir "shareT.txt") $ showDecor shareT
, goldenVsFile "selectT"
(goldDir "selectT.txt") (testDir "selectT.txt")
$ writeFile (testDir "selectT.txt") $ showDecor selectT
(goldDir "selectT.txt") (tmpDir "selectT.txt")
$ writeFile (tmpDir "selectT.txt") $ showDecor selectT
, goldenVsFile "tfModel"
(goldDir "tfModel.txt") (testDir "tfModel.txt")
$ writeFile (testDir "tfModel.txt") $ showUntyped defaultOptions tfModel
(goldDir "tfModel.txt") (tmpDir "tfModel.txt")
$ writeFile (tmpDir "tfModel.txt") $ showUntyped defaultOptions tfModel
]

-- | Tests for calling convention
Expand Down Expand Up @@ -529,20 +530,22 @@ main = do
cp <- getConsoleCP
setConsoleCP 65001
#endif
createDirectoryIfMissing True "tmp2"
defaultMain tests
`catch` (\(e :: ExitCode)-> do
#ifdef mingw32_HOST_OS
setConsoleCP cp -- Restore codepage before exit.
#endif
throwIO e)

-- | Prepend the test directory to a @FilePath@
testDir :: Prelude.FilePath -> Prelude.FilePath
testDir = (</>) "tests"
-- | Prepend the tmp output directory to a @FilePath@. Must be different
-- from the Plugins tmp directory which is "tmp".
tmpDir :: Prelude.FilePath -> Prelude.FilePath
tmpDir = (</>) "tmp2"

-- | Prepend the gold directory to a @FilePath@
goldDir :: Prelude.FilePath -> Prelude.FilePath
goldDir = (</>) (testDir "gold")
goldDir = (</>) ("tests" </> "gold")

nativeOpts :: Options
nativeOpts = defaultOptions{useNativeArrays=True}
Expand All @@ -557,7 +560,7 @@ openMPOpts = c99OpenMpPlatformOptions
mkGoldTest :: Syntactic a => a -> Prelude.FilePath -> Options -> TestTree
mkGoldTest fun n opts = do
let ref = goldDir n
new = testDir n
new = tmpDir n
act = compile fun n opts{outFileName = new}
cmp = simpleCmp $ printf "Files '%s.{c,h}' and '%s.{c,h}' differ" ref new
upd = LB.writeFile ref
Expand All @@ -567,7 +570,7 @@ mkGoldTest fun n opts = do
mkGoldTestUT :: UT.UntypedFeld ValueInfo -> Prelude.FilePath -> Options -> TestTree
mkGoldTestUT untyped n opts = do
let ref = goldDir n
new = testDir n
new = tmpDir n
act = compileUT untyped n opts{outFileName = new}
cmp = simpleCmp $ printf "Files '%s.{c,h}' and '%s.{c,h}' differ" ref new
upd = LB.writeFile ref
Expand All @@ -581,7 +584,7 @@ simpleCmp e x y =
mkParseTest :: Prelude.FilePath -> Options -> TestTree
mkParseTest n opts = do
let ref = goldDir n
new = testDir ("ep-" <> n)
new = tmpDir ("ep-" <> n)
act = compileFile ref opts{outFileName = new}
cmp = fuzzyCmp $ printf "Files '%s.{c,h}' and '%s.{c,h}' differ" ref new
upd = LB.writeFile ref
Expand All @@ -594,13 +597,13 @@ fuzzyCmp e x y =

-- | Removes "EP-"-related prefixes from the generated output.
filterEp :: LB.ByteString -> LB.ByteString
filterEp xs = LB.replace (B.pack "TESTS_EP-") (B.pack "TESTS_") xs'
filterEp xs = LB.replace (B.pack "TMP2_EP-") (B.pack "TMP2_") xs'
where xs' = LB.replace (B.pack "#include \"ep-") (B.pack "#include \"") xs

-- | Make a build test for a Feldspar expression
mkBuildTest :: Syntactic a => a -> Prelude.FilePath -> Options -> TestTree
mkBuildTest fun n opts = do
let new = testDir (n <> "_build_test")
let new = tmpDir (n <> "_build_test")
cfile = new <.> "c"
ofile = new <.> "o"
act = do compile fun n opts{outFileName = new}
Expand Down
6 changes: 3 additions & 3 deletions tests/gold/arrayInStruct.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_ARRAYINSTRUCT_H
#define TESTS_ARRAYINSTRUCT_H
#ifndef TMP2_ARRAYINSTRUCT_H
#define TMP2_ARRAYINSTRUCT_H

#include "feldspar_c99.h"

Expand All @@ -17,4 +17,4 @@ struct s_2_unsignedS32_awl_unsignedS32

void arrayInStruct(struct awl_unsignedS32 * v0, struct awl_unsignedS32 * out);

#endif // TESTS_ARRAYINSTRUCT_H
#endif // TMP2_ARRAYINSTRUCT_H
6 changes: 3 additions & 3 deletions tests/gold/arrayInStructInStruct.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_ARRAYINSTRUCTINSTRUCT_H
#define TESTS_ARRAYINSTRUCTINSTRUCT_H
#ifndef TMP2_ARRAYINSTRUCTINSTRUCT_H
#define TMP2_ARRAYINSTRUCTINSTRUCT_H

#include "feldspar_c99.h"

Expand All @@ -23,4 +23,4 @@ struct s_2_unsignedS32_s_2_unsignedS32_awl_unsignedS32

void arrayInStructInStruct(struct s_2_unsignedS32_s_2_unsignedS32_awl_unsignedS32 * v0, struct s_2_unsignedS32_s_2_unsignedS32_awl_unsignedS32 * out);

#endif // TESTS_ARRAYINSTRUCTINSTRUCT_H
#endif // TMP2_ARRAYINSTRUCTINSTRUCT_H
6 changes: 3 additions & 3 deletions tests/gold/arrayInStruct_openMP.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_ARRAYINSTRUCT_OPENMP_H
#define TESTS_ARRAYINSTRUCT_OPENMP_H
#ifndef TMP2_ARRAYINSTRUCT_OPENMP_H
#define TMP2_ARRAYINSTRUCT_OPENMP_H

#include "feldspar_c99.h"

Expand All @@ -17,4 +17,4 @@ struct s_2_unsignedS32_awl_unsignedS32

void arrayInStruct__openMP(struct awl_unsignedS32 * v0, struct awl_unsignedS32 * out);

#endif // TESTS_ARRAYINSTRUCT_OPENMP_H
#endif // TMP2_ARRAYINSTRUCT_OPENMP_H
6 changes: 3 additions & 3 deletions tests/gold/arrayInStruct_wool.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_ARRAYINSTRUCT_WOOL_H
#define TESTS_ARRAYINSTRUCT_WOOL_H
#ifndef TMP2_ARRAYINSTRUCT_WOOL_H
#define TMP2_ARRAYINSTRUCT_WOOL_H

#include "feldspar_c99.h"

Expand All @@ -17,4 +17,4 @@ struct s_2_unsignedS32_awl_unsignedS32

void arrayInStruct__wool(struct awl_unsignedS32 * v0, struct awl_unsignedS32 * out);

#endif // TESTS_ARRAYINSTRUCT_WOOL_H
#endif // TMP2_ARRAYINSTRUCT_WOOL_H
6 changes: 3 additions & 3 deletions tests/gold/complexWhileCond.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_COMPLEXWHILECOND_H
#define TESTS_COMPLEXWHILECOND_H
#ifndef TMP2_COMPLEXWHILECOND_H
#define TMP2_COMPLEXWHILECOND_H

#include "feldspar_c99.h"

Expand All @@ -11,4 +11,4 @@ struct s_2_signedS32_signedS32

void complexWhileCond(int32_t v0, struct s_2_signedS32_signedS32 * out);

#endif // TESTS_COMPLEXWHILECOND_H
#endif // TMP2_COMPLEXWHILECOND_H
6 changes: 3 additions & 3 deletions tests/gold/concatV.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_CONCATV_H
#define TESTS_CONCATV_H
#ifndef TMP2_CONCATV_H
#define TMP2_CONCATV_H

#include "feldspar_c99.h"

Expand All @@ -17,4 +17,4 @@ struct awl_awl_signedS32

void concatV(struct awl_awl_signedS32 * v1, struct awl_signedS32 * out);

#endif // TESTS_CONCATV_H
#endif // TMP2_CONCATV_H
6 changes: 3 additions & 3 deletions tests/gold/concatVM.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_CONCATVM_H
#define TESTS_CONCATVM_H
#ifndef TMP2_CONCATVM_H
#define TMP2_CONCATVM_H

#include "feldspar_c99.h"

Expand All @@ -17,4 +17,4 @@ struct awl_awl_signedS32

void concatVM(struct awl_awl_signedS32 * v1, struct awl_signedS32 * out);

#endif // TESTS_CONCATVM_H
#endif // TMP2_CONCATVM_H
6 changes: 3 additions & 3 deletions tests/gold/deepArrayCopy.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_DEEPARRAYCOPY_H
#define TESTS_DEEPARRAYCOPY_H
#ifndef TMP2_DEEPARRAYCOPY_H
#define TMP2_DEEPARRAYCOPY_H

#include "feldspar_c99.h"

Expand Down Expand Up @@ -49,4 +49,4 @@ void freeArray_awl_unsignedS32(struct awl_unsignedS32 * src, int32_t srcLen);

void deepArrayCopy(struct awl_awl_awl_unsignedS32 * v0, struct s_2_awl_awl_awl_unsignedS32_awl_awl_awl_unsignedS32 * out);

#endif // TESTS_DEEPARRAYCOPY_H
#endif // TMP2_DEEPARRAYCOPY_H
6 changes: 3 additions & 3 deletions tests/gold/divConq3.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_DIVCONQ3_H
#define TESTS_DIVCONQ3_H
#ifndef TMP2_DIVCONQ3_H
#define TMP2_DIVCONQ3_H

#include "feldspar_c99.h"

Expand All @@ -21,4 +21,4 @@ void task0(void * params);

void divConq3(struct awl_signedS32 * v1, struct awl_signedS32 * out);

#endif // TESTS_DIVCONQ3_H
#endif // TMP2_DIVCONQ3_H
6 changes: 3 additions & 3 deletions tests/gold/example9.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef TESTS_EXAMPLE9_H
#define TESTS_EXAMPLE9_H
#ifndef TMP2_EXAMPLE9_H
#define TMP2_EXAMPLE9_H

#include "feldspar_c99.h"

void example9(int32_t v0, int32_t * out);

#endif // TESTS_EXAMPLE9_H
#endif // TMP2_EXAMPLE9_H
6 changes: 3 additions & 3 deletions tests/gold/foreignEffect.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef TESTS_FOREIGNEFFECT_H
#define TESTS_FOREIGNEFFECT_H
#ifndef TMP2_FOREIGNEFFECT_H
#define TMP2_FOREIGNEFFECT_H

#include "feldspar_c99.h"

void foreignEffect(void * out);

#endif // TESTS_FOREIGNEFFECT_H
#endif // TMP2_FOREIGNEFFECT_H
6 changes: 3 additions & 3 deletions tests/gold/fut1.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_FUT1_H
#define TESTS_FUT1_H
#ifndef TMP2_FUT1_H
#define TMP2_FUT1_H

#include "feldspar_c99.h"

Expand All @@ -9,4 +9,4 @@ void task0(void * params);

void fut1(struct ivar v0, struct ivar * out);

#endif // TESTS_FUT1_H
#endif // TMP2_FUT1_H
6 changes: 3 additions & 3 deletions tests/gold/fut1_ret.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_FUT1_RET_H
#define TESTS_FUT1_RET_H
#ifndef TMP2_FUT1_RET_H
#define TMP2_FUT1_RET_H

#include "feldspar_c99.h"

Expand All @@ -9,4 +9,4 @@ void task0(void * params);

void fut1__ret(struct ivar v0, struct ivar * out);

#endif // TESTS_FUT1_RET_H
#endif // TMP2_FUT1_RET_H
6 changes: 3 additions & 3 deletions tests/gold/issue128_ex1.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef TESTS_ISSUE128_EX1_H
#define TESTS_ISSUE128_EX1_H
#ifndef TMP2_ISSUE128_EX1_H
#define TMP2_ISSUE128_EX1_H

#include "feldspar_c99.h"

void issue128__ex1(uint32_t v0, uint32_t * out);

#endif // TESTS_ISSUE128_EX1_H
#endif // TMP2_ISSUE128_EX1_H
6 changes: 3 additions & 3 deletions tests/gold/issue128_ex2.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef TESTS_ISSUE128_EX2_H
#define TESTS_ISSUE128_EX2_H
#ifndef TMP2_ISSUE128_EX2_H
#define TMP2_ISSUE128_EX2_H

#include "feldspar_c99.h"

void issue128__ex2(uint32_t v0, uint32_t * out);

#endif // TESTS_ISSUE128_EX2_H
#endif // TMP2_ISSUE128_EX2_H
6 changes: 3 additions & 3 deletions tests/gold/issue128_ex3.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef TESTS_ISSUE128_EX3_H
#define TESTS_ISSUE128_EX3_H
#ifndef TMP2_ISSUE128_EX3_H
#define TMP2_ISSUE128_EX3_H

#include "feldspar_c99.h"

void issue128__ex3(uint32_t v0, uint32_t * out);

#endif // TESTS_ISSUE128_EX3_H
#endif // TMP2_ISSUE128_EX3_H
6 changes: 3 additions & 3 deletions tests/gold/ivartest.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_IVARTEST_H
#define TESTS_IVARTEST_H
#ifndef TMP2_IVARTEST_H
#define TMP2_IVARTEST_H

#include "feldspar_c99.h"

Expand All @@ -9,4 +9,4 @@ void task0(void * params);

void ivartest(uint32_t v0, uint32_t * out);

#endif // TESTS_IVARTEST_H
#endif // TMP2_IVARTEST_H
6 changes: 3 additions & 3 deletions tests/gold/ivartest2.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_IVARTEST2_H
#define TESTS_IVARTEST2_H
#ifndef TMP2_IVARTEST2_H
#define TMP2_IVARTEST2_H

#include "feldspar_c99.h"

Expand All @@ -15,4 +15,4 @@ void task0(void * params);

void ivartest2(struct s_2_unsignedS32_unsignedS32 * v0, struct s_2_unsignedS32_unsignedS32 * out);

#endif // TESTS_IVARTEST2_H
#endif // TMP2_IVARTEST2_H
Loading

0 comments on commit 0d48b28

Please sign in to comment.