summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/lib/lmb.c5
-rw-r--r--test/print_ut.c18
-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
9 files changed, 72 insertions, 42 deletions
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index b2c2b99ef1..157c26394d 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -12,6 +12,11 @@
#include <test/test.h>
#include <test/ut.h>
+static inline bool lmb_is_nomap(struct lmb_property *m)
+{
+ return m->flags & LMB_NOMAP;
+}
+
static int check_lmb(struct unit_test_state *uts, struct lmb *lmb,
phys_addr_t ram_base, phys_size_t ram_size,
unsigned long num_reserved,
diff --git a/test/print_ut.c b/test/print_ut.c
index 152a8c3334..7b2e7bb152 100644
--- a/test/print_ut.c
+++ b/test/print_ut.c
@@ -31,6 +31,7 @@ static int print_guid(struct unit_test_state *uts)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
};
char str[40];
+ int ret;
sprintf(str, "%pUb", guid);
ut_assertok(strcmp("01020304-0506-0708-090a-0b0c0d0e0f10", str));
@@ -40,6 +41,9 @@ static int print_guid(struct unit_test_state *uts)
ut_assertok(strcmp("04030201-0605-0807-090a-0b0c0d0e0f10", str));
sprintf(str, "%pUL", guid);
ut_assertok(strcmp("04030201-0605-0807-090A-0B0C0D0E0F10", str));
+ ret = snprintf(str, 4, "%pUL", guid);
+ ut_asserteq(0, str[3]);
+ ut_asserteq(36, ret);
return 0;
}
@@ -349,6 +353,20 @@ static int print_itoa(struct unit_test_state *uts)
}
PRINT_TEST(print_itoa, 0);
+static int snprint(struct unit_test_state *uts)
+{
+ char buf[10] = "xxxxxxxxx";
+ int ret;
+
+ ret = snprintf(buf, 4, "%s:%s", "abc", "def");
+ ut_asserteq(0, buf[3]);
+ ut_asserteq(7, ret);
+ ret = snprintf(buf, 4, "%s:%d", "abc", 9999);
+ ut_asserteq(8, ret);
+ return 0;
+}
+PRINT_TEST(snprint, 0);
+
static int print_xtoa(struct unit_test_state *uts)
{
ut_asserteq_str("7f", simple_xtoa(127));
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