• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4# Copyright (c) 2021-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 functools import cached_property
19from pathlib import Path
20from runner.options.options_general import GeneralOptions
21
22
23class CoverageDir:
24    def __init__(self, general: GeneralOptions, work_dir: Path):
25        self.__general = general
26        self.__work_dir = work_dir
27
28    @property
29    def html_report_dir(self) -> Path:
30        if self.__general.coverage.llvm_cov_html_out_path:
31            html_out_path = Path(self.__general.coverage.llvm_cov_html_out_path)
32        else:
33            html_out_path = self.root / "html_report_dir"
34        html_out_path.mkdir(parents=True, exist_ok=True)
35        return html_out_path
36
37    @property
38    def info_file(self) -> Path:
39        return self.coverage_work_dir / "coverage_lcov_format.info"
40
41    @property
42    def profdata_files_list_file(self) -> Path:
43        return self.coverage_work_dir / "profdatalist.txt"
44
45    @property
46    def profdata_merged_file(self) -> Path:
47        return self.coverage_work_dir / "merged.profdata"
48
49    @cached_property
50    def root(self) -> Path:
51        root = self.__work_dir / "coverage"
52        root.mkdir(parents=True, exist_ok=True)
53        return root
54
55    @cached_property
56    def profdata_dir(self) -> Path:
57        if self.__general.coverage.llvm_profdata_out_path:
58            profdata_out_path = Path(self.__general.coverage.llvm_profdata_out_path)
59        else:
60            profdata_out_path = self.root / "profdata_dir"
61        profdata_out_path.mkdir(parents=True, exist_ok=True)
62        return profdata_out_path
63
64    @cached_property
65    def coverage_work_dir(self) -> Path:
66        work_dir = self.root / "work_dir"
67        work_dir.mkdir(parents=True, exist_ok=True)
68        return work_dir
69