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

make the tests buildable and runnable with cabal and run said testsuites in CI #6

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions
name: CI
on: [push, pull_request]
on: [push]

jobs:
ci:
Expand All @@ -26,6 +26,8 @@ jobs:
with:
path: /usr/local/
key: ${{ runner.os }}-${{ steps.get-tag.outputs.tag }}
restore-keys: |
${{ runner.os }}-${{ steps.get-tag.outputs.tag }}
- name: Install folly, fizz, wangle, rsocket-cpp, fbthrift
if: steps.cache-fb-packages.outputs.cache-hit != 'true'
run: ./install_deps.sh
Expand All @@ -36,13 +38,12 @@ jobs:
- name: Generate C++ code from thrift files
run: make thrift-cpp
- name: Build everything up to thrift-compiler
run: cabal build exe:thrift-compiler
run: cabal build --project-file=ci.cabal.project exe:thrift-compiler
- name: Generate Haskell code from thrift files
run: make thrift-hs
- name: Build all packages
run: cabal build all
# - name: Build all packages and their testsuites
# run: cabal build --enable-tests all
# - name: Run testsuites
# shell: bash {0}
# run: ./run_tests.sh
run: cabal build --project-file=ci.cabal.project all
- name: Run testsuites
run: cabal test --project-file=ci.cabal.project mangle fb-util thrift-compiler thrift-lib thrift-server --keep-going
# --keep-going is necessary to avoid stopping at the first failing
# testsuite('s package?)
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ util::

thrift:: thrift-cpp thrift-hs

THRIFT_COMPILE = $(CABAL) new-run exe:thrift-compiler --
THRIFT_COMPILE = $(CABAL) run exe:thrift-compiler --

thrift-hs::
$(THRIFT_COMPILE) --hs \
Expand All @@ -25,13 +25,15 @@ thrift-hs::
$(THRIFT_COMPILE) --hs \
lib/if/ApplicationException.thrift \
-o lib
$(THRIFT_COMPILE) --hs \
$(THRIFT_COMPILE) --hs --use-int \
lib/test/if/math.thrift \
-o lib/test
$(THRIFT_COMPILE) --hs \
$(THRIFT_COMPILE) --hs --use-int \
lib/test/if/echoer.thrift \
-o lib/test

$(THRIFT_COMPILE) --hs \
server/test/if/hash_map.thrift \
-o server/test

thrift-cpp::
cd lib && thrift1 -I . --gen mstch_cpp2 \
Expand Down
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ packages:
server/thrift-server.cabal
compiler/thrift-compiler.cabal
util/thrift-util.cabal

tests: true
17 changes: 17 additions & 0 deletions ci.cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
packages:
common/util/fb-util.cabal
common/mangle/mangle.cabal
lib/thrift-lib.cabal
server/thrift-server.cabal
compiler/thrift-compiler.cabal
util/thrift-util.cabal

tests: true

-- IPV6 is disabled in the Github Actions environment,
-- so we make sure the appropriate tests in those packages
-- turn to IPV4.
package thrift-lib
flags: +tests_use_ipv4
package thrift-server
flags: +tests_use_ipv4
3 changes: 2 additions & 1 deletion common/mangle/mangle.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ test-suite mangle-test
default-language: Haskell2010
default-extensions: LambdaCase
main-is: Test.hs
other-modules: TestRunner
build-depends: base, HUnit, hspec, hspec-contrib, mangle
ghc-options: -threaded
ghc-options: -threaded -main-is Test
198 changes: 149 additions & 49 deletions common/util/fb-util.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ library
cpp/HsStruct.cpp
cpp/IOBuf.cpp
cpp/EventBaseDataplane.cpp
-- Util/GFlags.cpp

-- necessary because of the use of 'is_trivially_destructible_v' and friends?
cxx-options: -std=c++17
Expand Down Expand Up @@ -190,60 +191,18 @@ library
pkgconfig-depends: libfolly, libglog
extra-libraries: double-conversion, gflags

test-suite fb-util-tests
import: fb-haskell
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: Main.hs
common test-common
extra-libraries: stdc++
cxx-options: -std=c++17
ghc-options: -threaded
other-modules:
Facebook.Init
SpecRunner
TestRunner

-- async
StreamTest

-- datastruct
MovingAverageRateLimiterTest
RateLimiterMapTest

-- util
IOBufTest
AllocLimitTest
UnitTests
RWVarTest
THTest
FilePathTest
OptParseTest
LensTest
ToExpTest
LogTest
-- GFlagsTest
AesonTest
EncodingLib
BufferTest
ExceptionTest
ControlExceptionTest
JSONPrettyTest
IOTest
TimeSecTest
ListTest
EncodingTest
LogTest.OverloadedStrings
LogTest.Explicit
LogTest.MonadStack
ConcurrentTest
MD5Test
Control.MonadTest
StringQuasiTest

hs-source-dirs: tests, tests/github
other-modules: SpecRunner, TestRunner, Facebook.Init
build-depends: base,
aeson,
async,
binary,
bytestring,
containers,
directory,
fb-util,
filepath,
Expand All @@ -267,5 +226,146 @@ test-suite fb-util-tests
vector,
vector-fftw

c-sources: tests/IOBufTest.cpp
tests/GFlagsTest.cpp
test-suite stream
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: StreamTest.hs
ghc-options: -main-is StreamTest
test-suite movavgrl
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: MovingAverageRateLimiterTest.hs
ghc-options: -main-is MovingAverageRateLimiterTest
test-suite rlmap
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: RateLimiterMapTest.hs
ghc-options: -main-is RateLimiterMapTest
test-suite iobuf
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: IOBufTest.hs
ghc-options: -main-is IOBufTest
cxx-sources: tests/IOBufTest.cpp
test-suite alloc-limit
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: AllocLimitTest.hs
ghc-options: -main-is AllocLimitTest
test-suite unit-tests
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: UnitTests.hs
ghc-options: -main-is UnitTests
test-suite rwvar
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: RWVarTest.hs
ghc-options: -main-is RWVarTest
test-suite th
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: THTest.hs
ghc-options: -main-is THTest
test-suite filepath
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: FilePathTest.hs
ghc-options: -main-is FilePathTest
test-suite optparse
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: OptParseTest.hs
ghc-options: -main-is OptParseTest
test-suite lens
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: LensTest.hs
ghc-options: -main-is LensTest
test-suite toexp
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: ToExpTest.hs
ghc-options: -main-is ToExpTest
test-suite aeson
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: AesonTest.hs
ghc-options: -main-is AesonTest
test-suite buffer
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: BufferTest.hs
ghc-options: -main-is BufferTest
test-suite exception
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: ExceptionTest.hs
ghc-options: -main-is ExceptionTest
test-suite control-exception
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: ControlExceptionTest.hs
ghc-options: -main-is ControlExceptionTest
test-suite json-pretty
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: JSONPrettyTest.hs
ghc-options: -main-is JSONPrettyTest
test-suite io
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: IOTest.hs
ghc-options: -main-is IOTest
test-suite time-sec
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: TimeSecTest.hs
ghc-options: -main-is TimeSecTest
test-suite list
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: ListTest.hs
ghc-options: -main-is ListTest
test-suite concurrent
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: ConcurrentTest.hs
ghc-options: -main-is ConcurrentTest
test-suite md5
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: MD5Test.hs
ghc-options: -main-is MD5Test
test-suite control-monad
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: Control/MonadTest.hs
ghc-options: -main-is Control.MonadTest
test-suite string-quasi
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: StringQuasiTest.hs
ghc-options: -main-is StringQuasiTest
test-suite dynamic
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: DynamicTest.hs
cxx-sources: tests/DynamicHelper.cpp
cxx-options: -std=c++17
ghc-options: -main-is DynamicTest
test-suite hs-struct
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: HsStructTest.hs
cxx-sources: tests/HsStructHelper.cpp
cxx-options: -std=c++17
ghc-options: -main-is HsStructTest

-- TODO: commented out because of a linker problem
-- test-suite gflags
-- import: fb-haskell, test-common
-- type: exitcode-stdio-1.0
-- main-is: GFlagsTest.hs
-- ghc-options: -main-is GFlagsTest
-- cxx-sources: tests/GFlagsTest.cpp
4 changes: 2 additions & 2 deletions compiler/test/github/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ withFixtureOptions f = do
let fbcode = fst $ breakOnEnd "fbcode" dir
compilerDir <-
if null fbcode
then -- running from FB source tree
then -- running from github repo
findCompilerDir
else -- running from github repo
else -- running from FB source tree
return (fbcode </> "common" </> "hs" </> "thrift" </> "compiler")
let outPath = "compiler/test/fixtures"
thriftTestsDir = compilerDir </> ".." </> "tests"
Expand Down
9 changes: 4 additions & 5 deletions compiler/thrift-compiler.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,10 @@ executable thrift-compiler
test-suite thrift-compiler-tests
import: fb-haskell
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Main.hs
ghc-options: -threaded
other-modules: TestFixtures
TestRunner
hs-source-dirs: test, test/github
main-is: TestFixtures.hs
ghc-options: -threaded -main-is TestFixtures
other-modules: TestRunner
Util
build-depends: aeson-pretty,
base,
Expand Down
3 changes: 2 additions & 1 deletion lib/test/HeaderChannelTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Control.Monad.Trans.Class
import Data.Proxy
import Foreign
import Foreign.C
import Network (testServerHost)
import Test.HUnit
import TestRunner
import Util.EventBase
Expand All @@ -24,7 +25,7 @@ myRpcOptions = defaultRpcOptions { rpc_timeout = 5000 }

mySvcConf :: Int -> HeaderConfig Calculator
mySvcConf port = HeaderConfig
{ headerHost = "::1"
{ headerHost = testServerHost
, headerPort = port
, headerProtocolId = compactProtocolId
, headerConnTimeout = 5000
Expand Down
12 changes: 12 additions & 0 deletions lib/test/Network.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{-# LANGUAGE CPP #-}
module Network where

import Data.ByteString.Char8 (ByteString, pack)

testServerHost :: ByteString
testServerHost = pack
#ifdef IPV4
"127.0.0.1"
#else
"::1"
#endif
8 changes: 6 additions & 2 deletions lib/test/cpp/MathServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ class CalculatorServiceHandler : public CalculatorSvIf {
};

ScopedServerInterfaceThread* createServer(int64_t& /*port*/) {
return new ScopedServerInterfaceThread(
make_shared<CalculatorServiceHandler>());
return new ScopedServerInterfaceThread( make_shared<CalculatorServiceHandler>()
#ifdef IPV4
, "127.0.0.1" ); // necessary to force IPV4 in e.g CI/docker
#else
, "::1" );
#endif
}

extern "C" {
Expand Down
Loading