import os
import pytest
import sqlite3
import subprocess
import sys
import threading
sys.path.append("..")
from tools.utils import run_and_get_output
SMALL_FILE_EXPECTED_SIZE = 1 * 1024
def task():
run_and_get_output(
r'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_hisysevent.txt -o /data/local/tmp/test_hisysevent.htrace -t 20 -s -k"')
def task2():
run_and_get_output(
r'hdc shell "echo 11 > /sys/devices/platform/modem_power/state"')
run_and_get_output(
r'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_hisysevent2.txt -o /data/local/tmp/test_hisysevent2.htrace -t 15 -s -k"')
def task3():
run_and_get_output(
r'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_hisysevent3.txt -o /data/local/tmp/test_hisysevent3.htrace -t 30 -s -k"')
class TestHiprofilerHisyseventPlugin:
@pytest.mark.L0
def test_hisysevent_plugin(self):
subprocess.run(r'hdc file send ..\inputfiles\hisysevent_plugin\config_hisysevent.txt /data/local/tmp',
text=True, encoding="utf-8")
task_thread = threading.Thread(target=task, args=())
task_thread.start()
task_thread.join()
subprocess.run(r'hdc file recv /data/local/tmp/test_hisysevent.htrace ..\outputfiles',
text=True, encoding="utf-8")
subprocess.run(
r'..\inputfiles\trace_streamer_db.exe ..\outputfiles\test_hisysevent.htrace -e ..\outputfiles\test_hisysevent.db')
conn = sqlite3.connect(r'..\outputfiles\test_hisysevent.db')
cursor = conn.cursor()
check = False
db_relative_path = "..\\outputfiles\\test_hisysevent.htrace"
absolute_path = os.path.abspath(db_relative_path)
db_size = os.path.getsize(absolute_path)
assert db_size > SMALL_FILE_EXPECTED_SIZE
table_list = [a for a in cursor.execute('SELECT name FROM sqlite_master WHERE type = "table"')]
cursor.execute('SELECT * FROM hisys_all_event')
result = cursor.fetchall()
if len(result) == 0:
check = True
assert check
@pytest.mark.L0
def test_hisysevent_plugin2(self):
subprocess.run(r'hdc file send ..\inputfiles\hisysevent_plugin\config_hisysevent2.txt /data/local/tmp',
text=True, encoding="utf-8")
task_thread = threading.Thread(target=task2, args=())
task_thread.start()
task_thread.join()
subprocess.run(r'hdc file recv /data/local/tmp/test_hisysevent2.htrace ..\outputfiles',
text=True, encoding="utf-8")
subprocess.run(
r'..\inputfiles\trace_streamer_db.exe ..\outputfiles\test_hisysevent2.htrace -e ..\outputfiles\test_hisysevent2.db')
conn = sqlite3.connect(r'..\outputfiles\test_hisysevent2.db')
cursor = conn.cursor()
check = False
db_relative_path = "..\\outputfiles\\test_hisysevent2.htrace"
absolute_path = os.path.abspath(db_relative_path)
db_size = os.path.getsize(absolute_path)
assert db_size > SMALL_FILE_EXPECTED_SIZE
table_list = [a for a in cursor.execute('SELECT name FROM sqlite_master WHERE type = "table"')]
cursor.execute('SELECT * FROM hisys_all_event')
result = cursor.fetchall()
if len(result):
check = True
assert check
@pytest.mark.L0
def test_hisysevent_plugin3(self):
subprocess.run(r'hdc file send ..\inputfiles\hisysevent_plugin\config_hisysevent3.txt /data/local/tmp',
text=True, encoding="utf-8")
task_thread = threading.Thread(target=task3, args=())
task_thread.start()
task_thread.join()
subprocess.run(r'hdc file recv /data/local/tmp/test_hisysevent3.htrace ..\outputfiles',
text=True, encoding="utf-8")
subprocess.run(
r'..\inputfiles\trace_streamer_db.exe ..\outputfiles\test_hisysevent3.htrace -e ..\outputfiles\test_hisysevent3.db')
conn = sqlite3.connect(r'..\outputfiles\test_hisysevent3.db')
cursor = conn.cursor()
check = False
db_relative_path = "..\\outputfiles\\test_hisysevent3.htrace"
absolute_path = os.path.abspath(db_relative_path)
db_size = os.path.getsize(absolute_path)
assert db_size > SMALL_FILE_EXPECTED_SIZE
table_list = [a for a in cursor.execute('SELECT name FROM sqlite_master WHERE type = "table"')]
cursor.execute('SELECT * FROM hisys_all_event')
result = cursor.fetchall()
if len(result) == 0:
check = True
assert check