summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/boot/bootflow.c29
-rw-r--r--test/boot/bootm.c3
-rw-r--r--test/cmd/bdinfo.c4
-rw-r--r--test/cmd/wget.c81
-rw-r--r--test/cmd_ut.c2
-rw-r--r--test/common/print.c8
-rw-r--r--test/dm/led.c18
-rw-r--r--test/dm/ofnode.c136
-rw-r--r--test/dm/sysinfo-gpio.c12
-rw-r--r--test/env/cmd_ut_env.c45
-rw-r--r--test/lib/kconfig.c10
-rw-r--r--test/lib/lmb.c92
-rw-r--r--test/lib/str.c8
-rw-r--r--test/py/tests/bootstd/flash1.img.xzbin4924 -> 0 bytes
-rw-r--r--test/py/tests/bootstd/mmc1.img.xzbin4480 -> 0 bytes
-rw-r--r--test/py/tests/bootstd/mmc4.img.xzbin7072 -> 0 bytes
-rw-r--r--test/py/tests/fs_helper.py11
-rw-r--r--test/py/tests/test_fs/conftest.py225
-rw-r--r--test/py/tests/test_mmc.py637
-rw-r--r--test/py/tests/test_trace.py30
-rw-r--r--test/py/tests/test_usb.py29
-rw-r--r--test/py/tests/test_ut.py294
-rw-r--r--test/py/tests/test_zynqmp_rpu.py84
-rw-r--r--test/py/u_boot_console_base.py7
24 files changed, 976 insertions, 789 deletions
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index da713d8ed72..e33b08aa8cd 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -1199,8 +1199,8 @@ static int bootflow_cros(struct unit_test_state *uts)
}
BOOTSTD_TEST(bootflow_cros, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT);
-/* Test Android bootmeth */
-static int bootflow_android(struct unit_test_state *uts)
+/* Test Android bootmeth with boot image version 4 */
+static int bootflow_android_image_v4(struct unit_test_state *uts)
{
if (!IS_ENABLED(CONFIG_BOOTMETH_ANDROID))
return -EAGAIN;
@@ -1220,7 +1220,30 @@ static int bootflow_android(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_android, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_android_image_v4, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT);
+
+/* Test Android bootmeth with boot image version 2 */
+static int bootflow_android_image_v2(struct unit_test_state *uts)
+{
+ if (!IS_ENABLED(CONFIG_BOOTMETH_ANDROID))
+ return -EAGAIN;
+
+ ut_assertok(scan_mmc_android_bootdev(uts, "mmc8"));
+ ut_assertok(run_command("bootflow list", 0));
+
+ ut_assert_nextlinen("Showing all");
+ ut_assert_nextlinen("Seq");
+ ut_assert_nextlinen("---");
+ ut_assert_nextlinen(" 0 extlinux");
+ ut_assert_nextlinen(" 1 android ready mmc 0 mmc8.bootdev.whole ");
+ ut_assert_nextlinen("---");
+ ut_assert_skip_to_line("(2 bootflows, 2 valid)");
+
+ ut_assert_console_end();
+
+ return 0;
+}
+BOOTSTD_TEST(bootflow_android_image_v2, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT);
/* Test EFI bootmeth */
static int bootflow_efi(struct unit_test_state *uts)
diff --git a/test/boot/bootm.c b/test/boot/bootm.c
index 52b83f149cb..9455f44884c 100644
--- a/test/boot/bootm.c
+++ b/test/boot/bootm.c
@@ -28,6 +28,7 @@ static int bootm_test_nop(struct unit_test_state *uts)
/* This tests relies on GD_FLG_SILENT not being set */
gd->flags &= ~GD_FLG_SILENT;
+ env_set("silent_linux", NULL);
*buf = '\0';
ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_ALL));
@@ -183,6 +184,7 @@ static int bootm_test_subst(struct unit_test_state *uts)
ut_asserteq(0, bootm_process_cmdline(buf, 22, BOOTM_CL_SUBST));
/* Check multiple substitutions */
+ ut_assertok(env_set("bvar", NULL));
ut_assertok(env_set("var", "abc"));
strcpy(buf, "some${var}thing${bvar}else");
ut_asserteq(0, bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SUBST));
@@ -201,6 +203,7 @@ BOOTM_TEST(bootm_test_subst, 0);
/* Test silent processing in the bootargs variable */
static int bootm_test_silent_var(struct unit_test_state *uts)
{
+ ut_assertok(env_set("var", NULL));
env_set("bootargs", NULL);
ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SUBST));
ut_assertnull(env_get("bootargs"));
diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c
index bb419ab2394..76429485708 100644
--- a/test/cmd/bdinfo.c
+++ b/test/cmd/bdinfo.c
@@ -104,7 +104,7 @@ static int lmb_test_dump_region(struct unit_test_state *uts,
{
struct lmb_region *rgn = lmb_rgn_lst->data;
unsigned long long base, size, end;
- enum lmb_flags flags;
+ u32 flags;
int i;
ut_assert_nextline(" %s.count = %#x", name, lmb_rgn_lst->count);
@@ -131,7 +131,7 @@ static int lmb_test_dump_all(struct unit_test_state *uts)
struct lmb *lmb = lmb_get();
ut_assert_nextline("lmb_dump_all:");
- ut_assertok(lmb_test_dump_region(uts, &lmb->free_mem, "memory"));
+ ut_assertok(lmb_test_dump_region(uts, &lmb->available_mem, "memory"));
ut_assertok(lmb_test_dump_region(uts, &lmb->used_mem, "reserved"));
return 0;
diff --git a/test/cmd/wget.c b/test/cmd/wget.c
index 7570c065a10..b020d20ad70 100644
--- a/test/cmd/wget.c
+++ b/test/cmd/wget.c
@@ -25,8 +25,7 @@
#define SHIFT_TO_TCPHDRLEN_FIELD(x) ((x) << 4)
#define LEN_B_TO_DW(x) ((x) >> 2)
-
-int net_set_ack_options(union tcp_build_pkt *b);
+#define GET_TCP_HDR_LEN_IN_BYTES(x) ((x) >> 2)
static int sb_arp_handler(struct udevice *dev, void *packet,
unsigned int len)
@@ -64,12 +63,14 @@ static int sb_syn_handler(struct udevice *dev, void *packet,
eth_send = (void *)priv->recv_packet_buffer[priv->recv_packets];
memcpy(eth_send->et_dest, eth->et_src, ARP_HLEN);
memcpy(eth_send->et_src, priv->fake_host_hwaddr, ARP_HLEN);
+ priv->irs = ntohl(tcp->tcp_seq);
+ priv->iss = ~priv->irs; /* just to differ from irs */
eth_send->et_protlen = htons(PROT_IP);
tcp_send = (void *)eth_send + ETHER_HDR_SIZE;
tcp_send->tcp_src = tcp->tcp_dst;
tcp_send->tcp_dst = tcp->tcp_src;
- tcp_send->tcp_seq = htonl(0);
- tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + 1);
+ tcp_send->tcp_seq = htonl(priv->iss);
+ tcp_send->tcp_ack = htonl(priv->irs + 1);
tcp_send->tcp_hlen = SHIFT_TO_TCPHDRLEN_FIELD(LEN_B_TO_DW(TCP_HDR_SIZE));
tcp_send->tcp_flags = TCP_SYN | TCP_ACK;
tcp_send->tcp_win = htons(PKTBUFSRX * TCP_MSS >> TCP_SCALE);
@@ -104,13 +105,24 @@ static int sb_ack_handler(struct udevice *dev, void *packet,
void *data;
int pkt_len;
int payload_len = 0;
- const char *payload1 = "HTTP/1.1 200 OK\r\n"
- "Content-Length: 30\r\n\r\n\r\n"
- "<html><body>Hi</body></html>\r\n";
- union tcp_build_pkt *b = (union tcp_build_pkt *)tcp;
- const int recv_payload_len = len - net_set_ack_options(b) - IP_HDR_SIZE - ETHER_HDR_SIZE;
- static int next_seq;
- const int bottom_payload_len = 10;
+ u32 tcp_seq, tcp_ack;
+ int tcp_data_len;
+ const char *payload1 =
+ /* response status line */
+ "HTTP/1.1 200 OK\r\n"
+ /* response header fields */
+ "Date: Mon, 23 Dec 2024 05:18:23 GMT\r\n"
+ "Server: Apache/2.4.62 (Debian)\r\n"
+ "Last-Modified: Mon, 23 Dec 2024 05:04:50 GMT\r\n"
+ "ETag: \"1d-629e8efb09e7b\"\r\n"
+ "Accept-Ranges: bytes\r\n"
+ "Content-Length: 29\r\n"
+ "Connection: close\r\n"
+ "Content-Type: text/html\r\n"
+ /* response header fields end marker */
+ "\r\n"
+ /* file data (for HTTP GET requests) */
+ "<html><body>Hi</body></html>\n";
/* Don't allow the buffer to overrun */
if (priv->recv_packets >= PKTBUFSRX)
@@ -125,35 +137,32 @@ static int sb_ack_handler(struct udevice *dev, void *packet,
tcp_send->tcp_dst = tcp->tcp_src;
data = (void *)tcp_send + IP_TCP_HDR_SIZE;
- if (ntohl(tcp->tcp_seq) == 1 && ntohl(tcp->tcp_ack) == 1 && recv_payload_len == 0) {
- // ignore ACK for three-way handshaking
- return 0;
- } else if (ntohl(tcp->tcp_seq) == 1 && ntohl(tcp->tcp_ack) == 1) {
- // recv HTTP request message and reply top half data
- tcp_send->tcp_seq = htonl(ntohl(tcp->tcp_ack));
- tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + recv_payload_len);
+ tcp_seq = ntohl(tcp->tcp_seq) - priv->irs;
+ tcp_ack = ntohl(tcp->tcp_ack) - priv->iss;
+ tcp_data_len = len - ETHER_HDR_SIZE - IP_HDR_SIZE - GET_TCP_HDR_LEN_IN_BYTES(tcp->tcp_hlen);
- payload_len = strlen(payload1) - bottom_payload_len;
- memcpy(data, payload1, payload_len);
- tcp_send->tcp_flags = TCP_ACK;
+ if (tcp->tcp_flags & TCP_FIN)
+ tcp_data_len++;
- next_seq = ntohl(tcp_send->tcp_seq) + payload_len;
- } else if (ntohl(tcp->tcp_ack) == next_seq) {
- // reply bottom half data
- const int top_payload_len = strlen(payload1) - bottom_payload_len;
+ tcp_send->tcp_seq = htonl(ntohl(tcp->tcp_ack));
+ tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + tcp_data_len);
- tcp_send->tcp_seq = htonl(next_seq);
- tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + recv_payload_len);
+ if (tcp_seq == 1 && tcp_ack == 1) {
+ if (tcp_data_len == 0) {
+ /* no data, wait for GET/HEAD request */
+ return -1;
+ }
- payload_len = bottom_payload_len;
- memcpy(data, payload1 + top_payload_len, payload_len);
+ /* reply to GET/HEAD request */
+ payload_len = strlen(payload1);
+ memcpy(data, payload1, payload_len);
tcp_send->tcp_flags = TCP_ACK;
- } else {
- // close connection
- tcp_send->tcp_seq = htonl(ntohl(tcp->tcp_ack));
- tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + 1);
+ } else if (tcp_ack == 1 + strlen(payload1)) {
payload_len = 0;
tcp_send->tcp_flags = TCP_ACK | TCP_FIN;
+ } else if (tcp_ack == 2 + strlen(payload1)) {
+ payload_len = 0;
+ tcp_send->tcp_flags = TCP_ACK;
}
tcp_send->tcp_hlen = SHIFT_TO_TCPHDRLEN_FIELD(LEN_B_TO_DW(TCP_HDR_SIZE));
@@ -217,14 +226,14 @@ static int net_test_wget(struct unit_test_state *uts)
env_set("ethrotate", "no");
env_set("loadaddr", "0x20000");
ut_assertok(run_command("wget ${loadaddr} 1.1.2.2:/index.html", 0));
- ut_assert_nextline("HTTP/1.1 200 OK");
+ ut_assert_nextline_empty();
ut_assert_nextline("Packets received 5, Transfer Successful");
- ut_assert_nextline("Bytes transferred = 32 (20 hex)");
+ ut_assert_nextline("Bytes transferred = 29 (1d hex)");
sandbox_eth_set_tx_handler(0, NULL);
run_command("md5sum ${loadaddr} ${filesize}", 0);
- ut_assert_nextline("md5 for 00020000 ... 0002001f ==> 234af48e94b0085060249ecb5942ab57");
+ ut_assert_nextline("md5 for 00020000 ... 0002001c ==> 847d5e7320a27462e90bc1ed75eb8cd8");
ut_assert_console_end();
env_set("ethact", prev_ethact);
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 195b7ea50ac..a14dbf4ca5e 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -104,10 +104,12 @@ static struct cmd_tbl cmd_ut_sub[] = {
"", ""),
#endif
#ifdef CONFIG_SANDBOX
+#if CONFIG_IS_ENABLED(BLOBLIST)
U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist,
"", ""),
U_BOOT_CMD_MKENT(bootm, CONFIG_SYS_MAXARGS, 1, do_ut_bootm, "", ""),
#endif
+#endif
#ifdef CONFIG_CMD_ADDRMAP
U_BOOT_CMD_MKENT(addrmap, CONFIG_SYS_MAXARGS, 1, do_ut_addrmap, "", ""),
#endif
diff --git a/test/common/print.c b/test/common/print.c
index 464e425edee..e3711b10809 100644
--- a/test/common/print.c
+++ b/test/common/print.c
@@ -241,7 +241,7 @@ COMMON_TEST(print_display_buffer, UTF_CONSOLE);
static int print_hexdump_line(struct unit_test_state *uts)
{
- char *linebuf;
+ u8 *linebuf;
u8 *buf;
int i;
@@ -254,10 +254,10 @@ static int print_hexdump_line(struct unit_test_state *uts)
linebuf = map_sysmem(0x400, BUF_SIZE);
memset(linebuf, '\xff', BUF_SIZE);
ut_asserteq(-ENOSPC, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 75));
- ut_asserteq(-1, linebuf[0]);
+ ut_asserteq(0xff, linebuf[0]);
ut_asserteq(0x10, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 76));
- ut_asserteq(0, linebuf[75]);
- ut_asserteq(-1, linebuf[76]);
+ ut_asserteq('\0', linebuf[75]);
+ ut_asserteq(0xff, linebuf[76]);
unmap_sysmem(buf);
diff --git a/test/dm/led.c b/test/dm/led.c
index 884f6410b70..e5b86326c3a 100644
--- a/test/dm/led.c
+++ b/test/dm/led.c
@@ -144,7 +144,7 @@ static int dm_test_led_boot(struct unit_test_state *uts)
{
struct udevice *dev
- /* options/u-boot/boot-led is set to "sandbox:green" */
+ /* options/u-boot/boot-led is set to phandle to "sandbox:green" */
ut_assertok(led_get_by_label("sandbox:green", &dev));
ut_asserteq(LEDST_OFF, led_get_state(dev));
ut_assertok(led_boot_on());
@@ -154,14 +154,15 @@ static int dm_test_led_boot(struct unit_test_state *uts)
return 0;
}
+DM_TEST(dm_test_led_boot, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test LED boot blink fallback */
#ifndef CONFIG_LED_BLINK
-static int dm_test_led_boot(struct unit_test_state *uts)
+static int dm_test_led_boot_blink(struct unit_test_state *uts)
{
struct udevice *dev
- /* options/u-boot/boot-led is set to "sandbox:green" */
+ /* options/u-boot/boot-led is set to phandle to "sandbox:green" */
ut_assertok(led_get_by_label("sandbox:green", &dev));
ut_asserteq(LEDST_OFF, led_get_state(dev));
ut_assertok(led_boot_blink());
@@ -171,16 +172,17 @@ static int dm_test_led_boot(struct unit_test_state *uts)
return 0;
}
+DM_TEST(dm_test_led_boot_blink, UTF_SCAN_PDATA | UTF_SCAN_FDT);
#endif
#endif
/* Test LED activity */
#ifdef CONFIG_LED_ACTIVITY
-static int dm_test_led_boot(struct unit_test_state *uts)
+static int dm_test_led_activity(struct unit_test_state *uts)
{
struct udevice *dev
- /* options/u-boot/activity-led is set to "sandbox:red" */
+ /* options/u-boot/activity-led is set to phandle to "sandbox:red" */
ut_assertok(led_get_by_label("sandbox:red", &dev));
ut_asserteq(LEDST_OFF, led_get_state(dev));
ut_assertok(led_activity_on());
@@ -190,14 +192,15 @@ static int dm_test_led_boot(struct unit_test_state *uts)
return 0;
}
+DM_TEST(dm_test_led_activity, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test LED activity blink fallback */
#ifndef CONFIG_LED_BLINK
-static int dm_test_led_boot(struct unit_test_state *uts)
+static int dm_test_led_activityt_blink(struct unit_test_state *uts)
{
struct udevice *dev
- /* options/u-boot/activity-led is set to "sandbox:red" */
+ /* options/u-boot/activity-led is set to phandle to "sandbox:red" */
ut_assertok(led_get_by_label("sandbox:red", &dev));
ut_asserteq(LEDST_OFF, led_get_state(dev));
ut_assertok(led_activity_blink());
@@ -207,5 +210,6 @@ static int dm_test_led_boot(struct unit_test_state *uts)
return 0;
}
+DM_TEST(dm_test_led_activityt_blink, UTF_SCAN_PDATA | UTF_SCAN_FDT);
#endif
#endif
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index ce996567c3c..f16b643fa3f 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -141,9 +141,16 @@ static int dm_test_ofnode_get_by_phandle_ot(struct unit_test_state *uts)
{
oftree otree = get_other_oftree(uts);
ofnode node;
+ u32 idx;
+ int ret;
- ut_assert(ofnode_valid(oftree_get_by_phandle(oftree_default(), 1)));
- node = oftree_get_by_phandle(otree, 1);
+ node = oftree_path(otree, "/node");
+ ut_assert(ofnode_valid(node));
+
+ ret = ofnode_read_u32(node, "other-phandle", &idx);
+ ut_assertok(ret);
+
+ node = oftree_get_by_phandle(otree, idx);
ut_assert(ofnode_valid(node));
ut_asserteq_str("target", ofnode_get_name(node));
@@ -273,15 +280,16 @@ static int dm_test_ofnode_read_ot(struct unit_test_state *uts)
}
DM_TEST(dm_test_ofnode_read_ot, UTF_SCAN_FDT | UTF_OTHER_FDT);
-/* test ofnode_count_/parse_phandle_with_args() */
+/* test ofnode_count_/parse/_phandle_with_args() */
static int dm_test_ofnode_phandle(struct unit_test_state *uts)
{
struct ofnode_phandle_args args;
- ofnode node;
+ ofnode node, phandle, target;
int ret;
const char prop[] = "test-gpios";
const char cell[] = "#gpio-cells";
const char prop2[] = "phandle-value";
+ const char prop3[] = "phandle-nodes";
node = ofnode_path("/a-test");
ut_assert(ofnode_valid(node));
@@ -345,34 +353,117 @@ static int dm_test_ofnode_phandle(struct unit_test_state *uts)
ret = ofnode_parse_phandle_with_args(node, prop2, NULL, 1, 3, &args);
ut_asserteq(-ENOENT, ret);
+ /* Test ofnode_parse_phandle */
+ phandle = ofnode_parse_phandle(node, "missing", 0);
+ ut_assert(ofnode_equal(ofnode_null(), phandle));
+
+ target = ofnode_path("/phandle-node-1");
+ ut_assert(ofnode_valid(target));
+ phandle = ofnode_parse_phandle(node, prop3, 0);
+ ut_assert(ofnode_equal(target, phandle));
+
+ target = ofnode_path("/phandle-node-2");
+ ut_assert(ofnode_valid(target));
+ phandle = ofnode_parse_phandle(node, prop3, 1);
+ ut_assert(ofnode_equal(target, phandle));
+
+ phandle = ofnode_parse_phandle(node, prop3, 3);
+ ut_assert(ofnode_equal(ofnode_null(), phandle));
+
return 0;
}
DM_TEST(dm_test_ofnode_phandle, UTF_SCAN_PDATA | UTF_SCAN_FDT);
-/* test ofnode_count_/parse_phandle_with_args() with 'other' tree */
+/* test oftree_count_/parse/_phandle_with_args() with 'other' tree */
static int dm_test_ofnode_phandle_ot(struct unit_test_state *uts)
{
oftree otree = get_other_oftree(uts);
struct ofnode_phandle_args args;
- ofnode node;
+ ofnode node, phandle, target;
int ret;
+ const char prop[] = "other-test-gpios";
+ const char cell[] = "#gpio-cells";
+ const char prop2[] = "other-phandle-value";
+ const char prop3[] = "other-phandle-nodes";
- node = oftree_path(otree, "/node");
+ node = oftree_path(otree, "/other-a-test");
+ ut_assert(ofnode_valid(node));
- /* Test ofnode_count_phandle_with_args with cell name */
- ret = ofnode_count_phandle_with_args(node, "missing", "#gpio-cells", 0);
+ /* Test oftree_count_phandle_with_args with cell name */
+ ret = oftree_count_phandle_with_args(otree, node, "missing", cell, 0);
+ ut_asserteq(-ENOENT, ret);
+ ret = oftree_count_phandle_with_args(otree, node, prop, "#invalid", 0);
+ ut_asserteq(-EINVAL, ret);
+ ret = oftree_count_phandle_with_args(otree, node, prop, cell, 0);
+ ut_asserteq(5, ret);
+
+ /* Test oftree_parse_phandle_with_args with cell name */
+ ret = oftree_parse_phandle_with_args(otree, node, "missing", cell, 0, 0,
+ &args);
ut_asserteq(-ENOENT, ret);
- ret = ofnode_count_phandle_with_args(node, "target", "#invalid", 0);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, "#invalid", 0, 0,
+ &args);
ut_asserteq(-EINVAL, ret);
- ret = ofnode_count_phandle_with_args(node, "target", "#gpio-cells", 0);
- ut_asserteq(1, ret);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 0, &args);
+ ut_assertok(ret);
+ ut_asserteq(1, args.args_count);
+ ut_asserteq(1, args.args[0]);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 1, &args);
+ ut_assertok(ret);
+ ut_asserteq(1, args.args_count);
+ ut_asserteq(4, args.args[0]);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 2, &args);
+ ut_assertok(ret);
+ ut_asserteq(5, args.args_count);
+ ut_asserteq(5, args.args[0]);
+ ut_asserteq(1, args.args[4]);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 3, &args);
+ ut_asserteq(-ENOENT, ret);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 4, &args);
+ ut_assertok(ret);
+ ut_asserteq(1, args.args_count);
+ ut_asserteq(12, args.args[0]);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 5, &args);
+ ut_asserteq(-ENOENT, ret);
+
+ /* Test oftree_count_phandle_with_args with cell count */
+ ret = oftree_count_phandle_with_args(otree, node, "missing", NULL, 2);
+ ut_asserteq(-ENOENT, ret);
+ ret = oftree_count_phandle_with_args(otree, node, prop2, NULL, 1);
+ ut_asserteq(3, ret);
- ret = ofnode_parse_phandle_with_args(node, "target", "#gpio-cells", 0,
- 0, &args);
+ /* Test oftree_parse_phandle_with_args with cell count */
+ ret = oftree_parse_phandle_with_args(otree, node, prop2, NULL, 1, 0, &args);
ut_assertok(ret);
- ut_asserteq(2, args.args_count);
- ut_asserteq(3, args.args[0]);
- ut_asserteq(4, args.args[1]);
+ ut_asserteq(1, ofnode_valid(args.node));
+ ut_asserteq(1, args.args_count);
+ ut_asserteq(10, args.args[0]);
+ ret = oftree_parse_phandle_with_args(otree, node, prop2, NULL, 1, 1, &args);
+ ut_asserteq(-EINVAL, ret);
+ ret = oftree_parse_phandle_with_args(otree, node, prop2, NULL, 1, 2, &args);
+ ut_assertok(ret);
+ ut_asserteq(1, ofnode_valid(args.node));
+ ut_asserteq(1, args.args_count);
+ ut_asserteq(30, args.args[0]);
+ ret = oftree_parse_phandle_with_args(otree, node, prop2, NULL, 1, 3, &args);
+ ut_asserteq(-ENOENT, ret);
+
+ /* Test oftree_parse_phandle */
+ phandle = oftree_parse_phandle(otree, node, "missing", 0);
+ ut_assert(ofnode_equal(ofnode_null(), phandle));
+
+ target = oftree_path(otree, "/other-phandle-node-1");
+ ut_assert(ofnode_valid(target));
+ phandle = oftree_parse_phandle(otree, node, prop3, 0);
+ ut_assert(ofnode_equal(target, phandle));
+
+ target = oftree_path(otree, "/other-phandle-node-2");
+ ut_assert(ofnode_valid(target));
+ phandle = oftree_parse_phandle(otree, node, prop3, 1);
+ ut_assert(ofnode_equal(target, phandle));
+
+ phandle = oftree_parse_phandle(otree, node, prop3, 3);
+ ut_assert(ofnode_equal(ofnode_null(), phandle));
return 0;
}
@@ -613,6 +704,10 @@ static int dm_test_ofnode_options(struct unit_test_state *uts)
{
u64 bootscr_address, bootscr_offset;
u64 bootscr_flash_offset, bootscr_flash_size;
+ ofnode node, phandle_node, target;
+
+ node = ofnode_path("/options/u-boot");
+ ut_assert(ofnode_valid(node));
ut_assert(!ofnode_options_read_bool("missing"));
ut_assert(ofnode_options_read_bool("testing-bool"));
@@ -623,6 +718,13 @@ static int dm_test_ofnode_options(struct unit_test_state *uts)
ut_assertnull(ofnode_options_read_str("missing"));
ut_asserteq_str("testing", ofnode_options_read_str("testing-str"));
+ ut_asserteq(-EINVAL, ofnode_options_get_by_phandle("missing", &phandle_node));
+
+ target = ofnode_path("/phandle-node-1");
+ ut_assert(ofnode_valid(target));
+ ut_assertok(ofnode_options_get_by_phandle("testing-phandle", &phandle_node));
+ ut_assert(ofnode_equal(target, phandle_node));
+
ut_assertok(ofnode_read_bootscript_address(&bootscr_address,
&bootscr_offset));
ut_asserteq_64(0, bootscr_address);
diff --git a/test/dm/sysinfo-gpio.c b/test/dm/sysinfo-gpio.c
index 155da3b6344..de9483c4291 100644
--- a/test/dm/sysinfo-gpio.c
+++ b/test/dm/sysinfo-gpio.c
@@ -29,9 +29,9 @@ static int dm_test_sysinfo_gpio(struct unit_test_state *uts)
sandbox_gpio_set_flags(gpio, 16, GPIOD_EXT_PULL_DOWN);
sandbox_gpio_set_flags(gpio, 17, 0);
ut_assertok(sysinfo_detect(sysinfo));
- ut_assertok(sysinfo_get_int(sysinfo, SYSINFO_ID_BOARD_MODEL, &val));
+ ut_assertok(sysinfo_get_int(sysinfo, SYSID_BOARD_MODEL, &val));
ut_asserteq(19, val);
- ut_assertok(sysinfo_get_str(sysinfo, SYSINFO_ID_BOARD_MODEL, sizeof(buf),
+ ut_assertok(sysinfo_get_str(sysinfo, SYSID_BOARD_MODEL, sizeof(buf),
buf));
ut_asserteq_str("rev_a", buf);
@@ -43,9 +43,9 @@ static int dm_test_sysinfo_gpio(struct unit_test_state *uts)
sandbox_gpio_set_flags(gpio, 16, GPIOD_EXT_PULL_UP);
sandbox_gpio_set_flags(gpio, 17, GPIOD_EXT_PULL_DOWN);
ut_assertok(sysinfo_detect(sysinfo));
- ut_assertok(sysinfo_get_int(sysinfo, SYSINFO_ID_BOARD_MODEL, &val));
+ ut_assertok(sysinfo_get_int(sysinfo, SYSID_BOARD_MODEL, &val));
ut_asserteq(5, val);
- ut_assertok(sysinfo_get_str(sysinfo, SYSINFO_ID_BOARD_MODEL, sizeof(buf),
+ ut_assertok(sysinfo_get_str(sysinfo, SYSID_BOARD_MODEL, sizeof(buf),
buf));
ut_asserteq_str("foo", buf);
@@ -57,9 +57,9 @@ static int dm_test_sysinfo_gpio(struct unit_test_state *uts)
sandbox_gpio_set_flags(gpio, 16, 0);
sandbox_gpio_set_flags(gpio, 17, GPIOD_EXT_PULL_UP);
ut_assertok(sysinfo_detect(sysinfo));
- ut_assertok(sysinfo_get_int(sysinfo, SYSINFO_ID_BOARD_MODEL, &val));
+ ut_assertok(sysinfo_get_int(sysinfo, SYSID_BOARD_MODEL, &val));
ut_asserteq(15, val);
- ut_assertok(sysinfo_get_str(sysinfo, SYSINFO_ID_BOARD_MODEL, sizeof(buf),
+ ut_assertok(sysinfo_get_str(sysinfo, SYSID_BOARD_MODEL, sizeof(buf),
buf));
ut_asserteq_str("unknown", buf);
diff --git a/test/env/cmd_ut_env.c b/test/env/cmd_ut_env.c
index 4af05764fb8..9f16a978f2a 100644
--- a/test/env/cmd_ut_env.c
+++ b/test/env/cmd_ut_env.c
@@ -14,16 +14,54 @@ static int env_test_env_cmd(struct unit_test_state *uts)
ut_assertok(run_command("setenv non_default_var1 1", 0));
ut_assert_console_end();
- ut_assertok(run_command("setenv non_default_var2 1", 0));
+ ut_assertok(run_command("setenv non_default_var2 2", 0));
ut_assert_console_end();
ut_assertok(run_command("env print non_default_var1", 0));
ut_assert_nextline("non_default_var1=1");
ut_assert_console_end();
- ut_assertok(run_command("env default non_default_var1 non_default_var2", 0));
+ ut_assertok(run_command("env default non_default_var1", 0));
ut_assert_nextline("WARNING: 'non_default_var1' not in imported env, deleting it!");
- ut_assert_nextline("WARNING: 'non_default_var2' not in imported env, deleting it!");
+ ut_assert_console_end();
+
+ ut_asserteq(1, run_command("env exists non_default_var1", 0));
+ ut_assert_console_end();
+
+ ut_asserteq(0, run_command("env exists non_default_var2", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("setenv non_default_var1 3", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("env default -k non_default_var1", 0));
+ ut_assert_console_end();
+
+ ut_asserteq(0, run_command("env exists non_default_var1", 0));
+ ut_assert_console_end();
+
+ ut_asserteq(0, run_command("env exists non_default_var2", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("env default -k -a -f", 0));
+ ut_assert_nextline("## Resetting to default environment");
+ ut_assert_console_end();
+
+ ut_asserteq(0, run_command("env exists non_default_var1", 0));
+ ut_assert_console_end();
+
+ ut_asserteq(0, run_command("env exists non_default_var2", 0));
+ ut_assert_console_end();
+
+ /*
+ * While the following test of "env default -a" by itself
+ * works, it unfortunately causes an unrelated test case,
+ * env_test_fdt_import(), to fail, because the "from_fdt"
+ * variable would be removed.
+ */
+#if 0
+ ut_assertok(run_command("env default -a", 0));
+ ut_assert_nextline("## Resetting to default environment");
ut_assert_console_end();
ut_asserteq(1, run_command("env exists non_default_var1", 0));
@@ -31,6 +69,7 @@ static int env_test_env_cmd(struct unit_test_state *uts)
ut_asserteq(1, run_command("env exists non_default_var2", 0));
ut_assert_console_end();
+#endif
return 0;
}
diff --git a/test/lib/kconfig.c b/test/lib/kconfig.c
index 0c463bb794a..a3645abf946 100644
--- a/test/lib/kconfig.c
+++ b/test/lib/kconfig.c
@@ -21,10 +21,12 @@ static int lib_test_is_enabled(struct unit_test_state *uts)
ut_asserteq(0, CONFIG_IS_ENABLED(OF_PLATDATA));
ut_asserteq(0, CONFIG_IS_ENABLED(_UNDEFINED));
- ut_asserteq(0xb000,
- IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED, CONFIG_BLOBLIST_ADDR));
- ut_asserteq(0xb000,
- CONFIG_IF_ENABLED_INT(BLOBLIST_FIXED, BLOBLIST_ADDR));
+ if (IS_ENABLED(CONFIG_BLOBLIST)) {
+ ut_asserteq(0xb000, IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED,
+ CONFIG_BLOBLIST_ADDR));
+ ut_asserteq(0xb000, CONFIG_IF_ENABLED_INT(BLOBLIST_FIXED,
+ BLOBLIST_ADDR));
+ }
/*
* This fails if CONFIG_TEST_KCONFIG_ENABLE is not enabled, since the
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index 48c3c966f8f..fcb5f1af532 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -65,7 +65,7 @@ static int setup_lmb_test(struct unit_test_state *uts, struct lmb *store,
ut_assertok(lmb_push(store));
lmb = lmb_get();
- *mem_lstp = &lmb->free_mem;
+ *mem_lstp = &lmb->available_mem;
*used_lstp = &lmb->used_mem;
return 0;
@@ -117,7 +117,7 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram,
}
/* reserve 64KiB somewhere */
- ret = lmb_reserve(alloc_64k_addr, 0x10000);
+ ret = lmb_reserve(alloc_64k_addr, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, 0, 0, 1, alloc_64k_addr, 0x10000,
0, 0, 0, 0);
@@ -128,7 +128,7 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram,
ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr, 0x10000,
ram_end - 4, 4, 0, 0);
/* alloc below end of reserved region -> below reserved region */
- b = lmb_alloc_base(4, 1, alloc_64k_end);
+ b = lmb_alloc_base(4, 1, alloc_64k_end, LMB_NONE);
ut_asserteq(b, alloc_64k_addr - 4);
ASSERT_LMB(mem_lst, used_lst, 0, 0, 2,
alloc_64k_addr - 4, 0x10000 + 4, ram_end - 4, 4, 0, 0);
@@ -138,7 +138,7 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram,
ut_asserteq(c, ram_end - 8);
ASSERT_LMB(mem_lst, used_lst, 0, 0, 2,
alloc_64k_addr - 4, 0x10000 + 4, ram_end - 8, 8, 0, 0);
- d = lmb_alloc_base(4, 1, alloc_64k_end);
+ d = lmb_alloc_base(4, 1, alloc_64k_end, LMB_NONE);
ut_asserteq(d, alloc_64k_addr - 8);
ASSERT_LMB(mem_lst, used_lst, 0, 0, 2,
alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 8, 0, 0);
@@ -163,7 +163,7 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram,
alloc_64k_addr - 8, 4, alloc_64k_addr, 0x10000,
ram_end - 8, 4);
/* allocate again to ensure we get the same address */
- b2 = lmb_alloc_base(4, 1, alloc_64k_end);
+ b2 = lmb_alloc_base(4, 1, alloc_64k_end, LMB_NONE);
ut_asserteq(b, b2);
ASSERT_LMB(mem_lst, used_lst, 0, 0, 2,
alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 4, 0, 0);
@@ -264,7 +264,7 @@ static int test_bigblock(struct unit_test_state *uts, const phys_addr_t ram)
ut_asserteq(ret, 0);
/* reserve 64KiB in the middle of RAM */
- ret = lmb_reserve(alloc_64k_addr, 0x10000);
+ ret = lmb_reserve(alloc_64k_addr, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, alloc_64k_addr, 0x10000,
0, 0, 0, 0);
@@ -363,7 +363,7 @@ static int test_noreserved(struct unit_test_state *uts, const phys_addr_t ram,
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
/* allocate a block with base*/
- b = lmb_alloc_base(alloc_size, align, ram_end);
+ b = lmb_alloc_base(alloc_size, align, ram_end, LMB_NONE);
ut_assert(a == b);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1,
ram + ram_size - alloc_size_aligned,
@@ -466,35 +466,35 @@ static int lib_test_lmb_overlapping_reserve(struct unit_test_state *uts)
ret = lmb_add(ram, ram_size);
ut_asserteq(ret, 0);
- ret = lmb_reserve(0x40010000, 0x10000);
+ ret = lmb_reserve(0x40010000, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000,
0, 0, 0, 0);
/* allocate overlapping region should return the coalesced count */
- ret = lmb_reserve(0x40011000, 0x10000);
+ ret = lmb_reserve(0x40011000, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x11000,
0, 0, 0, 0);
/* allocate 3nd region */
- ret = lmb_reserve(0x40030000, 0x10000);
+ ret = lmb_reserve(0x40030000, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40010000, 0x11000,
0x40030000, 0x10000, 0, 0);
/* allocate 2nd region , This should coalesced all region into one */
- ret = lmb_reserve(0x40020000, 0x10000);
+ ret = lmb_reserve(0x40020000, 0x10000, LMB_NONE);
ut_assert(ret >= 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x30000,
0, 0, 0, 0);
/* allocate 2nd region, which should be added as first region */
- ret = lmb_reserve(0x40000000, 0x8000);
+ ret = lmb_reserve(0x40000000, 0x8000, LMB_NONE);
ut_assert(ret >= 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x8000,
0x40010000, 0x30000, 0, 0);
/* allocate 3rd region, coalesce with first and overlap with second */
- ret = lmb_reserve(0x40008000, 0x10000);
+ ret = lmb_reserve(0x40008000, 0x10000, LMB_NONE);
ut_assert(ret >= 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40000000, 0x40000,
0, 0, 0, 0);
@@ -530,52 +530,52 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
ut_asserteq(ret, 0);
/* Try to allocate a page twice */
- b = lmb_alloc_addr_flags(alloc_addr_a, 0x1000, LMB_NONE);
+ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE);
ut_asserteq(b, alloc_addr_a);
- b = lmb_alloc_addr_flags(alloc_addr_a, 0x1000, LMB_NOOVERWRITE);
+ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE);
ut_asserteq(b, 0);
- b = lmb_alloc_addr_flags(alloc_addr_a, 0x1000, LMB_NONE);
+ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE);
ut_asserteq(b, alloc_addr_a);
- b = lmb_alloc_addr_flags(alloc_addr_a, 0x2000, LMB_NONE);
+ b = lmb_alloc_addr(alloc_addr_a, 0x2000, LMB_NONE);
ut_asserteq(b, alloc_addr_a);
ret = lmb_free(alloc_addr_a, 0x2000);
ut_asserteq(ret, 0);
- b = lmb_alloc_addr_flags(alloc_addr_a, 0x1000, LMB_NOOVERWRITE);
+ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE);
ut_asserteq(b, alloc_addr_a);
- b = lmb_alloc_addr_flags(alloc_addr_a, 0x1000, LMB_NONE);
+ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE);
ut_asserteq(b, 0);
- b = lmb_alloc_addr_flags(alloc_addr_a, 0x1000, LMB_NOOVERWRITE);
+ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE);
ut_asserteq(b, 0);
ret = lmb_free(alloc_addr_a, 0x1000);
ut_asserteq(ret, 0);
/* reserve 3 blocks */
- ret = lmb_reserve(alloc_addr_a, 0x10000);
+ ret = lmb_reserve(alloc_addr_a, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ret = lmb_reserve(alloc_addr_b, 0x10000);
+ ret = lmb_reserve(alloc_addr_b, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ret = lmb_reserve(alloc_addr_c, 0x10000);
+ ret = lmb_reserve(alloc_addr_c, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, alloc_addr_a, 0x10000,
alloc_addr_b, 0x10000, alloc_addr_c, 0x10000);
/* allocate blocks */
- a = lmb_alloc_addr(ram, alloc_addr_a - ram);
+ a = lmb_alloc_addr(ram, alloc_addr_a - ram, LMB_NONE);
ut_asserteq(a, ram);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, ram, 0x8010000,
alloc_addr_b, 0x10000, alloc_addr_c, 0x10000);
b = lmb_alloc_addr(alloc_addr_a + 0x10000,
- alloc_addr_b - alloc_addr_a - 0x10000);
+ alloc_addr_b - alloc_addr_a - 0x10000, LMB_NONE);
ut_asserteq(b, alloc_addr_a + 0x10000);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x10010000,
alloc_addr_c, 0x10000, 0, 0);
c = lmb_alloc_addr(alloc_addr_b + 0x10000,
- alloc_addr_c - alloc_addr_b - 0x10000);
+ alloc_addr_c - alloc_addr_b - 0x10000, LMB_NONE);
ut_asserteq(c, alloc_addr_b + 0x10000);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000,
0, 0, 0, 0);
d = lmb_alloc_addr(alloc_addr_c + 0x10000,
- ram_end - alloc_addr_c - 0x10000);
+ ram_end - alloc_addr_c - 0x10000, LMB_NONE);
ut_asserteq(d, alloc_addr_c + 0x10000);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, ram_size,
0, 0, 0, 0);
@@ -591,7 +591,7 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
/* allocate at 3 points in free range */
- d = lmb_alloc_addr(ram_end - 4, 4);
+ d = lmb_alloc_addr(ram_end - 4, 4, LMB_NONE);
ut_asserteq(d, ram_end - 4);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x18010000,
d, 4, 0, 0);
@@ -600,7 +600,7 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000,
0, 0, 0, 0);
- d = lmb_alloc_addr(ram_end - 128, 4);
+ d = lmb_alloc_addr(ram_end - 128, 4, LMB_NONE);
ut_asserteq(d, ram_end - 128);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x18010000,
d, 4, 0, 0);
@@ -609,7 +609,7 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000,
0, 0, 0, 0);
- d = lmb_alloc_addr(alloc_addr_c + 0x10000, 4);
+ d = lmb_alloc_addr(alloc_addr_c + 0x10000, 4, LMB_NONE);
ut_asserteq(d, alloc_addr_c + 0x10000);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010004,
0, 0, 0, 0);
@@ -624,18 +624,18 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram + 0x8000000,
0x10010000, 0, 0, 0, 0);
- d = lmb_alloc_addr(ram, 4);
+ d = lmb_alloc_addr(ram, 4, LMB_NONE);
ut_asserteq(d, ram);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, d, 4,
ram + 0x8000000, 0x10010000, 0, 0);
/* check that allocating outside memory fails */
if (ram_end != 0) {
- ret = lmb_alloc_addr(ram_end, 1);
+ ret = lmb_alloc_addr(ram_end, 1, LMB_NONE);
ut_asserteq(ret, 0);
}
if (ram != 0) {
- ret = lmb_alloc_addr(ram - 1, 1);
+ ret = lmb_alloc_addr(ram - 1, 1, LMB_NONE);
ut_asserteq(ret, 0);
}
@@ -680,11 +680,11 @@ static int test_get_unreserved_size(struct unit_test_state *uts,
ut_asserteq(ret, 0);
/* reserve 3 blocks */
- ret = lmb_reserve(alloc_addr_a, 0x10000);
+ ret = lmb_reserve(alloc_addr_a, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ret = lmb_reserve(alloc_addr_b, 0x10000);
+ ret = lmb_reserve(alloc_addr_b, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ret = lmb_reserve(alloc_addr_c, 0x10000);
+ ret = lmb_reserve(alloc_addr_c, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, alloc_addr_a, 0x10000,
alloc_addr_b, 0x10000, alloc_addr_c, 0x10000);
@@ -747,19 +747,19 @@ static int lib_test_lmb_flags(struct unit_test_state *uts)
ut_asserteq(ret, 0);
/* reserve, same flag */
- ret = lmb_reserve_flags(0x40010000, 0x10000, LMB_NOMAP);
+ ret = lmb_reserve(0x40010000, 0x10000, LMB_NOMAP);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000,
0, 0, 0, 0);
/* reserve again, same flag */
- ret = lmb_reserve_flags(0x40010000, 0x10000, LMB_NOMAP);
+ ret = lmb_reserve(0x40010000, 0x10000, LMB_NOMAP);
ut_asserteq(ret, -EEXIST);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000,
0, 0, 0, 0);
/* reserve again, new flag */
- ret = lmb_reserve_flags(0x40010000, 0x10000, LMB_NONE);
+ ret = lmb_reserve(0x40010000, 0x10000, LMB_NONE);
ut_asserteq(ret, -1);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000,
0, 0, 0, 0);
@@ -767,20 +767,20 @@ static int lib_test_lmb_flags(struct unit_test_state *uts)
ut_asserteq(lmb_is_nomap(&used[0]), 1);
/* merge after */
- ret = lmb_reserve_flags(0x40020000, 0x10000, LMB_NOMAP);
+ ret = lmb_reserve(0x40020000, 0x10000, LMB_NOMAP);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x20000,
0, 0, 0, 0);
/* merge before */
- ret = lmb_reserve_flags(0x40000000, 0x10000, LMB_NOMAP);
+ ret = lmb_reserve(0x40000000, 0x10000, LMB_NOMAP);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40000000, 0x30000,
0, 0, 0, 0);
ut_asserteq(lmb_is_nomap(&used[0]), 1);
- ret = lmb_reserve_flags(0x40030000, 0x10000, LMB_NONE);
+ ret = lmb_reserve(0x40030000, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x30000,
0x40030000, 0x10000, 0, 0);
@@ -789,7 +789,7 @@ static int lib_test_lmb_flags(struct unit_test_state *uts)
ut_asserteq(lmb_is_nomap(&used[1]), 0);
/* test that old API use LMB_NONE */
- ret = lmb_reserve(0x40040000, 0x10000);
+ ret = lmb_reserve(0x40040000, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x30000,
0x40030000, 0x20000, 0, 0);
@@ -797,18 +797,18 @@ static int lib_test_lmb_flags(struct unit_test_state *uts)
ut_asserteq(lmb_is_nomap(&used[0]), 1);
ut_asserteq(lmb_is_nomap(&used[1]), 0);
- ret = lmb_reserve_flags(0x40070000, 0x10000, LMB_NOMAP);
+ ret = lmb_reserve(0x40070000, 0x10000, LMB_NOMAP);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, 0x40000000, 0x30000,
0x40030000, 0x20000, 0x40070000, 0x10000);
- ret = lmb_reserve_flags(0x40050000, 0x10000, LMB_NOMAP);
+ ret = lmb_reserve(0x40050000, 0x10000, LMB_NOMAP);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 4, 0x40000000, 0x30000,
0x40030000, 0x20000, 0x40050000, 0x10000);
/* merge with 2 adjacent regions */
- ret = lmb_reserve_flags(0x40060000, 0x10000, LMB_NOMAP);
+ ret = lmb_reserve(0x40060000, 0x10000, LMB_NOMAP);
ut_asserteq(ret, 0);
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, 0x40000000, 0x30000,
0x40030000, 0x20000, 0x40050000, 0x30000);
diff --git a/test/lib/str.c b/test/lib/str.c
index e62045318c0..48351abc756 100644
--- a/test/lib/str.c
+++ b/test/lib/str.c
@@ -224,13 +224,13 @@ static int str_itoa(struct unit_test_state *uts)
ut_asserteq_str("4294967295", simple_itoa(0xffffffff));
/* Use #ifdef here to avoid a compiler warning on 32-bit machines */
-#ifdef CONFIG_PHYS_64BIT
+#ifdef CONFIG_64BIT
if (sizeof(ulong) == 8) {
ut_asserteq_str("9223372036854775807",
simple_itoa((1UL << 63) - 1));
ut_asserteq_str("18446744073709551615", simple_itoa(-1));
}
-#endif /* CONFIG_PHYS_64BIT */
+#endif /* CONFIG_64BIT */
return 0;
}
@@ -244,13 +244,13 @@ static int str_xtoa(struct unit_test_state *uts)
ut_asserteq_str("ffffffff", simple_xtoa(0xffffffff));
/* Use #ifdef here to avoid a compiler warning on 32-bit machines */
-#ifdef CONFIG_PHYS_64BIT
+#ifdef CONFIG_64BIT
if (sizeof(ulong) == 8) {
ut_asserteq_str("7fffffffffffffff",
simple_xtoa((1UL << 63) - 1));
ut_asserteq_str("ffffffffffffffff", simple_xtoa(-1));
}
-#endif /* CONFIG_PHYS_64BIT */
+#endif /* CONFIG_64BIT */
return 0;
}
diff --git a/test/py/tests/bootstd/flash1.img.xz b/test/py/tests/bootstd/flash1.img.xz
deleted file mode 100644
index 29b78c62a9b..00000000000
--- a/test/py/tests/bootstd/flash1.img.xz
+++ /dev/null
Binary files differ
diff --git a/test/py/tests/bootstd/mmc1.img.xz b/test/py/tests/bootstd/mmc1.img.xz
deleted file mode 100644
index cebf7b9c53b..00000000000
--- a/test/py/tests/bootstd/mmc1.img.xz
+++ /dev/null
Binary files differ
diff --git a/test/py/tests/bootstd/mmc4.img.xz b/test/py/tests/bootstd/mmc4.img.xz
deleted file mode 100644
index f4db011969f..00000000000
--- a/test/py/tests/bootstd/mmc4.img.xz
+++ /dev/null
Binary files differ
diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py
index 380f4c4dca3..ccfc0201a49 100644
--- a/test/py/tests/fs_helper.py
+++ b/test/py/tests/fs_helper.py
@@ -9,7 +9,7 @@ import re
import os
from subprocess import call, check_call, check_output, CalledProcessError
-def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
+def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):
"""Create a file system volume
Args:
@@ -17,6 +17,7 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
fs_type (str): File system type, e.g. 'ext4'
size (int): Size of file system in bytes
prefix (str): Prefix string of volume's file name
+ src_dir (str): Root directory to use, or None for none
size_gran (int): Size granularity of file system image in bytes
Raises:
@@ -39,6 +40,12 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
else:
fs_lnxtype = fs_type
+ if src_dir:
+ if fs_lnxtype == 'ext4':
+ mkfs_opt = mkfs_opt + ' -d ' + src_dir
+ elif fs_lnxtype != 'vfat':
+ raise ValueError(f'src_dir not implemented for fs {fs_lnxtype}')
+
count = (size + size_gran - 1) // size_gran
# Some distributions do not add /sbin to the default PATH, where mkfs lives
@@ -55,6 +62,8 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
shell=True).decode()
if 'metadata_csum' in sb_content:
check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True)
+ elif fs_lnxtype == 'vfat' and src_dir:
+ check_call(f'mcopy -i {fs_img} -vsmpQ {src_dir}/* ::/', shell=True)
return fs_img
except CalledProcessError:
call(f'rm -f {fs_img}', shell=True)
diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
index fca54488374..af2adaf1645 100644
--- a/test/py/tests/test_fs/conftest.py
+++ b/test/py/tests/test_fs/conftest.py
@@ -156,64 +156,6 @@ def tool_is_in_path(tool):
return True
return False
-fuse_mounted = False
-
-def mount_fs(fs_type, device, mount_point):
- """Mount a volume.
-
- Args:
- fs_type: File system type.
- device: Volume's file name.
- mount_point: Mount point.
-
- Return:
- Nothing.
- """
- global fuse_mounted
-
- try:
- check_call('guestmount --pid-file guestmount.pid -a %s -m /dev/sda %s'
- % (device, mount_point), shell=True)
- fuse_mounted = True
- return
- except CalledProcessError:
- fuse_mounted = False
-
- mount_opt = 'loop,rw'
- if re.match('fat', fs_type):
- mount_opt += ',umask=0000'
-
- check_call('sudo mount -o %s %s %s'
- % (mount_opt, device, mount_point), shell=True)
-
- # may not be effective for some file systems
- check_call('sudo chmod a+rw %s' % mount_point, shell=True)
-
-def umount_fs(mount_point):
- """Unmount a volume.
-
- Args:
- mount_point: Mount point.
-
- Return:
- Nothing.
- """
- if fuse_mounted:
- call('sync')
- call('guestunmount %s' % mount_point, shell=True)
-
- try:
- with open("guestmount.pid", "r") as pidfile:
- pid = int(pidfile.read())
- util.waitpid(pid, kill=True)
- os.remove("guestmount.pid")
-
- except FileNotFoundError:
- pass
-
- else:
- call('sudo umount %s' % mount_point, shell=True)
-
#
# Fixture for basic fs test
# derived from test/fs/fs-test.sh
@@ -236,38 +178,21 @@ def fs_obj_basic(request, u_boot_config):
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
- mount_dir = u_boot_config.persistent_data_dir + '/mnt'
-
- small_file = mount_dir + '/' + SMALL_FILE
- big_file = mount_dir + '/' + BIG_FILE
+ scratch_dir = u_boot_config.persistent_data_dir + '/scratch'
- try:
-
- # 3GiB volume
- fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB')
- except CalledProcessError as err:
- pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
- return
+ small_file = scratch_dir + '/' + SMALL_FILE
+ big_file = scratch_dir + '/' + BIG_FILE
try:
- check_call('mkdir -p %s' % mount_dir, shell=True)
+ check_call('mkdir -p %s' % scratch_dir, shell=True)
except CalledProcessError as err:
pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err))
call('rm -f %s' % fs_img, shell=True)
return
try:
- # Mount the image so we can populate it.
- mount_fs(fs_type, fs_img, mount_dir)
- except CalledProcessError as err:
- pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err))
- call('rmdir %s' % mount_dir, shell=True)
- call('rm -f %s' % fs_img, shell=True)
- return
-
- try:
# Create a subdirectory.
- check_call('mkdir %s/SUBDIR' % mount_dir, shell=True)
+ check_call('mkdir %s/SUBDIR' % scratch_dir, shell=True)
# Create big file in this image.
# Note that we work only on the start 1MB, couple MBs in the 2GB range
@@ -326,15 +251,20 @@ def fs_obj_basic(request, u_boot_config):
% big_file, shell=True).decode()
md5val.append(out.split()[0])
+ try:
+ # 3GiB volume
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB', scratch_dir)
+ except CalledProcessError as err:
+ pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
+ return
+
except CalledProcessError as err:
pytest.skip('Setup failed for filesystem: ' + fs_type + '. {}'.format(err))
- umount_fs(mount_dir)
return
else:
- umount_fs(mount_dir)
yield [fs_ubtype, fs_img, md5val]
finally:
- call('rmdir %s' % mount_dir, shell=True)
+ call('rm -rf %s' % scratch_dir, shell=True)
call('rm -f %s' % fs_img, shell=True)
#
@@ -358,38 +288,21 @@ def fs_obj_ext(request, u_boot_config):
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
- mount_dir = u_boot_config.persistent_data_dir + '/mnt'
-
- min_file = mount_dir + '/' + MIN_FILE
- tmp_file = mount_dir + '/tmpfile'
+ scratch_dir = u_boot_config.persistent_data_dir + '/scratch'
- try:
-
- # 128MiB volume
- fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
- except CalledProcessError as err:
- pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
- return
+ min_file = scratch_dir + '/' + MIN_FILE
+ tmp_file = scratch_dir + '/tmpfile'
try:
- check_call('mkdir -p %s' % mount_dir, shell=True)
+ check_call('mkdir -p %s' % scratch_dir, shell=True)
except CalledProcessError as err:
pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err))
call('rm -f %s' % fs_img, shell=True)
return
try:
- # Mount the image so we can populate it.
- mount_fs(fs_type, fs_img, mount_dir)
- except CalledProcessError as err:
- pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err))
- call('rmdir %s' % mount_dir, shell=True)
- call('rm -f %s' % fs_img, shell=True)
- return
-
- try:
# Create a test directory
- check_call('mkdir %s/dir1' % mount_dir, shell=True)
+ check_call('mkdir %s/dir1' % scratch_dir, shell=True)
# Create a small file and calculate md5
check_call('dd if=/dev/urandom of=%s bs=1K count=20'
@@ -427,15 +340,21 @@ def fs_obj_ext(request, u_boot_config):
md5val.append(out.split()[0])
check_call('rm %s' % tmp_file, shell=True)
+
+ try:
+ # 128MiB volume
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', scratch_dir)
+ except CalledProcessError as err:
+ pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
+ return
+
except CalledProcessError:
pytest.skip('Setup failed for filesystem: ' + fs_type)
- umount_fs(mount_dir)
return
else:
- umount_fs(mount_dir)
yield [fs_ubtype, fs_img, md5val]
finally:
- call('rmdir %s' % mount_dir, shell=True)
+ call('rm -rf %s' % scratch_dir, shell=True)
call('rm -f %s' % fs_img, shell=True)
#
@@ -461,7 +380,7 @@ def fs_obj_mkdir(request, u_boot_config):
try:
# 128MiB volume
- fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', None)
except:
pytest.skip('Setup failed for filesystem: ' + fs_type)
return
@@ -490,63 +409,51 @@ def fs_obj_unlink(request, u_boot_config):
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
- mount_dir = u_boot_config.persistent_data_dir + '/mnt'
-
- try:
-
- # 128MiB volume
- fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
- except CalledProcessError as err:
- pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
- return
+ scratch_dir = u_boot_config.persistent_data_dir + '/scratch'
try:
- check_call('mkdir -p %s' % mount_dir, shell=True)
+ check_call('mkdir -p %s' % scratch_dir, shell=True)
except CalledProcessError as err:
pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err))
call('rm -f %s' % fs_img, shell=True)
return
try:
- # Mount the image so we can populate it.
- mount_fs(fs_type, fs_img, mount_dir)
- except CalledProcessError as err:
- pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err))
- call('rmdir %s' % mount_dir, shell=True)
- call('rm -f %s' % fs_img, shell=True)
- return
-
- try:
# Test Case 1 & 3
- check_call('mkdir %s/dir1' % mount_dir, shell=True)
+ check_call('mkdir %s/dir1' % scratch_dir, shell=True)
check_call('dd if=/dev/urandom of=%s/dir1/file1 bs=1K count=1'
- % mount_dir, shell=True)
+ % scratch_dir, shell=True)
check_call('dd if=/dev/urandom of=%s/dir1/file2 bs=1K count=1'
- % mount_dir, shell=True)
+ % scratch_dir, shell=True)
# Test Case 2
- check_call('mkdir %s/dir2' % mount_dir, shell=True)
+ check_call('mkdir %s/dir2' % scratch_dir, shell=True)
for i in range(0, 20):
check_call('mkdir %s/dir2/0123456789abcdef%02x'
- % (mount_dir, i), shell=True)
+ % (scratch_dir, i), shell=True)
# Test Case 4
- check_call('mkdir %s/dir4' % mount_dir, shell=True)
+ check_call('mkdir %s/dir4' % scratch_dir, shell=True)
# Test Case 5, 6 & 7
- check_call('mkdir %s/dir5' % mount_dir, shell=True)
+ check_call('mkdir %s/dir5' % scratch_dir, shell=True)
check_call('dd if=/dev/urandom of=%s/dir5/file1 bs=1K count=1'
- % mount_dir, shell=True)
+ % scratch_dir, shell=True)
+
+ try:
+ # 128MiB volume
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', scratch_dir)
+ except CalledProcessError as err:
+ pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
+ return
except CalledProcessError:
pytest.skip('Setup failed for filesystem: ' + fs_type)
- umount_fs(mount_dir)
return
else:
- umount_fs(mount_dir)
yield [fs_ubtype, fs_img]
finally:
- call('rmdir %s' % mount_dir, shell=True)
+ call('rm -rf %s' % scratch_dir, shell=True)
call('rm -f %s' % fs_img, shell=True)
#
@@ -570,38 +477,21 @@ def fs_obj_symlink(request, u_boot_config):
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
- mount_dir = u_boot_config.persistent_data_dir + '/mnt'
-
- small_file = mount_dir + '/' + SMALL_FILE
- medium_file = mount_dir + '/' + MEDIUM_FILE
-
- try:
+ scratch_dir = u_boot_config.persistent_data_dir + '/scratch'
- # 1GiB volume
- fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB')
- except CalledProcessError as err:
- pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
- return
+ small_file = scratch_dir + '/' + SMALL_FILE
+ medium_file = scratch_dir + '/' + MEDIUM_FILE
try:
- check_call('mkdir -p %s' % mount_dir, shell=True)
+ check_call('mkdir -p %s' % scratch_dir, shell=True)
except CalledProcessError as err:
pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err))
call('rm -f %s' % fs_img, shell=True)
return
try:
- # Mount the image so we can populate it.
- mount_fs(fs_type, fs_img, mount_dir)
- except CalledProcessError as err:
- pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err))
- call('rmdir %s' % mount_dir, shell=True)
- call('rm -f %s' % fs_img, shell=True)
- return
-
- try:
# Create a subdirectory.
- check_call('mkdir %s/SUBDIR' % mount_dir, shell=True)
+ check_call('mkdir %s/SUBDIR' % scratch_dir, shell=True)
# Create a small file in this image.
check_call('dd if=/dev/urandom of=%s bs=1M count=1'
@@ -621,15 +511,20 @@ def fs_obj_symlink(request, u_boot_config):
% medium_file, shell=True).decode()
md5val.extend([out.split()[0]])
+ try:
+ # 1GiB volume
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB', scratch_dir)
+ except CalledProcessError as err:
+ pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
+ return
+
except CalledProcessError:
pytest.skip('Setup failed for filesystem: ' + fs_type)
- umount_fs(mount_dir)
return
else:
- umount_fs(mount_dir)
yield [fs_ubtype, fs_img, md5val]
finally:
- call('rmdir %s' % mount_dir, shell=True)
+ call('rm -rf %s' % scratch_dir, shell=True)
call('rm -f %s' % fs_img, shell=True)
#
@@ -665,7 +560,7 @@ def fs_obj_fat(request, u_boot_config):
try:
# the volume size depends on the filesystem
- fs_img = fs_helper.mk_fs(u_boot_config, fs_type, fs_size, f'{fs_size}', 1024)
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, fs_size, f'{fs_size}', None, 1024)
except:
pytest.skip('Setup failed for filesystem: ' + fs_type)
return
diff --git a/test/py/tests/test_mmc.py b/test/py/tests/test_mmc.py
index a96c4e8fd89..46240433884 100644
--- a/test/py/tests/test_mmc.py
+++ b/test/py/tests/test_mmc.py
@@ -18,16 +18,55 @@ For example:
# Setup env__mmc_device_test_skip to not skipping the test. By default, its
# value is set to True. Set it to False to run all tests for MMC device.
env__mmc_device_test_skip = False
+
+# Setup env__mmc_device to set the supported mmc modes to be tested
+env__mmc_device {
+ 'mmc_modes': ['MMC_LEGACY', 'SD_HS'],
+}
+
"""
mmc_set_up = False
controllers = 0
devices = {}
+mmc_modes_name = []
+mmc_modes = []
+
+def setup_mmc_modes(cons):
+ global mmc_modes, mmc_modes_name
+ f = cons.config.env.get('env__mmc_device', None)
+ if f:
+ mmc_modes_name = f.get('mmc_modes', None)
+
+ # Set mmc mode to default mode (legacy), if speed mode config isn't enabled
+ if cons.config.buildconfig.get('config_mmc_speed_mode_set', 'n') != 'y':
+ mmc_modes = [0]
+ return
+
+ if mmc_modes_name:
+ mmc_help = cons.run_command('mmc -help')
+ m = re.search(r"\[MMC_LEGACY(.*\n.+])", mmc_help)
+ modes = [
+ x.strip()
+ for x in m.group()
+ .replace('\n', '')
+ .replace('[', '')
+ .replace(']', '')
+ .split(',')
+ ]
+
+ for mode in mmc_modes_name:
+ mmc_modes += [modes.index(mode)]
+ else:
+ # Set mmc mode to default mode (legacy), if it is not defined in env
+ mmc_modes = [0]
def setup_mmc(u_boot_console):
if u_boot_console.config.env.get('env__mmc_device_test_skip', True):
pytest.skip('MMC device test is not enabled')
+ setup_mmc_modes(u_boot_console)
+
@pytest.mark.buildconfigspec('cmd_mmc')
def test_mmc_list(u_boot_console):
setup_mmc(u_boot_console)
@@ -58,21 +97,22 @@ def test_mmc_dev(u_boot_console):
fail = 0
for x in range(0, controllers):
devices[x]['detected'] = 'yes'
- output = u_boot_console.run_command('mmc dev %d' % x)
- # Some sort of switch here
- if 'Card did not respond to voltage select' in output:
- fail = 1
- devices[x]['detected'] = 'no'
+ for y in mmc_modes:
+ output = u_boot_console.run_command('mmc dev %d 0 %d' % x, y)
- if 'no mmc device at slot' in output:
- devices[x]['detected'] = 'no'
+ if 'Card did not respond to voltage select' in output:
+ fail = 1
+ devices[x]['detected'] = 'no'
- if 'MMC: no card present' in output:
- devices[x]['detected'] = 'no'
+ if 'no mmc device at slot' in output:
+ devices[x]['detected'] = 'no'
- if fail:
- pytest.fail('Card not present')
+ if 'MMC: no card present' in output:
+ devices[x]['detected'] = 'no'
+
+ if fail:
+ pytest.fail('Card not present')
@pytest.mark.buildconfigspec('cmd_mmc')
def test_mmcinfo(u_boot_console):
@@ -81,19 +121,22 @@ def test_mmcinfo(u_boot_console):
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
- output = u_boot_console.run_command('mmcinfo')
- if 'busy timeout' in output:
- pytest.skip('No SD/MMC/eMMC device present')
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d 0 %d' % x, y)
+ output = u_boot_console.run_command('mmcinfo')
+ if 'busy timeout' in output:
+ pytest.skip('No SD/MMC/eMMC device present')
- obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
- try:
- capacity = float(obj.groups()[0])
- print(capacity)
- devices[x]['capacity'] = capacity
- print('Capacity of dev %d is: %g GiB' % (x, capacity))
- except ValueError:
- pytest.fail('MMC capacity not recognized')
+ assert mmc_modes_name[mmc_modes.index(y)] in output
+
+ obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
+ try:
+ capacity = float(obj.groups()[0])
+ print(capacity)
+ devices[x]['capacity'] = capacity
+ print('Capacity of dev %d is: %g GiB' % (x, capacity))
+ except ValueError:
+ pytest.fail('MMC capacity not recognized')
@pytest.mark.buildconfigspec('cmd_mmc')
def test_mmc_info(u_boot_console):
@@ -102,19 +145,21 @@ def test_mmc_info(u_boot_console):
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d 0 %d' % x, y)
- output = u_boot_console.run_command('mmc info')
+ output = u_boot_console.run_command('mmc info')
+ assert mmc_modes_name[mmc_modes.index(y)] in output
- obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
- try:
- capacity = float(obj.groups()[0])
- print(capacity)
- if devices[x]['capacity'] != capacity:
- pytest.fail("MMC capacity doesn't match mmcinfo")
+ obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
+ try:
+ capacity = float(obj.groups()[0])
+ print(capacity)
+ if devices[x]['capacity'] != capacity:
+ pytest.fail("MMC capacity doesn't match mmcinfo")
- except ValueError:
- pytest.fail('MMC capacity not recognized')
+ except ValueError:
+ pytest.fail('MMC capacity not recognized')
@pytest.mark.buildconfigspec('cmd_mmc')
def test_mmc_rescan(u_boot_console):
@@ -126,12 +171,13 @@ def test_mmc_rescan(u_boot_console):
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
- output = u_boot_console.run_command('mmc rescan')
- if output:
- pytest.fail('mmc rescan has something to check')
- output = u_boot_console.run_command('echo $?')
- assert output.endswith('0')
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d 0 %d' % x, y)
+ output = u_boot_console.run_command('mmc rescan')
+ if output:
+ pytest.fail('mmc rescan has something to check')
+ output = u_boot_console.run_command('echo $?')
+ assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_mmc')
def test_mmc_part(u_boot_console):
@@ -148,7 +194,8 @@ def test_mmc_part(u_boot_console):
lines = output.split('\n')
part_fat = []
- part_ext = []
+ part_ext2 = []
+ part_ext4 = []
for line in lines:
obj = re.search(
r'(\d)\s+\d+\s+\d+\s+\w+\d+\w+-\d+\s+(\d+\w+)', line)
@@ -161,15 +208,21 @@ def test_mmc_part(u_boot_console):
print('Fat detected')
part_fat.append(part_id)
elif part_type == '83':
- print('ext detected')
- part_ext.append(part_id)
+ print('ext(2/4) detected')
+ output = u_boot_console.run_command(
+ 'fstype mmc %d:%d' % x, part_id
+ )
+ if 'ext2' in output:
+ part_ext2.append(part_id)
+ elif 'ext4' in output:
+ part_ext4.append(part_id)
else:
pytest.fail('Unsupported Filesystem on device %d' % x)
- devices[x]['ext4'] = part_ext
- devices[x]['ext2'] = part_ext
+ devices[x]['ext4'] = part_ext4
+ devices[x]['ext2'] = part_ext2
devices[x]['fat'] = part_fat
- if not part_ext and not part_fat:
+ if not part_ext2 and not part_ext4 and not part_fat:
pytest.fail('No partition detected on device %d' % x)
@pytest.mark.buildconfigspec('cmd_mmc')
@@ -185,7 +238,6 @@ def test_mmc_fatls_fatinfo(u_boot_console):
fs = 'fat'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -193,20 +245,22 @@ def test_mmc_fatls_fatinfo(u_boot_console):
continue
for part in partitions:
- output = u_boot_console.run_command(
- 'fatls mmc %d:%s' % (x, part))
- if 'Unrecognized filesystem type' in output:
- partitions.remove(part)
- pytest.fail('Unrecognized filesystem')
-
- if not re.search(r'\d file\(s\), \d dir\(s\)', output):
- pytest.fail('%s read failed on device %d' % (fs.upper, x))
- output = u_boot_console.run_command(
- 'fatinfo mmc %d:%s' % (x, part))
- string = 'Filesystem: %s' % fs.upper
- if re.search(string, output):
- pytest.fail('%s FS failed on device %d' % (fs.upper(), x))
- part_detect = 1
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
+ output = u_boot_console.run_command(
+ 'fatls mmc %d:%s' % (x, part))
+ if 'Unrecognized filesystem type' in output:
+ partitions.remove(part)
+ pytest.fail('Unrecognized filesystem')
+
+ if not re.search(r'\d file\(s\), \d dir\(s\)', output):
+ pytest.fail('%s read failed on device %d' % (fs.upper, x))
+ output = u_boot_console.run_command(
+ 'fatinfo mmc %d:%s' % (x, part))
+ string = 'Filesystem: %s' % fs.upper
+ if re.search(string, output):
+ pytest.fail('%s FS failed on device %d' % (fs.upper(), x))
+ part_detect = 1
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
@@ -226,7 +280,6 @@ def test_mmc_fatload_fatwrite(u_boot_console):
fs = 'fat'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -234,49 +287,51 @@ def test_mmc_fatload_fatwrite(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- addr = u_boot_utils.find_ram_base(u_boot_console)
- devices[x]['addr_%d' % part] = addr
- size = random.randint(4, 1 * 1024 * 1024)
- devices[x]['size_%d' % part] = size
- # count CRC32
- output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
- m = re.search('==> (.+?)', output)
- if not m:
- pytest.fail('CRC32 failed')
- expected_crc32 = m.group(1)
- devices[x]['expected_crc32_%d' % part] = expected_crc32
- # do write
- file = '%s_%d' % ('uboot_test', size)
- devices[x]['file_%d' % part] = file
- output = u_boot_console.run_command(
- '%swrite mmc %d:%s %x %s %x' % (fs, x, part, addr, file, size)
- )
- assert 'Unable to write' not in output
- assert 'Error' not in output
- assert 'overflow' not in output
- expected_text = '%d bytes written' % size
- assert expected_text in output
-
- alignment = int(
- u_boot_console.config.buildconfig.get(
- 'config_sys_cacheline_size', 128
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ addr = u_boot_utils.find_ram_base(u_boot_console)
+ devices[x]['addr_%d' % part] = addr
+ size = random.randint(4, 1 * 1024 * 1024)
+ devices[x]['size_%d' % part] = size
+ # count CRC32
+ output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
+ m = re.search('==> (.+?)', output)
+ if not m:
+ pytest.fail('CRC32 failed')
+ expected_crc32 = m.group(1)
+ devices[x]['expected_crc32_%d' % part] = expected_crc32
+ # do write
+ file = '%s_%d' % ('uboot_test', size)
+ devices[x]['file_%d' % part] = file
+ output = u_boot_console.run_command(
+ '%swrite mmc %d:%s %x %s %x' % (fs, x, part, addr, file, size)
)
- )
- offset = random.randrange(alignment, 1024, alignment)
- output = u_boot_console.run_command(
- '%sload mmc %d:%s %x %s' % (fs, x, part, addr + offset, file)
- )
- assert 'Invalid FAT entry' not in output
- assert 'Unable to read file' not in output
- assert 'Misaligned buffer address' not in output
- expected_text = '%d bytes read' % size
- assert expected_text in output
-
- output = u_boot_console.run_command(
- 'crc32 %x $filesize' % (addr + offset)
- )
- assert expected_crc32 in output
+ assert 'Unable to write' not in output
+ assert 'Error' not in output
+ assert 'overflow' not in output
+ expected_text = '%d bytes written' % size
+ assert expected_text in output
+
+ alignment = int(
+ u_boot_console.config.buildconfig.get(
+ 'config_sys_cacheline_size', 128
+ )
+ )
+ offset = random.randrange(alignment, 1024, alignment)
+ output = u_boot_console.run_command(
+ '%sload mmc %d:%s %x %s' % (fs, x, part, addr + offset, file)
+ )
+ assert 'Invalid FAT entry' not in output
+ assert 'Unable to read file' not in output
+ assert 'Misaligned buffer address' not in output
+ expected_text = '%d bytes read' % size
+ assert expected_text in output
+
+ output = u_boot_console.run_command(
+ 'crc32 %x $filesize' % (addr + offset)
+ )
+ assert expected_crc32 in output
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
@@ -300,13 +355,16 @@ def test_mmc_ext4ls(u_boot_console):
print('No %s table on this device' % fs.upper())
continue
- u_boot_console.run_command('mmc dev %d' % x)
for part in partitions:
- output = u_boot_console.run_command('%sls mmc %d:%s' % (fs, x, part))
- if 'Unrecognized filesystem type' in output:
- partitions.remove(part)
- pytest.fail('Unrecognized filesystem')
- part_detect = 1
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
+ output = u_boot_console.run_command(
+ '%sls mmc %d:%s' % (fs, x, part)
+ )
+ if 'Unrecognized filesystem type' in output:
+ partitions.remove(part)
+ pytest.fail('Unrecognized filesystem')
+ part_detect = 1
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
@@ -326,7 +384,6 @@ def test_mmc_ext4load_ext4write(u_boot_console):
fs = 'ext4'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -334,42 +391,44 @@ def test_mmc_ext4load_ext4write(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- addr = u_boot_utils.find_ram_base(u_boot_console)
- devices[x]['addr_%d' % part] = addr
- size = random.randint(4, 1 * 1024 * 1024)
- devices[x]['size_%d' % part] = size
- # count CRC32
- output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
- m = re.search('==> (.+?)', output)
- if not m:
- pytest.fail('CRC32 failed')
- expected_crc32 = m.group(1)
- devices[x]['expected_crc32_%d' % part] = expected_crc32
- # do write
-
- file = '%s_%d' % ('uboot_test', size)
- devices[x]['file_%d' % part] = file
- output = u_boot_console.run_command(
- '%swrite mmc %d:%s %x /%s %x' % (fs, x, part, addr, file, size)
- )
- assert 'Unable to write' not in output
- assert 'Error' not in output
- assert 'overflow' not in output
- expected_text = '%d bytes written' % size
- assert expected_text in output
-
- offset = random.randrange(128, 1024, 128)
- output = u_boot_console.run_command(
- '%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file)
- )
- expected_text = '%d bytes read' % size
- assert expected_text in output
-
- output = u_boot_console.run_command(
- 'crc32 %x $filesize' % (addr + offset)
- )
- assert expected_crc32 in output
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ addr = u_boot_utils.find_ram_base(u_boot_console)
+ devices[x]['addr_%d' % part] = addr
+ size = random.randint(4, 1 * 1024 * 1024)
+ devices[x]['size_%d' % part] = size
+ # count CRC32
+ output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
+ m = re.search('==> (.+?)', output)
+ if not m:
+ pytest.fail('CRC32 failed')
+ expected_crc32 = m.group(1)
+ devices[x]['expected_crc32_%d' % part] = expected_crc32
+
+ # do write
+ file = '%s_%d' % ('uboot_test', size)
+ devices[x]['file_%d' % part] = file
+ output = u_boot_console.run_command(
+ '%swrite mmc %d:%s %x /%s %x' % (fs, x, part, addr, file, size)
+ )
+ assert 'Unable to write' not in output
+ assert 'Error' not in output
+ assert 'overflow' not in output
+ expected_text = '%d bytes written' % size
+ assert expected_text in output
+
+ offset = random.randrange(128, 1024, 128)
+ output = u_boot_console.run_command(
+ '%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file)
+ )
+ expected_text = '%d bytes read' % size
+ assert expected_text in output
+
+ output = u_boot_console.run_command(
+ 'crc32 %x $filesize' % (addr + offset)
+ )
+ assert expected_crc32 in output
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
@@ -387,7 +446,6 @@ def test_mmc_ext2ls(u_boot_console):
fs = 'ext2'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -395,12 +453,16 @@ def test_mmc_ext2ls(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- output = u_boot_console.run_command('%sls mmc %d:%s' % (fs, x, part))
- if 'Unrecognized filesystem type' in output:
- partitions.remove(part)
- pytest.fail('Unrecognized filesystem')
- part_detect = 1
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ output = u_boot_console.run_command(
+ '%sls mmc %d:%s' % (fs, x, part)
+ )
+ if 'Unrecognized filesystem type' in output:
+ partitions.remove(part)
+ pytest.fail('Unrecognized filesystem')
+ part_detect = 1
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
@@ -421,7 +483,6 @@ def test_mmc_ext2load(u_boot_console):
fs = 'ext2'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -429,23 +490,25 @@ def test_mmc_ext2load(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- addr = devices[x]['addr_%d' % part]
- size = devices[x]['size_%d' % part]
- expected_crc32 = devices[x]['expected_crc32_%d' % part]
- file = devices[x]['file_%d' % part]
-
- offset = random.randrange(128, 1024, 128)
- output = u_boot_console.run_command(
- '%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file)
- )
- expected_text = '%d bytes read' % size
- assert expected_text in output
-
- output = u_boot_console.run_command(
- 'crc32 %x $filesize' % (addr + offset)
- )
- assert expected_crc32 in output
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ addr = devices[x]['addr_%d' % part]
+ size = devices[x]['size_%d' % part]
+ expected_crc32 = devices[x]['expected_crc32_%d' % part]
+ file = devices[x]['file_%d' % part]
+
+ offset = random.randrange(128, 1024, 128)
+ output = u_boot_console.run_command(
+ '%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file)
+ )
+ expected_text = '%d bytes read' % size
+ assert expected_text in output
+
+ output = u_boot_console.run_command(
+ 'crc32 %x $filesize' % (addr + offset)
+ )
+ assert expected_crc32 in output
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
@@ -462,8 +525,7 @@ def test_mmc_ls(u_boot_console):
part_detect = 0
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
- for fs in ['fat', 'ext4']:
+ for fs in ['fat', 'ext4', 'ext2']:
try:
partitions = devices[x][fs]
except:
@@ -471,12 +533,14 @@ def test_mmc_ls(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- output = u_boot_console.run_command('ls mmc %d:%s' % (x, part))
- if re.search(r'No \w+ table on this device', output):
- pytest.fail(
- '%s: Partition table not found %d' % (fs.upper(), x)
- )
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ output = u_boot_console.run_command('ls mmc %d:%s' % (x, part))
+ if re.search(r'No \w+ table on this device', output):
+ pytest.fail(
+ '%s: Partition table not found %d' % (fs.upper(), x)
+ )
if not part_detect:
pytest.skip('No partition detected')
@@ -493,8 +557,7 @@ def test_mmc_load(u_boot_console):
part_detect = 0
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
- for fs in ['fat', 'ext4']:
+ for fs in ['fat', 'ext4', 'ext2']:
try:
partitions = devices[x][fs]
except:
@@ -502,23 +565,25 @@ def test_mmc_load(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- addr = devices[x]['addr_%d' % part]
- size = devices[x]['size_%d' % part]
- expected_crc32 = devices[x]['expected_crc32_%d' % part]
- file = devices[x]['file_%d' % part]
-
- offset = random.randrange(128, 1024, 128)
- output = u_boot_console.run_command(
- 'load mmc %d:%s %x /%s' % (x, part, addr + offset, file)
- )
- expected_text = '%d bytes read' % size
- assert expected_text in output
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ addr = devices[x]['addr_%d' % part]
+ size = devices[x]['size_%d' % part]
+ expected_crc32 = devices[x]['expected_crc32_%d' % part]
+ file = devices[x]['file_%d' % part]
+
+ offset = random.randrange(128, 1024, 128)
+ output = u_boot_console.run_command(
+ 'load mmc %d:%s %x /%s' % (x, part, addr + offset, file)
+ )
+ expected_text = '%d bytes read' % size
+ assert expected_text in output
- output = u_boot_console.run_command(
- 'crc32 %x $filesize' % (addr + offset)
- )
- assert expected_crc32 in output
+ output = u_boot_console.run_command(
+ 'crc32 %x $filesize' % (addr + offset)
+ )
+ assert expected_crc32 in output
if not part_detect:
pytest.skip('No partition detected')
@@ -535,8 +600,7 @@ def test_mmc_save(u_boot_console):
part_detect = 0
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
- for fs in ['fat', 'ext4']:
+ for fs in ['fat', 'ext4', 'ext2']:
try:
partitions = devices[x][fs]
except:
@@ -544,18 +608,20 @@ def test_mmc_save(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- addr = devices[x]['addr_%d' % part]
- size = 0
- file = devices[x]['file_%d' % part]
-
- offset = random.randrange(128, 1024, 128)
- output = u_boot_console.run_command(
- 'save mmc %d:%s %x /%s %d'
- % (x, part, addr + offset, file, size)
- )
- expected_text = '%d bytes written' % size
- assert expected_text in output
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ addr = devices[x]['addr_%d' % part]
+ size = 0
+ file = devices[x]['file_%d' % part]
+
+ offset = random.randrange(128, 1024, 128)
+ output = u_boot_console.run_command(
+ 'save mmc %d:%s %x /%s %d'
+ % (x, part, addr + offset, file, size)
+ )
+ expected_text = '%d bytes written' % size
+ assert expected_text in output
if not part_detect:
pytest.skip('No partition detected')
@@ -582,7 +648,6 @@ def test_mmc_fat_read_write_files(u_boot_console):
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -590,82 +655,86 @@ def test_mmc_fat_read_write_files(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- addr = u_boot_utils.find_ram_base(u_boot_console)
- count_f = 0
- addr_l = []
- size_l = []
- file_l = []
- crc32_l = []
- offset_l = []
- addr_l.append(addr)
-
- while count_f < num_files:
- size_l.append(random.randint(4, 1 * 1024 * 1024))
-
- # CRC32 count
- output = u_boot_console.run_command(
- 'crc32 %x %x' % (addr_l[count_f], size_l[count_f])
- )
- m = re.search('==> (.+?)', output)
- if not m:
- pytest.fail('CRC32 failed')
- crc32_l.append(m.group(1))
-
- # Write operation
- file_l.append('%s_%d_%d' % ('uboot_test', count_f, size_l[count_f]))
- output = u_boot_console.run_command(
- '%swrite mmc %d:%s %x %s %x'
- % (
- fs,
- x,
- part,
- addr_l[count_f],
- file_l[count_f],
- size_l[count_f],
+ for y in mmc_modes:
+ u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ addr = u_boot_utils.find_ram_base(u_boot_console)
+ count_f = 0
+ addr_l = []
+ size_l = []
+ file_l = []
+ crc32_l = []
+ offset_l = []
+ addr_l.append(addr)
+
+ while count_f < num_files:
+ size_l.append(random.randint(4, 1 * 1024 * 1024))
+
+ # CRC32 count
+ output = u_boot_console.run_command(
+ 'crc32 %x %x' % (addr_l[count_f], size_l[count_f])
)
- )
- assert 'Unable to write' not in output
- assert 'Error' not in output
- assert 'overflow' not in output
- expected_text = '%d bytes written' % size_l[count_f]
- assert expected_text in output
-
- addr_l.append(addr_l[count_f] + size_l[count_f] + 1048576)
- count_f += 1
-
- count_f = 0
- while count_f < num_files:
- alignment = int(
- u_boot_console.config.buildconfig.get(
- 'config_sys_cacheline_size', 128
+ m = re.search('==> (.+?)', output)
+ if not m:
+ pytest.fail('CRC32 failed')
+ crc32_l.append(m.group(1))
+
+ # Write operation
+ file_l.append(
+ '%s_%d_%d' % ('uboot_test', count_f, size_l[count_f])
)
- )
- offset_l.append(random.randrange(alignment, 1024, alignment))
-
- # Read operation
- output = u_boot_console.run_command(
- '%sload mmc %d:%s %x %s'
- % (
- fs,
- x,
- part,
- addr_l[count_f] + offset_l[count_f],
- file_l[count_f],
+ output = u_boot_console.run_command(
+ '%swrite mmc %d:%s %x %s %x'
+ % (
+ fs,
+ x,
+ part,
+ addr_l[count_f],
+ file_l[count_f],
+ size_l[count_f],
+ )
)
- )
- assert 'Invalid FAT entry' not in output
- assert 'Unable to read file' not in output
- assert 'Misaligned buffer address' not in output
- expected_text = '%d bytes read' % size_l[count_f]
- assert expected_text in output
-
- output = u_boot_console.run_command(
- 'crc32 %x $filesize' % (addr_l[count_f] + offset_l[count_f])
- )
- assert crc32_l[count_f] in output
+ assert 'Unable to write' not in output
+ assert 'Error' not in output
+ assert 'overflow' not in output
+ expected_text = '%d bytes written' % size_l[count_f]
+ assert expected_text in output
+
+ addr_l.append(addr_l[count_f] + size_l[count_f] + 1048576)
+ count_f += 1
+
+ count_f = 0
+ while count_f < num_files:
+ alignment = int(
+ u_boot_console.config.buildconfig.get(
+ 'config_sys_cacheline_size', 128
+ )
+ )
+ offset_l.append(random.randrange(alignment, 1024, alignment))
+
+ # Read operation
+ output = u_boot_console.run_command(
+ '%sload mmc %d:%s %x %s'
+ % (
+ fs,
+ x,
+ part,
+ addr_l[count_f] + offset_l[count_f],
+ file_l[count_f],
+ )
+ )
+ assert 'Invalid FAT entry' not in output
+ assert 'Unable to read file' not in output
+ assert 'Misaligned buffer address' not in output
+ expected_text = '%d bytes read' % size_l[count_f]
+ assert expected_text in output
+
+ output = u_boot_console.run_command(
+ 'crc32 %x $filesize' % (addr_l[count_f] + offset_l[count_f])
+ )
+ assert crc32_l[count_f] in output
- count_f += 1
+ count_f += 1
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
diff --git a/test/py/tests/test_trace.py b/test/py/tests/test_trace.py
index ec1e624722c..44239da5280 100644
--- a/test/py/tests/test_trace.py
+++ b/test/py/tests/test_trace.py
@@ -70,6 +70,32 @@ def collect_trace(cons):
return fname, int(dm_f_time[0])
+def wipe_and_collect_trace(cons):
+ """Pause and wipe traces, return the number of calls (should be zero)
+
+ Args:
+ cons (ConsoleBase): U-Boot console
+
+ Returns:
+ int: the number of traced function calls reported by 'trace stats'
+ """
+ cons.run_command('trace pause')
+ cons.run_command('trace wipe')
+ out = cons.run_command('trace stats')
+
+ # The output is something like this:
+ # 117,221 function sites
+ # 0 function calls
+ # 0 untracked function calls
+ # 0 traced function calls
+
+ # Get a dict of values from the output
+ lines = [line.split(maxsplit=1) for line in out.splitlines() if line]
+ vals = {key: val.replace(',', '') for val, key in lines}
+
+ return int(vals['traced function calls'])
+
+
def check_function(cons, fname, proftool, map_fname, trace_dat):
"""Check that the 'function' output works
@@ -304,3 +330,7 @@ def test_trace(u_boot_console):
# This allows for CI being slow to run
diff = abs(fg_time - dm_f_time)
assert diff / dm_f_time < 0.3
+
+ # Check that the trace buffer can be wiped
+ numcalls = wipe_and_collect_trace(cons)
+ assert numcalls == 0
diff --git a/test/py/tests/test_usb.py b/test/py/tests/test_usb.py
index 2397fd3c2e7..e1f203b5cbc 100644
--- a/test/py/tests/test_usb.py
+++ b/test/py/tests/test_usb.py
@@ -227,7 +227,8 @@ def test_usb_part(u_boot_console):
lines = output.split('\n')
part_fat = []
- part_ext = []
+ part_ext2 = []
+ part_ext4 = []
for line in lines:
obj = re.search(r'(\d)\s+\d+\s+\d+\s+\w+\d+\w+-\d+\s+(\d+\w+)', line)
if obj:
@@ -239,15 +240,21 @@ def test_usb_part(u_boot_console):
print('Fat detected')
part_fat.append(part_id)
elif part_type == '83':
- print('ext detected')
- part_ext.append(part_id)
+ print('ext(2/4) detected')
+ output = u_boot_console.run_command(
+ 'fstype usb %d:%d' % i, part_id
+ )
+ if 'ext2' in output:
+ part_ext2.append(part_id)
+ elif 'ext4' in output:
+ part_ext4.append(part_id)
else:
pytest.fail('Unsupported Filesystem on device %d' % i)
- devices[i]['ext4'] = part_ext
- devices[i]['ext2'] = part_ext
+ devices[i]['ext4'] = part_ext4
+ devices[i]['ext2'] = part_ext2
devices[i]['fat'] = part_fat
- if not part_ext and not part_fat:
+ if not part_ext2 and not part_ext4 and not part_fat:
pytest.fail('No partition detected on device %d' % i)
return devices, controllers, storage_device
@@ -497,7 +504,7 @@ def test_usb_ext2load(u_boot_console):
for part in partitions:
part_detect = 1
file, size, expected_crc32 = \
- usb_ext4load_ext4write(u_boot_console, 'ext4', x, part)
+ usb_ext4load_ext4write(u_boot_console, fs, x, part)
addr = u_boot_utils.find_ram_base(u_boot_console)
offset = random.randrange(128, 1024, 128)
@@ -526,7 +533,7 @@ def test_usb_ls(u_boot_console):
for x in range(0, int(storage_device)):
if devices[x]['detected'] == 'yes':
u_boot_console.run_command('usb dev %d' % x)
- for fs in ['fat', 'ext4']:
+ for fs in ['fat', 'ext2', 'ext4']:
try:
partitions = devices[x][fs]
except:
@@ -556,7 +563,7 @@ def test_usb_load(u_boot_console):
for x in range(0, int(storage_device)):
if devices[x]['detected'] == 'yes':
u_boot_console.run_command('usb dev %d' % x)
- for fs in ['fat', 'ext4']:
+ for fs in ['fat', 'ext2', 'ext4']:
try:
partitions = devices[x][fs]
except:
@@ -570,7 +577,7 @@ def test_usb_load(u_boot_console):
if fs == 'fat':
file, size, expected_crc32 = \
usb_fatload_fatwrite(u_boot_console, fs, x, part)
- elif fs == 'ext4':
+ elif fs in ['ext4', 'ext2']:
file, size, expected_crc32 = \
usb_ext4load_ext4write(u_boot_console, fs, x, part)
@@ -600,7 +607,7 @@ def test_usb_save(u_boot_console):
for x in range(0, int(storage_device)):
if devices[x]['detected'] == 'yes':
u_boot_console.run_command('usb dev %d' % x)
- for fs in ['fat', 'ext4']:
+ for fs in ['fat', 'ext2', 'ext4']:
try:
partitions = devices[x][fs]
except:
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index 6d44191976b..10ec7e582e0 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -8,7 +8,6 @@ test one at a time, as well setting up some files needed by the tests.
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
"""
import collections
-import getpass
import gzip
import os
import os.path
@@ -28,70 +27,36 @@ def mkdir_cond(dirname):
if not os.path.exists(dirname):
os.mkdir(dirname)
-def setup_image(cons, devnum, part_type, second_part=False, basename='mmc'):
- """Create a 20MB disk image with a single partition
+def setup_image(cons, devnum, part_type, img_size=20, second_part=False,
+ basename='mmc'):
+ """Create a disk image with a single partition
Args:
cons (ConsoleBase): Console to use
devnum (int): Device number to use, e.g. 1
part_type (int): Partition type, e.g. 0xc for FAT32
+ img_size (int): Image size in MiB
second_part (bool): True to contain a small second partition
basename (str): Base name to use in the filename, e.g. 'mmc'
Returns:
tuple:
str: Filename of MMC image
- str: Directory name of 'mnt' directory
+ str: Directory name of scratch directory
"""
fname = os.path.join(cons.config.source_dir, f'{basename}{devnum}.img')
- mnt = os.path.join(cons.config.persistent_data_dir, 'mnt')
+ mnt = os.path.join(cons.config.persistent_data_dir, 'scratch')
mkdir_cond(mnt)
- spec = f'type={part_type:x}, size=18M, bootable'
+ spec = f'type={part_type:x}, size={img_size - 2}M, start=1M, bootable'
if second_part:
spec += '\ntype=c'
u_boot_utils.run_and_log(cons, f'qemu-img create {fname} 20M')
- u_boot_utils.run_and_log(cons, f'sudo sfdisk {fname}',
+ u_boot_utils.run_and_log(cons, f'sfdisk {fname}',
stdin=spec.encode('utf-8'))
return fname, mnt
-def mount_image(cons, fname, mnt, fstype):
- """Create a filesystem and mount it on partition 1
-
- Args:
- cons (ConsoleBase): Console to use
- fname (str): Filename of MMC image
- mnt (str): Directory name of 'mnt' directory
- fstype (str): Filesystem type ('vfat' or 'ext4')
-
- Returns:
- str: Name of loop device used
- """
- out = u_boot_utils.run_and_log(cons, f'sudo losetup --show -f -P {fname}')
- loop = out.strip()
- part = f'{loop}p1'
- u_boot_utils.run_and_log(cons, f'sudo mkfs.{fstype} {part}')
- opts = ''
- if fstype == 'vfat':
- opts += f' -o uid={os.getuid()},gid={os.getgid()}'
- u_boot_utils.run_and_log(cons, f'sudo mount -o loop {part} {mnt}{opts}')
- u_boot_utils.run_and_log(cons, f'sudo chown {getpass.getuser()} {mnt}')
- return loop
-
-def copy_prepared_image(cons, devnum, fname, basename='mmc'):
- """Use a prepared image since we cannot create one
-
- Args:
- cons (ConsoleBase): Console touse
- devnum (int): device number
- fname (str): Filename of MMC image
- basename (str): Base name to use in the filename, e.g. 'mmc'
- """
- infname = os.path.join(cons.config.source_dir,
- f'test/py/tests/bootstd/{basename}{devnum}.img.xz')
- u_boot_utils.run_and_log(cons, ['sh', '-c', f'xz -dc {infname} >{fname}'])
-
def setup_bootmenu_image(cons):
"""Create a 20MB disk image with a single ext4 partition
@@ -100,14 +65,7 @@ def setup_bootmenu_image(cons):
mmc_dev = 4
fname, mnt = setup_image(cons, mmc_dev, 0x83)
- loop = None
- mounted = False
- complete = False
- try:
- loop = mount_image(cons, fname, mnt, 'ext4')
- mounted = True
-
- script = '''# DO NOT EDIT THIS FILE
+ script = '''# DO NOT EDIT THIS FILE
#
# Please edit /boot/armbianEnv.txt to set supported parameters
#
@@ -181,64 +139,52 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
# Recompile with:
# mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
'''
- bootdir = os.path.join(mnt, 'boot')
- mkdir_cond(bootdir)
- cmd_fname = os.path.join(bootdir, 'boot.cmd')
- scr_fname = os.path.join(bootdir, 'boot.scr')
- with open(cmd_fname, 'w', encoding='ascii') as outf:
- print(script, file=outf)
-
- infname = os.path.join(cons.config.source_dir,
- 'test/py/tests/bootstd/armbian.bmp.xz')
- bmp_file = os.path.join(bootdir, 'boot.bmp')
- u_boot_utils.run_and_log(
- cons,
- ['sh', '-c', f'xz -dc {infname} >{bmp_file}'])
+ bootdir = os.path.join(mnt, 'boot')
+ mkdir_cond(bootdir)
+ cmd_fname = os.path.join(bootdir, 'boot.cmd')
+ scr_fname = os.path.join(bootdir, 'boot.scr')
+ with open(cmd_fname, 'w', encoding='ascii') as outf:
+ print(script, file=outf)
- u_boot_utils.run_and_log(
- cons, f'mkimage -C none -A arm -T script -d {cmd_fname} {scr_fname}')
-
- kernel = 'vmlinuz-5.15.63-rockchip64'
- target = os.path.join(bootdir, kernel)
- with open(target, 'wb') as outf:
- print('kernel', outf)
+ infname = os.path.join(cons.config.source_dir,
+ 'test/py/tests/bootstd/armbian.bmp.xz')
+ bmp_file = os.path.join(bootdir, 'boot.bmp')
+ u_boot_utils.run_and_log(
+ cons,
+ ['sh', '-c', f'xz -dc {infname} >{bmp_file}'])
- symlink = os.path.join(bootdir, 'Image')
- if os.path.exists(symlink):
- os.remove(symlink)
- u_boot_utils.run_and_log(
- cons, f'echo here {kernel} {symlink}')
- os.symlink(kernel, symlink)
+ mkimage = cons.config.build_dir + '/tools/mkimage'
+ u_boot_utils.run_and_log(
+ cons, f'{mkimage} -C none -A arm -T script -d {cmd_fname} {scr_fname}')
- complete = True
+ kernel = 'vmlinuz-5.15.63-rockchip64'
+ target = os.path.join(bootdir, kernel)
+ with open(target, 'wb') as outf:
+ print('kernel', outf)
- except ValueError as exc:
- print(f'Falled to create image, failing back to prepared copy: {exc}')
- finally:
- if mounted:
- u_boot_utils.run_and_log(cons, f'sudo umount --lazy {mnt}')
- if loop:
- u_boot_utils.run_and_log(cons, f'sudo losetup -d {loop}')
+ symlink = os.path.join(bootdir, 'Image')
+ if os.path.exists(symlink):
+ os.remove(symlink)
+ u_boot_utils.run_and_log(
+ cons, f'echo here {kernel} {symlink}')
+ os.symlink(kernel, symlink)
- if not complete:
- copy_prepared_image(cons, mmc_dev, fname)
+ fsfile = 'ext18M.img'
+ u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}')
+ u_boot_utils.run_and_log(cons, f'mkfs.ext4 {fsfile} -d {mnt}')
+ u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
+ u_boot_utils.run_and_log(cons, f'rm -rf {mnt}')
+ u_boot_utils.run_and_log(cons, f'rm -f {fsfile}')
def setup_bootflow_image(cons):
"""Create a 20MB disk image with a single FAT partition"""
mmc_dev = 1
fname, mnt = setup_image(cons, mmc_dev, 0xc, second_part=True)
- loop = None
- mounted = False
- complete = False
- try:
- loop = mount_image(cons, fname, mnt, 'vfat')
- mounted = True
-
- vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl'
- initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img'
- dtbdir = 'dtb-5.3.7-301.fc31.armv7hl'
- script = '''# extlinux.conf generated by appliance-creator
+ vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl'
+ initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img'
+ dtbdir = 'dtb-5.3.7-301.fc31.armv7hl'
+ script = '''# extlinux.conf generated by appliance-creator
ui menu.c32
menu autoboot Welcome to Fedora-Workstation-armhfp-31-1.9. Automatic boot in # second{,s}. Press a key for options.
menu title Fedora-Workstation-armhfp-31-1.9 Boot Options.
@@ -251,39 +197,36 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
append ro root=UUID=9732b35b-4cd5-458b-9b91-80f7047e0b8a rhgb quiet LANG=en_US.UTF-8 cma=192MB cma=256MB
fdtdir /%s/
initrd /%s''' % (vmlinux, dtbdir, initrd)
- ext = os.path.join(mnt, 'extlinux')
- mkdir_cond(ext)
+ ext = os.path.join(mnt, 'extlinux')
+ mkdir_cond(ext)
- conf = os.path.join(ext, 'extlinux.conf')
- with open(conf, 'w', encoding='ascii') as fd:
- print(script, file=fd)
-
- inf = os.path.join(cons.config.persistent_data_dir, 'inf')
- with open(inf, 'wb') as fd:
- fd.write(gzip.compress(b'vmlinux'))
- u_boot_utils.run_and_log(
- cons, f'mkimage -f auto -d {inf} {os.path.join(mnt, vmlinux)}')
+ conf = os.path.join(ext, 'extlinux.conf')
+ with open(conf, 'w', encoding='ascii') as fd:
+ print(script, file=fd)
- with open(os.path.join(mnt, initrd), 'w', encoding='ascii') as fd:
- print('initrd', file=fd)
+ inf = os.path.join(cons.config.persistent_data_dir, 'inf')
+ with open(inf, 'wb') as fd:
+ fd.write(gzip.compress(b'vmlinux'))
+ mkimage = cons.config.build_dir + '/tools/mkimage'
+ u_boot_utils.run_and_log(
+ cons, f'{mkimage} -f auto -d {inf} {os.path.join(mnt, vmlinux)}')
- mkdir_cond(os.path.join(mnt, dtbdir))
+ with open(os.path.join(mnt, initrd), 'w', encoding='ascii') as fd:
+ print('initrd', file=fd)
- dtb_file = os.path.join(mnt, f'{dtbdir}/sandbox.dtb')
- u_boot_utils.run_and_log(
- cons, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};')
- complete = True
- except ValueError as exc:
- print(f'Falled to create image, failing back to prepared copy: {exc}')
- finally:
- if mounted:
- u_boot_utils.run_and_log(cons, f'sudo umount --lazy {mnt}')
- if loop:
- u_boot_utils.run_and_log(cons, f'sudo losetup -d {loop}')
+ mkdir_cond(os.path.join(mnt, dtbdir))
- if not complete:
- copy_prepared_image(cons, mmc_dev, fname)
+ dtb_file = os.path.join(mnt, f'{dtbdir}/sandbox.dtb')
+ u_boot_utils.run_and_log(
+ cons, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};')
+ fsfile = 'vfat18M.img'
+ u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}')
+ u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}')
+ u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/'])
+ u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
+ u_boot_utils.run_and_log(cons, f'rm -rf {mnt}')
+ u_boot_utils.run_and_log(cons, f'rm -f {fsfile}')
def setup_cros_image(cons):
"""Create a 20MB disk image with ChromiumOS partitions"""
@@ -334,8 +277,6 @@ def setup_cros_image(cons):
mmc_dev = 5
fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img')
u_boot_utils.run_and_log(cons, f'qemu-img create {fname} 20M')
- #mnt = os.path.join(cons.config.persistent_data_dir, 'mnt')
- #mkdir_cond(mnt)
u_boot_utils.run_and_log(cons, f'cgpt create {fname}')
uuid_state = 'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7'
@@ -501,6 +442,55 @@ def setup_android_image(cons):
print(f'wrote to {fname}')
+ mmc_dev = 8
+ fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img')
+ u_boot_utils.run_and_log(cons, f'qemu-img create {fname} 20M')
+ u_boot_utils.run_and_log(cons, f'cgpt create {fname}')
+
+ ptr = 40
+
+ # Number of sectors in 1MB
+ sect_size = 512
+ sect_1mb = (1 << 20) // sect_size
+
+ required_parts = [
+ {'num': 1, 'label':'misc', 'size': '1M'},
+ {'num': 2, 'label':'boot_a', 'size': '4M'},
+ {'num': 3, 'label':'boot_b', 'size': '4M'},
+ ]
+
+ for part in required_parts:
+ size_str = part['size']
+ if 'M' in size_str:
+ size = int(size_str[:-1]) * sect_1mb
+ else:
+ size = int(size_str)
+ u_boot_utils.run_and_log(
+ cons,
+ f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t basicdata {fname}")
+ ptr += size
+
+ u_boot_utils.run_and_log(cons, f'cgpt boot -p {fname}')
+ out = u_boot_utils.run_and_log(cons, f'cgpt show -q {fname}')
+
+ # Create a dict (indexed by partition number) containing the above info
+ for line in out.splitlines():
+ start, size, num, name = line.split(maxsplit=3)
+ parts[int(num)] = Partition(int(start), int(size), name)
+
+ with open(fname, 'rb') as inf:
+ disk_data = inf.read()
+
+ test_abootimg.AbootimgTestDiskImage(cons, 'boot.img', test_abootimg.img_hex)
+ boot_img = os.path.join(cons.config.result_dir, 'boot.img')
+ with open(boot_img, 'rb') as inf:
+ set_part_data(2, inf.read())
+
+ with open(fname, 'wb') as outf:
+ outf.write(disk_data)
+
+ print(f'wrote to {fname}')
+
return fname
def setup_cedit_file(cons):
@@ -540,8 +530,8 @@ def test_ut_dm_init(u_boot_console):
u_boot_utils.run_and_log(
u_boot_console, f'sfdisk {fn}', stdin=b'type=83')
- fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB')
- fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB')
+ fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB', None)
+ fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB', None)
mmc_dev = 6
fn = os.path.join(u_boot_console.config.source_dir, f'mmc{mmc_dev}.img')
@@ -557,35 +547,23 @@ def setup_efi_image(cons):
fname, mnt = setup_image(cons, devnum, 0xc, second_part=True,
basename=basename)
- loop = None
- mounted = False
- complete = False
- try:
- loop = mount_image(cons, fname, mnt, 'ext4')
- mounted = True
- efi_dir = os.path.join(mnt, 'EFI')
- mkdir_cond(efi_dir)
- bootdir = os.path.join(efi_dir, 'BOOT')
- mkdir_cond(bootdir)
- efi_src = os.path.join(cons.config.build_dir,
- f'lib/efi_loader/testapp.efi')
- efi_dst = os.path.join(bootdir, 'BOOTSBOX.EFI')
- with open(efi_src, 'rb') as inf:
- with open(efi_dst, 'wb') as outf:
- outf.write(inf.read())
- complete = True
- except ValueError as exc:
- print(f'Falled to create image, failing back to prepared copy: {exc}')
-
- finally:
- if mounted:
- u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)
- if loop:
- u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
-
- if not complete:
- copy_prepared_image(cons, devnum, fname, basename)
-
+ efi_dir = os.path.join(mnt, 'EFI')
+ mkdir_cond(efi_dir)
+ bootdir = os.path.join(efi_dir, 'BOOT')
+ mkdir_cond(bootdir)
+ efi_src = os.path.join(cons.config.build_dir,
+ 'lib/efi_loader/testapp.efi')
+ efi_dst = os.path.join(bootdir, 'BOOTSBOX.EFI')
+ with open(efi_src, 'rb') as inf:
+ with open(efi_dst, 'wb') as outf:
+ outf.write(inf.read())
+ fsfile = 'vfat18M.img'
+ u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}')
+ u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}')
+ u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/'])
+ u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
+ u_boot_utils.run_and_log(cons, f'rm -rf {mnt}')
+ u_boot_utils.run_and_log(cons, f'rm -f {fsfile}')
@pytest.mark.buildconfigspec('cmd_bootflow')
@pytest.mark.buildconfigspec('sandbox')
diff --git a/test/py/tests/test_zynqmp_rpu.py b/test/py/tests/test_zynqmp_rpu.py
index 479a612b4ec..22f687dd6d3 100644
--- a/test/py/tests/test_zynqmp_rpu.py
+++ b/test/py/tests/test_zynqmp_rpu.py
@@ -70,7 +70,7 @@ def ret_code(u_boot_console):
# Initialize tcm
def tcminit(u_boot_console, rpu_mode):
- output = u_boot_console.run_command('zynqmp tcminit %s' % rpu_mode)
+ output = u_boot_console.run_command(f'zynqmp tcminit {rpu_mode}')
assert 'Initializing TCM overwrites TCM content' in output
return ret_code(u_boot_console)
@@ -89,6 +89,13 @@ def disable_cpus(u_boot_console, cpu_nums):
for num in cpu_nums:
u_boot_console.run_command(f'cpu {num} disable')
+# Get random RPU mode between string and integer
+def get_rpu_mode(rpu_mode):
+ if rpu_mode == 0 or rpu_mode == 'lockstep':
+ return random.choice(['lockstep', 0])
+ elif rpu_mode == 1 or rpu_mode == 'split':
+ return random.choice(['split', 1])
+
# Load apps on RPU cores
def rpu_apps_load(u_boot_console, rpu_mode):
apps, procs, cpu_nums, addrs, outputs, tftp_addrs = get_rpu_apps_env(
@@ -98,20 +105,20 @@ def rpu_apps_load(u_boot_console, rpu_mode):
test_net.test_net_setup_static(u_boot_console)
try:
- assert tcminit(u_boot_console, rpu_mode).endswith('0')
+ assert tcminit(u_boot_console, get_rpu_mode(rpu_mode)).endswith('0')
for i in range(len(apps)):
if rpu_mode == 'lockstep' and procs[i] != 'rpu0':
continue
load_app_ddr(u_boot_console, tftp_addrs[i], apps[i])
- rel_addr = int(addrs[i] + 0x3C)
+ rel_addr = hex(int(addrs[i] + 0x3C))
# Release cpu at app load address
cpu_num = cpu_nums[i]
- cmd = 'cpu %d release %x %s' % (cpu_num, rel_addr, rpu_mode)
+ cmd = f'cpu {cpu_num} release {rel_addr} {rpu_mode}'
output = u_boot_console.run_command(cmd)
- exp_op = f'Using TCM jump trampoline for address {hex(rel_addr)}'
+ exp_op = f'Using TCM jump trampoline for address {rel_addr}'
assert exp_op in output
assert f'R5 {rpu_mode} mode' in output
u_boot_console.wait_for(outputs[i])
@@ -133,16 +140,13 @@ def test_zynqmp_rpu_app_load_negative(u_boot_console):
u_boot_console)
# Invalid commands
- u_boot_console.run_command('zynqmp tcminit mode')
- assert ret_code(u_boot_console).endswith('1')
-
rand_str = ''.join(random.choices(string.ascii_lowercase, k=4))
- u_boot_console.run_command('zynqmp tcminit %s' % rand_str)
- assert ret_code(u_boot_console).endswith('1')
-
rand_num = random.randint(2, 100)
- u_boot_console.run_command('zynqmp tcminit %d' % rand_num)
- assert ret_code(u_boot_console).endswith('1')
+ inv_modes = ['mode', rand_str, rand_num, 'splittt', 'locksteppp', '00', 11]
+
+ for mode in inv_modes:
+ u_boot_console.run_command(f'zynqmp tcminit {mode}')
+ assert ret_code(u_boot_console).endswith('1')
test_net.test_net_dhcp(u_boot_console)
if not test_net.net_set_up:
@@ -150,56 +154,66 @@ def test_zynqmp_rpu_app_load_negative(u_boot_console):
try:
rpu_mode = 'split'
- assert tcminit(u_boot_console, rpu_mode).endswith('0')
+ assert tcminit(u_boot_console, get_rpu_mode(rpu_mode)).endswith('0')
+ inv_modes += [0, 1]
for i in range(len(apps)):
load_app_ddr(u_boot_console, tftp_addrs[i], apps[i])
# Run in split mode at different load address
- rel_addr = int(addrs[i]) + random.randint(200, 1000)
+ rel_addr = hex(int(addrs[i]) + random.randint(200, 1000))
cpu_num = cpu_nums[i]
- cmd = 'cpu %d release %x %s' % (cpu_num, rel_addr, rpu_mode)
+ cmd = f'cpu {cpu_num} release {rel_addr} {rpu_mode}'
output = u_boot_console.run_command(cmd)
- exp_op = f'Using TCM jump trampoline for address {hex(rel_addr)}'
+ exp_op = f'Using TCM jump trampoline for address {rel_addr}'
assert exp_op in output
assert f'R5 {rpu_mode} mode' in output
assert not outputs[i] in output
# Invalid rpu mode
- rand_str = ''.join(random.choices(string.ascii_lowercase, k=4))
- cmd = 'cpu %d release %x %s' % (cpu_num, rel_addr, rand_str)
- output = u_boot_console.run_command(cmd)
- assert exp_op in output
- assert f'Unsupported mode' in output
- assert not ret_code(u_boot_console).endswith('0')
+ for mode in inv_modes:
+ cmd = f'cpu {cpu_num} release {rel_addr} {mode}'
+ output = u_boot_console.run_command(cmd)
+ assert exp_op in output
+ assert f'Unsupported mode' in output
+ assert not ret_code(u_boot_console).endswith('0')
# Switch to lockstep mode, without disabling CPUs
rpu_mode = 'lockstep'
- u_boot_console.run_command('zynqmp tcminit %s' % rpu_mode)
- assert not ret_code(u_boot_console).endswith('0')
+ output = u_boot_console.run_command(
+ f'zynqmp tcminit {get_rpu_mode(rpu_mode)}'
+ )
+ assert 'ERROR: ' in output
# Disable cpus
disable_cpus(u_boot_console, cpu_nums)
# Switch to lockstep mode, after disabling CPUs
- output = u_boot_console.run_command('zynqmp tcminit %s' % rpu_mode)
+ output = u_boot_console.run_command(
+ f'zynqmp tcminit {get_rpu_mode(rpu_mode)}'
+ )
assert 'Initializing TCM overwrites TCM content' in output
assert ret_code(u_boot_console).endswith('0')
- # Run lockstep mode for RPU1
+ # Run lockstep mode for RPU1/RPU0
for i in range(len(apps)):
- if procs[i] == 'rpu0':
- continue
-
load_app_ddr(u_boot_console, tftp_addrs[i], apps[i])
- rel_addr = int(addrs[i] + 0x3C)
+ rel_addr = hex(int(addrs[i] + 0x3C))
cpu_num = cpu_nums[i]
- cmd = 'cpu %d release %x %s' % (cpu_num, rel_addr, rpu_mode)
+ cmd = f'cpu {cpu_num} release {rel_addr} {rpu_mode}'
output = u_boot_console.run_command(cmd)
- exp_op = f'Using TCM jump trampoline for address {hex(rel_addr)}'
+ exp_op = f'Using TCM jump trampoline for address {rel_addr}'
assert exp_op in output
- assert f'R5 {rpu_mode} mode' in output
- assert u_boot_console.p.expect([outputs[i]])
+
+ if procs[i] == 'rpu1':
+ assert 'Lockstep mode should run on ZYNQMP_CORE_RPU0' in output
+ assert not ret_code(u_boot_console).endswith('0')
+ elif procs[i] == 'rpu0':
+ assert f'R5 {rpu_mode} mode' in output
+ u_boot_console.wait_for(outputs[i])
+ assert ret_code(u_boot_console).endswith('0')
+ else:
+ assert False, 'ERROR: Invalid processor!'
finally:
disable_cpus(u_boot_console, cpu_nums)
# This forces the console object to be shutdown, so any subsequent test
diff --git a/test/py/u_boot_console_base.py b/test/py/u_boot_console_base.py
index fa9cd57b04b..7eaceb39d9d 100644
--- a/test/py/u_boot_console_base.py
+++ b/test/py/u_boot_console_base.py
@@ -342,11 +342,12 @@ class ConsoleBase(object):
# indentation.
return self.p.before.strip('\r\n')
except Timeout as exc:
- handle_exception(self.config, self, self.log, exc, 'Lab failure',
- True)
+ handle_exception(self.config, self, self.log, exc,
+ f"Lab failure: Timeout executing '{cmd}'", True)
raise
except BootFail as exc:
- handle_exception(self.config, self, self.log, exc, 'Boot fail',
+ handle_exception(self.config, self, self.log, exc,
+ f"'Boot fail '{cmd}'",
True, self.get_spawn_output())
raise
finally: