summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorStefano Babic <[email protected]>2021-10-21 13:57:38 +0200
committerStefano Babic <[email protected]>2021-10-21 13:58:13 +0200
commit5fac11e6d5ab350429b8c8ddf47d3d3877ca89d1 (patch)
treea6fd50ca6f8a79b0647469871fa99223a55d8a96 /test
parente03aa34bdf97f96ad478f7a105482d8231b98aa6 (diff)
parent79b8849d4c1e73df2a79a1d5a5f6166d0dd67a12 (diff)
Merge branch 'master' of git://git.denx.de/u-boot
Signed-off-by: Stefano Babic <[email protected]>
Diffstat (limited to 'test')
-rw-r--r--test/compression.c2
-rw-r--r--test/dm/fdtdec.c28
-rw-r--r--test/dm/k210_pll.c36
-rw-r--r--test/dm/nop.c2
-rw-r--r--test/lib/Makefile1
-rw-r--r--test/lib/abuf.c344
-rw-r--r--test/lib/string.c32
-rwxr-xr-xtest/py/test.py5
-rw-r--r--test/py/tests/test_bind.py7
-rw-r--r--test/py/u_boot_spawn.py56
10 files changed, 465 insertions, 48 deletions
diff --git a/test/compression.c b/test/compression.c
index 4cd1be564f3..26d3c80fb5a 100644
--- a/test/compression.c
+++ b/test/compression.c
@@ -9,11 +9,11 @@
#include <gzip.h>
#include <image.h>
#include <log.h>
-#include <lz4.h>
#include <malloc.h>
#include <mapmem.h>
#include <asm/io.h>
+#include <u-boot/lz4.h>
#include <u-boot/zlib.h>
#include <bzlib.h>
diff --git a/test/dm/fdtdec.c b/test/dm/fdtdec.c
index 1f630ea3eee..087d4846da8 100644
--- a/test/dm/fdtdec.c
+++ b/test/dm/fdtdec.c
@@ -28,21 +28,18 @@ static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts)
resv.start = 0x1000;
resv.end = 0x2000;
- ut_assertok(fdtdec_set_carveout(blob, "/a-test",
- "memory-region", 2, "test_resv1",
- &resv));
+ ut_assertok(fdtdec_set_carveout(blob, "/a-test", "memory-region", 2,
+ &resv, "test_resv1", NULL, 0, 0));
resv.start = 0x10000;
resv.end = 0x20000;
- ut_assertok(fdtdec_set_carveout(blob, "/a-test",
- "memory-region", 1, "test_resv2",
- &resv));
+ ut_assertok(fdtdec_set_carveout(blob, "/a-test", "memory-region", 1,
+ &resv, "test_resv2", NULL, 0, 0));
resv.start = 0x100000;
resv.end = 0x200000;
- ut_assertok(fdtdec_set_carveout(blob, "/a-test",
- "memory-region", 0, "test_resv3",
- &resv));
+ ut_assertok(fdtdec_set_carveout(blob, "/a-test", "memory-region", 0,
+ &resv, "test_resv3", NULL, 0, 0));
offset = fdt_path_offset(blob, "/a-test");
ut_assert(offset > 0);
@@ -67,6 +64,7 @@ static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts)
fdt_addr_t addr;
fdt_size_t size;
void *blob;
+ unsigned long flags = FDTDEC_RESERVED_MEMORY_NO_MAP;
int blob_sz, parent, subnode;
uint32_t phandle, phandle1;
@@ -80,8 +78,8 @@ static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts)
/* Insert a memory region in /reserved-memory node */
resv.start = 0x1000;
resv.end = 0x1fff;
- ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region",
- &resv, &phandle, false));
+ ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region", &resv,
+ NULL, 0, &phandle, 0));
/* Test /reserve-memory and its subnode should exist */
parent = fdt_path_offset(blob, "/reserved-memory");
@@ -101,8 +99,8 @@ static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts)
resv.start = 0x2000;
resv.end = 0x2fff;
- ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region1",
- &resv, &phandle1, true));
+ ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region1", &resv,
+ NULL, 0, &phandle1, flags));
subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region1");
ut_assert(subnode > 0);
@@ -118,8 +116,8 @@ static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts)
*/
resv.start = 0x1000;
resv.end = 0x1fff;
- ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region2",
- &resv, &phandle1, false));
+ ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region2", &resv,
+ NULL, 0, &phandle1, 0));
subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region2");
ut_assert(subnode < 0);
diff --git a/test/dm/k210_pll.c b/test/dm/k210_pll.c
index 54764f269c5..f55379f3365 100644
--- a/test/dm/k210_pll.c
+++ b/test/dm/k210_pll.c
@@ -69,27 +69,25 @@ static int dm_test_k210_pll(struct unit_test_state *uts)
&theirs));
ut_asserteq(-EINVAL, k210_pll_calc_config(1500000000, 20000000,
&theirs));
+ ut_asserteq(-EINVAL, k210_pll_calc_config(1750000000, 13300000,
+ &theirs));
/* Verify we get the same output with brute-force */
- ut_assertok(dm_test_k210_pll_calc_config(390000000, 26000000, &ours));
- ut_assertok(k210_pll_calc_config(390000000, 26000000, &theirs));
- ut_assertok(dm_test_k210_pll_compare(&ours, &theirs));
-
- ut_assertok(dm_test_k210_pll_calc_config(26000000, 390000000, &ours));
- ut_assertok(k210_pll_calc_config(26000000, 390000000, &theirs));
- ut_assertok(dm_test_k210_pll_compare(&ours, &theirs));
-
- ut_assertok(dm_test_k210_pll_calc_config(400000000, 26000000, &ours));
- ut_assertok(k210_pll_calc_config(400000000, 26000000, &theirs));
- ut_assertok(dm_test_k210_pll_compare(&ours, &theirs));
-
- ut_assertok(dm_test_k210_pll_calc_config(27000000, 26000000, &ours));
- ut_assertok(k210_pll_calc_config(27000000, 26000000, &theirs));
- ut_assertok(dm_test_k210_pll_compare(&ours, &theirs));
-
- ut_assertok(dm_test_k210_pll_calc_config(26000000, 27000000, &ours));
- ut_assertok(k210_pll_calc_config(26000000, 27000000, &theirs));
- ut_assertok(dm_test_k210_pll_compare(&ours, &theirs));
+#define compare(rate, rate_in) do { \
+ ut_assertok(dm_test_k210_pll_calc_config(rate, rate_in, &ours)); \
+ ut_assertok(k210_pll_calc_config(rate, rate_in, &theirs)); \
+ ut_assertok(dm_test_k210_pll_compare(&ours, &theirs)); \
+} while (0)
+
+ compare(390000000, 26000000);
+ compare(26000000, 390000000);
+ compare(400000000, 26000000);
+ compare(27000000, 26000000);
+ compare(26000000, 27000000);
+ compare(13300000 * 64, 13300000);
+ compare(21250000, 21250000 * 70);
+ compare(21250000, 1750000000);
+ compare(1750000000, 1750000000);
return 0;
}
diff --git a/test/dm/nop.c b/test/dm/nop.c
index 2cd92c52402..75b9e7b6cc0 100644
--- a/test/dm/nop.c
+++ b/test/dm/nop.c
@@ -25,7 +25,7 @@ static int noptest_bind(struct udevice *parent)
const char *bind_flag = ofnode_read_string(ofnode, "bind");
if (bind_flag && (strcmp(bind_flag, "True") == 0))
- lists_bind_fdt(parent, ofnode, &dev, false);
+ lists_bind_fdt(parent, ofnode, &dev, NULL, false);
ofnode = dev_read_next_subnode(ofnode);
}
diff --git a/test/lib/Makefile b/test/lib/Makefile
index 6fd05142510..d244bb431d4 100644
--- a/test/lib/Makefile
+++ b/test/lib/Makefile
@@ -3,6 +3,7 @@
# (C) Copyright 2018
# Mario Six, Guntermann & Drunck GmbH, [email protected]
obj-y += cmd_ut_lib.o
+obj-y += abuf.o
obj-$(CONFIG_EFI_LOADER) += efi_device_path.o
obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o
obj-y += hexdump.o
diff --git a/test/lib/abuf.c b/test/lib/abuf.c
new file mode 100644
index 00000000000..086c9b22821
--- /dev/null
+++ b/test/lib/abuf.c
@@ -0,0 +1,344 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#include <common.h>
+#include <abuf.h>
+#include <mapmem.h>
+#include <test/lib.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static char test_data[] = "1234";
+#define TEST_DATA_LEN sizeof(test_data)
+
+/* Test abuf_set() */
+static int lib_test_abuf_set(struct unit_test_state *uts)
+{
+ struct abuf buf;
+ ulong start;
+
+ start = ut_check_free();
+
+ abuf_init(&buf);
+ abuf_set(&buf, test_data, TEST_DATA_LEN);
+ ut_asserteq_ptr(test_data, buf.data);
+ ut_asserteq(TEST_DATA_LEN, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ /* Force it to allocate */
+ ut_asserteq(true, abuf_realloc(&buf, TEST_DATA_LEN + 1));
+ ut_assertnonnull(buf.data);
+ ut_asserteq(TEST_DATA_LEN + 1, buf.size);
+ ut_asserteq(true, buf.alloced);
+
+ /* Now set it again, to force it to free */
+ abuf_set(&buf, test_data, TEST_DATA_LEN);
+ ut_asserteq_ptr(test_data, buf.data);
+ ut_asserteq(TEST_DATA_LEN, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ /* Check for memory leaks */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_abuf_set, 0);
+
+/* Test abuf_map_sysmem() */
+static int lib_test_abuf_map_sysmem(struct unit_test_state *uts)
+{
+ struct abuf buf;
+ ulong addr;
+
+ abuf_init(&buf);
+ addr = 0x100;
+ abuf_map_sysmem(&buf, addr, TEST_DATA_LEN);
+
+ ut_asserteq_ptr(map_sysmem(0x100, 0), buf.data);
+ ut_asserteq(TEST_DATA_LEN, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ return 0;
+}
+LIB_TEST(lib_test_abuf_map_sysmem, 0);
+
+/* Test abuf_realloc() */
+static int lib_test_abuf_realloc(struct unit_test_state *uts)
+{
+ struct abuf buf;
+ ulong start;
+ void *ptr;
+
+ /*
+ * TODO: crashes on sandbox sometimes due to an apparent bug in
+ * realloc().
+ */
+ return 0;
+
+ start = ut_check_free();
+
+ abuf_init(&buf);
+
+ /* Allocate an empty buffer */
+ ut_asserteq(true, abuf_realloc(&buf, 0));
+ ut_assertnull(buf.data);
+ ut_asserteq(0, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ /* Allocate a non-empty abuf */
+ ut_asserteq(true, abuf_realloc(&buf, TEST_DATA_LEN));
+ ut_assertnonnull(buf.data);
+ ut_asserteq(TEST_DATA_LEN, buf.size);
+ ut_asserteq(true, buf.alloced);
+ ptr = buf.data;
+
+ /*
+ * Make it smaller; the pointer should remain the same. Note this relies
+ * on knowledge of how U-Boot's realloc() works
+ */
+ ut_asserteq(true, abuf_realloc(&buf, TEST_DATA_LEN - 1));
+ ut_asserteq(TEST_DATA_LEN - 1, buf.size);
+ ut_asserteq(true, buf.alloced);
+ ut_asserteq_ptr(ptr, buf.data);
+
+ /*
+ * Make it larger, forcing reallocation. Note this relies on knowledge
+ * of how U-Boot's realloc() works
+ */
+ ut_asserteq(true, abuf_realloc(&buf, 0x1000));
+ ut_assert(buf.data != ptr);
+ ut_asserteq(0x1000, buf.size);
+ ut_asserteq(true, buf.alloced);
+
+ /* Free it */
+ ut_asserteq(true, abuf_realloc(&buf, 0));
+ ut_assertnull(buf.data);
+ ut_asserteq(0, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ /* Check for memory leaks */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_abuf_realloc, 0);
+
+/* Test handling of buffers that are too large */
+static int lib_test_abuf_large(struct unit_test_state *uts)
+{
+ struct abuf buf;
+ ulong start;
+ size_t size;
+ int delta;
+ void *ptr;
+
+ /*
+ * This crashes at present due to trying to allocate more memory than
+ * available, which breaks something on sandbox.
+ */
+ return 0;
+
+ start = ut_check_free();
+
+ /* Try an impossible size */
+ abuf_init(&buf);
+ ut_asserteq(false, abuf_realloc(&buf, CONFIG_SYS_MALLOC_LEN));
+ ut_assertnull(buf.data);
+ ut_asserteq(0, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ abuf_uninit(&buf);
+ ut_assertnull(buf.data);
+ ut_asserteq(0, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ /* Start with a normal size then try to increase it, to check realloc */
+ ut_asserteq(true, abuf_realloc(&buf, TEST_DATA_LEN));
+ ut_assertnonnull(buf.data);
+ ut_asserteq(TEST_DATA_LEN, buf.size);
+ ut_asserteq(true, buf.alloced);
+ ptr = buf.data;
+ delta = ut_check_delta(start);
+ ut_assert(delta > 0);
+
+ /* try to increase it */
+ ut_asserteq(false, abuf_realloc(&buf, CONFIG_SYS_MALLOC_LEN));
+ ut_asserteq_ptr(ptr, buf.data);
+ ut_asserteq(TEST_DATA_LEN, buf.size);
+ ut_asserteq(true, buf.alloced);
+ ut_asserteq(delta, ut_check_delta(start));
+
+ /* Check for memory leaks */
+ abuf_uninit(&buf);
+ ut_assertok(ut_check_delta(start));
+
+ /* Start with a huge unallocated buf and try to move it */
+ abuf_init(&buf);
+ abuf_map_sysmem(&buf, 0, CONFIG_SYS_MALLOC_LEN);
+ ut_asserteq(CONFIG_SYS_MALLOC_LEN, buf.size);
+ ut_asserteq(false, buf.alloced);
+ ut_assertnull(abuf_uninit_move(&buf, &size));
+
+ /* Check for memory leaks */
+ abuf_uninit(&buf);
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_abuf_large, 0);
+
+/* Test abuf_uninit_move() */
+static int lib_test_abuf_uninit_move(struct unit_test_state *uts)
+{
+ void *ptr, *orig_ptr;
+ struct abuf buf;
+ size_t size;
+ ulong start;
+ int delta;
+
+ start = ut_check_free();
+
+ /*
+ * TODO: crashes on sandbox sometimes due to an apparent bug in
+ * realloc().
+ */
+ return 0;
+
+ /* Move an empty buffer */
+ abuf_init(&buf);
+ ut_assertnull(abuf_uninit_move(&buf, &size));
+ ut_asserteq(0, size);
+ ut_assertnull(abuf_uninit_move(&buf, NULL));
+
+ /* Move an unallocated buffer */
+ abuf_set(&buf, test_data, TEST_DATA_LEN);
+ ut_assertok(ut_check_delta(start));
+ ptr = abuf_uninit_move(&buf, &size);
+ ut_asserteq(TEST_DATA_LEN, size);
+ ut_asserteq_str(ptr, test_data);
+ ut_assertnonnull(ptr);
+ ut_assertnull(buf.data);
+ ut_asserteq(0, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ /* Check that freeing it frees the only allocation */
+ delta = ut_check_delta(start);
+ ut_assert(delta > 0);
+ free(ptr);
+ ut_assertok(ut_check_delta(start));
+
+ /* Move an allocated buffer */
+ ut_asserteq(true, abuf_realloc(&buf, TEST_DATA_LEN));
+ orig_ptr = buf.data;
+ strcpy(orig_ptr, test_data);
+
+ delta = ut_check_delta(start);
+ ut_assert(delta > 0);
+ ptr = abuf_uninit_move(&buf, &size);
+ ut_asserteq(TEST_DATA_LEN, size);
+ ut_assertnonnull(ptr);
+ ut_asserteq_ptr(ptr, orig_ptr);
+ ut_asserteq_str(ptr, test_data);
+ ut_assertnull(buf.data);
+ ut_asserteq(0, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ /* Check there was no new allocation */
+ ut_asserteq(delta, ut_check_delta(start));
+
+ /* Check that freeing it frees the only allocation */
+ free(ptr);
+ ut_assertok(ut_check_delta(start));
+
+ /* Move an unallocated buffer, without the size */
+ abuf_set(&buf, test_data, TEST_DATA_LEN);
+ ut_assertok(ut_check_delta(start));
+ ptr = abuf_uninit_move(&buf, NULL);
+ ut_asserteq_str(ptr, test_data);
+
+ return 0;
+}
+LIB_TEST(lib_test_abuf_uninit_move, 0);
+
+/* Test abuf_uninit() */
+static int lib_test_abuf_uninit(struct unit_test_state *uts)
+{
+ struct abuf buf;
+
+ /* Nothing in the buffer */
+ abuf_init(&buf);
+ abuf_uninit(&buf);
+ ut_assertnull(buf.data);
+ ut_asserteq(0, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ /* Not allocated */
+ abuf_set(&buf, test_data, TEST_DATA_LEN);
+ abuf_uninit(&buf);
+ ut_assertnull(buf.data);
+ ut_asserteq(0, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ return 0;
+}
+LIB_TEST(lib_test_abuf_uninit, 0);
+
+/* Test abuf_init_set() */
+static int lib_test_abuf_init_set(struct unit_test_state *uts)
+{
+ struct abuf buf;
+
+ abuf_init_set(&buf, test_data, TEST_DATA_LEN);
+ ut_asserteq_ptr(test_data, buf.data);
+ ut_asserteq(TEST_DATA_LEN, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ return 0;
+}
+LIB_TEST(lib_test_abuf_init_set, 0);
+
+/* Test abuf_init_move() */
+static int lib_test_abuf_init_move(struct unit_test_state *uts)
+{
+ struct abuf buf;
+ void *ptr;
+
+ /*
+ * TODO: crashes on sandbox sometimes due to an apparent bug in
+ * realloc().
+ */
+ return 0;
+
+ ptr = strdup(test_data);
+ ut_assertnonnull(ptr);
+
+ free(ptr);
+
+ abuf_init_move(&buf, ptr, TEST_DATA_LEN);
+ ut_asserteq_ptr(ptr, abuf_data(&buf));
+ ut_asserteq(TEST_DATA_LEN, abuf_size(&buf));
+ ut_asserteq(true, buf.alloced);
+
+ return 0;
+}
+LIB_TEST(lib_test_abuf_init_move, 0);
+
+/* Test abuf_init() */
+static int lib_test_abuf_init(struct unit_test_state *uts)
+{
+ struct abuf buf;
+
+ buf.data = &buf;
+ buf.size = 123;
+ buf.alloced = true;
+ abuf_init(&buf);
+ ut_assertnull(buf.data);
+ ut_asserteq(0, buf.size);
+ ut_asserteq(false, buf.alloced);
+
+ return 0;
+}
+LIB_TEST(lib_test_abuf_init, 0);
diff --git a/test/lib/string.c b/test/lib/string.c
index 64234bef36c..5dcf4d6db00 100644
--- a/test/lib/string.c
+++ b/test/lib/string.c
@@ -23,6 +23,8 @@
/* Allow for copying up to 32 bytes */
#define BUFLEN (SWEEP + 33)
+#define TEST_STR "hello"
+
/**
* init_buffer() - initialize buffer
*
@@ -193,3 +195,33 @@ static int lib_memmove(struct unit_test_state *uts)
}
LIB_TEST(lib_memmove, 0);
+
+/** lib_memdup() - unit test for memdup() */
+static int lib_memdup(struct unit_test_state *uts)
+{
+ char buf[BUFLEN];
+ size_t len;
+ char *p, *q;
+
+ /* Zero size should do nothing */
+ p = memdup(NULL, 0);
+ ut_assertnonnull(p);
+ free(p);
+
+ p = memdup(buf, 0);
+ ut_assertnonnull(p);
+ free(p);
+
+ strcpy(buf, TEST_STR);
+ len = sizeof(TEST_STR);
+ p = memdup(buf, len);
+ ut_asserteq_mem(p, buf, len);
+
+ q = memdup(p, len);
+ ut_asserteq_mem(q, buf, len);
+ free(q);
+ free(p);
+
+ return 0;
+}
+LIB_TEST(lib_memdup, 0);
diff --git a/test/py/test.py b/test/py/test.py
index 285fda54258..95859a66e29 100755
--- a/test/py/test.py
+++ b/test/py/test.py
@@ -17,4 +17,9 @@ if __name__ == '__main__':
# argv; py.test test_directory_name user-supplied-arguments
args = [os.path.dirname(__file__) + '/tests']
args.extend(sys.argv)
+
+ # Use short format by default
+ if not [arg for arg in args if '--tb=' in arg]:
+ args.append('--tb=short')
+
sys.exit(pytest.main(args))
diff --git a/test/py/tests/test_bind.py b/test/py/tests/test_bind.py
index 6703325c0b7..9f234fb6350 100644
--- a/test/py/tests/test_bind.py
+++ b/test/py/tests/test_bind.py
@@ -33,6 +33,13 @@ def test_bind_unbind_with_node(u_boot_console):
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
+ #bind usb_ether driver (which has no compatible) to usb@1 node.
+ ##New entry usb_ether should appear in the dm tree
+ response = u_boot_console.run_command('bind /usb@1 usb_ether')
+ assert response == ''
+ tree = u_boot_console.run_command('dm tree')
+ assert in_tree(tree, 'usb@1', 'ethernet', 'usb_ether', 1, True)
+
#Unbind child #1. No error expected and all devices should be there except for bind-test-child1
response = u_boot_console.run_command('unbind /bind-test/bind-test-child1')
assert response == ''
diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py
index 6991b78cca8..e34cb217e84 100644
--- a/test/py/u_boot_spawn.py
+++ b/test/py/u_boot_spawn.py
@@ -35,6 +35,8 @@ class Spawn(object):
"""
self.waited = False
+ self.exit_code = 0
+ self.exit_info = ''
self.buf = ''
self.output = ''
self.logfile_read = None
@@ -80,25 +82,44 @@ class Spawn(object):
os.kill(self.pid, sig)
- def isalive(self):
+ def checkalive(self):
"""Determine whether the child process is still running.
- Args:
- None.
-
Returns:
- Boolean indicating whether process is alive.
+ tuple:
+ True if process is alive, else False
+ 0 if process is alive, else exit code of process
+ string describing what happened ('' or 'status/signal n')
"""
if self.waited:
- return False
+ return False, self.exit_code, self.exit_info
w = os.waitpid(self.pid, os.WNOHANG)
if w[0] == 0:
- return True
-
+ return True, 0, 'running'
+ status = w[1]
+
+ if os.WIFEXITED(status):
+ self.exit_code = os.WEXITSTATUS(status)
+ self.exit_info = 'status %d' % self.exit_code
+ elif os.WIFSIGNALED(status):
+ signum = os.WTERMSIG(status)
+ self.exit_code = -signum
+ self.exit_info = 'signal %d (%s)' % (signum, signal.Signals(signum))
self.waited = True
- return False
+ return False, self.exit_code, self.exit_info
+
+ def isalive(self):
+ """Determine whether the child process is still running.
+
+ Args:
+ None.
+
+ Returns:
+ Boolean indicating whether process is alive.
+ """
+ return self.checkalive()[0]
def send(self, data):
"""Send data to the sub-process's stdin.
@@ -168,9 +189,20 @@ class Spawn(object):
events = self.poll.poll(poll_maxwait)
if not events:
raise Timeout()
- c = os.read(self.fd, 1024).decode(errors='replace')
- if not c:
- raise EOFError()
+ try:
+ c = os.read(self.fd, 1024).decode(errors='replace')
+ except OSError as err:
+ # With sandbox, try to detect when U-Boot exits when it
+ # 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()
+ if alive:
+ raise
+ else:
+ raise ValueError('U-Boot exited with %s' % info)
+ else:
+ raise
if self.logfile_read:
self.logfile_read.write(c)
self.buf += c