Commit 788b2708 authored by Inphi's avatar Inphi Committed by GitHub

cannon: Detect input/output codec mismatch before trace execution (#12676)

* cannon: Check --input and --output file formats in CLI

* cannon: Allow only binary state outputs in run cli

* golang lint
parent 0cb0cd6f
...@@ -29,16 +29,16 @@ import ( ...@@ -29,16 +29,16 @@ import (
var ( var (
RunInputFlag = &cli.PathFlag{ RunInputFlag = &cli.PathFlag{
Name: "input", Name: "input",
Usage: "path of input JSON state. Stdin if left empty.", Usage: "path of input binary state. Stdin if left empty.",
TakesFile: true, TakesFile: true,
Value: "state.json", Value: "state.bin.gz",
Required: true, Required: true,
} }
RunOutputFlag = &cli.PathFlag{ RunOutputFlag = &cli.PathFlag{
Name: "output", Name: "output",
Usage: "path of output JSON state. Not written if empty, use - to write to Stdout.", Usage: "path of output binary state. Not written if empty, use - to write to Stdout.",
TakesFile: true, TakesFile: true,
Value: "out.json", Value: "out.bin.gz",
Required: false, Required: false,
} }
patternHelp = "'never' (default), 'always', '=123' at exactly step 123, '%123' for every 123 steps" patternHelp = "'never' (default), 'always', '=123' at exactly step 123, '%123' for every 123 steps"
...@@ -63,7 +63,7 @@ var ( ...@@ -63,7 +63,7 @@ var (
RunSnapshotFmtFlag = &cli.StringFlag{ RunSnapshotFmtFlag = &cli.StringFlag{
Name: "snapshot-fmt", Name: "snapshot-fmt",
Usage: "format for snapshot output file names.", Usage: "format for snapshot output file names.",
Value: "state-%d.json", Value: "state-%d.bin.gz",
Required: false, Required: false,
} }
RunStopAtFlag = &cli.GenericFlag{ RunStopAtFlag = &cli.GenericFlag{
...@@ -279,6 +279,9 @@ func Run(ctx *cli.Context) error { ...@@ -279,6 +279,9 @@ func Run(ctx *cli.Context) error {
if ctx.Bool(RunPProfCPU.Name) { if ctx.Bool(RunPProfCPU.Name) {
defer profile.Start(profile.NoShutdownHook, profile.ProfilePath("."), profile.CPUProfile).Stop() defer profile.Start(profile.NoShutdownHook, profile.ProfilePath("."), profile.CPUProfile).Stop()
} }
if err := checkFlags(ctx); err != nil {
return err
}
guestLogger := Logger(os.Stderr, log.LevelInfo) guestLogger := Logger(os.Stderr, log.LevelInfo)
outLog := &mipsevm.LoggingWriter{Log: guestLogger.With("module", "guest", "stream", "stdout")} outLog := &mipsevm.LoggingWriter{Log: guestLogger.With("module", "guest", "stream", "stdout")}
...@@ -524,3 +527,17 @@ func CreateRunCommand(action cli.ActionFunc) *cli.Command { ...@@ -524,3 +527,17 @@ func CreateRunCommand(action cli.ActionFunc) *cli.Command {
} }
var RunCommand = CreateRunCommand(Run) var RunCommand = CreateRunCommand(Run)
func checkFlags(ctx *cli.Context) error {
if output := ctx.Path(RunOutputFlag.Name); output != "" {
if !serialize.IsBinaryFile(output) {
return errors.New("invalid --output file format. Only binary file formats (ending in .bin or bin.gz) are supported")
}
}
if snapshotFmt := ctx.String(RunSnapshotFmtFlag.Name); snapshotFmt != "" {
if !serialize.IsBinaryFile(fmt.Sprintf(snapshotFmt, 0)) {
return errors.New("invalid --snapshot-fmt file format. Only binary file formats (ending in .bin or bin.gz) are supported")
}
}
return nil
}
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