import pytest
import subprocess
import re
import time
import os
import threading
import sqlite3
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(
r'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_xpower.txt -o /data/local/tmp/test_xpower.htrace -t 30 -s -k"')
def task_total():
run_and_get_output(
r'hdc shell "hiprofiler_cmd -c /data/local/tmp/config_xpower_total.txt -o /data/local/tmp/test_xpower_total.htrace -t 35 -s -k"')
class TestHiprofilerXPowerPlugin:
@pytest.mark.L0
def test_xpowerplugin_app(self):
run_and_get_output(
r"hdc file send ..\inputfiles\xpower_plugin\config_xpower.txt /data/local/tmp/", shell=False,
text=True, encoding="utf-8")
task_thread = threading.Thread(target=task, args=())
task_thread.start()
task_thread.join()
run_and_get_output(
r"hdc file recv /data/local/tmp/test_xpower.htrace ../outputfiles/ ", shell=False,
text=True, encoding="utf-8")
file_size = get_file_size(f"../outputfiles/test_xpower.htrace")
assert (file_size > 1024)
run_and_get_output(
r"../inputfiles/trace_streamer_db.exe ../outputfiles/test_xpower.htrace -e ../outputfiles/test_xpower.db")
conn = sqlite3.connect(r'../outputfiles/test_xpower.db')
cursor = conn.cursor()
cursor.execute("select end_ts - start_ts as time from trace_range")
result = cursor.fetchall()
for row in result:
assert(row[0] == 27 * 1000 * 1000 * 1000)
cursor.execute("select count(0) from xpower_measure")
result = cursor.fetchall()
for row in result:
assert(row[0] > 0)
cursor.execute("select * from xpower_measure where filter_id = 0 order by ts limit 0,10")
result = cursor.fetchall()
for row in result:
assert(row[3] > 0)
cursor.execute("select * from xpower_measure where filter_id = 2 order by ts limit 0,10")
result = cursor.fetchall()
for row in result:
assert(row[3] > 0)
cursor.close()
conn.close()
@pytest.mark.L0
def test_xpowerplugin_total(self):
run_and_get_output(
r"hdc file send ..\inputfiles\xpower_plugin\config_xpower_total.txt /data/local/tmp/", shell=False,
text=True, encoding="utf-8")
task_thread = threading.Thread(target=task_total, args=())
task_thread.start()
task_thread.join()
run_and_get_output(
r"hdc file recv /data/local/tmp/test_xpower_total.htrace ../outputfiles/ ", shell=False,
text=True, encoding="utf-8")
file_size = get_file_size(f"../outputfiles/test_xpower_total.htrace")
assert (file_size > 1024)
run_and_get_output(
r"../inputfiles/trace_streamer_db.exe ../outputfiles/test_xpower_total.htrace -e ../outputfiles/test_xpower_total.db")
conn = sqlite3.connect(r'../outputfiles/test_xpower_total.db')
cursor = conn.cursor()
cursor.execute("select end_ts - start_ts as time from trace_range")
result = cursor.fetchall()
for row in result:
assert(row[0] == 33 * 1000 * 1000 * 1000)
cursor.execute("select count(0) from xpower_measure")
result = cursor.fetchall()
for row in result:
assert(row[0] > 0)
cursor.execute("select * from xpower_measure, measure_filter where filter_id = id and name = 'Battery.Level' limit 0,10")
result = cursor.fetchall()
for row in result:
assert(row[3] > 0)
cursor.execute("select * from xpower_measure, measure_filter where filter_id = id and name = 'ThermalReport.ShellTemp' limit 0,10")
result = cursor.fetchall()
for row in result:
assert(row[3] > 0)
cursor.execute("select * from xpower_measure, measure_filter where filter_id = id and name = 'ThermalReport.ThermalLevel' limit 0,10")
result = cursor.fetchall()
for row in result:
assert(row[3] >= 0)
cursor.close()
conn.close()