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