AUTHOR = """
uril@redhat.com (Uri Lublin)
drusso@redhat.com (Dror Russo)
mgoldish@redhat.com (Michael Goldish)
dhuff@redhat.com (David Huff)
aeromenk@redhat.com (Alexey Eromenko)
mburns@redhat.com (Mike Burns)
"""
TIME = 'MEDIUM'
NAME = 'KVM test'
TEST_TYPE = 'client'
TEST_CLASS = 'Virtualization'
TEST_CATEGORY = 'Functional'

DOC = """
Executes the KVM test framework on a given host. This module is separated in
minor functions, that execute different tests for doing Quality Assurance on
KVM (both kernelspace and userspace) code.

For online docs, please refer to http://www.linux-kvm.org/page/KVM-Autotest
"""

import sys, os, logging
# Add the KVM tests dir to the python path
kvm_test_dir = os.path.join(os.environ['AUTODIR'],'tests/kvm')
sys.path.append(kvm_test_dir)
# Now we can import modules inside the KVM tests dir
import kvm_utils, kvm_config

# set English environment (command output might be localized, need to be safe)
os.environ['LANG'] = 'en_US.UTF-8'

str = """
# This string will be parsed after build.cfg.  Make any desired changes to the
# build configuration here.  For example:
#release_tag = 84
"""
build_cfg = kvm_config.config()
# As the base test config is quite large, in order to save memory, we use the
# fork_and_parse() method, that creates another parser process and destroys it
# at the end of the parsing, so the memory spent can be given back to the OS.
build_cfg_path = os.path.join(kvm_test_dir, "build.cfg")
build_cfg.fork_and_parse(build_cfg_path, str)
if not kvm_utils.run_tests(build_cfg.get_generator(), job):
    logging.error("KVM build step failed, exiting.")
    sys.exit(1)

str = """
# This string will be parsed after tests.cfg.  Make any desired changes to the
# test configuration here.  For example:
#display = sdl
#install|setup: timeout_multiplier = 3
"""
tests_cfg = kvm_config.config()
tests_cfg_path = os.path.join(kvm_test_dir, "tests.cfg")
tests_cfg.fork_and_parse(tests_cfg_path, str)

# Run the tests
kvm_utils.run_tests(tests_cfg.get_generator(), job)

# Generate a nice HTML report inside the job's results dir
kvm_utils.create_report(kvm_test_dir, job.resultdir)

