]> Git Repo - J-u-boot.git/blobdiff - test/boot/bootflow.c
Merge tag 'v2023.10-rc4' into next
[J-u-boot.git] / test / boot / bootflow.c
index 0b3a2fa6acc260d4358546bfc17a0c774494a396..f5b2059140acae8f5a9d463ebf99b9c3462e3106 100644 (file)
@@ -27,7 +27,8 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-extern U_BOOT_DRIVER(bootmeth_script);
+extern U_BOOT_DRIVER(bootmeth_cros);
+extern U_BOOT_DRIVER(bootmeth_2script);
 
 static int inject_response(struct unit_test_state *uts)
 {
@@ -57,7 +58,7 @@ static int bootflow_cmd(struct unit_test_state *uts)
        ut_assert_nextlinen("---");
        ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
        ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
-       ut_assert_nextline("  0  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
+       ut_assert_nextline("  0  extlinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
        ut_assert_nextline("No more bootdevs");
        ut_assert_nextlinen("---");
        ut_assert_nextline("(1 bootflow, 1 valid)");
@@ -67,7 +68,7 @@ static int bootflow_cmd(struct unit_test_state *uts)
        ut_assert_nextline("Showing bootflows for bootdev 'mmc1.bootdev'");
        ut_assert_nextline("Seq  Method       State   Uclass    Part  Name                      Filename");
        ut_assert_nextlinen("---");
-       ut_assert_nextline("  0  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
+       ut_assert_nextline("  0  extlinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
        ut_assert_nextlinen("---");
        ut_assert_nextline("(1 bootflow, 1 valid)");
        ut_assert_console_end();
@@ -136,7 +137,7 @@ static int bootflow_cmd_glob(struct unit_test_state *uts)
        ut_assert_nextlinen("---");
        ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
        ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
-       ut_assert_nextline("  0  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
+       ut_assert_nextline("  0  extlinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
        ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':");
        ut_assert_nextline("No more bootdevs");
        ut_assert_nextlinen("---");
@@ -147,7 +148,7 @@ static int bootflow_cmd_glob(struct unit_test_state *uts)
        ut_assert_nextline("Showing all bootflows");
        ut_assert_nextline("Seq  Method       State   Uclass    Part  Name                      Filename");
        ut_assert_nextlinen("---");
-       ut_assert_nextline("  0  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
+       ut_assert_nextline("  0  extlinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
        ut_assert_nextlinen("---");
        ut_assert_nextline("(1 bootflow, 1 valid)");
        ut_assert_console_end();
@@ -167,22 +168,23 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts)
        ut_assert_nextline("Seq  Method       State   Uclass    Part  Name                      Filename");
        ut_assert_nextlinen("---");
        ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
-       ut_assert_nextline("  0  syslinux     media   mmc          0  mmc2.bootdev.whole        <NULL>");
-       ut_assert_nextline("     ** No partition found, err=-93");
-       ut_assert_nextline("  1  efi          media   mmc          0  mmc2.bootdev.whole        <NULL>");
-       ut_assert_nextline("     ** No partition found, err=-93");
+       ut_assert_nextline("  0  extlinux     media   mmc          0  mmc2.bootdev.whole        ");
+       ut_assert_nextline("     ** No partition found, err=-93: Protocol not supported");
+       ut_assert_nextline("  1  efi          media   mmc          0  mmc2.bootdev.whole        ");
+       ut_assert_nextline("     ** No partition found, err=-93: Protocol not supported");
 
        ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
-       ut_assert_nextline("  2  syslinux     media   mmc          0  mmc1.bootdev.whole        <NULL>");
-       ut_assert_nextline("     ** No partition found, err=-2");
-       ut_assert_nextline("  3  efi          media   mmc          0  mmc1.bootdev.whole        <NULL>");
-       ut_assert_nextline("     ** No partition found, err=-2");
-       ut_assert_nextline("  4  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
+       ut_assert_nextline("  2  extlinux     media   mmc          0  mmc1.bootdev.whole        ");
+       ut_assert_nextline("     ** No partition found, err=-2: No such file or directory");
+       ut_assert_nextline("  3  efi          media   mmc          0  mmc1.bootdev.whole        ");
+       ut_assert_nextline("     ** No partition found, err=-2: No such file or directory");
+       ut_assert_nextline("  4  extlinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
        ut_assert_nextline("  5  efi          fs      mmc          1  mmc1.bootdev.part_1       efi/boot/bootsbox.efi");
 
        ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':");
-       ut_assert_skip_to_line(" 3f  efi          media   mmc          0  mmc0.bootdev.whole        <NULL>");
-       ut_assert_nextline("     ** No partition found, err=-93");
+       ut_assert_skip_to_line(
+               " 3f  efi          media   mmc          0  mmc0.bootdev.whole        ");
+       ut_assert_nextline("     ** No partition found, err=-93: Protocol not supported");
        ut_assert_nextline("No more bootdevs");
        ut_assert_nextlinen("---");
        ut_assert_nextline("(64 bootflows, 1 valid)");
@@ -192,10 +194,11 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts)
        ut_assert_nextline("Showing all bootflows");
        ut_assert_nextline("Seq  Method       State   Uclass    Part  Name                      Filename");
        ut_assert_nextlinen("---");
-       ut_assert_nextline("  0  syslinux     media   mmc          0  mmc2.bootdev.whole        <NULL>");
-       ut_assert_nextline("  1  efi          media   mmc          0  mmc2.bootdev.whole        <NULL>");
-       ut_assert_skip_to_line("  4  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
-       ut_assert_skip_to_line(" 3f  efi          media   mmc          0  mmc0.bootdev.whole        <NULL>");
+       ut_assert_nextline("  0  extlinux     media   mmc          0  mmc2.bootdev.whole        ");
+       ut_assert_nextline("  1  efi          media   mmc          0  mmc2.bootdev.whole        ");
+       ut_assert_skip_to_line(
+               "  4  extlinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
+       ut_assert_skip_to_line(" 3f  efi          media   mmc          0  mmc0.bootdev.whole        ");
        ut_assert_nextlinen("---");
        ut_assert_nextline("(64 bootflows, 1 valid)");
        ut_assert_console_end();
@@ -218,7 +221,7 @@ static int bootflow_cmd_info(struct unit_test_state *uts)
        ut_assert_nextline("Name:      mmc1.bootdev.part_1");
        ut_assert_nextline("Device:    mmc1.bootdev");
        ut_assert_nextline("Block dev: mmc1.blk");
-       ut_assert_nextline("Method:    syslinux");
+       ut_assert_nextline("Method:    extlinux");
        ut_assert_nextline("State:     ready");
        ut_assert_nextline("Partition: 1");
        ut_assert_nextline("Subdir:    (none)");
@@ -226,6 +229,7 @@ static int bootflow_cmd_info(struct unit_test_state *uts)
        ut_assert_nextlinen("Buffer:    ");
        ut_assert_nextline("Size:      253 (595 bytes)");
        ut_assert_nextline("OS:        Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)");
+       ut_assert_nextline("Cmdline:   (none)");
        ut_assert_nextline("Logo:      (none)");
        ut_assert_nextline("FDT:       <NULL>");
        ut_assert_nextline("Error:     0");
@@ -251,7 +255,7 @@ static int bootflow_scan_boot(struct unit_test_state *uts)
        ut_assertok(inject_response(uts));
        ut_assertok(run_command("bootflow scan -b", 0));
        ut_assert_nextline(
-               "** Booting bootflow 'mmc1.bootdev.part_1' with syslinux");
+               "** Booting bootflow 'mmc1.bootdev.part_1' with extlinux");
        ut_assert_nextline("Ignoring unknown command: ui");
 
        /*
@@ -276,12 +280,13 @@ static int bootflow_iter(struct unit_test_state *uts)
 
        /* The first device is mmc2.bootdev which has no media */
        ut_asserteq(-EPROTONOSUPPORT,
-                   bootflow_scan_first(&iter, BOOTFLOWF_ALL | BOOTFLOWF_SKIP_GLOBAL, &bflow));
+                   bootflow_scan_first(NULL, NULL, &iter,
+                                       BOOTFLOWIF_ALL | BOOTFLOWIF_SKIP_GLOBAL, &bflow));
        ut_asserteq(2, iter.num_methods);
        ut_asserteq(0, iter.cur_method);
        ut_asserteq(0, iter.part);
        ut_asserteq(0, iter.max_part);
-       ut_asserteq_str("syslinux", iter.method->name);
+       ut_asserteq_str("extlinux", iter.method->name);
        ut_asserteq(0, bflow.err);
 
        /*
@@ -308,7 +313,7 @@ static int bootflow_iter(struct unit_test_state *uts)
        ut_asserteq(0, iter.cur_method);
        ut_asserteq(0, iter.part);
        ut_asserteq(0x1e, iter.max_part);
-       ut_asserteq_str("syslinux", iter.method->name);
+       ut_asserteq_str("extlinux", iter.method->name);
        ut_asserteq(0, bflow.err);
        ut_asserteq(BOOTFLOWST_MEDIA, bflow.state);
        bootflow_free(&bflow);
@@ -329,7 +334,7 @@ static int bootflow_iter(struct unit_test_state *uts)
        ut_asserteq(0, iter.cur_method);
        ut_asserteq(1, iter.part);
        ut_asserteq(0x1e, iter.max_part);
-       ut_asserteq_str("syslinux", iter.method->name);
+       ut_asserteq_str("extlinux", iter.method->name);
        ut_asserteq(0, bflow.err);
        ut_asserteq(BOOTFLOWST_READY, bflow.state);
        bootflow_free(&bflow);
@@ -350,7 +355,7 @@ static int bootflow_iter(struct unit_test_state *uts)
        ut_asserteq(0, iter.cur_method);
        ut_asserteq(2, iter.part);
        ut_asserteq(0x1e, iter.max_part);
-       ut_asserteq_str("syslinux", iter.method->name);
+       ut_asserteq_str("extlinux", iter.method->name);
        ut_asserteq(0, bflow.err);
        ut_asserteq(BOOTFLOWST_MEDIA, bflow.state);
        bootflow_free(&bflow);
@@ -382,7 +387,7 @@ static int bootflow_system(struct unit_test_state *uts)
        console_record_reset_enable();
        ut_assertok(run_command("bootflow scan -lH", 0));
        ut_assert_skip_to_line(
-               "  0  efi_mgr      ready   (none)       0  <NULL>                    <NULL>");
+               "  0  efi_mgr      ready   (none)       0  <NULL>                    ");
        ut_assert_skip_to_line("No more bootdevs");
        ut_assert_skip_to_line("(2 bootflows, 2 valid)");
        ut_assert_console_end();
@@ -415,7 +420,7 @@ static int bootflow_iter_disable(struct unit_test_state *uts)
 
        /* Try to boot the bootmgr flow, which will fail */
        console_record_reset_enable();
-       ut_assertok(bootflow_scan_first(&iter, 0, &bflow));
+       ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
        ut_asserteq(3, iter.num_methods);
        ut_asserteq_str("sandbox", iter.method->name);
        ut_assertok(inject_response(uts));
@@ -488,7 +493,7 @@ static int bootflow_cmd_boot(struct unit_test_state *uts)
        ut_assertok(inject_response(uts));
        ut_asserteq(1, run_command("bootflow boot", 0));
        ut_assert_nextline(
-               "** Booting bootflow 'mmc1.bootdev.part_1' with syslinux");
+               "** Booting bootflow 'mmc1.bootdev.part_1' with extlinux");
        ut_assert_nextline("Ignoring unknown command: ui");
 
        /*
@@ -504,29 +509,40 @@ static int bootflow_cmd_boot(struct unit_test_state *uts)
 BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
 
 /**
- * prep_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian
+ * prep_mmc_bootdev() - Set up an mmc bootdev so we can access other distros
  *
  * @uts: Unit test state
+ * @mmc_dev: MMC device to use, e.g. "mmc4"
  * Returns 0 on success, -ve on failure
  */
-static int prep_mmc4_bootdev(struct unit_test_state *uts)
+static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
+                           bool bind_cros)
 {
-       static const char *order[] = {"mmc2", "mmc1", "mmc4", NULL};
+       const char *order[] = {"mmc2", "mmc1", mmc_dev, NULL};
        struct udevice *dev, *bootstd;
        struct bootstd_priv *std;
        const char **old_order;
-       ofnode node;
+       ofnode root, node;
 
        /* Enable the mmc4 node since we need a second bootflow */
-       node = ofnode_path("/mmc4");
+       root = oftree_root(oftree_default());
+       node = ofnode_find_subnode(root, mmc_dev);
+       ut_assert(ofnode_valid(node));
        ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
 
        /* Enable the script bootmeth too */
        ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
-       ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_script),
+       ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_2script),
                                "bootmeth_script", 0, ofnode_null(), &dev));
 
-       /* Change the order to include mmc4 */
+       /* Enable the cros bootmeth if needed */
+       if (bind_cros) {
+               ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
+               ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_cros),
+                                       "cros", 0, ofnode_null(), &dev));
+       }
+
+       /* Change the order to include the device */
        std = dev_get_priv(bootstd);
        old_order = std->bootdev_order;
        std->bootdev_order = order;
@@ -541,6 +557,19 @@ static int prep_mmc4_bootdev(struct unit_test_state *uts)
        return 0;
 }
 
+/**
+ * prep_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian
+ *
+ * @uts: Unit test state
+ * Returns 0 on success, -ve on failure
+ */
+static int prep_mmc4_bootdev(struct unit_test_state *uts)
+{
+       ut_assertok(prep_mmc_bootdev(uts, "mmc4", false));
+
+       return 0;
+}
+
 /* Check 'bootflow menu' to select a bootflow */
 static int bootflow_cmd_menu(struct unit_test_state *uts)
 {
@@ -613,7 +642,7 @@ static int bootflow_cmd_hunt_label(struct unit_test_state *uts)
        ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
        ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
        ut_assert_nextline(
-               "  0  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
+               "  0  extlinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
        ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':");
        ut_assert_skip_to_line("(1 bootflow, 1 valid)");
        ut_assert_console_end();
@@ -681,3 +710,286 @@ static int bootflow_menu_theme(struct unit_test_state *uts)
        return 0;
 }
 BOOTSTD_TEST(bootflow_menu_theme, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+
+/**
+ * check_arg() - Check both the normal case and the buffer-overflow case
+ *
+ * @uts: Unit-test state
+ * @expect_ret: Expected return value (i.e. buffer length)
+ * @expect_str: String expected to be returned
+ * @buf: Buffer to use
+ * @from: Original cmdline to update
+ * @arg: Argument to update (e.g. "console")
+ * @val: Value to set (e.g. "ttyS2") or NULL to delete the argument if present,
+ * "" to set it to an empty value (e.g. "console=") and BOOTFLOWCL_EMPTY to add
+ * it without any value ("initrd")
+ */
+static int check_arg(struct unit_test_state *uts, int expect_ret,
+                    const char *expect_str, char *buf, const char *from,
+                    const char *arg, const char *val)
+{
+       /* check for writing outside the reported bounds */
+       buf[expect_ret] = '[';
+       ut_asserteq(expect_ret,
+                   cmdline_set_arg(buf, expect_ret, from, arg, val, NULL));
+       ut_asserteq_str(expect_str, buf);
+       ut_asserteq('[', buf[expect_ret]);
+
+       /* do the test again but with one less byte in the buffer */
+       ut_asserteq(-E2BIG, cmdline_set_arg(buf, expect_ret - 1, from, arg,
+                                           val, NULL));
+
+       return 0;
+}
+
+/* Test of bootflow_cmdline_set_arg() */
+static int test_bootflow_cmdline_set(struct unit_test_state *uts)
+{
+       char buf[50];
+       const int size = sizeof(buf);
+
+       /*
+        * note that buffer-overflow tests are immediately each test case, just
+        * top keep the code together
+        */
+
+       /* add an arg that doesn't already exist, starting from empty */
+       ut_asserteq(-ENOENT, cmdline_set_arg(buf, size, NULL, "me", NULL,
+                                            NULL));
+
+       ut_assertok(check_arg(uts, 3, "me", buf, NULL, "me", BOOTFLOWCL_EMPTY));
+       ut_assertok(check_arg(uts, 4, "me=", buf, NULL, "me", ""));
+       ut_assertok(check_arg(uts, 8, "me=fred", buf, NULL, "me", "fred"));
+
+       /* add an arg that doesn't already exist, starting from non-empty */
+       ut_assertok(check_arg(uts, 11, "arg=123 me", buf, "arg=123", "me",
+                             BOOTFLOWCL_EMPTY));
+       ut_assertok(check_arg(uts, 12, "arg=123 me=", buf, "arg=123", "me",
+                             ""));
+       ut_assertok(check_arg(uts, 16, "arg=123 me=fred", buf, "arg=123", "me",
+                             "fred"));
+
+       /* update an arg at the start */
+       ut_assertok(check_arg(uts, 1, "", buf, "arg=123", "arg", NULL));
+       ut_assertok(check_arg(uts, 4, "arg", buf, "arg=123", "arg",
+                             BOOTFLOWCL_EMPTY));
+       ut_assertok(check_arg(uts, 5, "arg=", buf, "arg=123", "arg", ""));
+       ut_assertok(check_arg(uts, 6, "arg=1", buf, "arg=123", "arg", "1"));
+       ut_assertok(check_arg(uts, 9, "arg=1234", buf, "arg=123", "arg",
+                             "1234"));
+
+       /* update an arg at the end */
+       ut_assertok(check_arg(uts, 5, "mary", buf, "mary arg=123", "arg",
+                             NULL));
+       ut_assertok(check_arg(uts, 9, "mary arg", buf, "mary arg=123", "arg",
+                             BOOTFLOWCL_EMPTY));
+       ut_assertok(check_arg(uts, 10, "mary arg=", buf, "mary arg=123", "arg",
+                             ""));
+       ut_assertok(check_arg(uts, 11, "mary arg=1", buf, "mary arg=123", "arg",
+                             "1"));
+       ut_assertok(check_arg(uts, 14, "mary arg=1234", buf, "mary arg=123",
+                             "arg", "1234"));
+
+       /* update an arg in the middle */
+       ut_assertok(check_arg(uts, 16, "mary=abc john=2", buf,
+                             "mary=abc arg=123 john=2", "arg", NULL));
+       ut_assertok(check_arg(uts, 20, "mary=abc arg john=2", buf,
+                             "mary=abc arg=123 john=2", "arg",
+                             BOOTFLOWCL_EMPTY));
+       ut_assertok(check_arg(uts, 21, "mary=abc arg= john=2", buf,
+                             "mary=abc arg=123 john=2", "arg", ""));
+       ut_assertok(check_arg(uts, 22, "mary=abc arg=1 john=2", buf,
+                             "mary=abc arg=123 john=2", "arg", "1"));
+       ut_assertok(check_arg(uts, 25, "mary=abc arg=1234 john=2", buf,
+                             "mary=abc arg=123 john=2", "arg", "1234"));
+
+       /* handle existing args with quotes */
+       ut_assertok(check_arg(uts, 16, "mary=\"abc\" john", buf,
+                             "mary=\"abc\" arg=123 john", "arg", NULL));
+
+       /* handle existing args with quoted spaces */
+       ut_assertok(check_arg(uts, 20, "mary=\"abc def\" john", buf,
+                             "mary=\"abc def\" arg=123 john", "arg", NULL));
+
+       ut_assertok(check_arg(uts, 34, "mary=\"abc def\" arg=123 john def=4",
+                             buf, "mary=\"abc def\" arg=123 john", "def",
+                             "4"));
+
+       /* quote at the start */
+       ut_asserteq(-EBADF, cmdline_set_arg(buf, size,
+                                           "mary=\"abc def\" arg=\"123 456\"",
+                                           "arg", "\"4 5 6", NULL));
+
+       /* quote at the end */
+       ut_asserteq(-EBADF, cmdline_set_arg(buf, size,
+                                           "mary=\"abc def\" arg=\"123 456\"",
+                                           "arg", "4 5 6\"", NULL));
+
+       /* quote in the middle */
+       ut_asserteq(-EBADF, cmdline_set_arg(buf, size,
+                                           "mary=\"abc def\" arg=\"123 456\"",
+                                           "arg", "\"4 \"5 6\"", NULL));
+
+       /* handle updating a quoted arg */
+       ut_assertok(check_arg(uts, 27, "mary=\"abc def\" arg=\"4 5 6\"", buf,
+                             "mary=\"abc def\" arg=\"123 456\"", "arg",
+                             "4 5 6"));
+
+       /* changing a quoted arg to a non-quoted arg */
+       ut_assertok(check_arg(uts, 23, "mary=\"abc def\" arg=789", buf,
+                             "mary=\"abc def\" arg=\"123 456\"", "arg",
+                             "789"));
+
+       /* changing a non-quoted arg to a quoted arg */
+       ut_assertok(check_arg(uts, 29, "mary=\"abc def\" arg=\"456 789\"", buf,
+                             "mary=\"abc def\" arg=123", "arg", "456 789"));
+
+       /* handling of spaces */
+       ut_assertok(check_arg(uts, 8, "arg=123", buf, " ", "arg", "123"));
+       ut_assertok(check_arg(uts, 8, "arg=123", buf, "   ", "arg", "123"));
+       ut_assertok(check_arg(uts, 13, "john arg=123", buf, " john  ", "arg",
+                             "123"));
+       ut_assertok(check_arg(uts, 13, "john arg=123", buf, " john  arg=123  ",
+                             "arg", "123"));
+       ut_assertok(check_arg(uts, 18, "john arg=123 mary", buf,
+                             " john  arg=123 mary ", "arg", "123"));
+
+       /* unchanged arg */
+       ut_assertok(check_arg(uts, 3, "me", buf, "me", "me", BOOTFLOWCL_EMPTY));
+
+       /* arg which starts with the same name */
+       ut_assertok(check_arg(uts, 28, "mary=abc johnathon=2 john=3", buf,
+                             "mary=abc johnathon=2 john=1", "john", "3"));
+
+       return 0;
+}
+BOOTSTD_TEST(test_bootflow_cmdline_set, 0);
+
+/* Test of bootflow_cmdline_set_arg() */
+static int bootflow_set_arg(struct unit_test_state *uts)
+{
+       struct bootflow s_bflow, *bflow = &s_bflow;
+       ulong mem_start;
+
+       ut_assertok(env_set("bootargs", NULL));
+
+       mem_start = ut_check_delta(0);
+
+       /* Do a simple sanity check. Rely on bootflow_cmdline() for the rest */
+       bflow->cmdline = NULL;
+       ut_assertok(bootflow_cmdline_set_arg(bflow, "fred", "123", false));
+       ut_asserteq_str(bflow->cmdline, "fred=123");
+
+       ut_assertok(bootflow_cmdline_set_arg(bflow, "mary", "and here", false));
+       ut_asserteq_str(bflow->cmdline, "fred=123 mary=\"and here\"");
+
+       ut_assertok(bootflow_cmdline_set_arg(bflow, "mary", NULL, false));
+       ut_asserteq_str(bflow->cmdline, "fred=123");
+       ut_assertok(bootflow_cmdline_set_arg(bflow, "fred", NULL, false));
+       ut_asserteq_ptr(bflow->cmdline, NULL);
+
+       ut_asserteq(0, ut_check_delta(mem_start));
+
+       ut_assertok(bootflow_cmdline_set_arg(bflow, "mary", "here", true));
+       ut_asserteq_str("mary=here", env_get("bootargs"));
+       ut_assertok(env_set("bootargs", NULL));
+
+       return 0;
+}
+BOOTSTD_TEST(bootflow_set_arg, 0);
+
+/* Test of bootflow_cmdline_get_arg() */
+static int bootflow_cmdline_get(struct unit_test_state *uts)
+{
+       int pos;
+
+       /* empty string */
+       ut_asserteq(-ENOENT, cmdline_get_arg("", "fred", &pos));
+
+       /* arg with empty value */
+       ut_asserteq(0, cmdline_get_arg("fred= mary", "fred", &pos));
+       ut_asserteq(5, pos);
+
+       /* arg with a value */
+       ut_asserteq(2, cmdline_get_arg("fred=23", "fred", &pos));
+       ut_asserteq(5, pos);
+
+       /* arg with a value */
+       ut_asserteq(3, cmdline_get_arg("mary=1 fred=234", "fred", &pos));
+       ut_asserteq(12, pos);
+
+       /* arg with a value, after quoted arg */
+       ut_asserteq(3, cmdline_get_arg("mary=\"1 2\" fred=234", "fred", &pos));
+       ut_asserteq(16, pos);
+
+       /* arg in the middle */
+       ut_asserteq(0, cmdline_get_arg("mary=\"1 2\" fred john=23", "fred",
+                                      &pos));
+       ut_asserteq(15, pos);
+
+       /* quoted arg */
+       ut_asserteq(3, cmdline_get_arg("mary=\"1 2\" fred=\"3 4\" john=23",
+                                      "fred", &pos));
+       ut_asserteq(17, pos);
+
+       /* args starting with the same prefix */
+       ut_asserteq(1, cmdline_get_arg("mary=abc johnathon=3 john=1", "john",
+                                      &pos));
+       ut_asserteq(26, pos);
+
+       return 0;
+}
+BOOTSTD_TEST(bootflow_cmdline_get, 0);
+
+static int bootflow_cmdline(struct unit_test_state *uts)
+{
+       ut_assertok(run_command("bootflow scan mmc", 0));
+       ut_assertok(run_command("bootflow sel 0", 0));
+       console_record_reset_enable();
+
+       ut_asserteq(1, run_command("bootflow cmdline get fred", 0));
+       ut_assert_nextline("Argument not found");
+       ut_assert_console_end();
+
+       ut_asserteq(0, run_command("bootflow cmdline set fred 123", 0));
+       ut_asserteq(0, run_command("bootflow cmdline get fred", 0));
+       ut_assert_nextline("123");
+
+       ut_asserteq(0, run_command("bootflow cmdline set mary abc", 0));
+       ut_asserteq(0, run_command("bootflow cmdline get mary", 0));
+       ut_assert_nextline("abc");
+
+       ut_asserteq(0, run_command("bootflow cmdline delete fred", 0));
+       ut_asserteq(1, run_command("bootflow cmdline get fred", 0));
+       ut_assert_nextline("Argument not found");
+
+       ut_asserteq(0, run_command("bootflow cmdline clear mary", 0));
+       ut_asserteq(0, run_command("bootflow cmdline get mary", 0));
+       ut_assert_nextline_empty();
+
+       ut_assert_console_end();
+
+       return 0;
+}
+BOOTSTD_TEST(bootflow_cmdline, 0);
+
+/* Test ChromiumOS bootmeth */
+static int bootflow_cros(struct unit_test_state *uts)
+{
+       ut_assertok(prep_mmc_bootdev(uts, "mmc5", true));
+       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  cros         ready   mmc          2  mmc5.bootdev.part_2       ");
+       ut_assert_nextlinen("  2  cros         ready   mmc          4  mmc5.bootdev.part_4       ");
+       ut_assert_nextlinen("---");
+       ut_assert_skip_to_line("(3 bootflows, 3 valid)");
+
+       ut_assert_console_end();
+
+       return 0;
+}
+BOOTSTD_TEST(bootflow_cros, 0);
This page took 0.05125 seconds and 4 git commands to generate.