Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved. |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 3 | |
| 4 | # Test basic shell functionality, such as commands separate by semi-colons. |
| 5 | |
Michal Simek | e710ab7 | 2017-05-15 14:29:02 +0200 | [diff] [blame] | 6 | import pytest |
| 7 | |
| 8 | pytestmark = pytest.mark.buildconfigspec('cmd_echo') |
| 9 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 10 | def test_shell_execute(ubman): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 11 | """Test any shell command.""" |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 12 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 13 | response = ubman.run_command('echo hello') |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 14 | assert response.strip() == 'hello' |
| 15 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 16 | def test_shell_semicolon_two(ubman): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 17 | """Test two shell commands separate by a semi-colon.""" |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 18 | |
| 19 | cmd = 'echo hello; echo world' |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 20 | response = ubman.run_command(cmd) |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 21 | # This validation method ignores the exact whitespace between the strings |
| 22 | assert response.index('hello') < response.index('world') |
| 23 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 24 | def test_shell_semicolon_three(ubman): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 25 | """Test three shell commands separate by a semi-colon, with variable |
| 26 | expansion dependencies between them.""" |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 27 | |
| 28 | cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \ |
| 29 | 'echo ${list}' |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 30 | response = ubman.run_command(cmd) |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 31 | assert response.strip() == '123' |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 32 | ubman.run_command('setenv list') |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 33 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 34 | def test_shell_run(ubman): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 35 | """Test the "run" shell command.""" |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 36 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 37 | 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 Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 40 | assert response.strip() == '1' |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 41 | response = ubman.run_command('echo ${python}') |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 42 | assert response.strip() == '2' |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 43 | ubman.run_command('setenv foo') |
| 44 | ubman.run_command('setenv monty') |
| 45 | ubman.run_command('setenv python') |