• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright (C) 2024 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17import pytest
18import sqlite3
19import subprocess
20import sys
21import threading
22sys.path.append("..")
23from tools.utils import SMALL_TRACE_EXPECTED_SIZE, SMALL_TRACE_EXPECTED_SIZE_2
24
25
26def task():
27    subprocess.check_output(f'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_gpu.txt -o /data/local/tmp/test_gpu.htrace -t 15 -s -k"')
28
29
30def task_process_report_is_false():
31    subprocess.check_output(f'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_gpu_report_process_is_false.txt -o /data/local/tmp/test_gpu2.htrace -t 15 -s -k"')
32
33
34def task_no_pid():
35    subprocess.check_output(f'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_gpu_no_pid.txt -o /data/local/tmp/test_gpu3.htrace -t 15 -s -k"')
36
37
38class TestHiprofilerGpuPlugin:
39
40    @pytest.mark.L0
41    def test_gpu_plugin(self):
42        subprocess.run(r'hdc file send ..\inputfiles\gpu_plugin\config_gpu.txt /data/local/tmp', text=True, encoding="utf-8")
43        task_thread = threading.Thread(target=task, args=())
44        task_thread.start()
45        task_thread.join()
46        subprocess.run(r'hdc file recv /data/local/tmp/test_gpu.htrace ..\outputfiles', text=True, encoding="utf-8")
47
48        subprocess.run(
49            r'..\inputfiles\trace_streamer_db.exe ..\outputfiles\test_gpu.htrace -e ..\outputfiles\test_gpu.db')
50
51        # 连接数据库文件
52        conn = sqlite3.connect(r'..\outputfiles\test_gpu.db')
53
54        # # 创建游标对象
55        cursor = conn.cursor()
56
57        # # 执行SQL查询
58        db_relative_path = "..\\outputfiles\\test_gpu.htrace"
59        absolute_path = os.path.abspath(db_relative_path)
60        trace_size = os.path.getsize(absolute_path)
61        # # 判断数据库大小
62        assert trace_size > SMALL_TRACE_EXPECTED_SIZE
63        assert trace_size < SMALL_TRACE_EXPECTED_SIZE_2
64
65    @pytest.mark.L0
66    def test_gpu_plugin_process_report_is_false(self):
67        subprocess.run(r'hdc file send ..\inputfiles\gpu_plugin\config_gpu_report_process_is_false.txt /data/local/tmp', text=True, encoding="utf-8")
68        task_thread = threading.Thread(target=task_process_report_is_false, args=())
69        task_thread.start()
70        task_thread.join()
71        subprocess.run(r'hdc file recv /data/local/tmp/test_gpu2.htrace ..\outputfiles', text=True, encoding="utf-8")
72
73        subprocess.run(
74            r'..\inputfiles\trace_streamer_db.exe ..\outputfiles\test_gpu2.htrace -e ..\outputfiles\test_gpu2.db')
75
76        # 连接数据库文件
77        conn = sqlite3.connect(r'..\outputfiles\test_gpu2.db')
78
79        # # 创建游标对象
80        cursor = conn.cursor()
81
82        # # 执行SQL查询
83        db_relative_path = "..\\outputfiles\\test_gpu2.htrace"
84        absolute_path = os.path.abspath(db_relative_path)
85        trace_size = os.path.getsize(absolute_path)
86        # # 判断数据库大小
87        assert trace_size > SMALL_TRACE_EXPECTED_SIZE
88        assert trace_size < SMALL_TRACE_EXPECTED_SIZE_2
89
90    @pytest.mark.L0
91    def test_gpu_plugin_no_pid(self):
92        subprocess.run(r'hdc file send ..\inputfiles\gpu_plugin\config_gpu_no_pid.txt /data/local/tmp', text=True, encoding="utf-8")
93        task_thread = threading.Thread(target=task_no_pid, args=())
94        task_thread.start()
95        task_thread.join()
96        subprocess.run(r'hdc file recv /data/local/tmp/test_gpu3.htrace ..\outputfiles', text=True, encoding="utf-8")
97
98        subprocess.run(
99            r'..\inputfiles\trace_streamer_db.exe ..\outputfiles\test_gpu3.htrace -e ..\outputfiles\test_gpu3.db')
100
101        # 连接数据库文件
102        conn = sqlite3.connect(r'..\outputfiles\test_gpu3.db')
103
104        # # 创建游标对象
105        cursor = conn.cursor()
106
107        # # 执行SQL查询
108        db_relative_path = "..\\outputfiles\\test_gpu3.htrace"
109        absolute_path = os.path.abspath(db_relative_path)
110        trace_size = os.path.getsize(absolute_path)
111        # # 判断数据库大小
112        assert trace_size > SMALL_TRACE_EXPECTED_SIZE
113        assert trace_size < SMALL_TRACE_EXPECTED_SIZE_2