From 9e497f09e5cf677f77952ea52b65a80e61d4dadb Mon Sep 17 00:00:00 2001 From: Mike Izbicki Date: Mon, 21 Sep 2015 16:37:44 -0700 Subject: [PATCH] updated test suite --- .gitmodules | 2 +- .travis.yml | 47 ++++++++++++ herbie-haskell.cabal => HerbiePlugin.cabal | 15 +++- test/{Test1.hs => Tests.hs} | 86 ++++++---------------- 4 files changed, 86 insertions(+), 64 deletions(-) create mode 100644 .travis.yml rename herbie-haskell.cabal => HerbiePlugin.cabal (88%) rename test/{Test1.hs => Tests.hs} (70%) diff --git a/.gitmodules b/.gitmodules index ddc9c18..96d55e7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "herbie"] path = herbie - url = ./herbie + url = https://github.com/uwplse/herbie diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c19c0ac --- /dev/null +++ b/.travis.yml @@ -0,0 +1,47 @@ +# NB: don't set `language: haskell` here + +# The following enables several GHC versions to be tested; often it's enough to test only against the last release in a major GHC version. Feel free to omit lines listings versions you don't need/want testing for. +env: + - CABALVER=1.22 GHCVER=7.10.1 RACKET_VERSION=6.1 + - CABALVER=1.22 GHCVER=7.10.2 RACKET_VERSION=6.1 + # - CABALVER=head GHCVER=head # see section about GHC HEAD snapshots + +# Note: the distinction between `before_install` and `install` is not important. +before_install: + + - travis_retry sudo add-apt-repository -y ppa:hvr/ghc + - travis_retry sudo apt-get update + - travis_retry sudo apt-get install cabal-install-$CABALVER ghc-$GHCVER # see note about happy/alex + - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH + - travis_retry sudo apt-get install libblas-dev liblapack-dev + + # install Racket + - git clone https://github.com/greghendershott/travis-racket.git + - cat travis-racket/install-racket.sh | bash # pipe to bash not sh! + +install: + + # install herbie-exec + - /usr/racket/bin/raco exe -o herbie-exec herbie/herbie/interface/inout.rkt + - sudo mv herbie-exec /usr/local/bin + + # install HerbiePlugin + - cabal --version + - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]" + - travis_retry cabal update + - travis_retry cabal install -j4 --only-dependencies --enable-tests --enable-benchmarks + +# Here starts the actual work to be performed for the package under test; any command which exits with a non-zero exit code causes the build to fail. +script: + - if [ -f configure.ac ]; then autoreconf -i; fi + - cabal configure --enable-tests --enable-benchmarks -v2 # -v2 provides useful information for debugging + - cabal build # this builds all libraries and executables (including tests/benchmarks) + - cabal test + - cabal check + - cabal sdist # tests that a source-distribution can be generated + +# Check that the resulting source distribution can be built & installed. +# If there are no other `.tar.gz` files in `dist`, this can be even simpler: +# `cabal install --force-reinstalls dist/*-*.tar.gz` + - SRC_TGZ=$(cabal info . | awk '{print $2;exit}').tar.gz && + (cd dist && cabal install --force-reinstalls "$SRC_TGZ") diff --git a/herbie-haskell.cabal b/HerbiePlugin.cabal similarity index 88% rename from herbie-haskell.cabal rename to HerbiePlugin.cabal index ba38d99..b515117 100644 --- a/herbie-haskell.cabal +++ b/HerbiePlugin.cabal @@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ -- The name of the package. -name: herbie-haskell +name: HerbiePlugin -- The package version. See the Haskell package versioning policy (PVP) -- for standards guiding when and how versions should be incremented. @@ -86,3 +86,16 @@ library -- Base language which the package is written in. default-language: Haskell2010 +Test-Suite Tests + default-language: Haskell2010 + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: Tests.hs + + ghc-options: + -fplugin=Herbie + -dcore-lint + + build-depends: + subhask, + HerbiePlugin diff --git a/test/Test1.hs b/test/Tests.hs similarity index 70% rename from test/Test1.hs rename to test/Tests.hs index 536edd3..84a1c39 100644 --- a/test/Test1.hs +++ b/test/Tests.hs @@ -1,9 +1,14 @@ {-# LANGUAGE GADTs,RebindableSyntax,CPP,FlexibleContexts,FlexibleInstances,ConstraintKinds #-} +{- + - The idea of this test suite is that it should be compiled + - with the -fplugin=Herbie and -dcore-lint flags. + - Then we check to make sure GHC didn't throw any errors during + - the core type checking process. + -} module Main where import SubHask -import qualified Prelude as P -------------------------------------------------------------------------------- @@ -87,8 +92,9 @@ bigenough3 a b c = f1(c) -------------------------------------------------------------------------------- -{- -example1 :: Float -> Float -> Float +-- This section contains lots of examples of expressions that the Herbie plugin can parse +-- and find improved versions. + example1 x1 x2 = sqrt (x1*x1 + x2*x2) example2 x = exp(log(x)+8) @@ -113,7 +119,7 @@ example11 x = sin(x)-x example12 x = 1-cos(x) --- example13 x1 x2 = sqrt((x1 - x2) * (x1 - x2)) +example13 x1 x2 = sqrt((x1 - x2) * (x1 - x2)) example14 x y z = sqrt(x*x + y*y + z*z) @@ -141,7 +147,7 @@ example25 a = sqrt(a^2-1) example26 a b c d = ((a*b)+(c*d))/(a+c) --- example27 x = sqrt(x^2) +example27 x = sqrt(x^2) example28 x y = sqrt(x) * y * y @@ -149,7 +155,7 @@ example29 x y z = sqrt(x*x+y*y+z*z) example30 x y = 1.75 * x * y*y + sqrt(x/y) --- example31 x = exp(3*log(x)+2) +example31 x = exp(3*log(x)+2) example32 x = exp(2*log(x)) @@ -169,8 +175,6 @@ example39 minval minstep val = (minval/minstep + val) * minstep example40 x = x*x*cos(x/2 - sqrt(x)) --- example41 x4 = sqrt(x4^5) - sqrt(2) - example41 x = sqrt(4+x^2+x) example42 x y z = x / sqrt(x*x + y*y + z*z) @@ -183,7 +187,7 @@ example45 x = (sin(x) - tan(x)) / x example46 x y = 1 / sqrt(x^2 - y^2) --- example47 x1 x2 = sqrt((x1 - x2)^2) +example47 x1 x2 = sqrt((x1 - x2)^2) example48 x = x - sin(x) @@ -193,7 +197,7 @@ example50 a b c = (a*a - c*c)/b example51 x y = sin(x+y)-cos(x+y) --- example52 x = (x + 1)^2 - 1 +example52 x = (x + 1)^2 - 1 example53 x = sqrt(1+x) - sqrt(x) @@ -214,36 +218,31 @@ example60 a b c = -b + sqrt(b*b-4*a*c)/(2*a) example61 a c an cn = log(exp(a)*an + exp(c)*cn) - log(an+cn) example62 x = sqrt(sin(x)) - sqrt(x) + example63 x = log(1+x) example64 a b = a * b / (1 - b + a * b) -example65 :: Logic Float ~ Bool => Float -> Float -> Float example65 a b = b*sqrt(a * a + 1.0) -example65' :: Real a => a -> a example65' a = sqrt(a * a + 1.0) -example66 :: Float -> Float -> Float example66 x y = x * y * x*pi/y example67 x = sqrt(x + 1) - sqrt(x - 1) --- example68 x = cos(x + 1) * x^2 -example69 :: RealOrd a => a -> a -> a +example68 x = cos(x + 1) * x^2 + example69 a b = b*(a/b - log(1 + a/b)) -example70 :: RealOrd a => a -> a -> a example70 a b = b*(a/b - 1 - log(a/b)) --- example71 x = (6/(x^99))*(x^101) +example71 x = (6/(x^99))*(x^101) +example72 x = (1/(x^99))*(x^101) --- example72 x = (1/(x^99))*(x^101) +example73 x = (1/(x^100))*(x^100) --- example73 x = (1/(x^100))*(x^100) - -example74 :: RealOrd a => a -> a -> a -> a example74 x y z = cos(sqrt(x*x+y*y+z*z)) example75 x = sqrt(sqrt(x*x+1)+1) @@ -254,66 +253,29 @@ example77 a k = -a - sqrt(a*a-k) example78 a b x = x*x*a+x*(a+b) +x*b --- example79 x = (x + x) ^ 3 / x +example79 x = (x + x) ^ 3 / x example80 x = sqrt(x+1)-sqrt 1 -example81 :: Real a => a -> a example81 x = (x+1)-x example82 x = sqrt(x+100)-sqrt(x) example83 x = 1-cos(x) -example84 :: Real a => a -> a -> a example84 u v = sqrt(sqrt(u^2 + v^2) - u) -example85 :: Real a => a -> a example85 x = exp(log(x)) -example86 :: Real a => a -> a example86 x = sqrt(x + 1) - sqrt x + sin(x - 1) --- example87 :: (Floating a, Real a, Ord a) => a -> a --- -- example87 :: Float -> Float -example87 :: Real a => a -> a example87 x = exp x / sqrt(exp x - 1) * sqrt x -example88 :: Real a => a -> a example88 x = (exp(x) - 1) / x -example89 :: Real a => a -> a example89 x = sqrt(x + 2) - sqrt(x) --} -------------------------------------------------------------------------------- --- main - - -main = do --- P.putStrLn $ show $ test (5::Float) (2::Float) --- P.putStrLn $ show $ test (4::Float) (4::Float) --- P.putStrLn $ show $ test (3::Float) (6::Float) - --- P.putStrLn $ show $ example84 (5::Float) (5::Float) --- P.putStrLn $ show $ example85 (5::Float) --- P.putStrLn $ show $ example86 (5::Float) --- P.putStrLn $ show $ example87 (5::Float) --- P.putStrLn $ show $ example88 (5::Float) --- P.putStrLn $ show $ example89 (5::Float) - --- P.putStrLn $ "example1="++show (example1 2 3::Float) --- P.putStrLn $ "example1="++show (example1 3 2::Float) --- P.putStrLn $ "example1="++show (example1 4 1::Float) - --- P.putStrLn $ "types_Int ="++show (types_Int 5) --- P.putStrLn $ "types_Float="++show (types_Float 5) --- P.putStrLn $ "test1="++show (test1 (5::Float)) --- P.putStrLn $ "test1="++show (test1 (5::Double)) --- P.putStrLn $ "test2="++show (test2 (5::Float)) --- P.putStrLn $ "test3="++show (test3 5) --- P.putStrLn $ "test5="++test5 "str" (5::Float) --- P.putStrLn $ "test5="++test5 "str" (5::Double) --- P.putStrLn $ "test6="++test6 (5::Float) "str" --- P.putStrLn $ "test6="++test6 (5::Double) "str" - P.putStrLn "done" + +-- The main function does nothing +main = return ()