import pytest
import subprocess
import re
import time
import threading
import sqlite3
import os
from tools.utils import run_and_get_output
def get_file_size(file_path):
size = os.path.getsize(file_path)
return size
def task():
run_and_get_output(f'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_hidumper.txt -o /data/local/tmp/test_hidumper.htrace -t 30 -s -k"')
def task_nosec():
run_and_get_output(f'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_hidumper_nosec.txt -o /data/local/tmp/test_hidumper_nosec.htrace -t 30 -s -k"')
def task_section_60():
run_and_get_output(f'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_hidumper_60.txt -o /data/local/tmp/test_hidumper_60.htrace -t 30 -s -k"')
def task_fps():
run_and_get_output(f'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_hidumper_fps.txt -o /data/local/tmp/test_hidumper_fps.htrace -t 30 -s -k"')
def check_process():
count = 0
while (count < 5):
output_text = subprocess.run(f'hdc shell "ps -ef | grep SP_daemon"', stdout=subprocess.PIPE, text=True, check=True)
process_info = output_text.stdout
lines = process_info.strip().split('\n')
check_index = False
for line in lines:
if line.find("SP_daemon -profilerfps") != -1:
check_index = True
assert (check_index)
time.sleep(10)
count = count + 1
class TestHiprofilerHidumpPlugin:
@pytest.mark.L0
def test_hidump_plugin(self):
run_and_get_output(
r"hdc file send ..\inputfiles\hidumper_plugin\config_hidumper.txt /data/local/tmp/", shell=False,
text=True, encoding="utf-8")
task_thread = threading.Thread(target=task, args=())
task_thread.start()
subprocess.check_call("hdc shell power-shell wakeup", shell=False)
subprocess.check_call("hdc shell power-shell setmode 602", shell=False)
time.sleep(3)
subprocess.check_call("hdc shell uinput -T -g 100 100 500 500", shell=False)
time.sleep(3)
run_and_get_output(f"hdc shell uitest uiInput keyEvent Home", shell=False,
text=True, encoding="utf-8")
time.sleep(5)
run_and_get_output(f"hdc shell uinput -T -c 650 2447", shell=False, text=True, encoding="utf-8")
time.sleep(1)
run_and_get_output(f"hdc shell uinput -T -c 104 1532", shell=False, text=True, encoding="utf-8")
task_thread.join()
subprocess.run(f'hdc file recv /data/local/tmp/test_hidumper.htrace ../outputfiles/', shell=False,
text=True, encoding="utf-8")
file_size = get_file_size(f"../outputfiles/test_hidumper.htrace")
assert (file_size > 1024)
run_and_get_output(
r"../inputfiles/trace_streamer_db.exe ../outputfiles/test_hidumper.htrace -e ../outputfiles/test_hidumper.db")
conn = sqlite3.connect(r'../outputfiles/test_hidumper.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM hidump order by ts limit 0,10')
result = cursor.fetchall()
row_count = len(result)
assert(row_count == 10)
for row in result:
assert(row[2] >= 0)
last_row = result[0][1]
for row in result[1:]:
assert((row[1] - last_row) == 100 * 1000 * 1000 or (row[1] - last_row) == 1000 * 1000 * 1000)
last_row = row[1]
cursor.close()
conn.close()
@pytest.mark.L0
def test_hidump_plugin_nosec(self):
run_and_get_output(
r"hdc file send ..\inputfiles\hidumper_plugin\config_hidumper_nosec.txt /data/local/tmp/", shell=False,
text=True, encoding="utf-8")
task_thread = threading.Thread(target=task_nosec, args=())
task_thread.start()
task_thread.join()
subprocess.run(f'hdc file recv /data/local/tmp/test_hidumper_nosec.htrace ../outputfiles/', shell=False,
text=True, encoding="utf-8")
file_size = get_file_size(f"../outputfiles/test_hidumper_nosec.htrace")
assert (file_size > 1024)
run_and_get_output(
r"../inputfiles/trace_streamer_db.exe ../outputfiles/test_hidumper_nosec.htrace -e ../outputfiles/test_hidumper_nosec.db")
conn = sqlite3.connect(r'../outputfiles/test_hidumper_nosec.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM hidump order by ts limit 0,10')
result = cursor.fetchall()
row_count = len(result)
assert(row_count > 0)
for row in result:
assert(row[2] >= 0)
cursor.close()
conn.close()
@pytest.mark.L0
def test_hidumper_process(self):
run_and_get_output(
r"hdc file send ..\inputfiles\hidumper_plugin\config_hidumper.txt /data/local/tmp/", shell=False,
text=True, encoding="utf-8")
task_thread = threading.Thread(target=task, args=())
task_thread.start()
time.sleep(2)
task_check = threading.Thread(target=check_process, args=())
task_check.start()
task_thread.join()
task_check.join()
output_text = subprocess.run(f'hdc shell "ps -ef | grep SP_daemon"', stdout=subprocess.PIPE, text=True, check=True)
process_info = output_text.stdout
lines = process_info.strip().split('\n')
check_index = False
for line in lines:
if line.find("SP_daemon -profilerfps") != -1:
check_index = True
assert(check_index == False)
subprocess.run(f'hdc file recv /data/local/tmp/test_hidumper.htrace ../outputfiles/', shell=False,
text=True, encoding="utf-8")
file_size = get_file_size(f"../outputfiles/test_hidumper.htrace")
assert (file_size > 1024)
@pytest.mark.L0
def test_hidump_plugin_section_60(self):
run_and_get_output(
r"hdc file send ..\inputfiles\hidumper_plugin\config_hidumper_60.txt /data/local/tmp/", shell=False,
text=True, encoding="utf-8")
task_thread = threading.Thread(target=task_section_60, args=())
task_thread.start()
subprocess.check_call("hdc shell power-shell wakeup", shell=False)
subprocess.check_call("hdc shell power-shell setmode 602", shell=False)
time.sleep(3)
subprocess.check_call("hdc shell uinput -T -g 100 100 500 500", shell=False)
time.sleep(3)
run_and_get_output(
f"hdc shell uitest uiInput keyEvent Home", shell=False,
text=True, encoding="utf-8")
time.sleep(5)
run_and_get_output(
f"hdc shell uinput -T -c 650 2447", shell=False, text=True, encoding="utf-8")
time.sleep(1)
run_and_get_output(
f"hdc shell uinput -T -c 104 1532", shell=False, text=True, encoding="utf-8")
task_thread.join()
subprocess.run(
r"hdc file recv /data/local/tmp/test_hidumper_60.htrace ..\outputfiles\ ", shell=False,
text=True, encoding="utf-8")
file_size = get_file_size(f"../outputfiles/test_hidumper_60.htrace")
assert (file_size > 1024)
run_and_get_output(
r"../inputfiles/trace_streamer_db.exe ../outputfiles/test_hidumper_60.htrace -e ../outputfiles/test_hidumper_60.db")
conn = sqlite3.connect(r'../outputfiles/test_hidumper_60.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM hidump order by ts limit 0,10')
result = cursor.fetchall()
row_count = len(result)
assert(row_count == 0)
@pytest.mark.L0
def test_hidump_plugin_fps(self):
run_and_get_output(f"hdc file send ..\\inputfiles\\hidumper_plugin\\config_hidumper_fps.txt /data/local/tmp/", shell=False,
text=True, encoding="utf-8")
task_thread = threading.Thread(target=task_fps, args=())
task_thread.start()
task_thread.join()
subprocess.run(f'hdc file recv /data/local/tmp/test_hidumper_fps.htrace ../outputfiles/', shell=False,
text=True, encoding="utf-8")
file_size = get_file_size(f"../outputfiles/test_hidumper_fps.htrace")
assert (file_size > 1024)
run_and_get_output(
r"../inputfiles/trace_streamer_db.exe ../outputfiles/test_hidumper_fps.htrace -e ../outputfiles/test_hidumper_fps.db")
conn = sqlite3.connect(r'../outputfiles/test_hidumper_fps.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM hidump order by ts limit 0,10')
result = cursor.fetchall()
row_count = len(result)
assert(row_count > 0)
for row in result:
assert(row[2] == 0)
cursor.close()
conn.close()