linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>,
	Frank Rowand <frowand.list@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Namhyung Kim <namhyung@kernel.org>, Tim Bird <Tim.Bird@sony.com>,
	Jiri Olsa <jolsa@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Tom Zanussi <tom.zanussi@linux.intel.com>,
	Rob Herring <robh+dt@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH v4 04/22] tools: bootconfig: Add bootconfig test script
Date: Mon,  2 Dec 2019 19:14:03 +0900	[thread overview]
Message-ID: <157528164332.22451.6910566428510922314.stgit@devnote2> (raw)
In-Reply-To: <157528159833.22451.14878731055438721716.stgit@devnote2>

Add a bootconfig test script to ensure the tool and
boot config parser are working correctly.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/bootconfig/Makefile                     |    3 +
 tools/bootconfig/samples/bad-dotword.bconf    |    4 +
 tools/bootconfig/samples/bad-empty.bconf      |    1 
 tools/bootconfig/samples/bad-keyerror.bconf   |    2 +
 tools/bootconfig/samples/bad-longkey.bconf    |    1 
 tools/bootconfig/samples/bad-manywords.bconf  |    1 
 tools/bootconfig/samples/bad-no-keyword.bconf |    2 +
 tools/bootconfig/samples/bad-spaceword.bconf  |    2 +
 tools/bootconfig/samples/bad-tree.bconf       |    5 ++
 tools/bootconfig/samples/bad-value.bconf      |    3 +
 tools/bootconfig/samples/good-simple.bconf    |   11 +++
 tools/bootconfig/samples/good-single.bconf    |    4 +
 tools/bootconfig/samples/good-tree.bconf      |   15 +++++
 tools/bootconfig/test-bootconfig.sh           |   80 +++++++++++++++++++++++++
 14 files changed, 134 insertions(+)
 create mode 100644 tools/bootconfig/samples/bad-dotword.bconf
 create mode 100644 tools/bootconfig/samples/bad-empty.bconf
 create mode 100644 tools/bootconfig/samples/bad-keyerror.bconf
 create mode 100644 tools/bootconfig/samples/bad-longkey.bconf
 create mode 100644 tools/bootconfig/samples/bad-manywords.bconf
 create mode 100644 tools/bootconfig/samples/bad-no-keyword.bconf
 create mode 100644 tools/bootconfig/samples/bad-spaceword.bconf
 create mode 100644 tools/bootconfig/samples/bad-tree.bconf
 create mode 100644 tools/bootconfig/samples/bad-value.bconf
 create mode 100644 tools/bootconfig/samples/good-simple.bconf
 create mode 100644 tools/bootconfig/samples/good-single.bconf
 create mode 100644 tools/bootconfig/samples/good-tree.bconf
 create mode 100755 tools/bootconfig/test-bootconfig.sh

diff --git a/tools/bootconfig/Makefile b/tools/bootconfig/Makefile
index e15e98eef412..bbbcbc26b8c5 100644
--- a/tools/bootconfig/Makefile
+++ b/tools/bootconfig/Makefile
@@ -18,5 +18,8 @@ bootconfig: ../../lib/bootconfig.c main.c $(HEADER)
 install: $(PROGS)
 	install bootconfig $(DESTDIR)$(bindir)
 
+test: bootconfig
+	./test-bootconfig.sh
+
 clean:
 	$(RM) -f *.o bootconfig
diff --git a/tools/bootconfig/samples/bad-dotword.bconf b/tools/bootconfig/samples/bad-dotword.bconf
new file mode 100644
index 000000000000..ba5557b2bdd3
--- /dev/null
+++ b/tools/bootconfig/samples/bad-dotword.bconf
@@ -0,0 +1,4 @@
+# do not start keyword with .
+key {
+  .word = 1
+}
diff --git a/tools/bootconfig/samples/bad-empty.bconf b/tools/bootconfig/samples/bad-empty.bconf
new file mode 100644
index 000000000000..2ba3f6cc6a47
--- /dev/null
+++ b/tools/bootconfig/samples/bad-empty.bconf
@@ -0,0 +1 @@
+# Wrong boot config: comment only
diff --git a/tools/bootconfig/samples/bad-keyerror.bconf b/tools/bootconfig/samples/bad-keyerror.bconf
new file mode 100644
index 000000000000..b6e247a099d0
--- /dev/null
+++ b/tools/bootconfig/samples/bad-keyerror.bconf
@@ -0,0 +1,2 @@
+# key word can not contain ","
+key,word
diff --git a/tools/bootconfig/samples/bad-longkey.bconf b/tools/bootconfig/samples/bad-longkey.bconf
new file mode 100644
index 000000000000..eb97369f91a8
--- /dev/null
+++ b/tools/bootconfig/samples/bad-longkey.bconf
@@ -0,0 +1 @@
+key_word_is_too_long01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
diff --git a/tools/bootconfig/samples/bad-manywords.bconf b/tools/bootconfig/samples/bad-manywords.bconf
new file mode 100644
index 000000000000..8db81967c48a
--- /dev/null
+++ b/tools/bootconfig/samples/bad-manywords.bconf
@@ -0,0 +1 @@
+key1.is2.too3.long4.5.6.7.8.9.10.11.12.13.14.15.16.17
diff --git a/tools/bootconfig/samples/bad-no-keyword.bconf b/tools/bootconfig/samples/bad-no-keyword.bconf
new file mode 100644
index 000000000000..eff26808566c
--- /dev/null
+++ b/tools/bootconfig/samples/bad-no-keyword.bconf
@@ -0,0 +1,2 @@
+# No keyword
+{}
diff --git a/tools/bootconfig/samples/bad-spaceword.bconf b/tools/bootconfig/samples/bad-spaceword.bconf
new file mode 100644
index 000000000000..90c703d32a9a
--- /dev/null
+++ b/tools/bootconfig/samples/bad-spaceword.bconf
@@ -0,0 +1,2 @@
+# No space between words
+key . word
diff --git a/tools/bootconfig/samples/bad-tree.bconf b/tools/bootconfig/samples/bad-tree.bconf
new file mode 100644
index 000000000000..5a6038edcd55
--- /dev/null
+++ b/tools/bootconfig/samples/bad-tree.bconf
@@ -0,0 +1,5 @@
+# brace is not closing
+tree {
+  node {
+    value = 1
+}
diff --git a/tools/bootconfig/samples/bad-value.bconf b/tools/bootconfig/samples/bad-value.bconf
new file mode 100644
index 000000000000..a1217fed86cc
--- /dev/null
+++ b/tools/bootconfig/samples/bad-value.bconf
@@ -0,0 +1,3 @@
+# Quotes error
+value = "data
+
diff --git a/tools/bootconfig/samples/good-simple.bconf b/tools/bootconfig/samples/good-simple.bconf
new file mode 100644
index 000000000000..37dd6d21c176
--- /dev/null
+++ b/tools/bootconfig/samples/good-simple.bconf
@@ -0,0 +1,11 @@
+# A good simple bootconfig
+
+key.word1 = 1
+key.word2=2
+key.word3 = 3;
+
+key {
+word4 = 4 }
+
+key { word5 = 5; word6 = 6 }
+
diff --git a/tools/bootconfig/samples/good-single.bconf b/tools/bootconfig/samples/good-single.bconf
new file mode 100644
index 000000000000..98e55ad8b711
--- /dev/null
+++ b/tools/bootconfig/samples/good-single.bconf
@@ -0,0 +1,4 @@
+# single key style
+key = 1
+key2 = 2
+key3 = "alpha", "beta"
diff --git a/tools/bootconfig/samples/good-tree.bconf b/tools/bootconfig/samples/good-tree.bconf
new file mode 100644
index 000000000000..17d43b7957b0
--- /dev/null
+++ b/tools/bootconfig/samples/good-tree.bconf
@@ -0,0 +1,15 @@
+key {
+  word {
+    tree {
+      value = "0"
+    }
+  }
+  word2 {
+    tree {
+      value = 1
+    }
+  }
+}
+other.tree {
+  value = 2; value2 = 3;
+}
diff --git a/tools/bootconfig/test-bootconfig.sh b/tools/bootconfig/test-bootconfig.sh
new file mode 100755
index 000000000000..210af5ca8af5
--- /dev/null
+++ b/tools/bootconfig/test-bootconfig.sh
@@ -0,0 +1,80 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-only
+
+echo "Boot config test script"
+
+BOOTCONF=./bootconfig
+INITRD=`mktemp initrd-XXXX`
+TEMPCONF=`mktemp temp-XXXX.bconf`
+NG=0
+
+cleanup() {
+  rm -f $INITRD $TEMPCONF
+  exit $NG
+}
+
+trap cleanup EXIT TERM
+
+NO=1
+
+xpass() { # pass test command
+  echo "test case $NO ... "
+  if ! ($* && echo "\t\t[OK]"); then
+     echo "\t\t[NG]"; NG=$((NG + 1))
+  fi
+  NO=$((NO + 1))
+}
+
+xfail() { # fail test command
+  echo "test case $NO ... "
+  if ! (! $* && echo "\t\t[OK]"); then
+     echo "\t\t[NG]"; NG=$((NG + 1))
+  fi
+  NO=$((NO + 1))
+}
+
+echo "Basic command test"
+xpass $BOOTCONF $INITRD
+
+echo "Delete command should success without bootconfig"
+xpass $BOOTCONF -d $INITRD
+
+echo "Max node number check"
+
+echo -n > $TEMPCONF
+for i in `seq 1 1024` ; do
+   echo "node$i" >> $TEMPCONF
+done
+xpass $BOOTCONF -a $TEMPCONF $INITRD
+
+echo "badnode" >> $TEMPCONF
+xfail $BOOTCONF -a $TEMPCONF $INITRD
+
+echo "Max filesize check"
+
+# Max size is 32767 (including terminal byte)
+echo -n "data = \"" > $TEMPCONF
+dd if=/dev/urandom bs=768 count=32 | base64 -w0 >> $TEMPCONF
+echo "\"" >> $TEMPCONF
+xfail $BOOTCONF -a $TEMPCONF $INITRD
+
+truncate -s 32764 $TEMPCONF
+echo "\"" >> $TEMPCONF	# add 2 bytes + terminal ('\"\n\0')
+xpass $BOOTCONF -a $TEMPCONF $INITRD
+
+echo "=== expected failure cases ==="
+for i in samples/bad-* ; do
+xfail $BOOTCONF -a $i $INITRD
+done
+
+echo "=== expected success cases ==="
+for i in samples/good-* ; do
+xpass $BOOTCONF -a $i $INITRD
+done
+
+echo
+if [ $NG -eq 0 ]; then
+	echo "All tests passed"
+else
+	echo "$NG tests failed"
+fi


  parent reply	other threads:[~2019-12-02 10:14 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-02 10:13 [RFC PATCH v4 00/22] tracing: bootconfig: Boot-time tracing and Extra boot config Masami Hiramatsu
2019-12-02 10:13 ` [RFC PATCH v4 01/22] bootconfig: Add Extra Boot Config support Masami Hiramatsu
2019-12-08 19:34   ` Randy Dunlap
2019-12-09  5:50     ` Masami Hiramatsu
2019-12-09 15:54       ` Steven Rostedt
2019-12-10 14:15         ` Masami Hiramatsu
2020-02-06  9:08         ` Geert Uytterhoeven
2020-02-06  9:41           ` Masami Hiramatsu
2019-12-02 10:13 ` [RFC PATCH v4 02/22] bootconfig: Load boot config from the tail of initrd Masami Hiramatsu
2019-12-02 10:13 ` [RFC PATCH v4 03/22] tools: bootconfig: Add bootconfig command Masami Hiramatsu
2019-12-02 10:14 ` Masami Hiramatsu [this message]
2019-12-02 10:14 ` [RFC PATCH v4 05/22] proc: bootconfig: Add /proc/bootconfig to show boot config list Masami Hiramatsu
2019-12-02 10:14 ` [RFC PATCH v4 06/22] init/main.c: Alloc initcall_command_line in do_initcall() and free it Masami Hiramatsu
2019-12-02 10:14 ` [RFC PATCH v4 07/22] bootconfig: init: Allow admin to use bootconfig for kernel command line Masami Hiramatsu
2019-12-02 10:14 ` [RFC PATCH v4 08/22] bootconfig: init: Allow admin to use bootconfig for init " Masami Hiramatsu
2019-12-02 10:14 ` [RFC PATCH v4 09/22] Documentation: bootconfig: Add a doc for extended boot config Masami Hiramatsu
2019-12-02 10:15 ` [RFC PATCH v4 10/22] tracing: Apply soft-disabled and filter to tracepoints printk Masami Hiramatsu
2019-12-02 10:15 ` [RFC PATCH v4 11/22] tracing: kprobes: Output kprobe event to printk buffer Masami Hiramatsu
2019-12-02 10:15 ` [RFC PATCH v4 12/22] tracing: kprobes: Register to dynevent earlier stage Masami Hiramatsu
2019-12-02 10:15 ` [RFC PATCH v4 13/22] tracing: Accept different type for synthetic event fields Masami Hiramatsu
2019-12-02 10:15 ` [RFC PATCH v4 14/22] tracing: Add NULL trace-array check in print_synth_event() Masami Hiramatsu
2019-12-02 10:16 ` [RFC PATCH v4 15/22] tracing/boot: Add boot-time tracing Masami Hiramatsu
2019-12-02 10:16 ` [RFC PATCH v4 16/22] tracing/boot: Add per-event settings Masami Hiramatsu
2019-12-02 10:16 ` [RFC PATCH v4 17/22] tracing/boot Add kprobe event support Masami Hiramatsu
2019-12-02 10:16 ` [RFC PATCH v4 18/22] tracing/boot: Add synthetic " Masami Hiramatsu
2019-12-02 10:16 ` [RFC PATCH v4 19/22] tracing/boot: Add instance node support Masami Hiramatsu
2019-12-02 10:17 ` [RFC PATCH v4 20/22] tracing/boot: Add cpu_mask option support Masami Hiramatsu
2019-12-02 10:17 ` [RFC PATCH v4 21/22] tracing/boot: Add function tracer filter options Masami Hiramatsu
2019-12-02 10:17 ` [RFC PATCH v4 22/22] Documentation: tracing: Add boot-time tracing document Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=157528164332.22451.6910566428510922314.stgit@devnote2 \
    --to=mhiramat@kernel.org \
    --cc=Tim.Bird@sony.com \
    --cc=acme@kernel.org \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=frowand.list@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jolsa@redhat.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=tom.zanussi@linux.intel.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).