gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/benchmarks/fs/bazel_test.go (about)

     1  // Copyright 2020 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //	http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package bazel_test benchmarks builds using bazel.
    16  package bazel_test
    17  
    18  import (
    19  	"context"
    20  	"os"
    21  	"testing"
    22  
    23  	"gvisor.dev/gvisor/test/benchmarks/fs/fsbench"
    24  	"gvisor.dev/gvisor/test/benchmarks/harness"
    25  )
    26  
    27  // Note: CleanCache versions of this test require running with root permissions.
    28  func BenchmarkBuildABSL(b *testing.B) {
    29  	runBuildBenchmark(b, "benchmarks/absl", "/abseil-cpp", "absl/base/...")
    30  }
    31  
    32  // Note: CleanCache versions of this test require running with root permissions.
    33  // Note: This test takes on the order of 6m per permutation for runsc on kvm.
    34  func BenchmarkBuildGRPC(b *testing.B) {
    35  	runBuildBenchmark(b, "benchmarks/build-grpc", "/grpc", ":grpc")
    36  }
    37  
    38  func runBuildBenchmark(b *testing.B, image, workDir, target string) {
    39  	b.Helper()
    40  	ctx := context.Background()
    41  	// Get a machine from the Harness on which to run.
    42  	machine, err := harness.GetMachine()
    43  	if err != nil {
    44  		b.Fatalf("Failed to get machine: %v", err)
    45  	}
    46  	defer machine.CleanUp()
    47  	fsbench.RunWithDifferentFilesystems(ctx, b, machine, fsbench.FSBenchmark{
    48  		Image:      image,
    49  		WorkDir:    workDir,
    50  		RunCmd:     []string{"bazel", "build", "-c", "opt", target},
    51  		WantOutput: "Build completed successfully",
    52  		CleanCmd:   []string{"blaze", "clean"},
    53  	})
    54  }
    55  
    56  // TestMain is the main method for package fs.
    57  func TestMain(m *testing.M) {
    58  	harness.Init()
    59  	harness.SetFixedBenchmarks()
    60  	os.Exit(m.Run())
    61  }