cmd/bench: benchmark baseline toolchain

If BENCH_BASELINE_GOROOT is set, additionally benchmark that toolchain.
The benchfmt label 'toolchain' differentiates the 'experiment' and
'baseline' toolchains.

For golang/go#49207.

Change-Id: I737fa56786dc482172942462c5776c4c2773c0c5
Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/376096
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
diff --git a/cmd/bench/main.go b/cmd/bench/main.go
index 3699331..67d0d8b 100644
--- a/cmd/bench/main.go
+++ b/cmd/bench/main.go
@@ -4,9 +4,13 @@
 
 // Binary bench provides a unified wrapper around the different types of
 // benchmarks in x/benchmarks.
+//
+// Benchmarks are run against the toolchain in GOROOT, and optionally an
+// additional baseline toolchain in BENCH_BASELINE_GOROOT.
 package main
 
 import (
+	"fmt"
 	"log"
 	"os"
 	"os/exec"
@@ -34,12 +38,7 @@
 	return cmd
 }
 
-func main() {
-	goroot, err := determineGOROOT()
-	if err != nil {
-		log.Fatalf("Unable to determine GOROOT: %v", err)
-	}
-
+func run(goroot string) error {
 	log.Printf("GOROOT under test: %s", goroot)
 
 	pass := true
@@ -55,6 +54,34 @@
 	}
 
 	if !pass {
+		return fmt.Errorf("benchmarks failed")
+	}
+	return nil
+}
+
+func main() {
+	goroot, err := determineGOROOT()
+	if err != nil {
+		log.Fatalf("Unable to determine GOROOT: %v", err)
+	}
+
+	fmt.Println("toolchain: experiment")
+
+	pass := true
+	if err := run(goroot); err != nil {
+		pass = false
+	}
+
+	baseline := os.Getenv("BENCH_BASELINE_GOROOT")
+	if baseline != "" {
+		fmt.Println("toolchain: baseline")
+
+		if err := run(baseline); err != nil {
+			pass = false
+		}
+	}
+
+	if !pass {
 		log.Printf("FAIL")
 		os.Exit(1)
 	}