1*fa32a634SThomas Huth# Test class and utilities for functional tests 2*fa32a634SThomas Huth# 3*fa32a634SThomas Huth# Copyright 2018, 2024 Red Hat, Inc. 4*fa32a634SThomas Huth# 5*fa32a634SThomas Huth# Original Author (Avocado-based tests): 6*fa32a634SThomas Huth# Cleber Rosa <crosa@redhat.com> 7*fa32a634SThomas Huth# 8*fa32a634SThomas Huth# Adaption for standalone version: 9*fa32a634SThomas Huth# Thomas Huth <thuth@redhat.com> 10*fa32a634SThomas Huth# 11*fa32a634SThomas Huth# This work is licensed under the terms of the GNU GPL, version 2 or 12*fa32a634SThomas Huth# later. See the COPYING file in the top-level directory. 13*fa32a634SThomas Huth 14*fa32a634SThomas Huthimport os 15*fa32a634SThomas Huthfrom pathlib import Path 16*fa32a634SThomas Huth 17*fa32a634SThomas Huth 18*fa32a634SThomas Huthdef _source_dir(): 19*fa32a634SThomas Huth # Determine top-level directory of the QEMU sources 20*fa32a634SThomas Huth return Path(__file__).parent.parent.parent.parent 21*fa32a634SThomas Huth 22*fa32a634SThomas Huthdef _build_dir(): 23*fa32a634SThomas Huth root = os.getenv('QEMU_BUILD_ROOT') 24*fa32a634SThomas Huth if root is not None: 25*fa32a634SThomas Huth return Path(root) 26*fa32a634SThomas Huth # Makefile.mtest only exists in build dir, so if it is available, use CWD 27*fa32a634SThomas Huth if os.path.exists('Makefile.mtest'): 28*fa32a634SThomas Huth return Path(os.getcwd()) 29*fa32a634SThomas Huth 30*fa32a634SThomas Huth root = os.path.join(_source_dir(), 'build') 31*fa32a634SThomas Huth if os.path.exists(root): 32*fa32a634SThomas Huth return Path(root) 33*fa32a634SThomas Huth 34*fa32a634SThomas Huth raise Exception("Cannot identify build dir, set QEMU_BUILD_ROOT") 35*fa32a634SThomas Huth 36*fa32a634SThomas HuthBUILD_DIR = _build_dir() 37