[U-Boot] [PATCH v6 18/18] tests: Add GPT over MTD test

Patrick Delaunay patrick.delaunay at st.com
Thu May 11 07:52:08 UTC 2017


test/fs/gpt_mtd-test.sh
today only test for SF device (nor0)

Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
---

Changes in v6:
- add sandbox test (test/fs/gpt_mtd-test.sh) for modified commands

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 test/fs/gpt_mtd-test.sh | 209 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 209 insertions(+)
 create mode 100755 test/fs/gpt_mtd-test.sh

diff --git a/test/fs/gpt_mtd-test.sh b/test/fs/gpt_mtd-test.sh
new file mode 100755
index 0000000..6cb2994
--- /dev/null
+++ b/test/fs/gpt_mtd-test.sh
@@ -0,0 +1,209 @@
+#!/bin/bash
+#
+# (C) Copyright 2017 Patrick Delaunay
+#
+#  SPDX-License-Identifier:	GPL-2.0+
+#
+
+# Invoke this test script from U-Boot base directory as
+#      ./test/fs/gpt_mtd-test.sh
+# It currently tests the gpt over mtd support
+# Expected results are as follows:
+# Total Summary: TOTAL PASS: 7 TOTAL FAIL: 0
+
+# pre-requisite binaries list.
+PREREQ_BINS="dd "
+
+# Location of generated sandbox u-boot
+SANDBOX_DIR="sandbox"
+UBOOT="$SANDBOX_DIR/u-boot"
+
+# All generated output files from this test will be in $OUT_DIR
+# Hence everything is sandboxed.
+OUT_DIR="$SANDBOX_DIR/test/fs"
+
+# $OUT shall be the prefix of the test output. Their suffix will be .out
+OUT="${OUT_DIR}/fs-test"
+
+# DTB file to use
+DTB="$SANDBOX_DIR/arch/sandbox/dts/test.dtb"
+
+# ************************
+# * Functions start here *
+# ************************
+
+# Check if the prereq binaries exist, or exit
+function check_prereq() {
+	for prereq in $PREREQ_BINS; do
+		if [ ! -x "`which $prereq`" ]; then
+			echo "Missing $prereq binary. Exiting!"
+			exit
+		fi
+	done
+}
+
+# If 1st param is "clean", then clean out the generated files and exit
+function check_clean() {
+	if [ "$1" = "clean" ]; then
+		rm -rf "$OUT_DIR"
+		echo "Cleaned up generated files. Exiting"
+		exit
+	fi
+}
+
+# Generate sandbox U-Boot - gleaned from /test/dm/test-dm.sh
+function compile_sandbox() {
+	unset CROSS_COMPILE
+	NUM_CPUS=$(cat /proc/cpuinfo |grep -c processor)
+	make O=$SANDBOX_DIR sandbox_config
+	make O=$SANDBOX_DIR -s -j${NUM_CPUS}
+
+	# Check if U-Boot exists
+	if [ ! -x "$UBOOT" ]; then
+		echo "$UBOOT does not exist or is not executable"
+		echo "Build error?"
+		echo "Please run this script as ./test/fs/`basename $0`"
+		exit
+	fi
+}
+
+# Clean out all generated files other than the file system images
+# We save time by not deleting and recreating the file system images
+function prepare_env() {
+	dd if=/dev/zero of=spi.bin bs=1M count=4
+	mkdir -p ${OUT_DIR}
+}
+
+
+function test_gpt_mtd_nor() {
+
+	$UBOOT -d $DTB << EOF
+sf probe
+#
+# Test Case 1 - gpt write
+gpt write nor 0 "name=part1,size=64KiB;name=part2,type=system,size=128KiB;\
+name=boot,type=linux,bootable,size=512KiB"
+#
+# Test Case 2 - part list
+part list nor 0
+#
+# Test Case 3 - mtdparts
+setenv mtdids "nor0=nor0"
+setenv mtdparts "mtdparts="
+mtdparts gpt nor0
+mtdparts
+#
+# Test Case 4 - part list
+part list nor 0 -bootable boot_part
+printenv boot_part
+#
+# Test Case 5 - test filtering feature
+mtdparts delall
+setenv mtdparts "mtdparts="
+setenv mtdids "nor0=nor0"
+#
+# Test Case 5.1 - only add MTD for some guid = linux
+mtdparts gpt nor0 linux
+mtdparts
+#
+# Test Case 5.2 - then add MTD for some guid = data
+mtdparts gpt nor0 data
+mtdparts
+#
+# Test Case 5.3 - then add MTD for some guid = system
+mtdparts gpt nor0 system
+mtdparts
+#
+# Test Case 6.1 - check backup GPT header
+sf erase 0 0x10000
+part list nor 0
+# Test Case 6.2 - check backup GPT header
+sf erase 0x1F0000 0x10000
+part list nor 0
+#
+reset
+
+EOF
+}
+
+# 1st parameter is the text to print
+# if $? is 0 its a pass, else a fail
+# As a side effect it shall update env variable PASS and FAIL
+function pass_fail() {
+	if [ $? -eq 0 ]; then
+		echo pass - "$1"
+		PASS=$((PASS + 1))
+	else
+		echo FAIL - "$1"
+		FAIL=$((FAIL + 1))
+	fi
+}
+
+
+# 1st parameter is the name of the output file to check
+function check_results() {
+	echo "** Start $1"
+
+	PASS=0
+	FAIL=0
+
+	grep -A2 "Test Case 1 " "$1" | egrep -q "Writing GPT: success!"
+	pass_fail "TC1: gpt write"
+
+	grep -A6 "Test Case 2 " "$1" | egrep -q "part1"
+	pass_fail "TC2: part list"
+
+	grep -A7 "Test Case 3 " "$1" | egrep -q "parts = 3"
+	pass_fail "TC3: mtdparts"
+
+	grep -A4 "Test Case 4 " "$1" | egrep -q "boot_part=2 3"
+	pass_fail "TC4: part list"
+
+	grep -A4 "Test Case 5.1 " "$1" | egrep -q "parts = 1"
+	pass_fail "TC5.1: mtdparts gpt for linux"
+
+	grep -A4 "Test Case 5.2 " "$1" | egrep -q "parts = 2"
+	pass_fail "TC5.2: mtdparts gpt for data"
+
+	grep -A4 "Test Case 5.3 " "$1" | egrep -q "parts = 3"
+	pass_fail "TC5.2: mtdparts gpt for system"
+
+	grep -A6 "Test Case 6.1 " "$1" | egrep -q "Using Backup GPT"
+	pass_fail "TC6.1: check backup GPT use"
+
+	grep -A8 "Test Case 6.2 " "$1" | egrep -q "Invalid Backup GPT"
+	pass_fail "TC6.2: check backup GPT erase"
+
+	echo "** End $1"
+}
+
+# ********************
+# * End of functions *
+# ********************
+
+check_clean "$1"
+check_prereq
+compile_sandbox
+prepare_env
+
+# Track TOTAL_FAIL and TOTAL_PASS
+TOTAL_FAIL=0
+TOTAL_PASS=0
+
+OUT_FILE="${OUT}.sb.gpt_mtd_nor.out"
+test_gpt_mtd_nor > ${OUT_FILE} 2>&1
+
+check_results $OUT_FILE
+TOTAL_FAIL=$((TOTAL_FAIL + FAIL))
+TOTAL_PASS=$((TOTAL_PASS + PASS))
+
+
+echo "Total Summary: TOTAL PASS: $TOTAL_PASS TOTAL FAIL: $TOTAL_FAIL"
+echo "--------------------------------------------"
+if [ $TOTAL_FAIL -eq 0 ]; then
+	echo "PASSED"
+	exit 0
+else
+	echo "FAILED"
+	exit 1
+fi
-- 
1.9.1



More information about the U-Boot mailing list