Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions pkg/cmd/roachtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Check --parallelism, --run-forever and --wait-before-next-execution flags`,
rootCmd.AddCommand(runOperationCmd)

var listOperationCmd = &cobra.Command{
Use: "list-operations",
Use: "list-operations [regex...]",
Short: "list all operation names",
Long: `List all available operations that can be run with the run-operation command.

Expand All @@ -245,12 +245,13 @@ This command lists the names of all registered operations.
Example:

roachtest list-operations
roachtest list-operations node-kill/.*m$
`,
RunE: func(cmd *cobra.Command, args []string) error {
r := makeTestRegistry()
operations.RegisterOperations(&r)

ops := r.AllOperations()
ops := r.FilteredOperations(registry.MergeRegEx(args))
for _, op := range ops {
fmt.Printf("%s\n", op.Name)
}
Expand Down Expand Up @@ -459,12 +460,7 @@ func opsToRun(r testRegistryImpl, filter string) ([]registry.OperationSpec, erro
if err != nil {
return nil, err
}
var filteredOps []registry.OperationSpec
for _, opSpec := range r.AllOperations() {
if regex.MatchString(opSpec.Name) {
filteredOps = append(filteredOps, opSpec)
}
}
filteredOps := r.FilteredOperations(regex)
if len(filteredOps) == 0 {
return nil, errors.New("no matching operations to run")
}
Expand Down
31 changes: 16 additions & 15 deletions pkg/cmd/roachtest/registry/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,8 @@ func OnlyBenchmarks() TestFilterOption {
// NewTestFilter initializes a new filter. The strings are interpreted as
// regular expressions (which are joined with |).
func NewTestFilter(regexps []string, options ...TestFilterOption) (*TestFilter, error) {
makeRE := func(strs []string) *regexp.Regexp {
switch len(strs) {
case 0:
return regexp.MustCompile(`.`)
case 1:
return regexp.MustCompile(strs[0])
default:
for i := range strs {
strs[i] = "(" + strs[i] + ")"
}
return regexp.MustCompile(strings.Join(strs, "|"))
}
}

tf := &TestFilter{
Name: makeRE(regexps),
Name: MergeRegEx(regexps),
}
for _, o := range options {
o(tf)
Expand All @@ -89,6 +75,21 @@ func NewTestFilter(regexps []string, options ...TestFilterOption) (*TestFilter,
return tf, nil
}

// MergeRegEx merges the given strings into a single regexp.
func MergeRegEx(strs []string) *regexp.Regexp {
switch len(strs) {
case 0:
return regexp.MustCompile(`.`)
case 1:
return regexp.MustCompile(strs[0])
default:
for i := range strs {
strs[i] = "(" + strs[i] + ")"
}
return regexp.MustCompile(strings.Join(strs, "|"))
}
}

// MatchFailReason describes the reason(s) a filter did not match the test.
type MatchFailReason struct {
// If true, the filter requires a benchmark and the test is not one.
Expand Down
11 changes: 11 additions & 0 deletions pkg/cmd/roachtest/test_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,14 @@ func (r testRegistryImpl) AllOperations() []registry.OperationSpec {
})
return ops
}

// FilteredOperations returns operations filtered by the given regex.
func (r testRegistryImpl) FilteredOperations(regex *regexp.Regexp) []registry.OperationSpec {
var filteredOps []registry.OperationSpec
for _, opSpec := range r.AllOperations() {
if regex.MatchString(opSpec.Name) {
filteredOps = append(filteredOps, opSpec)
}
}
return filteredOps
}
Loading