tests: Add support for testing KVM-based CPUs
This changeset adds support for initializing a KVM VM in the BaseSystem test class and adds the following methods in run.py: require_file -- Test if a file exists and abort/skip if not. require_kvm -- Test if KVM support has been compiled into gem5 (i.e., BaseKvmCPU exists) and the KVM device exists on the host.
This commit is contained in:
parent
7865d6e838
commit
dc83d23425
2 changed files with 56 additions and 0 deletions
|
@ -43,6 +43,8 @@ m5.util.addToPath('../configs/common')
|
||||||
import FSConfig
|
import FSConfig
|
||||||
from Caches import *
|
from Caches import *
|
||||||
|
|
||||||
|
_have_kvm_support = 'BaseKvmCPU' in globals()
|
||||||
|
|
||||||
class BaseSystem(object):
|
class BaseSystem(object):
|
||||||
"""Base system builder.
|
"""Base system builder.
|
||||||
|
|
||||||
|
@ -111,6 +113,14 @@ class BaseSystem(object):
|
||||||
"""
|
"""
|
||||||
cpu.createInterruptController()
|
cpu.createInterruptController()
|
||||||
|
|
||||||
|
def init_kvm(self, system):
|
||||||
|
"""Do KVM-specific system initialization.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
system -- System to work on.
|
||||||
|
"""
|
||||||
|
system.vm = KvmVM()
|
||||||
|
|
||||||
def init_system(self, system):
|
def init_system(self, system):
|
||||||
"""Initialize a system.
|
"""Initialize a system.
|
||||||
|
|
||||||
|
@ -119,6 +129,10 @@ class BaseSystem(object):
|
||||||
"""
|
"""
|
||||||
system.cpu = self.create_cpus()
|
system.cpu = self.create_cpus()
|
||||||
|
|
||||||
|
if _have_kvm_support and \
|
||||||
|
any([isinstance(c, BaseKvmCPU) for c in system.cpu]):
|
||||||
|
self.init_kvm(system)
|
||||||
|
|
||||||
sha_bus = self.create_caches_shared(system)
|
sha_bus = self.create_caches_shared(system)
|
||||||
for cpu in system.cpu:
|
for cpu in system.cpu:
|
||||||
if not cpu.switched_out:
|
if not cpu.switched_out:
|
||||||
|
|
42
tests/run.py
42
tests/run.py
|
@ -44,6 +44,8 @@ import re
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from os.path import join as joinpath
|
from os.path import join as joinpath
|
||||||
|
import os.path
|
||||||
|
import os
|
||||||
|
|
||||||
import m5
|
import m5
|
||||||
|
|
||||||
|
@ -93,6 +95,46 @@ def require_sim_object(name, fatal=False):
|
||||||
else:
|
else:
|
||||||
skip_test(msg)
|
skip_test(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def require_file(path, fatal=False, mode=os.F_OK):
|
||||||
|
"""Test if a file exists and abort/skip test if not.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
path -- File to test for.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
fatal -- Set to True to indicate that the test should fail
|
||||||
|
instead of being skipped.
|
||||||
|
modes -- Mode to test for, default to existence. See the
|
||||||
|
Python documentation for os.access().
|
||||||
|
"""
|
||||||
|
|
||||||
|
if os.access(path, mode):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
msg = "Test requires '%s'" % path
|
||||||
|
if not os.path.exists(path):
|
||||||
|
msg += " which does not exist."
|
||||||
|
else:
|
||||||
|
msg += " which has incorrect permissions."
|
||||||
|
|
||||||
|
if fatal:
|
||||||
|
m5.fatal(msg)
|
||||||
|
else:
|
||||||
|
skip_test(msg)
|
||||||
|
|
||||||
|
def require_kvm(kvm_dev="/dev/kvm", fatal=False):
|
||||||
|
"""Test if KVM is available.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
kvm_dev -- Device to test (normally /dev/kvm)
|
||||||
|
fatal -- Set to True to indicate that the test should fail
|
||||||
|
instead of being skipped.
|
||||||
|
"""
|
||||||
|
|
||||||
|
require_sim_object("BaseKvmCPU", fatal=fatal)
|
||||||
|
require_file(kvm_dev, fatal=fatal, mode=os.R_OK | os.W_OK)
|
||||||
|
|
||||||
def run_test(root):
|
def run_test(root):
|
||||||
"""Default run_test implementations. Scripts can override it."""
|
"""Default run_test implementations. Scripts can override it."""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue