summaryrefslogtreecommitdiff
path: root/test/py
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2021-11-29 20:00:57 +0300
committerTom Rini <trini@konsulko.com>2021-11-29 20:00:57 +0300
commit2402c93130c09b881f9cc1369459fb49d9fa0f74 (patch)
treeb98fcb4632c62e8693d8ee1acfa3af55c52f634a /test/py
parentc087b5ad974441d1408c028eb7087d86b6d127e9 (diff)
parentade37460a944aed36ae6ee634c4d4a9a22690461 (diff)
downloadu-boot-2402c93130c09b881f9cc1369459fb49d9fa0f74.tar.xz
Merge tag 'v2022.01-rc3' into next
Prepare v2022.01-rc3 Signed-off-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'test/py')
-rw-r--r--test/py/multiplexed_log.py14
-rw-r--r--test/py/tests/test_efi_loader.py10
-rw-r--r--test/py/tests/test_efi_selftest.py6
-rw-r--r--test/py/u_boot_console_exec_attach.py6
-rw-r--r--test/py/u_boot_console_sandbox.py4
-rw-r--r--test/py/u_boot_spawn.py26
-rw-r--r--test/py/u_boot_utils.py25
7 files changed, 49 insertions, 42 deletions
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
index 6688207fb3..5e79075f2e 100644
--- a/test/py/multiplexed_log.py
+++ b/test/py/multiplexed_log.py
@@ -2,8 +2,10 @@
# Copyright (c) 2015 Stephen Warren
# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
-# Generate an HTML-formatted log file containing multiple streams of data,
-# each represented in a well-delineated/-structured fashion.
+"""
+Generate an HTML-formatted log file containing multiple streams of data,
+each represented in a well-delineated/-structured fashion.
+"""
import datetime
import html
@@ -180,7 +182,7 @@ class RunAndLog(object):
raise exception
return output
-class SectionCtxMgr(object):
+class SectionCtxMgr:
"""A context manager for Python's "with" statement, which allows a certain
portion of test code to be logged to a separate section of the log file.
Objects of this type should be created by factory functions in the Logfile
@@ -208,7 +210,7 @@ class SectionCtxMgr(object):
def __exit__(self, extype, value, traceback):
self.log.end_section(self.marker)
-class Logfile(object):
+class Logfile:
"""Generates an HTML-formatted log file containing multiple streams of
data, each represented in a well-delineated/-structured fashion."""
@@ -322,8 +324,8 @@ $(document).ready(function () {
# The set of characters that should be represented as hexadecimal codes in
# the log file.
_nonprint = {ord('%')}
- _nonprint.update({c for c in range(0, 32) if c not in (9, 10)})
- _nonprint.update({c for c in range(127, 256)})
+ _nonprint.update(c for c in range(0, 32) if c not in (9, 10))
+ _nonprint.update(range(127, 256))
def _escape(self, data):
"""Render data format suitable for inclusion in an HTML document.
diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py
index fc8d6b8655..85473a9049 100644
--- a/test/py/tests/test_efi_loader.py
+++ b/test/py/tests/test_efi_loader.py
@@ -6,9 +6,6 @@
# Test efi loader implementation
-import pytest
-import u_boot_utils
-
"""
Note: This test relies on boardenv_* containing configuration values to define
which network environment is available for testing. Without this, the parts
@@ -50,6 +47,9 @@ env__efi_loader_helloworld_file = {
}
"""
+import pytest
+import u_boot_utils
+
net_set_up = False
def test_efi_pre_commands(u_boot_console):
@@ -80,7 +80,7 @@ def test_efi_setup_dhcp(u_boot_console):
env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None)
if not env_vars:
pytest.skip('No DHCP server available')
- return None
+ return
u_boot_console.run_command('setenv autoload no')
output = u_boot_console.run_command('dhcp')
@@ -193,7 +193,7 @@ def test_efi_grub_net(u_boot_console):
check_smbios = u_boot_console.config.env.get('env__efi_loader_check_smbios', False)
if check_smbios:
u_boot_console.wait_for('grub>')
- output = u_boot_console.run_command('lsefisystab', wait_for_prompt=False, wait_for_echo=False)
+ u_boot_console.run_command('lsefisystab', wait_for_prompt=False, wait_for_echo=False)
u_boot_console.wait_for('SMBIOS')
# Then exit cleanly
diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py
index 63218efbc2..0161a6ea24 100644
--- a/test/py/tests/test_efi_selftest.py
+++ b/test/py/tests/test_efi_selftest.py
@@ -73,8 +73,7 @@ def test_efi_selftest_text_input(u_boot_console):
This function calls the text input EFI selftest.
"""
u_boot_console.run_command(cmd='setenv efi_selftest text input')
- output = u_boot_console.run_command(cmd='bootefi selftest',
- wait_for_prompt=False)
+ u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
m = u_boot_console.p.expect([r'To terminate type \'x\''])
if m != 0:
raise Exception('No prompt for \'text input\' test')
@@ -143,8 +142,7 @@ def test_efi_selftest_text_input_ex(u_boot_console):
This function calls the extended text input EFI selftest.
"""
u_boot_console.run_command(cmd='setenv efi_selftest extended text input')
- output = u_boot_console.run_command(cmd='bootefi selftest',
- wait_for_prompt=False)
+ u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
m = u_boot_console.p.expect([r'To terminate type \'CTRL\+x\''])
if m != 0:
raise Exception('No prompt for \'text input\' test')
diff --git a/test/py/u_boot_console_exec_attach.py b/test/py/u_boot_console_exec_attach.py
index 27834b55cd..8dd8cc1230 100644
--- a/test/py/u_boot_console_exec_attach.py
+++ b/test/py/u_boot_console_exec_attach.py
@@ -2,8 +2,10 @@
# Copyright (c) 2015 Stephen Warren
# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
-# Logic to interact with U-Boot running on real hardware, typically via a
-# physical serial port.
+"""
+Logic to interact with U-Boot running on real hardware, typically via a
+physical serial port.
+"""
import sys
from u_boot_spawn import Spawn
diff --git a/test/py/u_boot_console_sandbox.py b/test/py/u_boot_console_sandbox.py
index 836f5a9e2b..7e1eb0e0b4 100644
--- a/test/py/u_boot_console_sandbox.py
+++ b/test/py/u_boot_console_sandbox.py
@@ -2,7 +2,9 @@
# Copyright (c) 2015 Stephen Warren
# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
-# Logic to interact with the sandbox port of U-Boot, running as a sub-process.
+"""
+Logic to interact with the sandbox port of U-Boot, running as a sub-process.
+"""
import time
from u_boot_spawn import Spawn
diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py
index e34cb217e8..7c48d96210 100644
--- a/test/py/u_boot_spawn.py
+++ b/test/py/u_boot_spawn.py
@@ -1,7 +1,9 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
-# Logic to spawn a sub-process and interact with its stdio.
+"""
+Logic to spawn a sub-process and interact with its stdio.
+"""
import os
import re
@@ -9,12 +11,12 @@ import pty
import signal
import select
import time
+import traceback
class Timeout(Exception):
"""An exception sub-class that indicates that a timeout occurred."""
- pass
-class Spawn(object):
+class Spawn:
"""Represents the stdio of a freshly created sub-process. Commands may be
sent to the process, and responses waited for.
@@ -58,14 +60,14 @@ class Spawn(object):
os.execvp(args[0], args)
except:
print('CHILD EXECEPTION:')
- import traceback
traceback.print_exc()
finally:
os._exit(255)
try:
self.poll = select.poll()
- self.poll.register(self.fd, select.POLLIN | select.POLLPRI | select.POLLERR | select.POLLHUP | select.POLLNVAL)
+ self.poll.register(self.fd, select.POLLIN | select.POLLPRI | select.POLLERR |
+ select.POLLHUP | select.POLLNVAL)
except:
self.close()
raise
@@ -106,7 +108,7 @@ class Spawn(object):
elif os.WIFSIGNALED(status):
signum = os.WTERMSIG(status)
self.exit_code = -signum
- self.exit_info = 'signal %d (%s)' % (signum, signal.Signals(signum))
+ self.exit_info = 'signal %d (%s)' % (signum, signal.Signals(signum).name)
self.waited = True
return False, self.exit_code, self.exit_info
@@ -196,13 +198,11 @@ class Spawn(object):
# shouldn't and explain why. This is much more friendly than
# just dying with an I/O error
if err.errno == 5: # Input/output error
- alive, exit_code, info = self.checkalive()
+ alive, _, info = self.checkalive()
if alive:
- raise
- else:
- raise ValueError('U-Boot exited with %s' % info)
- else:
- raise
+ raise err
+ raise ValueError('U-Boot exited with %s' % info)
+ raise err
if self.logfile_read:
self.logfile_read.write(c)
self.buf += c
@@ -227,7 +227,7 @@ class Spawn(object):
"""
os.close(self.fd)
- for i in range(100):
+ for _ in range(100):
if not self.isalive():
break
time.sleep(0.1)
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py
index f44442e0c7..c4fc23aeda 100644
--- a/test/py/u_boot_utils.py
+++ b/test/py/u_boot_utils.py
@@ -1,17 +1,20 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
-# Utility code shared across multiple tests.
+"""
+Utility code shared across multiple tests.
+"""
import hashlib
import inspect
import os
import os.path
-import pytest
+import pathlib
import signal
import sys
import time
import re
+import pytest
def md5sum_data(data):
"""Calculate the MD5 hash of some data.
@@ -48,7 +51,7 @@ def md5sum_file(fn, max_length=None):
data = fh.read(*params)
return md5sum_data(data)
-class PersistentRandomFile(object):
+class PersistentRandomFile:
"""Generate and store information about a persistent file containing
random data."""
@@ -144,7 +147,7 @@ def wait_until_file_open_fails(fn, ignore_errors):
Nothing.
"""
- for i in range(100):
+ for _ in range(100):
fh = attempt_to_open_file(fn)
if not fh:
return
@@ -193,9 +196,9 @@ def run_and_log_expect_exception(u_boot_console, cmd, retcode, msg):
try:
runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
runner.run(cmd)
- except Exception as e:
- assert(retcode == runner.exit_status)
- assert(msg in runner.output)
+ except Exception:
+ assert retcode == runner.exit_status
+ assert msg in runner.output
else:
raise Exception("Expected an exception with retcode %d message '%s',"
"but it was not raised" % (retcode, msg))
@@ -280,17 +283,17 @@ class PersistentFileHelperCtxMgr(object):
if filename_timestamp < self.module_timestamp:
self.log.action('Removing stale generated file ' +
self.filename)
- os.unlink(self.filename)
+ pathlib.Path(self.filename).unlink()
def __exit__(self, extype, value, traceback):
if extype:
try:
- os.path.unlink(self.filename)
- except:
+ pathlib.Path(self.filename).unlink()
+ except Exception:
pass
return
logged = False
- for i in range(20):
+ for _ in range(20):
filename_timestamp = os.path.getmtime(self.filename)
if filename_timestamp > self.module_timestamp:
break