| // Copyright 2019 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package crostini |
| |
| import ( |
| "context" |
| "strings" |
| "time" |
| |
| "chromiumos/tast/local/crostini" |
| "chromiumos/tast/local/testexec" |
| "chromiumos/tast/shutil" |
| "chromiumos/tast/testing" |
| ) |
| |
| func init() { |
| testing.AddTest(&testing.Test{ |
| Func: GPUEnabled, |
| Desc: "Tests that Crostini starts with the correct GPU device depending on whether the GPU flag is set or not", |
| Contacts: []string{"hollingum@google.com", "cros-containers-dev@google.com"}, |
| Attr: []string{"group:mainline"}, |
| Vars: []string{"keepState"}, |
| SoftwareDeps: []string{"chrome", "vm_host", "crosvm_gpu"}, |
| Params: []testing.Param{ |
| // Parameters generated by gpu_enabled_test.go. DO NOT EDIT. |
| { |
| Name: "sw_stretch_amd64_stable", |
| ExtraData: []string{"crostini_vm_amd64.zip", "crostini_test_container_metadata_stretch_amd64.tar.xz", "crostini_test_container_rootfs_stretch_amd64.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_no_gpu", "amd64"}, |
| ExtraHardwareDeps: crostini.CrostiniStable, |
| Pre: crostini.StartedByComponentStretch(), |
| Timeout: 7 * time.Minute, |
| Val: "llvmpipe", |
| }, { |
| Name: "sw_stretch_amd64_unstable", |
| ExtraAttr: []string{"informational"}, |
| ExtraData: []string{"crostini_vm_amd64.zip", "crostini_test_container_metadata_stretch_amd64.tar.xz", "crostini_test_container_rootfs_stretch_amd64.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_no_gpu", "amd64"}, |
| ExtraHardwareDeps: crostini.CrostiniUnstable, |
| Pre: crostini.StartedByComponentStretch(), |
| Timeout: 7 * time.Minute, |
| Val: "llvmpipe", |
| }, { |
| Name: "sw_stretch_arm_stable", |
| ExtraData: []string{"crostini_vm_arm.zip", "crostini_test_container_metadata_stretch_arm.tar.xz", "crostini_test_container_rootfs_stretch_arm.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_no_gpu", "arm"}, |
| ExtraHardwareDeps: crostini.CrostiniStable, |
| Pre: crostini.StartedByComponentStretch(), |
| Timeout: 7 * time.Minute, |
| Val: "llvmpipe", |
| }, { |
| Name: "sw_stretch_arm_unstable", |
| ExtraAttr: []string{"informational"}, |
| ExtraData: []string{"crostini_vm_arm.zip", "crostini_test_container_metadata_stretch_arm.tar.xz", "crostini_test_container_rootfs_stretch_arm.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_no_gpu", "arm"}, |
| ExtraHardwareDeps: crostini.CrostiniUnstable, |
| Pre: crostini.StartedByComponentStretch(), |
| Timeout: 7 * time.Minute, |
| Val: "llvmpipe", |
| }, { |
| Name: "sw_buster_amd64_stable", |
| ExtraData: []string{"crostini_vm_amd64.zip", "crostini_test_container_metadata_buster_amd64.tar.xz", "crostini_test_container_rootfs_buster_amd64.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_no_gpu", "amd64"}, |
| ExtraHardwareDeps: crostini.CrostiniStable, |
| Pre: crostini.StartedByComponentBuster(), |
| Timeout: 7 * time.Minute, |
| Val: "llvmpipe", |
| }, { |
| Name: "sw_buster_amd64_unstable", |
| ExtraAttr: []string{"informational"}, |
| ExtraData: []string{"crostini_vm_amd64.zip", "crostini_test_container_metadata_buster_amd64.tar.xz", "crostini_test_container_rootfs_buster_amd64.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_no_gpu", "amd64"}, |
| ExtraHardwareDeps: crostini.CrostiniUnstable, |
| Pre: crostini.StartedByComponentBuster(), |
| Timeout: 7 * time.Minute, |
| Val: "llvmpipe", |
| }, { |
| Name: "sw_buster_arm_stable", |
| ExtraData: []string{"crostini_vm_arm.zip", "crostini_test_container_metadata_buster_arm.tar.xz", "crostini_test_container_rootfs_buster_arm.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_no_gpu", "arm"}, |
| ExtraHardwareDeps: crostini.CrostiniStable, |
| Pre: crostini.StartedByComponentBuster(), |
| Timeout: 7 * time.Minute, |
| Val: "llvmpipe", |
| }, { |
| Name: "sw_buster_arm_unstable", |
| ExtraAttr: []string{"informational"}, |
| ExtraData: []string{"crostini_vm_arm.zip", "crostini_test_container_metadata_buster_arm.tar.xz", "crostini_test_container_rootfs_buster_arm.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_no_gpu", "arm"}, |
| ExtraHardwareDeps: crostini.CrostiniUnstable, |
| Pre: crostini.StartedByComponentBuster(), |
| Timeout: 7 * time.Minute, |
| Val: "llvmpipe", |
| }, { |
| Name: "gpu_stretch_amd64_stable", |
| ExtraData: []string{"crostini_vm_amd64.zip", "crostini_test_container_metadata_stretch_amd64.tar.xz", "crostini_test_container_rootfs_stretch_amd64.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_gpu", "amd64"}, |
| ExtraHardwareDeps: crostini.CrostiniStable, |
| Pre: crostini.StartedByComponentStretch(), |
| Timeout: 7 * time.Minute, |
| Val: "virgl", |
| }, { |
| Name: "gpu_stretch_amd64_unstable", |
| ExtraAttr: []string{"informational"}, |
| ExtraData: []string{"crostini_vm_amd64.zip", "crostini_test_container_metadata_stretch_amd64.tar.xz", "crostini_test_container_rootfs_stretch_amd64.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_gpu", "amd64"}, |
| ExtraHardwareDeps: crostini.CrostiniUnstable, |
| Pre: crostini.StartedByComponentStretch(), |
| Timeout: 7 * time.Minute, |
| Val: "virgl", |
| }, { |
| Name: "gpu_stretch_arm_stable", |
| ExtraData: []string{"crostini_vm_arm.zip", "crostini_test_container_metadata_stretch_arm.tar.xz", "crostini_test_container_rootfs_stretch_arm.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_gpu", "arm"}, |
| ExtraHardwareDeps: crostini.CrostiniStable, |
| Pre: crostini.StartedByComponentStretch(), |
| Timeout: 7 * time.Minute, |
| Val: "virgl", |
| }, { |
| Name: "gpu_stretch_arm_unstable", |
| ExtraAttr: []string{"informational"}, |
| ExtraData: []string{"crostini_vm_arm.zip", "crostini_test_container_metadata_stretch_arm.tar.xz", "crostini_test_container_rootfs_stretch_arm.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_gpu", "arm"}, |
| ExtraHardwareDeps: crostini.CrostiniUnstable, |
| Pre: crostini.StartedByComponentStretch(), |
| Timeout: 7 * time.Minute, |
| Val: "virgl", |
| }, { |
| Name: "gpu_buster_amd64_stable", |
| ExtraData: []string{"crostini_vm_amd64.zip", "crostini_test_container_metadata_buster_amd64.tar.xz", "crostini_test_container_rootfs_buster_amd64.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_gpu", "amd64"}, |
| ExtraHardwareDeps: crostini.CrostiniStable, |
| Pre: crostini.StartedByComponentBuster(), |
| Timeout: 7 * time.Minute, |
| Val: "virgl", |
| }, { |
| Name: "gpu_buster_amd64_unstable", |
| ExtraAttr: []string{"informational"}, |
| ExtraData: []string{"crostini_vm_amd64.zip", "crostini_test_container_metadata_buster_amd64.tar.xz", "crostini_test_container_rootfs_buster_amd64.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_gpu", "amd64"}, |
| ExtraHardwareDeps: crostini.CrostiniUnstable, |
| Pre: crostini.StartedByComponentBuster(), |
| Timeout: 7 * time.Minute, |
| Val: "virgl", |
| }, { |
| Name: "gpu_buster_arm_stable", |
| ExtraData: []string{"crostini_vm_arm.zip", "crostini_test_container_metadata_buster_arm.tar.xz", "crostini_test_container_rootfs_buster_arm.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_gpu", "arm"}, |
| ExtraHardwareDeps: crostini.CrostiniStable, |
| Pre: crostini.StartedByComponentBuster(), |
| Timeout: 7 * time.Minute, |
| Val: "virgl", |
| }, { |
| Name: "gpu_buster_arm_unstable", |
| ExtraAttr: []string{"informational"}, |
| ExtraData: []string{"crostini_vm_arm.zip", "crostini_test_container_metadata_buster_arm.tar.xz", "crostini_test_container_rootfs_buster_arm.tar.xz"}, |
| ExtraSoftwareDeps: []string{"crosvm_gpu", "arm"}, |
| ExtraHardwareDeps: crostini.CrostiniUnstable, |
| Pre: crostini.StartedByComponentBuster(), |
| Timeout: 7 * time.Minute, |
| Val: "virgl", |
| }, |
| }, |
| }) |
| } |
| |
| func GPUEnabled(ctx context.Context, s *testing.State) { |
| cont := s.PreValue().(crostini.PreData).Container |
| expectedDevice := s.Param().(string) |
| defer crostini.RunCrostiniPostTest(ctx, s.PreValue().(crostini.PreData)) |
| |
| cmd := cont.Command(ctx, "sh", "-c", "glxinfo -B | grep Device:") |
| if out, err := cmd.Output(testexec.DumpLogOnError); err != nil { |
| s.Fatalf("Failed to run %q: %v", shutil.EscapeSlice(cmd.Args), err) |
| } else { |
| output := string(out) |
| if !strings.Contains(output, expectedDevice) { |
| s.Fatalf("Failed to verify GPU device: got %q; want %q", output, expectedDevice) |
| } |
| s.Logf("GPU is %q", output) |
| } |
| } |