blob: 97e22af5da56fa0185fd85a5f787192380828ab8 [file] [log] [blame]
Stephen Warren9367d4d2016-01-15 11:15:28 -07001# SPDX-License-Identifier: GPL-2.0
Tom Rini10e47792018-05-06 17:58:06 -04002# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
Stephen Warren9367d4d2016-01-15 11:15:28 -07003
4# Test basic shell functionality, such as commands separate by semi-colons.
5
Michal Simeke710ab72017-05-15 14:29:02 +02006import pytest
7
8pytestmark = pytest.mark.buildconfigspec('cmd_echo')
9
Simon Glassddba5202025-02-09 09:07:14 -070010def test_shell_execute(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -070011 """Test any shell command."""
Stephen Warren9367d4d2016-01-15 11:15:28 -070012
Simon Glassddba5202025-02-09 09:07:14 -070013 response = ubman.run_command('echo hello')
Stephen Warren9367d4d2016-01-15 11:15:28 -070014 assert response.strip() == 'hello'
15
Simon Glassddba5202025-02-09 09:07:14 -070016def test_shell_semicolon_two(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -070017 """Test two shell commands separate by a semi-colon."""
Stephen Warren9367d4d2016-01-15 11:15:28 -070018
19 cmd = 'echo hello; echo world'
Simon Glassddba5202025-02-09 09:07:14 -070020 response = ubman.run_command(cmd)
Stephen Warren9367d4d2016-01-15 11:15:28 -070021 # This validation method ignores the exact whitespace between the strings
22 assert response.index('hello') < response.index('world')
23
Simon Glassddba5202025-02-09 09:07:14 -070024def test_shell_semicolon_three(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -070025 """Test three shell commands separate by a semi-colon, with variable
26 expansion dependencies between them."""
Stephen Warren9367d4d2016-01-15 11:15:28 -070027
28 cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \
29 'echo ${list}'
Simon Glassddba5202025-02-09 09:07:14 -070030 response = ubman.run_command(cmd)
Stephen Warren9367d4d2016-01-15 11:15:28 -070031 assert response.strip() == '123'
Simon Glassddba5202025-02-09 09:07:14 -070032 ubman.run_command('setenv list')
Stephen Warren9367d4d2016-01-15 11:15:28 -070033
Simon Glassddba5202025-02-09 09:07:14 -070034def test_shell_run(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -070035 """Test the "run" shell command."""
Stephen Warren9367d4d2016-01-15 11:15:28 -070036
Simon Glassddba5202025-02-09 09:07:14 -070037 ubman.run_command('setenv foo \'setenv monty 1; setenv python 2\'')
38 ubman.run_command('run foo')
39 response = ubman.run_command('echo ${monty}')
Stephen Warren9367d4d2016-01-15 11:15:28 -070040 assert response.strip() == '1'
Simon Glassddba5202025-02-09 09:07:14 -070041 response = ubman.run_command('echo ${python}')
Stephen Warren9367d4d2016-01-15 11:15:28 -070042 assert response.strip() == '2'
Simon Glassddba5202025-02-09 09:07:14 -070043 ubman.run_command('setenv foo')
44 ubman.run_command('setenv monty')
45 ubman.run_command('setenv python')