From c116f08ee3fc4137b4a0a36484d3a32e785a32c2 Mon Sep 17 00:00:00 2001 From: T Karthik Reddy Date: Tue, 2 Jul 2019 16:30:34 +0530 Subject: [PATCH] test: py: Add py-test case for test command This patch adds py-test case for test command. Signed-off-by: T Karthik Reddy State: pending --- test/py/tests/test_test.py | 94 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 test/py/tests/test_test.py diff --git a/test/py/tests/test_test.py b/test/py/tests/test_test.py new file mode 100644 index 00000000000..ea4e61cf93d --- /dev/null +++ b/test/py/tests/test_test.py @@ -0,0 +1,94 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2019, Xilinx Inc. + +import pytest +import random + +MAX_SIZE = 0x7FFFFFFF + +def test_eq_test(u_boot_console): + val1 = random.randint(0, MAX_SIZE) + output = u_boot_console.run_command('test %d -eq %d && echo "true"' % (val1, val1)) + if not "true" in output: + pytest.fail('test -eq failed') + output = u_boot_console.run_command('test %d -eq %d && echo "true"' % (val1, ~val1)) + if "true" in output: + pytest.fail('test -eq failed') + +def test_neq_test(u_boot_console): + val1 = random.randint(0, MAX_SIZE) + output = u_boot_console.run_command('test %d -ne %d && echo "true"' % (val1, ~val1)) + if not "true" in output: + pytest.fail('test -ne failed') + output = u_boot_console.run_command('test %d -ne %d && echo "true"' % (val1, val1)) + if "true" in output: + pytest.fail('test -ne failed') + +def test_gt_test(u_boot_console): + val1 = 0 + val2 = 0 + while val1 <= val2: + val1 = random.randint(0, MAX_SIZE) + val2 = random.randint(0, MAX_SIZE) +# Test hexa decimal numbers + output = u_boot_console.run_command('test 0x%x -gt 0x%x && echo "true"' % (val1, val2)) + if not "true" in output: + pytest.fail('test -gt failed') +# Test case negative + output = u_boot_console.run_command('test 0x%x -gt 0x%x && echo "true"' % (val2, val1)) + if "true" in output: + pytest.fail('test -gt failed') +# Test decimal numbers + output = u_boot_console.run_command('test %d -gt %d && echo "true"' % (val1, val2)) + if not "true" in output: + pytest.fail('test -gt failed') +#Test case >= + output = u_boot_console.run_command('test 0x%x -ge 0x%x && echo "true"' % (val1, val1)) + if not "true" in output: + pytest.fail('test -ge failed') + +def test_lt_test(u_boot_console): + val1 = 0 + val2 = 0 + while val1 >= val2: + val1 = random.randint(0, MAX_SIZE) + val2 = random.randint(0, MAX_SIZE) +# Test hexa decimal numbers + output = u_boot_console.run_command('test 0x%x -lt 0x%x && echo "true"' % (val1, val2)) + if not "true" in output: + pytest.fail('test -lt failed') +# Negative test case + output = u_boot_console.run_command('test 0x%x -lt 0x%x && echo "true"' % (val2, val1)) + if "true" in output: + pytest.fail('test -lt failed') +# Test decimal numbers + output = u_boot_console.run_command('test %d -lt %d && echo "true"' % (val1, val2)) + if not "true" in output: + pytest.fail('test -lt failed') +# Test case <= + output = u_boot_console.run_command('test 0x%x -le 0x%x && echo "true"' % (val1, val1)) + if not "true" in output: + pytest.fail('test -le failed') + +def test_str_test(u_boot_console): + str1 = "hello" + str2 = "bye" +#str compare test + output = u_boot_console.run_command('test %s > %s && echo "true"' % (str1, str2)) + if not "true" in output: + pytest.fail('test strlen > compare failed') + output = u_boot_console.run_command('test %s < %s && echo "true"' % (str1, str2)) + if "true" in output: + pytest.fail('test strlen < compare failed') + output = u_boot_console.run_command('test %s = %s && echo "true"' % (str1, str1)) + if not "true" in output: + pytest.fail('test strlen = compare failed') + output = u_boot_console.run_command('test %s != %s && echo "true"' % (str1, str2)) + if not "true" in output: + pytest.fail('test strlen != compare failed') + output = u_boot_console.run_command('test -z %s && echo "true"' % (str1)) + if "true" in output: + pytest.fail('test strlen empty failed') + output = u_boot_console.run_command('test -n %s && echo "true"' % (str1)) + if not "true" in output: + pytest.fail('test strlen non empty failed') -- 2.47.3