diff --git a/Makefile b/Makefile index 057ae558a..271101756 100644 --- a/Makefile +++ b/Makefile @@ -349,7 +349,6 @@ rts: $(ARCHIVES) test: cd compiler && stack test $(MAKE) -C backend test - $(MAKE) -C test test-builtins: cd compiler && stack test --ta '-p "Builtins"' diff --git a/compiler/test.hs b/compiler/test.hs index 726584980..c4bdc6845 100644 --- a/compiler/test.hs +++ b/compiler/test.hs @@ -1,10 +1,10 @@ {-# LANGUAGE CPP #-} +import Control.Concurrent import Data.List import Data.List.Split import Data.Maybe import Data.Ord import Data.Time.Clock.POSIX - import System.Directory import System.Directory.Recursive import System.Exit @@ -51,6 +51,7 @@ main = do , regressionSegfaultTests , rtsAutoTests , rtsTests + , rtsDDBTests , stdlibAutoTests , stdlibTests ] @@ -140,6 +141,66 @@ rtsTests = (returnCode, cmdOut, cmdErr) <- runThing "--rts-wthreads" "../test/rts/argv7.act" assertEqual "RTS wthreads error retCode" (ExitFailure 1) returnCode assertEqual "RTS wthreads error cmdErr" "ERROR: --rts-wthreads requires an argument.\n" cmdErr + + , testCase "thread count" $ do + -- check the number of threads, which should be 10, consisting of 7 + -- worker threads (as specified on command line), IO+new IO & main + testBuild "" ExitSuccess False "../test/rts/wthreads1.act" + (pin, pout, perr, ph) <- runInteractiveProcess "../test/rts/wthreads1" ["--rts-wthreads=7"] Nothing Nothing + threadDelay 100000 + mpid <- getPid ph + case mpid of + Just pid -> do +#if defined(darwin_HOST_OS) + let cmd = "ps -M " ++ show pid ++ " | tail -n +2 | wc -l" +#else + let cmd = "ps -o thcount " ++ show pid +#endif + (returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ cmd) "" + let tCount = read (last $ lines cmdOut)::Int + assertEqual "RTS thread count" 10 tCount + Nothing -> do + assertFailure "whtreads1 program should be running" + terminateProcess ph + waitForProcess ph + return () + ] + +rtsDDBTests = + testGroup "RTS DDB" + [ + testCase "DDB: db app test" $ do + testBuild "" ExitSuccess False "../test/rts/ddb_test_app.act" + let cmd = "./test_db.py TestDbApps.test_app" + wd = "../test" + (returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ cmd){ cwd = Just wd } "" + iff (returnCode /= ExitSuccess) ( + putStrLn("\nERROR: when running test application\nSTDOUT: " ++ cmdOut ++ "\nSTDERR: " ++ cmdErr) + ) + assertEqual "DB client test success retCode" ExitSuccess returnCode + + , testCase "DDB: TCP server resume" $ do + testBuild "" ExitSuccess False "../test/rts/ddb_test_server.act" + let cmd = "./test_db.py TestDbApps.test_app_resume_tcp_server" + wd = "../test" + (returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ cmd){ cwd = Just wd } "" + iff (returnCode /= ExitSuccess) ( + putStrLn("\nERROR: when running test application\nSTDOUT: " ++ cmdOut ++ "\nSTDERR: " ++ cmdErr) + ) + assertEqual "DB client test success retCode" ExitSuccess returnCode + + , after AllFinish "TCP server resume" $ + testCase "DDB: TCP client resume" $ do + testBuild "" ExitSuccess False "../test/rts/ddb_test_server.act" + testBuild "" ExitSuccess False "../test/rts/ddb_test_client.act" + let cmd = "./test_db.py TestDbApps.test_app_resume_tcp_client" + wd = "../test" + (returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ cmd){ cwd = Just wd } "" + iff (returnCode /= ExitSuccess) ( + putStrLn("\nERROR: when running test application\nSTDOUT: " ++ cmdOut ++ "\nSTDERR: " ++ cmdErr) + ) + assertEqual "DB server test success retCode" ExitSuccess returnCode + ] stdlibTests = @@ -151,6 +212,8 @@ stdlibTests = ] + + -- Creates testgroup from .act files found in specified directory --createTests :: String -> String -> List -> TestTree createTests name dir allExpFail fails testFunc = do diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index 5199a2de3..000000000 --- a/test/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -MK_PATH:=$(shell dirname $(dir $(abspath $(lastword $(MAKEFILE_LIST))))) -ACTONC=$(MK_PATH)/dist/bin/actonc --cpedantic -DDB_SERVER=../dist/bin/actondb -TESTS= \ - $(DDB_TESTS) -test: - $(MAKE) $(TESTS) - - -ddb-tests: - $(MAKE) $(DDB_TESTS) - -DDB_TESTS=test_db_app test_db_app_no_quorum test_db_app_recovery test_db_app_resume_tcp_client test_db_app_resume_tcp_server -.PHONY: $(DDB_TESTS) - -# Starts up a database cluster, checks membership is ok before proceeding to run -# a simple app. We do not really verify that the RTS uses the database - we -# assume it does and would fail catastrohpically if it encounters an error. -test_db_app: - $(ACTONC) --root main test_db_app.act - ./test_db.py TestDbApps.test_app - -test_db_app_no_quorum: - @echo "Skipping because this is essentially broken" - #$(ACTONC) --root main test_db_app.act - #./test_db.py TestDbAppsNoQuorum - -test_db_app_resume_tcp_server: - $(ACTONC) --root main --dev rts/ddb_test_server.act - ./test_db.py TestDbApps.test_app_resume_tcp_server - -test_db_app_resume_tcp_client: - $(ACTONC) --root main --dev rts/ddb_test_server.act - $(ACTONC) --root main --dev rts/ddb_test_client.act - ./test_db.py TestDbApps.test_app_resume_tcp_client - - -# Expect 9 threads given 7 workers + main process + IO -rts/wthreads1: - $(ACTONC) --root main $@.act - ./$@ --rts-wthreads 7 & PID=$$! && ps -o thcount $${PID} | tail -n1 | awk '{ print $$1 }' | grep "^9$$" diff --git a/test/test_db_app.act b/test/rts/ddb_test_app.act similarity index 91% rename from test/test_db_app.act rename to test/rts/ddb_test_app.act index 697963d9e..806101184 100644 --- a/test/test_db_app.act +++ b/test/rts/ddb_test_app.act @@ -1,7 +1,7 @@ # Basic test case of the Acton RTS together with the database backend. We want # to focus on things that lead to database interaction, so in essence calling -# actor methods / sending methods and execution of continuations. We also want -# to test the timer queue. +# actor methods / sending methods and execution of continuations, including +# using an "after" statement to test the timer queue. # # main -> Foo."init" -> timerQ after 0 -> Foo.callback() -> main.final() -> exit diff --git a/test/test_db.py b/test/test_db.py index 38c8d75df..fa3bfa9d4 100755 --- a/test/test_db.py +++ b/test/test_db.py @@ -379,7 +379,7 @@ def tearDown(self): def test_app(self): - cmd = ["./test_db_app", "--rts-verbose", + cmd = ["./rts/ddb_test_app", "--rts-verbose", "--rts-ddb-replication", str(self.replication_factor) ] + get_db_args(self.dbc.port_chunk, self.replication_factor) self.p = subprocess.run(cmd, capture_output=True, timeout=3)