1#!/usr/bin/env python3
2# coding=utf-8
3
4#
5# Copyright (c) 2020 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19import os
20import sys
21import subprocess
22
23from xdevice import IReporter
24from xdevice import Plugin
25from xdevice import TestType
26
27from _core.logger import platform_logger
28
29__all__ = ["BenchmarkReporter"]
30LOG = platform_logger("BenchmarkReporter")
31
32
33@Plugin(type=Plugin.REPORTER, id=TestType.benchmark)
34class BenchmarkReporter(IReporter):
35
36    def __generate_reports__(self, report_path, **kwargs):
37        del kwargs
38        LOG.info("report_path = %s" % report_path)
39        self._make_benchmark_report(report_path)
40
41    def _make_benchmark_report(self, result_path):
42        result_path = os.path.join(result_path, "benchmark")
43        reports_dir = os.path.join(result_path, "benchmark", "report")
44        if not os.path.exists(reports_dir):
45            os.makedirs(reports_dir)
46        report_generate_tool = os.path.abspath(
47            os.path.join(os.path.dirname(os.path.realpath(__file__)),
48                         "generate_report.py"))
49
50        command = [sys.executable, report_generate_tool, result_path,
51                   reports_dir]
52        LOG.info(command)
53        subprocess.call(command, shell=False)
54