1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# 4# Copyright (c) 2024 Huawei Device Co., Ltd. 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18from dataclasses import replace 19from pathlib import Path 20 21from pytest import Config, FixtureRequest, fixture 22 23from arkdb import compiler, disassembler, runtime 24 25 26def get_config(config: Config, name: str): 27 return config.getoption(name, config.getini(name), True) 28 29 30# CC-OFFNXT(G.CTL.01) This is exactly the signature of the function that required. 31# Any changes will complicate the code and its processing. 32def str2bool(val: str | None) -> None | bool: 33 if val is None: 34 return None 35 val = val.lower() 36 if val in ("", "none", "null"): 37 return None 38 if val in ("y", "yes", "t", "true", "on", "1"): 39 return True 40 if val in ("n", "no", "f", "false", "off", "0"): 41 return False 42 raise ValueError("invalid truth value %r" % (val,)) 43 44 45@fixture(scope="session") 46def ark_build_path( 47 request: FixtureRequest, 48) -> Path: 49 """ 50 Path to cmake ``build`` directory of panda. 51 """ 52 return Path(get_config(request.config, "ark_build_path")).absolute() 53 54 55@fixture(scope="session") 56def ark_compiler_default_options( 57 ark_build_path: Path, 58) -> compiler.Options: 59 """ 60 Return a :class:`compiler.Options` instance for `ark_compiler_options` fixture. 61 """ 62 return compiler.Options( 63 app_path=ark_build_path / "bin" / "es2panda", 64 arktsconfig=ark_build_path / "bin" / "arktsconfig.json", 65 ) 66 67 68@fixture 69def ark_compiler_options( 70 ark_compiler_default_options: compiler.Options, 71) -> compiler.Options: 72 """ 73 Return a :class:`compiler.Options` instance for `ark_compiler` fixture. 74 75 You can override fixture in your tests or conftest 76 See https://docs.pytest.org/en/stable/how-to/fixtures.html#overriding-fixtures-on-various-levels 77 """ 78 return replace(ark_compiler_default_options) 79 80 81@fixture 82def ark_disassembler_default_options( 83 ark_build_path: Path, 84) -> disassembler.Options: 85 """ 86 Return a :class:`disassembler.Options` instance for `ark_disassembler_options` fixture. 87 """ 88 return disassembler.Options( 89 app_path=ark_build_path / "bin" / "ark_disasm", 90 ) 91 92 93@fixture 94def ark_disassembler_options( 95 ark_disassembler_default_options: disassembler.Options, 96) -> disassembler.Options: 97 """ 98 Return a :class:`disassembler.Options` instance for `ark_disassembler` fixture. 99 100 You can override fixture in your tests or conftest 101 See https://docs.pytest.org/en/stable/how-to/fixtures.html#overriding-fixtures-on-various-levels 102 """ 103 return replace(ark_disassembler_default_options) 104 105 106@fixture 107def ark_runtime_default_options( 108 ark_build_path: Path, 109) -> runtime.Options: 110 """ 111 Return a :class:`runtime.Options` instance for `ark_runtime_options` fixture. 112 """ 113 return runtime.Options( 114 app_path=ark_build_path / "bin" / "ark", 115 log_debug=["debugger"], # Always log debugger for CI launches 116 interpreter_type="cpp", 117 boot_panda_files=[ark_build_path / "plugins" / "ets" / "etsstdlib.abc"], 118 debugger_library_path=ark_build_path / "lib" / "libarkinspector.so", 119 ) 120 121 122@fixture 123def ark_runtime_options( 124 ark_runtime_default_options: runtime.Options, 125) -> runtime.Options: 126 """ 127 Return a :class:`runtime.Options` instance for `ark_runtime` fixture. 128 129 You can override fixture in your tests or conftest 130 See https://docs.pytest.org/en/stable/how-to/fixtures.html#overriding-fixtures-on-various-levels 131 """ 132 return replace(ark_runtime_default_options) 133