1# Copyright 2018 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from autotest_lib.client.bin import test 6from autotest_lib.client.bin import utils 7from autotest_lib.client.common_lib import error 8 9 10class crosvm_Sanity(test.test): 11 """Set baseline expectations for hosting Chrome OS VM images. 12 13 In the Chrome OS lab these are based on current Google Compute Engine 14 (GCE) server offerings and represent the lowest common denominator to 15 effectively run QEMU/kvm. As a result VMs can be thought of as a 16 slightly outdated Intel Chromebox. GCE is not the only host 17 environment, and it runs in a VM as well. We attempt to control this 18 environment as well as possible. This test ensures relevant changes 19 are detected over time 20 """ 21 version = 1 22 23 def initialize(self): 24 """Initialize baseline parameters.""" 25 26 # We expect to use 8 Haswell CPU cores. 27 self.cpu_cores = 8 28 # The current GCE offering is a stripped Haswell. This is similar to 29 # Z840. Matching CPU arch and flags are requested by 30 # crosutils/lib/cros_vm_lib.sh. 31 # TODO(pwang): Replace with 'Haswell, no TSX' once lab is ready. 32 self.cpu_arch = 'Sandy Bridge' 33 34 # These are flags that sampled from GCE builders on cros lab. 35 self.cpu_flags = [ 36 'abm', 'aes', 'apic', 'arat', 'avx', 'avx2', 'bmi1', 'bmi2', 37 'clflush', 'cmov', 'constant_tsc', 'cx16', 'cx8', 'de', 'eagerfpu', 38 'erms', 'f16c', 'fma', 'fpu', 'fsgsbase', 'fxsr', 'hypervisor', 39 'kaiser', 'lahf_lm', 'lm', 'mca', 'mce', 'mmx', 'movbe', 'msr', 40 'mtrr', 'nopl', 'nx', 'pae', 'pat', 'pcid', 'pclmulqdq', 'pge', 41 'pni', 'popcnt', 'pse', 'pse36', 'rdrand', 'rdtscp', 'rep_good', 42 'sep', 'smep', 'sse', 'sse2', 'sse4_1', 'sse4_2', 'ssse3', 43 'syscall', 'tsc', 'vme', 'x2apic', 'xsave', 'xsaveopt' 44 ] 45 self.min_memory_kb = 7.5 * 1024 * 1024 46 47 def cleanup(self): 48 """Test cleanup.""" 49 50 def run_once(self): 51 """Run the test.""" 52 errors = '' 53 warnings = '' 54 funcs = [self.test_cpu, self.test_gpu, self.test_mem] 55 for func in funcs: 56 error_msg, warning_msg = func() 57 errors += error_msg 58 warnings += warning_msg 59 60 if errors: 61 raise error.TestFail('Failed: %s' % (errors + warnings)) 62 if warnings: 63 raise error.TestWarn('Warning: %s' % warnings) 64 65 def test_cpu(self): 66 """Test the CPU configuration.""" 67 errors = '' 68 warning = '' 69 if self.cpu_cores != utils.count_cpus(): 70 errors += 'Expecting %d CPU cores but found %d cores\n' % ( 71 self.cpu_cores, utils.count_cpus()) 72 73 for cpu_info in utils.get_cpuinfo(): 74 if self.cpu_arch not in cpu_info['model name']: 75 errors += 'Expecting %s CPU but found %s' % ( 76 self.cpu_arch, cpu_info['model name']) 77 78 flags = sorted(cpu_info['flags'].split(' ')) 79 if flags != self.cpu_flags: 80 # TODO(pwang): convert warning to error once VM got better 81 # infra support. 82 warning += 'Expecting CPU flags %s but found %s\n' % ( 83 self.cpu_flags, flags) 84 return errors, warning 85 86 def test_gpu(self): 87 """Test the GPU configuration.""" 88 89 # TODO(pwang): Add check once virgl is fully introduced to VM. 90 errors = '' 91 warning = '' 92 return errors, warning 93 94 def test_mem(self): 95 """Test the RAM configuration.""" 96 errors = '' 97 warning = '' 98 if self.min_memory_kb > utils.memtotal(): 99 errors += 'Expecting at least %dKB memory but found %sKB\n' % ( 100 self.min_memory_kb, utils.memtotal()) 101 return errors, warning 102