Skip to content

Commit

Permalink
cli support for alternate exec (#200)
Browse files Browse the repository at this point in the history
cli support for alternate exec

---------

Co-authored-by: housekeeping-bot <[email protected]>
  • Loading branch information
sha1n and housekeeping-bot authored Jun 1, 2023
1 parent 9c6b09f commit 6f4a936
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 11 deletions.
9 changes: 8 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
interval: weekly
open-pull-requests-limit: 10
assignees:
- sha1n
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
assignees:
- sha1n
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -39,7 +39,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -53,4 +53,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- [Report Formats](#report-formats)
- [Accumulating Data](#accumulating-data)
- [Labelling Data](#labelling-data)
- [Understanding User & System Time Measurements](#understanding-user--system-time-measurements)
- [Understanding User \& System Time Measurements](#understanding-user--system-time-measurements)
- [Examples](#examples)
- [Text Example](#text-example)
- [JSON Example](#json-example)
Expand Down Expand Up @@ -119,6 +119,9 @@ bert 'command -opt' --executions 100

# Multiple commands
bert 'command -optA' 'command -optB' 'anotherCommand' --executions 100

# Multiple commands with alternate execution
bert 'command -optA' 'command -optB' 'anotherCommand' --executions 100 --alternate
```

### Using a Configuration File
Expand Down
7 changes: 5 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- [Report Formats](#report-formats)
- [Accumulating Data](#accumulating-data)
- [Labelling Data](#labelling-data)
- [Understanding User & System Time Measurements](#understanding-user--system-time-measurements)
- [Understanding User \& System Time Measurements](#understanding-user--system-time-measurements)
- [Examples](#examples)
- [Text Example](#text-example)
- [JSON Example](#json-example)
Expand Down Expand Up @@ -119,12 +119,15 @@ bert 'command -opt' --executions 100

# Multiple commands
bert 'command -optA' 'command -optB' 'anotherCommand' --executions 100

# Multiple commands with alternate execution
bert 'command -optA' 'command -optB' 'anotherCommand' --executions 100 --alternate
```

### Using a Configuration File
In order to gain full control over benchmark configuration `bert` uses a configuration file. The configuration file can be either in YAML or JSON format. `bert` treats files with the `.json` extension as JSON, otherwise it assumes YAML. You may create a configuration file manually or use the `config` command to interactively generate your configuration.

**Why use a config files?**
**Why use a config file?**

- unlock advanced features such as alternate execution, custom environment variables, working directories and setup commands per scenario
- easily share elaborate benchmark configurations, store them in VCS and reuse them on different environments and over time
Expand Down
2 changes: 2 additions & 0 deletions internal/cli/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
ArgNameConfig = "config"
// ArgNameExecutions : program arg name
ArgNameExecutions = "executions"
// ArgNameAlternate : program arg name
ArgNameAlternate = "alternate"
// ArgNameOutputFile : program arg name
ArgNameOutputFile = "out-file"
// ArgNameConfigExample : program arg name
Expand Down
6 changes: 5 additions & 1 deletion internal/cli/main_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Build label: %s`, version, build),
rootCmd.Flags().IntP(ArgNameExecutions, "e", 0, `the number of executions per scenario.
required when no configuration file is provided.
when specified with a configuration file, this argument has priority.`)
rootCmd.Flags().BoolP(ArgNameAlternate, "a", false, `whether to use alternate executions or finish one scenario before commencing to the next one.`)

// Reporting
rootCmd.Flags().StringP(ArgNameOutputFile, "o", "", `output file path. Optional. Writes to stdout by default.`)
Expand Down Expand Up @@ -130,6 +131,7 @@ func runFn(ctx api.IOContext) func(*cobra.Command, []string) {

func loadSpec(cmd *cobra.Command, args []string) (spec api.BenchmarkSpec, err error) {
executions := GetInt(cmd, ArgNameExecutions)
alternate := GetBool(cmd, ArgNameAlternate)

if len(args) > 0 { // positional args are used for ad-hoc config
commands := []api.CommandSpec{}
Expand All @@ -138,7 +140,7 @@ func loadSpec(cmd *cobra.Command, args []string) (spec api.BenchmarkSpec, err er
Cmd: parseCommand(strings.Trim(args[i], "'\"")),
})
}
spec, err = specs.CreateSpecFrom(executions, false, commands...)
spec, err = specs.CreateSpecFrom(executions, alternate, commands...)

} else {
var filePath string
Expand All @@ -165,6 +167,8 @@ func loadSpec(cmd *cobra.Command, args []string) (spec api.BenchmarkSpec, err er
spec.Executions = executions
}

spec.Alternate = alternate

return spec, err
}

Expand Down
17 changes: 14 additions & 3 deletions internal/cli/main_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,22 @@ func Test_loadSpecWithExecutionsOverride(t *testing.T) {
assert.Equal(t, expectedSpec, spec)
}

func Test_loadSpecWithAlternateOverride(t *testing.T) {
expectedSpec, _ := specs.LoadSpec(itConfigFilePath)
expectedSpec.Alternate = true
command := newDummyCommandWith("-c", itConfigFilePath, "--alternate")

spec, err := loadSpec(command, []string{})

assert.NoError(t, err)
assert.Equal(t, expectedSpec, spec)
}

func Test_loadSpecFromPositionalArguments(t *testing.T) {
expectedExecutions := rand.Intn(100)
expectedValidSpec, _ := specs.CreateSpecFrom(
expectedExecutions,
false,
true,
api.CommandSpec{Cmd: []string{"cmd", "-a"}},
api.CommandSpec{Cmd: []string{"cmd", "-b"}},
api.CommandSpec{Cmd: []string{"cmd", "a string"}},
Expand All @@ -153,7 +164,7 @@ func Test_loadSpecFromPositionalArguments(t *testing.T) {
{
name: "call with positional single-quote framed commands",
args: args{
cmd: newDummyCommandWith("--executions", fmt.Sprint(expectedExecutions)),
cmd: newDummyCommandWith("--alternate", "--executions", fmt.Sprint(expectedExecutions)),
args: []string{"'cmd -a'", "'cmd -b'", "'cmd \"a string\"'"},
},
wantSpec: expectedValidSpec,
Expand All @@ -162,7 +173,7 @@ func Test_loadSpecFromPositionalArguments(t *testing.T) {
{
name: "call with positional double-quote framed commands",
args: args{
cmd: newDummyCommandWith("--executions", fmt.Sprint(expectedExecutions)),
cmd: newDummyCommandWith("--alternate", "--executions", fmt.Sprint(expectedExecutions)),
args: []string{"\"cmd -a\"", "\"cmd -b\"", "\"cmd 'a string'\""},
},
wantSpec: expectedValidSpec,
Expand Down
1 change: 1 addition & 0 deletions test/data/integration.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
executions: 1
alternate: false
scenarios:
- name: NAME
command:
Expand Down

0 comments on commit 6f4a936

Please sign in to comment.