Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cover smaller genio tests (New) #1060

Merged
merged 10 commits into from
Mar 13, 2024
28 changes: 15 additions & 13 deletions contrib/genio/bin/dvfs_gpu_check_governors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,43 @@

import argparse

GOVERNORS = ['userspace', 'powersave', 'performance', 'simple_ondemand']
print(f'Expected Governos: {GOVERNORS}')
GOVERNORS = ["userspace", "powersave", "performance", "simple_ondemand"]
print(f"Expected Governors: {GOVERNORS}")


def test_sysfs_attrs_read(soc):
fail = 0
mail_type = '13000000.mali'
if soc == 'mt8365':
mail_type = '13040000.mali'
mail_type = "13000000.mali"
if soc == "mt8365":
mail_type = "13040000.mali"
node_path = (
f'/sys/devices/platform/soc/{mail_type}/devfreq/{mail_type}/'
f'available_governors'
f"/sys/devices/platform/soc/{mail_type}/devfreq/{mail_type}/"
f"available_governors"
)

with open(node_path) as f:
for node in f.read().strip().split():
if node not in GOVERNORS:
fail = 1
print(f"Failed: found governor '{node}' out of expextation")
print(
f"Failed: found governor '{node}' out of expectation"
)
return fail


def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'soc',
help='SoC type. e.g mt8395',
choices=['mt8395', 'mt8390', 'mt8365']
"soc",
help="SoC type. e.g mt8395",
choices=["mt8395", "mt8390", "mt8365"],
)
args = parser.parse_args()
ret = test_sysfs_attrs_read(args.soc)
if ret:
exit(1)
print('Pass')
print("Pass")


if __name__ == '__main__':
if __name__ == "__main__":
main()
91 changes: 52 additions & 39 deletions contrib/genio/bin/linux_ccf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
import argparse
import subprocess

PLAINBOX_SESSION_SHARE = os.environ.get('PLAINBOX_SESSION_SHARE')
if not PLAINBOX_SESSION_SHARE:
print("no env var PLAINBOX_SESSION_SHARE")
exit(1)

PLAINBOX_PROVIDER_DATA = os.environ.get('PLAINBOX_PROVIDER_DATA')
if not PLAINBOX_PROVIDER_DATA:
print("no env var PLAINBOX_PROVIDER_DATA")
exit(1)
PLAINBOX_SESSION_SHARE = os.environ.get("PLAINBOX_SESSION_SHARE")
PLAINBOX_PROVIDER_DATA = os.environ.get("PLAINBOX_PROVIDER_DATA")


def runcmd(command):
Expand All @@ -22,61 +15,81 @@ def runcmd(command):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
timeout=1
timeout=1,
)
return ret


def check_env_variables():
if not PLAINBOX_SESSION_SHARE:
print("no env var PLAINBOX_SESSION_SHARE")
exit(1)
if not PLAINBOX_PROVIDER_DATA:
print("no env var PLAINBOX_PROVIDER_DATA")
exit(1)


def test_linux_ccf(soc):
if soc == 'mt8365':
print('mt8365 is not supported')
if soc == "mt8365":
print("mt8365 is not supported")
exit(1)

clk_summary_path = f"{PLAINBOX_SESSION_SHARE}/clk-summary.txt"
cat_ret = runcmd(
[f"cat /sys/kernel/debug/clk/clk_summary | tee {clk_summary_path}"])
[f"cat /sys/kernel/debug/clk/clk_summary | tee {clk_summary_path}"]
)

if cat_ret.returncode:
print(f'Failed: unable to dump clk_summary data to {clk_summary_path}')
print(f"Failed: unable to dump clk_summary data to {clk_summary_path}")
exit(1)
print('Dump /sys/kernel/debug/clk/clk_summary:')
print("Dump /sys/kernel/debug/clk/clk_summary:")
print(cat_ret.stdout)

if soc == 'mt8390':
verify_ret = runcmd([
(
f"verify-mt8188-ccf.sh"
f" -t {PLAINBOX_PROVIDER_DATA}/linux-ccf/mt8188-clk.h"
f" -s {clk_summary_path}"
)
])
elif soc == 'mt8395' or soc == 'mt8195':
verify_ret = runcmd([
(
f"verify-mt8195-ccf.sh"
f" -t {PLAINBOX_PROVIDER_DATA}/linux-ccf/mt8195-clk.h"
f" -s {clk_summary_path}"
)
])
if soc == "mt8390":
verify_ret = runcmd(
[
(
f"verify-mt8188-ccf.sh"
f" -t {PLAINBOX_PROVIDER_DATA}/linux-ccf/mt8188-clk.h"
f" -s {clk_summary_path}"
)
]
)
elif soc == "mt8395" or soc == "mt8195":
verify_ret = runcmd(
[
(
f"verify-mt8195-ccf.sh"
f" -t {PLAINBOX_PROVIDER_DATA}/linux-ccf/mt8195-clk.h"
f" -s {clk_summary_path}"
)
]
)

if verify_ret.returncode:
print(f'Failed: {verify_ret.stdout}')
print(f"Failed: {verify_ret.stdout}")
exit(1)
if verify_ret.stdout.split('\n')[0] \
== '[-] Success, all clocks are mapped !':
print('Test Pass')
if (
verify_ret.stdout.split("\n")[0]
!= "[-] Success, all clocks are mapped !"
):
print(f"Wrong output: {verify_ret.stdout}")
exit(1)

print("Test Pass")


def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'soc',
help='SoC type. e.g mt8395',
choices=['mt8395', 'mt8390']
"soc",
help="SoC type. e.g mt8395",
choices=["mt8395", "mt8195", "mt8390", "mt8390"],
)
args = parser.parse_args()
check_env_variables()
test_linux_ccf(args.soc)


if __name__ == '__main__':
if __name__ == "__main__":
main()
7 changes: 4 additions & 3 deletions contrib/genio/bin/serialcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ def test_uart_by_serialcheck(soc):
38400, 19200, 9600, 4800, 2400, 1200, 600, 300, 110
]

fail = 0
fail = False
for br in available_baudrate:
print('\n' + '*' * 80)
print(f'Testing baudrate: {br}\n')
ret = runcmd([cmd.format(tty_node, file_path, br)])
print(ret.stdout)
if ret.returncode != 0 or ret.stdout.split('\n')[-2] != golden_msg:
fail = 1
fail = True
print('Fail: the output doesn\'t match the golden sample')

raise SystemExit(fail)
kissiel marked this conversation as resolved.
Show resolved Hide resolved
if fail:
raise SystemExit(1)


def main():
Expand Down
5 changes: 3 additions & 2 deletions contrib/genio/bin/spidev_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ def test_spi_content_consistency(platform):
spi_ret = runcmd([cmd])
print(spi_ret.stdout)

packets = spi_ret.stdout.split('\n')
if not len(packets):
if not spi_ret.stdout:
raise SystemExit(
'ERROR: no any output be reported')

packets = spi_ret.stdout.split('\n')
for rx, tx in zip(packets[-2:-1], packets[-3:-2]):
tx_content = tx.split('|')[2]
rx_content = rx.split('|')[2]
Expand Down
55 changes: 55 additions & 0 deletions contrib/genio/tests/test_dvfs_gpu_check_governors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import unittest
from unittest.mock import mock_open, patch
import dvfs_gpu_check_governors as dvfs


class TestDvfsGpuCheckGovernors(unittest.TestCase):

def test_all_expected_governors(self):
# Test when all expected governors are present
governors = "userspace powersave performance simple_ondemand"
with patch("builtins.open", mock_open(read_data=governors)):
result = dvfs.test_sysfs_attrs_read("mt8365")
self.assertEqual(result, 0)

with patch("builtins.open", mock_open(read_data=governors)):
result = dvfs.test_sysfs_attrs_read("mt8364")
self.assertEqual(result, 0)

def test_unexpected_governor(self):
# Test when an unexpected governor is present
governors = "userspace powersave performance unexpected_governor"
with patch("builtins.open", mock_open(read_data=governors)):
result = dvfs.test_sysfs_attrs_read("mt8365")
self.assertEqual(result, 1)

@patch("builtins.open", mock_open(read_data=""))
def test_empty_file(self):
# Test when the file is empty
governors = ""
with patch("builtins.open", mock_open(read_data=governors)):
result = dvfs.test_sysfs_attrs_read("mt8365")
self.assertEqual(result, 0)

@patch("dvfs_gpu_check_governors.test_sysfs_attrs_read")
def test_main(self, mock_attrs_read):
mock_attrs_read.return_value = 0
with patch("sys.argv", ["script_name", "mt8395"]):
result = dvfs.main()
self.assertEqual(mock_attrs_read.call_count, 1)
self.assertEqual(result, None)

@patch("dvfs_gpu_check_governors.test_sysfs_attrs_read")
def test_main_bad_args(self, mock_attrs_read):
with patch("sys.argv", ["script_name", "bad_soc"]):
with self.assertRaises(SystemExit):
dvfs.main()
self.assertEqual(mock_attrs_read.call_count, 0)

@patch("dvfs_gpu_check_governors.test_sysfs_attrs_read")
def test_main_wrong_attrs(self, mock_attrs_read):
mock_attrs_read.return_value = 1
with patch("sys.argv", ["script_name", "mt8395"]):
with self.assertRaises(SystemExit):
dvfs.main()
self.assertEqual(mock_attrs_read.call_count, 1)
Loading
Loading