import os
import pytest
import sqlite3
import subprocess
import sys
import threading
sys.path.append("..")
from tools.utils import run_and_get_output
SMALL_TRACE_EXPECTED_SIZE_3 = 1 * 1024
SMALL_TRACE_EXPECTED_SIZE_2 = 1024 * 1024 * 1024
MID_TRACE_EXPECTED_SIZE = 1 * 1024
def task():
run_and_get_output(
r'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_diskio.txt -o /data/local/tmp/test_diskio.htrace -t 10 -s -k"')
def task_ex():
run_and_get_output(
r'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_diskio_ex.txt -o /data/local/tmp/test_diskio_ex.htrace -t 10 -s -k"')
def task_no_report():
run_and_get_output(
r'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_diskio_no_report.txt -o /data/local/tmp/test_diskio_no_report.htrace -t 10 -s -k"')
class TestHiprofilerDiskioPlugin:
@pytest.mark.L0
def test_diskio_plugin(self):
subprocess.run(r'hdc file send ..\inputfiles\diskio\config_diskio.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_diskio.htrace ..\outputfiles',
text=True, encoding="utf-8")
subprocess.run(
r'..\inputfiles\trace_streamer_db.exe ..\outputfiles\test_diskio.htrace -e ..\outputfiles\test_diskio.db')
conn = sqlite3.connect(r'..\outputfiles\test_diskio.db')
cursor = conn.cursor()
check = False
db_relative_path = "..\\outputfiles\\test_diskio.htrace"
absolute_path = os.path.abspath(db_relative_path)
db_size = os.path.getsize(absolute_path)
print("liuwei db_size0 = ", db_size)
assert db_size > MID_TRACE_EXPECTED_SIZE
table_list = [a for a in cursor.execute('SELECT name FROM sqlite_master WHERE type = "table"')]
cursor.execute('SELECT * FROM diskio')
result = cursor.fetchall()
if len(result):
check = True
assert check
for row in result:
assert (row[6] > 0)
assert (row[7] > 0)
assert (row[8] > 0)
assert (row[9] > 0)
@pytest.mark.L0
def test_diskio_plugin_report_ex(self):
subprocess.run(r'hdc file send ..\inputfiles\diskio\config_diskio_ex.txt /data/local/tmp',
text=True, encoding="utf-8")
task_thread = threading.Thread(target=task_ex, args=())
task_thread.start()
task_thread.join()
subprocess.run(r'hdc file recv /data/local/tmp/test_diskio_ex.htrace ..\outputfiles',
text=True, encoding="utf-8")
subprocess.run(
r'..\inputfiles\trace_streamer_db.exe ..\outputfiles\test_diskio_ex.htrace -e ..\outputfiles\test_diskio_ex.db')
conn = sqlite3.connect(r'..\outputfiles\test_diskio_ex.db')
cursor = conn.cursor()
check = False
db_relative_path = "..\\outputfiles\\test_diskio_ex.htrace"
absolute_path = os.path.abspath(db_relative_path)
db_size = os.path.getsize(absolute_path)
assert db_size > SMALL_TRACE_EXPECTED_SIZE_3
table_list = [a for a in cursor.execute('SELECT name FROM sqlite_master WHERE type = "table"')]
cursor.execute('SELECT * FROM diskio')
result = cursor.fetchall()
if len(result):
check = True
assert check
for row in result:
assert (row[6] == 0)
assert (row[7] == 0)
assert (row[8] == 0)
assert (row[9] == 0)
@pytest.mark.L0
def test_diskio_plugin_no_report(self):
subprocess.run(r'hdc file send ..\inputfiles\diskio\config_diskio_no_report.txt /data/local/tmp',
text=True, encoding="utf-8")
task_thread = threading.Thread(target=task_no_report, args=())
task_thread.start()
task_thread.join()
subprocess.run(r'hdc file recv /data/local/tmp/test_diskio_no_report.htrace ..\outputfiles',
text=True, encoding="utf-8")
subprocess.run(
r'..\inputfiles\trace_streamer_db.exe ..\outputfiles\test_diskio_no_report.htrace -e ..\outputfiles\test_diskio_no_report.db')
conn = sqlite3.connect(r'..\outputfiles\test_diskio_no_report.db')
cursor = conn.cursor()
check = False
db_relative_path = "..\\outputfiles\\test_diskio_no_report.htrace"
absolute_path = os.path.abspath(db_relative_path)
db_size = os.path.getsize(absolute_path)
assert db_size < SMALL_TRACE_EXPECTED_SIZE_3
table_list = [a for a in cursor.execute('SELECT name FROM sqlite_master WHERE type = "table"')]
cursor.execute('SELECT * FROM diskio')
result = cursor.fetchall()
if len(result):
check = True
assert check
for row in result:
assert (row[6] == 0)
assert (row[7] == 0)
assert (row[8] == 0)
assert (row[9] == 0)