Skip to content

Commit af1fd21

Browse files
authored
kore-rpc-client: Add an --omit-details flag for run-tarball mode (#3961)
When running fall-back analysis, it is usually not interesting whether all response terms match exactly with the expectations. (For instance, one might change the definition and expect fewer fall-backs, but also cause slightly changed output) The new flag `--omit-details` for `kore-rpc-client run-tarball` only checks that the response _type_ matches (i.e., no unexpected errors have happened).
1 parent a7b2d28 commit af1fd21

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

booster/tools/rpc-client/RpcClient.hs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ import Text.Read (readMaybe)
5252

5353
import Booster.JsonRpc (rpcJsonConfig)
5454
import Booster.JsonRpc.Utils (
55+
DiffResult (DifferentType),
5556
KoreRpcJson (RpcRequest),
5657
decodeKoreRpc,
5758
diffJson,
5859
isIdentical,
5960
methodOfRpcCall,
6061
renderResult,
62+
rpcTypeOf,
6163
)
6264
import Booster.Prettyprinter (renderDefault)
6365
import Booster.Syntax.Json qualified as Syntax
@@ -85,8 +87,8 @@ handleRunOptions common@CommonOptions{dryRun} s = \case
8587
[] -> case s of
8688
Just sock -> shutdown sock ShutdownReceive
8789
Nothing -> pure ()
88-
(RunTarball tarFile keepGoing runOnly : xs) -> do
89-
runTarball common s tarFile keepGoing runOnly
90+
(RunTarball tarFile keepGoing runOnly noDetails : xs) -> do
91+
runTarball common s tarFile keepGoing runOnly (not noDetails)
9092
handleRunOptions common s xs
9193
(RunSingle mode optionFile options processingOptions : xs) -> do
9294
let ProcessingOptions{postProcessing, prettify, time} = processingOptions
@@ -246,7 +248,8 @@ data RunOptions
246248
RunTarball
247249
FilePath -- tar file
248250
Bool -- do not stop on first diff if set to true
249-
[Kore.JsonRpc.Types.APIMethod] -- only run specified types of requests. run all if empty
251+
[Kore.JsonRpc.Types.APIMethod] -- only run specified types of requests. Run all if empty.
252+
Bool -- omit detailed comparison with expected output
250253
deriving stock (Show)
251254

252255
data ProcessingOptions = ProcessingOptions
@@ -448,6 +451,10 @@ parseMode =
448451
( long "run-only"
449452
<> help "Only run the specified request(s), e.g. --run-only \"add-module implies\""
450453
)
454+
<*> switch
455+
( long "omit-details"
456+
<> help "only compare response types, not contents"
457+
)
451458
<**> helper
452459
)
453460
(progDesc "Run all requests and compare responses from a bug report tarball")
@@ -479,9 +486,15 @@ parseMode =
479486
-- Running all requests contained in the `rpc_*` directory of a tarball
480487

481488
runTarball ::
482-
CommonOptions -> Maybe Socket -> FilePath -> Bool -> [Kore.JsonRpc.Types.APIMethod] -> IO ()
483-
runTarball _ Nothing _ _ _ = pure ()
484-
runTarball common (Just sock) tarFile keepGoing runOnly = do
489+
CommonOptions ->
490+
Maybe Socket ->
491+
FilePath ->
492+
Bool ->
493+
[Kore.JsonRpc.Types.APIMethod] ->
494+
Bool ->
495+
IO ()
496+
runTarball _ Nothing _ _ _ _ = pure ()
497+
runTarball common (Just sock) tarFile keepGoing runOnly compareDetails = do
485498
-- unpack tar files, determining type from extension(s)
486499
let unpackTar
487500
| ".tar" == takeExtension tarFile = Tar.read
@@ -509,6 +522,7 @@ runTarball common (Just sock) tarFile keepGoing runOnly = do
509522
-- we should not rely on the requests being returned in a sorted order and
510523
-- should therefore sort them explicitly
511524
let requests = sort $ mapMaybe (stripSuffix "_request.json") jsonFiles
525+
successMsg = if compareDetails then "matches expected" else "has expected type"
512526
results <-
513527
forM requests $ \r -> do
514528
mbError <- runRequest skt tmp jsonFiles r
@@ -519,7 +533,7 @@ runTarball common (Just sock) tarFile keepGoing runOnly = do
519533
liftIO $
520534
shutdown skt ShutdownReceive >> exitWith (ExitFailure 2)
521535
Nothing ->
522-
logInfo_ $ "Response to " <> r <> " matched with expected"
536+
logInfo_ $ unwords ["Response to", r, successMsg]
523537
pure mbError
524538
liftIO $ shutdown skt ShutdownReceive
525539
liftIO $ exitWith (if all isNothing results then ExitSuccess else ExitFailure 2)
@@ -569,13 +583,22 @@ runTarball common (Just sock) tarFile keepGoing runOnly = do
569583
request <- liftIO . BS.readFile $ tmpDir </> basename <> "_request.json"
570584
expected <- liftIO . BS.readFile $ tmpDir </> basename <> "_response.json"
571585

586+
let showResult =
587+
renderResult "expected response" "actual response"
572588
makeRequest False basename (Just skt) request pure runOnly >>= \case
573589
Nothing -> pure Nothing -- should not be reachable
574-
Just actual -> do
575-
let diff = diffJson expected actual
576-
if isIdentical diff
577-
then pure Nothing
578-
else pure . Just $ renderResult "expected response" "actual response" diff
590+
Just actual
591+
| compareDetails -> do
592+
let diff = diffJson expected actual
593+
if isIdentical diff
594+
then pure Nothing
595+
else pure . Just $ showResult diff
596+
| otherwise -> do
597+
let expectedType = rpcTypeOf (decodeKoreRpc expected)
598+
actualType = rpcTypeOf (decodeKoreRpc actual)
599+
if expectedType == actualType
600+
then pure Nothing
601+
else pure . Just $ showResult (DifferentType expectedType actualType)
579602

580603
noServerError :: MonadLoggerIO m => CommonOptions -> IOException -> m ()
581604
noServerError common e@IOError{ioe_type = NoSuchThing} = do

scripts/booster-analysis.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export PLUGIN_DIR=$(nix build github:runtimeverification/blockchain-k-plugin/$PL
4646

4747
run_tarball(){
4848
echo "######## $1 ########";
49-
$SCRIPT_DIR/run-with-tarball.sh "$1" -l Aborts --log-format json --log-file "$LOG_DIR/$(basename "$1").json.log" --print-stats ${SERVER_OPTS} 2>&1 | tee "$LOG_DIR/$(basename "$1").out";
49+
$SCRIPT_DIR/run-with-tarball.sh "$1" -l Aborts --log-format json --log-file "$LOG_DIR/$(basename "$1").json.log" -l Timing ${SERVER_OPTS} 2>&1 | tee "$LOG_DIR/$(basename "$1").out";
5050
}
5151

5252
export -f run_tarball

scripts/run-with-tarball.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ server_port=$($LSOF -a -p${server_pid} -sTCP:LISTEN -iTCP | grep ${server_pid} |
135135
echo "Server listening on port ${server_port}"
136136

137137

138-
echo "Running requests from $tarball against the server: $client run-tarball '$tarball' --keep-going -p ${server_port} -h 127.0.0.1"
139-
$client run-tarball "$tarball" --keep-going -p ${server_port} -h 127.0.0.1
138+
echo "Running requests from $tarball against the server: $client run-tarball '$tarball' --keep-going --omit-details -p ${server_port} -h 127.0.0.1"
139+
$client run-tarball "$tarball" --keep-going --omit-details -p ${server_port} -h 127.0.0.1
140140

141141
echo "Done with '$tarball'"

0 commit comments

Comments
 (0)