[PATCH v2] tools/bootconfig: Preserve arrays starting with an empty value

Eduardo Mucelli Rezende Oliveira posted 1 patch 1 day, 21 hours ago
tools/bootconfig/main.c             |  2 +-
tools/bootconfig/test-bootconfig.sh | 27 ++++++++++++++++++++++++++-
2 files changed, 27 insertions(+), 2 deletions(-)
[PATCH v2] tools/bootconfig: Preserve arrays starting with an empty value
Posted by Eduardo Mucelli Rezende Oliveira 1 day, 21 hours ago
bootconfig -l treats an empty first value as a key without a value.
When the value is an array, this drops every subsequent entry from the
output. For example, 'key = "", "value"' is printed as 'key = ""'.
Reading the list output back loses the second entry.

Check for a child value node instead of checking the contents of the
first string. This lets xbc_show_value() print all the array entries
and keeps the existing output for keys without a value.

Add tests for direct arrays, appended values, nested keys, empty
scalars and keys without values. Exercise list output from both a
configuration file and a test initrd.

Fixes: e4f70b7badb4 ("tools/bootconfig: Add list option")
Signed-off-by: Eduardo Mucelli Rezende Oliveira <edumucelli@gmail.com>
---
Hi Masami,

Thanks for catching the test issue. The plain-file and initrd cases now
use the same original input and compare against a separate expected
output file. I reran the bootconfig test suite on my Ubuntu machine.

Thanks,
Eduardo

Changes in v2
- Keep the input file intact for the initrd case.
- Rebase onto the current bootconfig/fixes.

 tools/bootconfig/main.c             |  2 +-
 tools/bootconfig/test-bootconfig.sh | 27 ++++++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index c32fb1e2140cf..256d2ba7523c8 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -170,7 +170,7 @@ static void xbc_show_list(void)
 			break;
 		}
 		printf("%s = ", key);
-		if (!val || val[0] == '\0') {
+		if (!val || !xbc_node_get_child(leaf)) {
 			printf("\"\"\n");
 			continue;
 		}
diff --git a/tools/bootconfig/test-bootconfig.sh b/tools/bootconfig/test-bootconfig.sh
index a93a40d11d278..1f41ccd9ed3b2 100755
--- a/tools/bootconfig/test-bootconfig.sh
+++ b/tools/bootconfig/test-bootconfig.sh
@@ -14,10 +14,11 @@ ALIGN=4
 INITRD=`mktemp ${TESTDIR}/initrd-XXXX`
 TEMPCONF=`mktemp ${TESTDIR}/temp-XXXX.bconf`
 OUTFILE=`mktemp ${TESTDIR}/tempout-XXXX`
+EXPECTED=`mktemp ${TESTDIR}/expected-XXXX`
 NG=0
 
 cleanup() {
-  rm -f $INITRD $TEMPCONF $OUTFILE
+  rm -f $INITRD $TEMPCONF $OUTFILE $EXPECTED
   exit $NG
 }
 
@@ -169,6 +170,30 @@ $BOOTCONF $INITRD > $TEMPCONF
 cat $TEMPCONF
 xpass grep \'\"string\"\' $TEMPCONF
 
+echo "List output preserves arrays starting with an empty value"
+cat > $TEMPCONF << EOF
+flag
+empty = ""
+array = "", "value", ""
+append = ""
+append += "value"
+nested.array = "", "value"
+EOF
+$BOOTCONF -l $TEMPCONF > $OUTFILE
+cat > $EXPECTED << EOF
+flag = ""
+empty = ""
+array = "", "value", ""
+append = "", "value"
+nested.array = "", "value"
+EOF
+xpass diff -u $EXPECTED $OUTFILE
+
+echo "List output preserves empty array values in an initrd"
+xpass $BOOTCONF -a $TEMPCONF $INITRD
+$BOOTCONF -l $INITRD > $OUTFILE
+xpass diff -u $EXPECTED $OUTFILE
+
 echo "Repeat same-key tree"
 cat > $TEMPCONF << EOF
 foo

base-commit: 51934668ca98f1b23c51ce4edea3c61018da342c
-- 
2.53.0