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