Commit 87081c28 authored by Valentin Reis's avatar Valentin Reis

Added a 'perfwrapper test' that runs the hello world command through

a perf-wrapper enabled container.
parent 00212f73
Pipeline #4714 passed with stage
in 29 seconds
......@@ -11,19 +11,21 @@ import System.IO ( withFile )
import Debug.Trace
import Filesystem.Path ( (</>) )
import Control.Concurrent.Async
import System.Console.ANSI
import System.Console.ANSI
import System.Console.ANSI.Types ( Color )
import Data.Text as Text
hiding ( empty )
import Data.Text.IO as Text
import Argo.Utils
import System.Process as P hiding (shell)
import System.Process as P
hiding ( shell )
data StackArgs = StackArgs
{ dargs :: [Text] --"Daemon arguments. Properly quote this."
, app :: Text --"Target application call, sh+path valid"
, workingDirectory :: FilePath --"Working directory."
, manifest :: FilePath --"Input file, manifest."
, manifestDir :: FilePath --"Manifest lookup directory"
, manifestName :: FilePath --"Manifest file name"
, cmd_out :: FilePath --"Output file, application stdout"
, cmd_err :: FilePath --"Output file, application stderr"
, daemon_out :: FilePath --"Output file, daemon stdout"
......@@ -35,8 +37,9 @@ instance Default StackArgs where
def = StackArgs
{ dargs = []
, app = "echo \"HelloWorld\""
, workingDirectory = "./."
, manifest = "basic.json"
, workingDirectory = "_output"
, manifestDir = "manifests"
, manifestName = "basic.json"
, cmd_out = "cmd_out.log"
, cmd_err = "cmd_err.log"
, daemon_out = "daemon_out.log"
......@@ -45,10 +48,6 @@ instance Default StackArgs where
, time_file = "time.log"
}
-- | override the output directory of the stack.
outputDir :: FilePath -> StackArgs -> StackArgs
outputDir dir sa = sa { workingDirectory = dir }
cleanLeftovers
:: FilePath
-> FilePath
......@@ -69,6 +68,7 @@ cleanLeftovers wd daemon_out daemon_err cmd_out cmd_err time_file nrm_log = do
, wd </> time_file
, wd </> nrm_log
, wd </> ".argo_nodeos_config_exit_message"
, wd </> "argo_nodeos_config"
]
mapM_ cleanSocket ["/tmp/nrm-downstream-in", "/tmp/nrm-upstream-in"]
......@@ -123,7 +123,7 @@ prepareDaemonShell wd dargs daemon_out daemon_err nrm_log = do
-- | See at the bottom of this file for discussion of this function. (1)
cmdShell :: FilePath -> Text -> FilePath -> FilePath -> Shell ()
cmdShell manifest app cmd_out cmd_err = do
cmdShell manifest app cmd_out cmd_err =
shell
(format ("cmd run -u toto " % fp % " " % s % " > " % fp % " 2>" % fp)
manifest
......@@ -167,11 +167,14 @@ runSimpleStack a@StackArgs {..} = sh $ do
nrm_log
liftIO $ withAsync daemonShell $ \daemon -> do
kbInstallHandler $ cancel daemon
withAsync (time $ sh $ cmdShell manifest app cmd_out cmd_err) $ \cmd -> do
kbInstallHandler $ cancel daemon >> cancel cmd
waitEitherCancel daemon cmd >>= \case
Left _ -> die "Daemon died."
Right (_, t) -> writeTextFile time_file (repr t)
withAsync
(time $ sh $ cmdShell (manifestDir </> manifestName) app cmd_out cmd_err
)
$ \cmd -> do
kbInstallHandler $ cancel daemon >> cancel cmd
waitEitherCancel daemon cmd >>= \case
Left _ -> die "Daemon died."
Right (_, t) -> writeTextFile time_file (repr t)
-- | (1)
--
......
......@@ -17,14 +17,6 @@ import Options.Applicative
import System.Posix.Signals
import Control.Monad
wdOption = strOption
( long "working_directory"
<> short 'w'
<> metavar "DIRECTORY"
<> help "Working directory. Will be used for logging."
<> value "./."
)
opts :: StackArgs -> Parser (IO ())
opts sa = hsubparser
( command "clean"
......@@ -32,7 +24,7 @@ opts sa = hsubparser
<> command
"daemon"
(info
(runDaemon sa <$> wdOption)
(pure $ runDaemon sa)
(progDesc
"Set up and launch the daemon in synchronous mode, \
\with properly cleaned sockets, logfiles."
......@@ -41,7 +33,7 @@ opts sa = hsubparser
<> command
"application"
(info
(runApp sa <$> wdOption <*> strArgument
(runApp sa <$> strArgument
( metavar "COMMAND"
<> help "Application to run inside the container"
)
......@@ -53,23 +45,30 @@ opts sa = hsubparser
(info
(pure $ runHelloWorld sa)
(progDesc
"Test 1: Setup stack and check that hello world app sends \
"Test 1: Setup stack and check that a hello world app sends \
\message back to cmd."
)
)
<> command
"perfwrapper"
(info
(pure $ runHelloWorld (sa { manifestName = "perfwrap.json" }))
(progDesc
"Test 2: Setup stack and check that a hello world app sends \
\message back to cmd. Uses argo-perf-wrapper."
)
)
<> help "Type of action to run"
)
main :: IO ()
main = do
manifests <- getEnv "MANIFESTS"
let sa = (outputDir "_output" def)
{ manifest = decodeString manifests </> manifest def
}
let sa = def { manifestDir = decodeString manifests }
join $ execParser (info (opts sa <**> helper) idm)
runApp :: StackArgs -> FilePath -> Text -> IO ()
runApp sa wd app = runSimpleStack $ outputDir wd (sa { app = app })
runApp :: StackArgs -> Text -> IO ()
runApp sa myApp = runSimpleStack $ sa { app = myApp }
runHelloWorld :: StackArgs -> IO ()
runHelloWorld a@StackArgs {..} = do
......@@ -92,8 +91,8 @@ runClean StackArgs {..} = sh $ cleanLeftovers workingDirectory
time_file
nrm_log
runDaemon :: StackArgs -> FilePath -> IO ()
runDaemon StackArgs {..} workingDir =
runDaemon :: StackArgs -> IO ()
runDaemon StackArgs {..} =
sh
$ prepareDaemonShell workingDir dargs daemon_out daemon_err nrm_log
$ prepareDaemonShell workingDirectory dargs daemon_out daemon_err nrm_log
>>= liftIO
......@@ -58,7 +58,7 @@ in rec
argotk = pkgs.stdenv.mkDerivation rec {
name = "env";
env = pkgs.buildEnv { name = name; paths = buildInputs ++ propagatedBuildInputs; };
src = ./argotk;
src = filterHdevTools ./argotk;
installPhase =''
mkdir -p $out/bin
mkdir -p $out/share
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment