From 8a00021b2ab5529640e5acaca30a27cdaca04178 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 13 Jul 2016 16:10:28 +0200 Subject: Integrate tests into autotools build system Add automake files for the test binaries. If configured to do so, install the test binaries to libexec/mtd-utils and use autoconf to fix the paths in the test scripts. Signed-off-by: David Oberhollenzer Signed-off-by: Richard Weinberger --- tests/ubi-tests/Makefile | 24 ---- tests/ubi-tests/Makefile.am | 7 -- tests/ubi-tests/Makemodule.am | 68 +++++++++++ tests/ubi-tests/runtests.sh | 36 ------ tests/ubi-tests/runubitests.sh.in | 42 +++++++ tests/ubi-tests/stress-test.sh | 212 --------------------------------- tests/ubi-tests/ubi-stress-test.sh.in | 215 ++++++++++++++++++++++++++++++++++ 7 files changed, 325 insertions(+), 279 deletions(-) delete mode 100644 tests/ubi-tests/Makefile delete mode 100644 tests/ubi-tests/Makefile.am create mode 100644 tests/ubi-tests/Makemodule.am delete mode 100755 tests/ubi-tests/runtests.sh create mode 100755 tests/ubi-tests/runubitests.sh.in delete mode 100755 tests/ubi-tests/stress-test.sh create mode 100755 tests/ubi-tests/ubi-stress-test.sh.in (limited to 'tests/ubi-tests') diff --git a/tests/ubi-tests/Makefile b/tests/ubi-tests/Makefile deleted file mode 100644 index c434a6f..0000000 --- a/tests/ubi-tests/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -LIBUBI_PATH = ../../ubi-utils/ -LIBUBI_HEADER_PATH = $(LIBUBI_PATH)/include -UBIUTILS_PATH=../../ubi-utils/ - -KERNELHDR := ../../include - -LIBS = libubi -TARGETS=io_update volrefcnt integ io_paral io_read io_basic \ - mkvol_basic mkvol_bad mkvol_paral rsvol - -CFLAGS += -I$(LIBUBI_HEADER_PATH) -I $(KERNELHDR) -LDLIBS += -lpthread - -include ../../common.mk - -# Compile ubilib with the udevsettle hack -libubi.a: $(LIBUBI_PATH)/libubi.c $(LIBUBI_HEADER_PATH)/libubi.h $(LIBUBI_PATH)/libubi_int.h - $(CC) $(CFLAGS) -I $(LIBUBI_PATH) -I../../include -DUDEV_SETTLE_HACK -c $(LIBUBI_PATH)/libubi.c -o libubi.o - ar cr libubi.a libubi.o - -$(TARGETS): $(addprefix $(BUILDDIR)/, helpers.o) libubi.a - -clean:: - rm -f libubi.a diff --git a/tests/ubi-tests/Makefile.am b/tests/ubi-tests/Makefile.am deleted file mode 100644 index d57316a..0000000 --- a/tests/ubi-tests/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -io_basic_SOURCES = io_basic.c helpers.c -io_basic_LDADD = libmtd.a libubi.a -io_basic_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include - -UBITEST_BINS = io_basic - -noinst_PROGRAMS += $(UBITEST_BINS) diff --git a/tests/ubi-tests/Makemodule.am b/tests/ubi-tests/Makemodule.am new file mode 100644 index 0000000..805aeaf --- /dev/null +++ b/tests/ubi-tests/Makemodule.am @@ -0,0 +1,68 @@ +io_basic_SOURCES = tests/ubi-tests/io_basic.c tests/ubi-tests/helpers.c +io_basic_LDADD = libubi.a +io_basic_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include + +io_update_SOURCES = tests/ubi-tests/io_update.c tests/ubi-tests/helpers.c +io_update_LDADD = libubi.a +io_update_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include + +io_paral_SOURCES = tests/ubi-tests/io_paral.c tests/ubi-tests/helpers.c +io_paral_LDADD = libubi.a $(PTHREAD_LIBS) +io_paral_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include + +io_paral_LDADD += $(PTHREAD_CFLAGS) +io_paral_CPPFLAGS += $(PTHREAD_CFLAGS) + +io_read_SOURCES = tests/ubi-tests/io_read.c tests/ubi-tests/helpers.c +io_read_LDADD = libubi.a +io_read_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include + +volrefcnt_SOURCES = tests/ubi-tests/volrefcnt.c tests/ubi-tests/helpers.c +volrefcnt_LDADD = libubi.a +volrefcnt_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include + +integ_SOURCES = tests/ubi-tests/integ.c tests/ubi-tests/helpers.c +integ_LDADD = libubi.a +integ_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include + +mkvol_basic_SOURCES = tests/ubi-tests/mkvol_basic.c tests/ubi-tests/helpers.c +mkvol_basic_LDADD = libubi.a +mkvol_basic_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include + +mkvol_bad_SOURCES = tests/ubi-tests/mkvol_bad.c tests/ubi-tests/helpers.c +mkvol_bad_LDADD = libubi.a +mkvol_bad_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include + +mkvol_paral_SOURCES = tests/ubi-tests/mkvol_paral.c tests/ubi-tests/helpers.c +mkvol_paral_LDADD = libubi.a $(PTHREAD_LIBS) +mkvol_paral_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include + +mkvol_paral_LDADD += $(PTHREAD_CFLAGS) +mkvol_paral_CPPFLAGS += $(PTHREAD_CFLAGS) + +rsvol_SOURCES = tests/ubi-tests/rsvol.c tests/ubi-tests/helpers.c +rsvol_LDADD = libubi.a +rsvol_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include + +UBITEST_BINS = \ + io_basic io_update io_paral io_read volrefcnt integ \ + mkvol_basic mkvol_bad mkvol_paral rsvol + +UBITEST_SH = \ + tests/ubi-tests/runubitests.sh tests/ubi-tests/ubi-stress-test.sh + +UBITEST_HEADER = \ + tests/ubi-tests/helpers.h + +UBITEST_EXTRA = \ + tests/ubi-tests/README.udev + +EXTRA_DIST += $(UBITEST_EXTRA) $(UBITEST_HEADER) + +if INSTALL_TESTS +pkglibexec_SCRIPTS += $(UBITEST_SH) +pkglibexec_PROGRAMS += $(UBITEST_BINS) +else +noinst_SCRIPTS += $(UBITEST_SH) +noinst_PROGRAMS += $(UBITEST_BINS) +endif diff --git a/tests/ubi-tests/runtests.sh b/tests/ubi-tests/runtests.sh deleted file mode 100755 index 539ef9d..0000000 --- a/tests/ubi-tests/runtests.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -euf - -tests="mkvol_basic mkvol_bad mkvol_paral rsvol io_basic io_read io_update io_paral volrefcnt" - -fatal() -{ - echo "Error: $1" 1>&2 - echo "FAILURE" - exit 1 -} - -usage() -{ - cat 1>&2 < -Example: - ${0##*/} /dev/ubi1 - test /dev/ubi1. -EOF -} - -if [ "$#" -lt 1 ]; then - usage - exit 1 -fi - -ubidev="$1" -[ -c "$ubidev" ] || fatal "$ubidev is not character device" - -for t in $tests; do - echo "Running $t $ubidev" - "./$t" "$ubidev" || fatal "$t failed" -done - -echo "SUCCESS" diff --git a/tests/ubi-tests/runubitests.sh.in b/tests/ubi-tests/runubitests.sh.in new file mode 100755 index 0000000..a1b23c4 --- /dev/null +++ b/tests/ubi-tests/runubitests.sh.in @@ -0,0 +1,42 @@ +#!/bin/sh -euf + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ +libexecpath=@libexecdir@/mtd-utils +TESTBINDIR=@testbindir@ + +tests="mkvol_basic mkvol_bad mkvol_paral rsvol io_basic io_read io_update io_paral volrefcnt" + +fatal() +{ + echo "Error: $1" 1>&2 + echo "FAILURE" + exit 1 +} + +usage() +{ + cat 1>&2 < +Example: + ${0##*/} /dev/ubi1 - test /dev/ubi1. +EOF +} + +if [ "$#" -lt 1 ]; then + usage + exit 1 +fi + +ubidev="$1" +[ -c "$ubidev" ] || fatal "$ubidev is not character device" + +for t in $tests; do + echo "Running $t $ubidev" + "$TESTBINDIR/$t" "$ubidev" || fatal "$t failed" +done + +echo "SUCCESS" diff --git a/tests/ubi-tests/stress-test.sh b/tests/ubi-tests/stress-test.sh deleted file mode 100755 index a150495..0000000 --- a/tests/ubi-tests/stress-test.sh +++ /dev/null @@ -1,212 +0,0 @@ -#!/bin/sh -euf - -srcdir="$(readlink -ev -- ${0%/*})" -PATH="$srcdir:$srcdir/../..:$PATH" - -fatal() -{ - echo "Error: $1" 1>&2 - exit 1 -} - -usage() -{ - cat 1>&2 </dev/null 2>&1 ||: - rmmod nandsim >/dev/null 2>&1 ||: - rmmod mtdram >/dev/null 2>&1 ||: - - # Below is magic to exit with correct exit code - if [ "$ret" != "0" ]; then - trap false EXIT - else - trap true EXIT - fi -} -trap 'cleanup_handler $?' EXIT -trap 'cleanup_handler 1' HUP PIPE INT QUIT TERM - -# Find MTD device number by pattern in /proc/mtd -# Usage: find_mtd_device -find_mtd_device() -{ - printf "%s" "$(grep "$1" /proc/mtd | sed -e "s/^mtd\([0-9]\+\):.*$/\1/")" -} - -# Just print parameters of the 'run_test' funcion in a user-friendly form. -print_params() -{ - local module="$1"; shift - local size="$1"; shift - local peb_size="$1"; shift - local page_size="$1"; shift - local vid_offs="$1"; shift - local fastmap="$1"; shift - - printf "%s" "$module: ${size}MiB, PEB size ${peb_size}KiB, " - if [ "$module" = "nandsim" ]; then - printf "%s" "page size ${page_size}KiB, VID offset $vid_offs, " - fi - printf "%s\n" "fastmap $fastmap" -} - -# Load mtdram with specified size and PEB size -# Usage: load_mtdram -# 1. Flash size is specified in MiB -# 2. PEB size is specified in KiB -load_mtdram() -{ - local size="$1"; shift - local peb_size="$1"; shift - - size="$(($size * 1024))" - modprobe mtdram total_size="$size" erase_size="$peb_size" || - echo "Error: cannot load $size MiB mtdram" -} - -print_separator() -{ - echo "======================================================================" -} - -# Run a test on nandsim or mtdram with certain geometry. -# Usage: run_test \ -# -# 1. Simulator type (nandsim or mtdram) -# 2. Flash size is specified in MiB -# 3. PEB size is specified in KiB -# 4. Page size is specified in bytes (mtdram ingores this) -# 5. VID header offset (mtdram ingores this) -# 6. Whether fast-map should be enabled (pass "enabled" or "disabled") -run_test() -{ - local module="$1"; - local size="$2"; - local peb_size="$3"; - local page_size="$4"; - local vid_offs="$5" - local fastmap="$6"; - local fm_supported fm_param mtdnum - - print_separator - - # Check if fastmap is supported by UBI - if modinfo ubi | grep -q fm_auto; then - fm_supported="yes" - else - fm_supported="no" - fi - - if [ "$fastmap" = "enabled" ]; then - fm_param= - elif [ "$fm_supported" = "yes" ]; then - fastmap="disabled" - fm_param="fm_auto" - else - echo "Fastmap is not supported, skip" - return 0 - fi - - if [ "$module" = "nandsim" ]; then - print_params "$@" - - load_nandsim.sh "$size" "$peb_size" "$page_size" || - echo "Cannot load nandsim, test skipped" - - mtdnum="$(find_mtd_device "$nandsim_patt")" - elif [ "$module" = "mtdram" ]; then - print_params "$@" - - load_mtdram "$size" "$peb_size" - - mtdnum="$(find_mtd_device "$mtdram_patt")" - else - fatal "$module is not supported" || - echo "Cannot load nandsim, test skipped" - fi - - modprobe ubi mtd="$mtdnum,$vid_offs" $fm_param - runtests.sh /dev/ubi0 ||: - - sudo rmmod ubi - sudo rmmod "$module" -} - -if [ "$#" -lt 1 ] || [ "$1" != "run" ]; then - usage - exit 1 -fi - -# Make sure neither mtdram nor nandsim are used -nandsim_patt="NAND simulator" -mtdram_patt="mtdram test device" -if [ -e /proc/mtd ]; then - ! grep -q "$nandsim_patt" /proc/mtd || - fatal "the nandsim driver is already used" - ! grep -q "$mtdram_patt" /proc/mtd || - fatal "the mtdram driver is already used" -fi - -rmmod ubi >/dev/null 2>&1 ||: - -for module in "mtdram" "nandsim"; do - for fm in "enabled" "disabled"; do - for vid_factor in 1 0; do - print_separator - print_separator - print_separator - echo "Test on $module, fastmap $fm, VID header offset factor $vid_factor" - print_separator - print_separator - - pg_size="512" - vid_offs="$(($pg_size * $vid_factor))" - - run_test "$module" "16" "16" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "32" "16" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "64" "16" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "128" "16" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "256" "16" "$pg_size" "$vid_offs" "$fm" - - pg_size="2048" - vid_offs="$(($pg_size * $vid_factor))" - - run_test "$module" "64" "64" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "128" "64" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "256" "64" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "512" "64" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "1024" "64" "$pg_size" "$vid_offs" "$fm" - - run_test "$module" "64" "128" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "128" "128" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "256" "128" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "512" "128" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "1024" "128" "$pg_size" "$vid_offs" "$fm" - - run_test "$module" "64" "256" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "128" "256" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "256" "256" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "512" "256" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "1024" "256" "$pg_size" "$vid_offs" "$fm" - - run_test "$module" "64" "512" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "128" "512" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "256" "512" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "512" "512" "$pg_size" "$vid_offs" "$fm" - run_test "$module" "1024" "512" "$pg_size" "$vid_offs" "$fm" - done - done -done diff --git a/tests/ubi-tests/ubi-stress-test.sh.in b/tests/ubi-tests/ubi-stress-test.sh.in new file mode 100755 index 0000000..42ccec5 --- /dev/null +++ b/tests/ubi-tests/ubi-stress-test.sh.in @@ -0,0 +1,215 @@ +#!/bin/sh -euf + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ +libexecpath=@libexecdir@/mtd-utils +TESTBINDIR=@testbindir@ + +fatal() +{ + echo "Error: $1" 1>&2 + exit 1 +} + +usage() +{ + cat 1>&2 </dev/null 2>&1 ||: + rmmod nandsim >/dev/null 2>&1 ||: + rmmod mtdram >/dev/null 2>&1 ||: + + # Below is magic to exit with correct exit code + if [ "$ret" != "0" ]; then + trap false EXIT + else + trap true EXIT + fi +} +trap 'cleanup_handler $?' EXIT +trap 'cleanup_handler 1' HUP PIPE INT QUIT TERM + +# Find MTD device number by pattern in /proc/mtd +# Usage: find_mtd_device +find_mtd_device() +{ + printf "%s" "$(grep "$1" /proc/mtd | sed -e "s/^mtd\([0-9]\+\):.*$/\1/")" +} + +# Just print parameters of the 'run_test' funcion in a user-friendly form. +print_params() +{ + local module="$1"; shift + local size="$1"; shift + local peb_size="$1"; shift + local page_size="$1"; shift + local vid_offs="$1"; shift + local fastmap="$1"; shift + + printf "%s" "$module: ${size}MiB, PEB size ${peb_size}KiB, " + if [ "$module" = "nandsim" ]; then + printf "%s" "page size ${page_size}KiB, VID offset $vid_offs, " + fi + printf "%s\n" "fastmap $fastmap" +} + +# Load mtdram with specified size and PEB size +# Usage: load_mtdram +# 1. Flash size is specified in MiB +# 2. PEB size is specified in KiB +load_mtdram() +{ + local size="$1"; shift + local peb_size="$1"; shift + + size="$(($size * 1024))" + modprobe mtdram total_size="$size" erase_size="$peb_size" || + echo "Error: cannot load $size MiB mtdram" +} + +print_separator() +{ + echo "======================================================================" +} + +# Run a test on nandsim or mtdram with certain geometry. +# Usage: run_test \ +# +# 1. Simulator type (nandsim or mtdram) +# 2. Flash size is specified in MiB +# 3. PEB size is specified in KiB +# 4. Page size is specified in bytes (mtdram ingores this) +# 5. VID header offset (mtdram ingores this) +# 6. Whether fast-map should be enabled (pass "enabled" or "disabled") +run_test() +{ + local module="$1"; + local size="$2"; + local peb_size="$3"; + local page_size="$4"; + local vid_offs="$5" + local fastmap="$6"; + local fm_supported fm_param mtdnum + + print_separator + + # Check if fastmap is supported by UBI + if modinfo ubi | grep -q fm_auto; then + fm_supported="yes" + else + fm_supported="no" + fi + + if [ "$fastmap" = "enabled" ]; then + fm_param= + elif [ "$fm_supported" = "yes" ]; then + fastmap="disabled" + fm_param="fm_auto" + else + echo "Fastmap is not supported, skip" + return 0 + fi + + if [ "$module" = "nandsim" ]; then + print_params "$@" + + $TESTBINDIR/load_nandsim.sh "$size" "$peb_size" "$page_size" || + echo "Cannot load nandsim, test skipped" + + mtdnum="$(find_mtd_device "$nandsim_patt")" + elif [ "$module" = "mtdram" ]; then + print_params "$@" + + load_mtdram "$size" "$peb_size" + + mtdnum="$(find_mtd_device "$mtdram_patt")" + else + fatal "$module is not supported" || + echo "Cannot load nandsim, test skipped" + fi + + modprobe ubi mtd="$mtdnum,$vid_offs" $fm_param + $TESTBINDIR/runubitests.sh /dev/ubi0 ||: + + sudo rmmod ubi + sudo rmmod "$module" +} + +if [ "$#" -lt 1 ] || [ "$1" != "run" ]; then + usage + exit 1 +fi + +# Make sure neither mtdram nor nandsim are used +nandsim_patt="NAND simulator" +mtdram_patt="mtdram test device" +if [ -e /proc/mtd ]; then + ! grep -q "$nandsim_patt" /proc/mtd || + fatal "the nandsim driver is already used" + ! grep -q "$mtdram_patt" /proc/mtd || + fatal "the mtdram driver is already used" +fi + +rmmod ubi >/dev/null 2>&1 ||: + +for module in "mtdram" "nandsim"; do + for fm in "enabled" "disabled"; do + for vid_factor in 1 0; do + print_separator + print_separator + print_separator + echo "Test on $module, fastmap $fm, VID header offset factor $vid_factor" + print_separator + print_separator + + pg_size="512" + vid_offs="$(($pg_size * $vid_factor))" + + run_test "$module" "16" "16" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "32" "16" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "64" "16" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "128" "16" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "256" "16" "$pg_size" "$vid_offs" "$fm" + + pg_size="2048" + vid_offs="$(($pg_size * $vid_factor))" + + run_test "$module" "64" "64" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "128" "64" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "256" "64" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "512" "64" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "1024" "64" "$pg_size" "$vid_offs" "$fm" + + run_test "$module" "64" "128" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "128" "128" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "256" "128" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "512" "128" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "1024" "128" "$pg_size" "$vid_offs" "$fm" + + run_test "$module" "64" "256" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "128" "256" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "256" "256" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "512" "256" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "1024" "256" "$pg_size" "$vid_offs" "$fm" + + run_test "$module" "64" "512" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "128" "512" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "256" "512" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "512" "512" "$pg_size" "$vid_offs" "$fm" + run_test "$module" "1024" "512" "$pg_size" "$vid_offs" "$fm" + done + done +done -- cgit v1.2.3