blob: f24f9f0d67d9f8ea324d632c3d452c9e062e1bd5 [file] [log] [blame]
Love Kumar44f13682024-01-03 15:59:42 +05301# SPDX-License-Identifier: GPL-2.0
2# (C) Copyright 2023, Advanced Micro Devices, Inc.
3
4import pytest
5
6"""
7Note: This test relies on boardenv_* containing configuration values to define
8the memory test parameters such as start address, memory size, pattern,
9iterations and timeout. This test will be automatically skipped without this.
10
11For example:
12
13# Setup env__memtest to set the start address of the memory range, size of the
14# memory range to test from starting address, pattern to be written to memory,
15# number of test iterations, and expected time to complete the test of mtest
16# command. start address, size, and pattern parameters value should be in hex
17# and rest of the params value should be integer.
18env__memtest = {
19 'start_addr': 0x0,
20 'size': 0x1000,
21 'pattern': 0x0,
22 'iteration': 16,
23 'timeout': 50000,
24}
25"""
26
Simon Glassddba5202025-02-09 09:07:14 -070027def get_memtest_env(ubman):
28 f = ubman.config.env.get("env__memtest", None)
Love Kumar44f13682024-01-03 15:59:42 +053029 if not f:
30 pytest.skip("memtest is not enabled!")
31 else:
Andrew Goodbody159fa1d2025-03-28 16:30:37 +000032 start = hex(f.get("start_addr", 0x0))
33 size = hex(f.get("size", 0x1000))
34 pattern = hex(f.get("pattern", 0x0))
Love Kumar44f13682024-01-03 15:59:42 +053035 iteration = f.get("iteration", 2)
36 timeout = f.get("timeout", 50000)
Andrew Goodbody159fa1d2025-03-28 16:30:37 +000037 end = hex(int(start, 16) + int(size, 16))
Love Kumar44f13682024-01-03 15:59:42 +053038 return start, end, pattern, iteration, timeout
39
40@pytest.mark.buildconfigspec("cmd_memtest")
Simon Glassddba5202025-02-09 09:07:14 -070041def test_memtest_negative(ubman):
Love Kumar44f13682024-01-03 15:59:42 +053042 """Negative testcase where end address is smaller than starting address and
43 pattern is invalid."""
Simon Glassddba5202025-02-09 09:07:14 -070044 start, end, pattern, iteration, timeout = get_memtest_env(ubman)
Love Kumar44f13682024-01-03 15:59:42 +053045 expected_response = "Refusing to do empty test"
Simon Glassddba5202025-02-09 09:07:14 -070046 response = ubman.run_command(
Love Kumar44f13682024-01-03 15:59:42 +053047 f"mtest 2000 1000 {pattern} {hex(iteration)}"
48 )
49 assert expected_response in response
Simon Glassddba5202025-02-09 09:07:14 -070050 output = ubman.run_command("echo $?")
Love Kumar44f13682024-01-03 15:59:42 +053051 assert not output.endswith("0")
Simon Glassddba5202025-02-09 09:07:14 -070052 ubman.run_command(f"mtest {start} {end} 'xyz' {hex(iteration)}")
53 output = ubman.run_command("echo $?")
Love Kumar44f13682024-01-03 15:59:42 +053054 assert not output.endswith("0")
55
56@pytest.mark.buildconfigspec("cmd_memtest")
Simon Glassddba5202025-02-09 09:07:14 -070057def test_memtest_ddr(ubman):
Love Kumar44f13682024-01-03 15:59:42 +053058 """Test that md reads memory as expected, and that memory can be modified
59 using the mw command."""
Simon Glassddba5202025-02-09 09:07:14 -070060 start, end, pattern, iteration, timeout = get_memtest_env(ubman)
Love Kumar44f13682024-01-03 15:59:42 +053061 expected_response = f"Tested {str(iteration)} iteration(s) with 0 errors."
Simon Glassddba5202025-02-09 09:07:14 -070062 with ubman.temporary_timeout(timeout):
63 response = ubman.run_command(
Love Kumar44f13682024-01-03 15:59:42 +053064 f"mtest {start} {end} {pattern} {hex(iteration)}"
65 )
66 assert expected_response in response
Simon Glassddba5202025-02-09 09:07:14 -070067 output = ubman.run_command("echo $?")
Love Kumar44f13682024-01-03 15:59:42 +053068 assert output.endswith("0")