Skip to content

Commit

Permalink
cmd/gomote: fix up printed test commands
Browse files Browse the repository at this point in the history
Make the test commands easier to just use directly:
- Fix std packages having the wrong directory.
- Add GOMOTE_GROUP prefix if the instances were created in a group.
- Add the instance name (just the first) to the command if not created
  in a group.

Change-Id: I1dffde676a51e69100a1ea8a902c4a67cbde6fce
Reviewed-on: https://go-review.googlesource.com/c/build/+/614161
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
mknyszek authored and gopherbot committed Sep 19, 2024
1 parent a9d3b3b commit 509ea4f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
14 changes: 7 additions & 7 deletions cmd/gomote/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func create(args []string) error {
fs.Usage()
}
builderType := fs.Arg(0)
_, err := createInstances(context.Background(), builderType, &cfg)
_, _, err := createInstances(context.Background(), builderType, &cfg)
return err
}

Expand All @@ -159,20 +159,20 @@ type createConfig struct {
useGolangbuild bool
}

func createInstances(ctx context.Context, builderType string, cfg *createConfig) ([]string, error) {
func createInstances(ctx context.Context, builderType string, cfg *createConfig) ([]string, *groupData, error) {
var groupMu sync.Mutex
group := activeGroup
var err error
if cfg.newGroup != "" {
group, err = doCreateGroup(cfg.newGroup)
if err != nil {
return nil, err
return nil, nil, err
}
}
if group == nil && os.Getenv("GOMOTE_GROUP") != "" {
group, err = doCreateGroup(os.Getenv("GOMOTE_GROUP"))
if err != nil {
return nil, err
return nil, nil, err
}
}

Expand Down Expand Up @@ -275,12 +275,12 @@ func createInstances(ctx context.Context, builderType string, cfg *createConfig)
})
}
if err := eg.Wait(); err != nil {
return nil, err
return nil, nil, err
}
if group != nil {
if err := storeGroup(group); err != nil {
return nil, err
return nil, nil, err
}
}
return instances, nil
return instances, group, nil
}
23 changes: 16 additions & 7 deletions cmd/gomote/repro.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ func repro(args []string) error {
log.Printf("Selected build %d to initialize the gomote.", gomoteReproID)

log.Printf("Creating %d instance(s) of type %s...", cfg.count, gomoteBuilderType)
instances, err := createInstances(ctx, gomoteBuilderType, &cfg)
instances, group, err := createInstances(ctx, gomoteBuilderType, &cfg)
if err != nil {
return err
}
log.Printf("Initializing %d instance(s) with environment of %d...", len(instances), gomoteReproID)
if err := initReproInstances(ctx, instances, gomoteReproID); err != nil {
return err
}
return printTestCommands(ctx, hc, build)
return printTestCommands(ctx, hc, build, instances, group)
}

func initReproInstances(ctx context.Context, instances []string, reproBuildID int64) error {
Expand Down Expand Up @@ -205,7 +205,7 @@ func initReproInstances(ctx context.Context, instances []string, reproBuildID in
return eg.Wait()
}

func printTestCommands(ctx context.Context, hc *http.Client, build *bbpb.Build) error {
func printTestCommands(ctx context.Context, hc *http.Client, build *bbpb.Build, instances []string, group *groupData) error {
// Figure out what project this build is for.
props := build.Input.Properties.AsMap()
projValue, ok := props["project"]
Expand Down Expand Up @@ -279,24 +279,33 @@ func printTestCommands(ctx context.Context, hc *http.Client, build *bbpb.Build)
if strings.HasPrefix(rest, project) {
t.path = "./x_" + rest
} else {
// We are almsot definitely unable to run this test -- something went very wrong.
// We are almost definitely unable to run this test -- something went very wrong.
unknownTests = append(unknownTests, result.TestId)
}
} else {
// Assume it's a std test.
t.path = "goroot/src/" + t.pkg
}
if bench {
benchmarks = append(benchmarks, t)
} else {
tests = append(tests, t)
}
}
prefix := ""
instName := " " + instances[0]
if group != nil {
prefix = "GOMOTE_GROUP=" + group.Name + " "
instName = ""
}
for _, t := range tests {
log.Printf("$ gomote run -dir %s goroot/bin/go test -run='%s' .", t.pkgPath(), t.regexp())
log.Printf("$ %sgomote run%s -dir %s goroot/bin/go test -run='%s' .", prefix, instName, t.pkgPath(), t.regexp())
}
for _, t := range benchmarks {
log.Printf("$ gomote run -dir %s goroot/bin/go test -run='^$' -bench='%s' .", t.pkgPath(), t.regexp())
log.Printf("$ %sgomote run%s -dir %s goroot/bin/go test -run='^$' -bench='%s' .", prefix, instName, t.pkgPath(), t.regexp())
}
for _, pkg := range specialPackages {
log.Printf("$ gomote run -dir ./goroot goroot/bin/go tool dist test %s", pkg)
log.Printf("$ %sgomote run%s -dir ./goroot goroot/bin/go tool dist test %s", prefix, instName, pkg)
}
for _, pkg := range packageFailures {
log.Printf("Note: Found package-level test failure for %s.", pkg)
Expand Down

0 comments on commit 509ea4f

Please sign in to comment.