1# Copyright (c) 2023 Intel Corporation
2#
3# SPDX-License-Identifier: Apache-2.0
4
5from pathlib import Path
6
7import pytest
8
9
10def pytest_addoption(parser):
11    parser.addoption('--tool')
12    parser.addoption('--tool-options')
13    parser.addoption('--sys-clock-hw-cycles-per-sec', default=None)
14
15
16@pytest.fixture()
17def tool(request):
18    return request.config.getoption('--tool')
19
20
21@pytest.fixture()
22def tool_options(request):
23    return request.config.getoption('--tool-options')
24
25
26@pytest.fixture()
27def config(request):
28    build_dir = Path(request.config.getoption('--build-dir'))
29    file_name = build_dir / 'zephyr' / '.config'
30
31    cfgs = {}
32    with open(file_name) as fp:
33        for line in fp:
34            if line.startswith('CONFIG_'):
35                k, v = line.split('=', maxsplit=1)
36                cfgs[k[7:]] = v
37
38    return cfgs
39
40
41@pytest.fixture()
42def sys_clock_hw_cycles_per_sec(request, config):
43    if request.config.getoption('--sys-clock-hw-cycles-per-sec'):
44        return int(request.config.getoption('--sys-clock-hw-cycles-per-sec'))
45
46    return int(config['SYS_CLOCK_HW_CYCLES_PER_SEC'])
47