16c016485SSuriyan Ramasami#!/bin/bash 26c016485SSuriyan Ramasami# SPDX-License-Identifier: GPL-2.0+ 36c016485SSuriyan Ramasami# 4f739fcd8STom Rini# (C) Copyright 2014 Suriyan Ramasami 56c016485SSuriyan Ramasami 66c016485SSuriyan Ramasami# Invoke this test script from U-Boot base directory as ./test/fs/fs-test.sh 76c016485SSuriyan Ramasami# It currently tests the fs/sb and native commands for ext4 and fat partitions 86c016485SSuriyan Ramasami# Expected results are as follows: 96c016485SSuriyan Ramasami# EXT4 tests: 109461fcceSAKASHI Takahiro# fs-test.sb.ext4 Summary: PASS: 24 FAIL: 0 119461fcceSAKASHI Takahiro# fs-test.nonfs.ext4 Summary: PASS: 24 FAIL: 0 129461fcceSAKASHI Takahiro# fs-test.fs.ext4 Summary: PASS: 24 FAIL: 0 13edce588aSTuomas Tynkkynen# FAT16 tests: 149461fcceSAKASHI Takahiro# fs-test.sb.fat16 Summary: PASS: 24 FAIL: 0 159461fcceSAKASHI Takahiro# fs-test.nonfs.fat16 Summary: PASS: 24 FAIL: 0 169461fcceSAKASHI Takahiro# fs-test.fs.fat16 Summary: PASS: 24 FAIL: 0 17edce588aSTuomas Tynkkynen# FAT32 tests: 189461fcceSAKASHI Takahiro# fs-test.sb.fat32 Summary: PASS: 24 FAIL: 0 199461fcceSAKASHI Takahiro# fs-test.nonfs.fat32 Summary: PASS: 24 FAIL: 0 209461fcceSAKASHI Takahiro# fs-test.fs.fat32 Summary: PASS: 24 FAIL: 0 219461fcceSAKASHI Takahiro# -------------------------------------------- 229461fcceSAKASHI Takahiro# Total Summary: TOTAL PASS: 216 TOTAL FAIL: 0 239461fcceSAKASHI Takahiro# -------------------------------------------- 246c016485SSuriyan Ramasami 256c016485SSuriyan Ramasami# pre-requisite binaries list. 266c016485SSuriyan RamasamiPREREQ_BINS="md5sum mkfs mount umount dd fallocate mkdir" 276c016485SSuriyan Ramasami 286c016485SSuriyan Ramasami# All generated output files from this test will be in $OUT_DIR 296c016485SSuriyan Ramasami# Hence everything is sandboxed. 306c016485SSuriyan RamasamiOUT_DIR="sandbox/test/fs" 316c016485SSuriyan Ramasami 326c016485SSuriyan Ramasami# Location of generated sandbox u-boot 336c016485SSuriyan RamasamiUBOOT="./sandbox/u-boot" 346c016485SSuriyan Ramasami 356c016485SSuriyan Ramasami# Our mount directory will be in the sandbox 366c016485SSuriyan RamasamiMOUNT_DIR="${OUT_DIR}/mnt" 376c016485SSuriyan Ramasami 386c016485SSuriyan Ramasami# The file system image we create will have the $IMG prefix. 396c016485SSuriyan RamasamiIMG="${OUT_DIR}/3GB" 406c016485SSuriyan Ramasami 416c016485SSuriyan Ramasami# $SMALL_FILE is the name of the 1MB file in the file system image 426c016485SSuriyan RamasamiSMALL_FILE="1MB.file" 436c016485SSuriyan Ramasami 446c016485SSuriyan Ramasami# $BIG_FILE is the name of the 2.5GB file in the file system image 456c016485SSuriyan RamasamiBIG_FILE="2.5GB.file" 466c016485SSuriyan Ramasami 476c016485SSuriyan Ramasami# $MD5_FILE will have the expected md5s when we do the test 48edce588aSTuomas Tynkkynen# They shall have a suffix which represents their file system (ext4/fat16/...) 496c016485SSuriyan RamasamiMD5_FILE="${OUT_DIR}/md5s.list" 506c016485SSuriyan Ramasami 516c016485SSuriyan Ramasami# $OUT shall be the prefix of the test output. Their suffix will be .out 526c016485SSuriyan RamasamiOUT="${OUT_DIR}/fs-test" 536c016485SSuriyan Ramasami 546c016485SSuriyan Ramasami# Full Path of the 1 MB file that shall be created in the fs image. 556c016485SSuriyan RamasamiMB1="${MOUNT_DIR}/${SMALL_FILE}" 566c016485SSuriyan RamasamiGB2p5="${MOUNT_DIR}/${BIG_FILE}" 576c016485SSuriyan Ramasami 586c016485SSuriyan Ramasami# ************************ 596c016485SSuriyan Ramasami# * Functions start here * 606c016485SSuriyan Ramasami# ************************ 616c016485SSuriyan Ramasami 626c016485SSuriyan Ramasami# Check if the prereq binaries exist, or exit 636c016485SSuriyan Ramasamifunction check_prereq() { 646c016485SSuriyan Ramasami for prereq in $PREREQ_BINS; do 6547b71644SStephen Warren if [ ! -x "`which $prereq`" ]; then 666c016485SSuriyan Ramasami echo "Missing $prereq binary. Exiting!" 676c016485SSuriyan Ramasami exit 686c016485SSuriyan Ramasami fi 696c016485SSuriyan Ramasami done 706c016485SSuriyan Ramasami 716c016485SSuriyan Ramasami # We use /dev/urandom to create files. Check if it exists. 726c016485SSuriyan Ramasami if [ ! -c /dev/urandom ]; then 736c016485SSuriyan Ramasami echo "Missing character special /dev/urandom. Exiting!" 746c016485SSuriyan Ramasami exit 756c016485SSuriyan Ramasami fi 766c016485SSuriyan Ramasami} 776c016485SSuriyan Ramasami 786c016485SSuriyan Ramasami# If 1st param is "clean", then clean out the generated files and exit 796c016485SSuriyan Ramasamifunction check_clean() { 806c016485SSuriyan Ramasami if [ "$1" = "clean" ]; then 816c016485SSuriyan Ramasami rm -rf "$OUT_DIR" 826c016485SSuriyan Ramasami echo "Cleaned up generated files. Exiting" 836c016485SSuriyan Ramasami exit 846c016485SSuriyan Ramasami fi 856c016485SSuriyan Ramasami} 866c016485SSuriyan Ramasami 876c016485SSuriyan Ramasami# Generate sandbox U-Boot - gleaned from /test/dm/test-dm.sh 886c016485SSuriyan Ramasamifunction compile_sandbox() { 896c016485SSuriyan Ramasami unset CROSS_COMPILE 906c016485SSuriyan Ramasami NUM_CPUS=$(cat /proc/cpuinfo |grep -c processor) 916c016485SSuriyan Ramasami make O=sandbox sandbox_config 926c016485SSuriyan Ramasami make O=sandbox -s -j${NUM_CPUS} 936c016485SSuriyan Ramasami 946c016485SSuriyan Ramasami # Check if U-Boot exists 956c016485SSuriyan Ramasami if [ ! -x "$UBOOT" ]; then 966c016485SSuriyan Ramasami echo "$UBOOT does not exist or is not executable" 976c016485SSuriyan Ramasami echo "Build error?" 986c016485SSuriyan Ramasami echo "Please run this script as ./test/fs/`basename $0`" 996c016485SSuriyan Ramasami exit 1006c016485SSuriyan Ramasami fi 1016c016485SSuriyan Ramasami} 1026c016485SSuriyan Ramasami 1036c016485SSuriyan Ramasami# Clean out all generated files other than the file system images 1046c016485SSuriyan Ramasami# We save time by not deleting and recreating the file system images 1056c016485SSuriyan Ramasamifunction prepare_env() { 1066c016485SSuriyan Ramasami rm -f ${MD5_FILE}.* ${OUT}.* 10708eee271SStephen Warren mkdir -p ${OUT_DIR} 1086c016485SSuriyan Ramasami} 1096c016485SSuriyan Ramasami 1106c016485SSuriyan Ramasami# 1st parameter is the name of the image file to be created 111edce588aSTuomas Tynkkynen# 2nd parameter is the filesystem - fat16 ext4 etc 1126c016485SSuriyan Ramasami# -F cant be used with fat as it means something else. 1136c016485SSuriyan Ramasamifunction create_image() { 1146c016485SSuriyan Ramasami # Create image if not already present - saves time, while debugging 115edce588aSTuomas Tynkkynen case "$2" in 116edce588aSTuomas Tynkkynen fat16) 117edce588aSTuomas Tynkkynen MKFS_OPTION="-F 16" 118edce588aSTuomas Tynkkynen FS_TYPE="fat" 119edce588aSTuomas Tynkkynen ;; 120edce588aSTuomas Tynkkynen fat32) 121edce588aSTuomas Tynkkynen MKFS_OPTION="-F 32" 122edce588aSTuomas Tynkkynen FS_TYPE="fat" 123edce588aSTuomas Tynkkynen ;; 124edce588aSTuomas Tynkkynen ext4) 1256c016485SSuriyan Ramasami MKFS_OPTION="-F" 126edce588aSTuomas Tynkkynen FS_TYPE="ext4" 127edce588aSTuomas Tynkkynen ;; 128edce588aSTuomas Tynkkynen esac 129edce588aSTuomas Tynkkynen 1306c016485SSuriyan Ramasami if [ ! -f "$1" ]; then 1316c016485SSuriyan Ramasami fallocate -l 3G "$1" &> /dev/null 13208eee271SStephen Warren if [ $? -ne 0 ]; then 13308eee271SStephen Warren echo fallocate failed - using dd instead 13408eee271SStephen Warren dd if=/dev/zero of=$1 bs=1024 count=$((3 * 1024 * 1024)) 13508eee271SStephen Warren if [ $? -ne 0 ]; then 13608eee271SStephen Warren echo Could not create empty disk image 13708eee271SStephen Warren exit $? 13808eee271SStephen Warren fi 13908eee271SStephen Warren fi 140edce588aSTuomas Tynkkynen mkfs -t "$FS_TYPE" $MKFS_OPTION "$1" &> /dev/null 141edce588aSTuomas Tynkkynen if [ $? -ne 0 -a "$FS_TYPE" = "fat" ]; then 1426c016485SSuriyan Ramasami # If we fail and we did fat, try vfat. 1436c016485SSuriyan Ramasami mkfs -t vfat $MKFS_OPTION "$1" &> /dev/null 1446c016485SSuriyan Ramasami fi 14508eee271SStephen Warren if [ $? -ne 0 ]; then 14608eee271SStephen Warren echo Could not create filesystem 14708eee271SStephen Warren exit $? 14808eee271SStephen Warren fi 1496c016485SSuriyan Ramasami fi 1506c016485SSuriyan Ramasami} 1516c016485SSuriyan Ramasami 1526c016485SSuriyan Ramasami# 1st parameter is image file 153edce588aSTuomas Tynkkynen# 2nd parameter is file system type - fat16/ext4/... 1546c016485SSuriyan Ramasami# 3rd parameter is name of small file 1556c016485SSuriyan Ramasami# 4th parameter is name of big file 1566c016485SSuriyan Ramasami# 5th parameter is fs/nonfs/sb - to dictate generic fs commands or 1576c016485SSuriyan Ramasami# otherwise or sb hostfs 1586c016485SSuriyan Ramasami# 6th parameter is the directory path for the files. Its "" for generic 1596c016485SSuriyan Ramasami# fs and ext4/fat and full patch for sb hostfs 1606c016485SSuriyan Ramasami# UBOOT is set in env 1616c016485SSuriyan Ramasamifunction test_image() { 1626c016485SSuriyan Ramasami addr="0x01000008" 1636c016485SSuriyan Ramasami length="0x00100000" 1646c016485SSuriyan Ramasami 1656c016485SSuriyan Ramasami case "$2" in 166edce588aSTuomas Tynkkynen fat*) 16786853568SStefan Brüns FPATH="" 1686c016485SSuriyan Ramasami PREFIX="fat" 1696c016485SSuriyan Ramasami WRITE="write" 1706c016485SSuriyan Ramasami ;; 1716c016485SSuriyan Ramasami 1726c016485SSuriyan Ramasami ext4) 17386853568SStefan Brüns # ext4 needs absolute path 17486853568SStefan Brüns FPATH="/" 1756c016485SSuriyan Ramasami PREFIX="ext4" 1766c016485SSuriyan Ramasami WRITE="write" 1776c016485SSuriyan Ramasami ;; 1786c016485SSuriyan Ramasami 1796c016485SSuriyan Ramasami *) 1806c016485SSuriyan Ramasami echo "Unhandled filesystem $2. Exiting!" 1816c016485SSuriyan Ramasami exit 1826c016485SSuriyan Ramasami ;; 1836c016485SSuriyan Ramasami esac 1846c016485SSuriyan Ramasami 1856c016485SSuriyan Ramasami case "$5" in 1866c016485SSuriyan Ramasami fs) 1876c016485SSuriyan Ramasami PREFIX="" 1886c016485SSuriyan Ramasami WRITE="save" 1896c016485SSuriyan Ramasami SUFFIX=" 0:0" 1906c016485SSuriyan Ramasami ;; 1916c016485SSuriyan Ramasami 1926c016485SSuriyan Ramasami nonfs) 1936c016485SSuriyan Ramasami SUFFIX=" 0:0" 1946c016485SSuriyan Ramasami ;; 1956c016485SSuriyan Ramasami 1966c016485SSuriyan Ramasami sb) 197*734e207cSTom Rini PREFIX="host " 1986c016485SSuriyan Ramasami WRITE="save" 1996c016485SSuriyan Ramasami SUFFIX="fs -" 2006c016485SSuriyan Ramasami ;; 2016c016485SSuriyan Ramasami 2026c016485SSuriyan Ramasami *) 2036c016485SSuriyan Ramasami echo "Unhandled mode $5. Exiting!" 2046c016485SSuriyan Ramasami exit 2056c016485SSuriyan Ramasami ;; 2066c016485SSuriyan Ramasami 2076c016485SSuriyan Ramasami esac 2086c016485SSuriyan Ramasami 20986853568SStefan Brüns # sb always uses full path to mointpoint, irrespective of filesystem 21086853568SStefan Brüns if [ "$5" = "sb" ]; then 21186853568SStefan Brüns FPATH=${6}/ 21286853568SStefan Brüns fi 21386853568SStefan Brüns 21486853568SStefan Brüns FILE_WRITE=${3}.w 2156c016485SSuriyan Ramasami FILE_SMALL=$3 2166c016485SSuriyan Ramasami FILE_BIG=$4 2176c016485SSuriyan Ramasami 2186c016485SSuriyan Ramasami # In u-boot commands, <interface> stands for host or hostfs 2196c016485SSuriyan Ramasami # hostfs maps to the host fs. 220*734e207cSTom Rini # host maps to the "host bind" that we do 2216c016485SSuriyan Ramasami 2226c016485SSuriyan Ramasami $UBOOT << EOF 2236c016485SSuriyan Ramasamisb=$5 224*734e207cSTom Rinisetenv bind 'if test "\$sb" != sb; then host bind 0 "$1"; fi' 2256c016485SSuriyan Ramasamirun bind 2266c016485SSuriyan Ramasami# Test Case 1 - ls 2276c016485SSuriyan Ramasami${PREFIX}ls host${SUFFIX} $6 22878ccbd13SEugen Hristev# In addition, test with a nonexistent directory to see if we crash. 22978ccbd13SEugen Hristev${PREFIX}ls host${SUFFIX} invalid_d 2306c016485SSuriyan Ramasami# 2316c016485SSuriyan Ramasami# We want ${PREFIX}size host 0:0 $3 for host commands and 232*734e207cSTom Rini# host size hostfs - $3 for hostfs commands. 2336c016485SSuriyan Ramasami# 1MB is 0x0010 0000 2347c890f14STuomas Tynkkynen# Test Case 2a - size of small file 23586853568SStefan Brüns${PREFIX}size host${SUFFIX} ${FPATH}$FILE_SMALL 2366c016485SSuriyan Ramasamiprintenv filesize 2376c016485SSuriyan Ramasamisetenv filesize 2387c890f14STuomas Tynkkynen# Test Case 2b - size of small file via a path using '..' 2397c890f14STuomas Tynkkynen${PREFIX}size host${SUFFIX} ${FPATH}SUBDIR/../$FILE_SMALL 2407c890f14STuomas Tynkkynenprintenv filesize 2417c890f14STuomas Tynkkynensetenv filesize 2426c016485SSuriyan Ramasami 2436c016485SSuriyan Ramasami# 2.5GB (1024*1024*2500) is 0x9C40 0000 2446c016485SSuriyan Ramasami# Test Case 3 - size of big file 24586853568SStefan Brüns${PREFIX}size host${SUFFIX} ${FPATH}$FILE_BIG 2466c016485SSuriyan Ramasamiprintenv filesize 2476c016485SSuriyan Ramasamisetenv filesize 2486c016485SSuriyan Ramasami 2496c016485SSuriyan Ramasami# Notes about load operation 2506c016485SSuriyan Ramasami# If I use 0x01000000 I get DMA misaligned error message 2516c016485SSuriyan Ramasami# Last two parameters are size and offset. 2526c016485SSuriyan Ramasami 2536c016485SSuriyan Ramasami# Test Case 4a - Read full 1MB of small file 25486853568SStefan Brüns${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL 2556c016485SSuriyan Ramasamiprintenv filesize 2566c016485SSuriyan Ramasami# Test Case 4b - Read full 1MB of small file 2576c016485SSuriyan Ramasamimd5sum $addr \$filesize 2586c016485SSuriyan Ramasamisetenv filesize 2596c016485SSuriyan Ramasami 2606c016485SSuriyan Ramasami# Test Case 5a - First 1MB of big file 26186853568SStefan Brüns${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x0 2626c016485SSuriyan Ramasamiprintenv filesize 2636c016485SSuriyan Ramasami# Test Case 5b - First 1MB of big file 2646c016485SSuriyan Ramasamimd5sum $addr \$filesize 2656c016485SSuriyan Ramasamisetenv filesize 2666c016485SSuriyan Ramasami 2676c016485SSuriyan Ramasami# fails for ext as no offset support 2686c016485SSuriyan Ramasami# Test Case 6a - Last 1MB of big file 26986853568SStefan Brüns${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x9C300000 2706c016485SSuriyan Ramasamiprintenv filesize 2716c016485SSuriyan Ramasami# Test Case 6b - Last 1MB of big file 2726c016485SSuriyan Ramasamimd5sum $addr \$filesize 2736c016485SSuriyan Ramasamisetenv filesize 2746c016485SSuriyan Ramasami 2756c016485SSuriyan Ramasami# fails for ext as no offset support 2766c016485SSuriyan Ramasami# Test Case 7a - One from the last 1MB chunk of 2GB 27786853568SStefan Brüns${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x7FF00000 2786c016485SSuriyan Ramasamiprintenv filesize 2796c016485SSuriyan Ramasami# Test Case 7b - One from the last 1MB chunk of 2GB 2806c016485SSuriyan Ramasamimd5sum $addr \$filesize 2816c016485SSuriyan Ramasamisetenv filesize 2826c016485SSuriyan Ramasami 2836c016485SSuriyan Ramasami# fails for ext as no offset support 2846c016485SSuriyan Ramasami# Test Case 8a - One from the start 1MB chunk from 2GB 28586853568SStefan Brüns${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x80000000 2866c016485SSuriyan Ramasamiprintenv filesize 2876c016485SSuriyan Ramasami# Test Case 8b - One from the start 1MB chunk from 2GB 2886c016485SSuriyan Ramasamimd5sum $addr \$filesize 2896c016485SSuriyan Ramasamisetenv filesize 2906c016485SSuriyan Ramasami 2916c016485SSuriyan Ramasami# fails for ext as no offset support 2926c016485SSuriyan Ramasami# Test Case 9a - One 1MB chunk crossing the 2GB boundary 29386853568SStefan Brüns${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x7FF80000 2946c016485SSuriyan Ramasamiprintenv filesize 2956c016485SSuriyan Ramasami# Test Case 9b - One 1MB chunk crossing the 2GB boundary 2966c016485SSuriyan Ramasamimd5sum $addr \$filesize 2976c016485SSuriyan Ramasamisetenv filesize 2986c016485SSuriyan Ramasami 2996c016485SSuriyan Ramasami# Generic failure case 3006c016485SSuriyan Ramasami# Test Case 10 - 2MB chunk from the last 1MB of big file 30186853568SStefan Brüns${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG 0x00200000 0x9C300000 3026c016485SSuriyan Ramasamiprintenv filesize 3036c016485SSuriyan Ramasami# 3046c016485SSuriyan Ramasami 3056c016485SSuriyan Ramasami# Read 1MB from small file 30686853568SStefan Brüns${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL 3076c016485SSuriyan Ramasami# Write it back to test the writes 3086c016485SSuriyan Ramasami# Test Case 11a - Check that the write succeeded 30986853568SStefan Brüns${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}$FILE_WRITE \$filesize 3106c016485SSuriyan Ramasamimw.b $addr 00 100 31186853568SStefan Brüns${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_WRITE 3126c016485SSuriyan Ramasami# Test Case 11b - Check md5 of written to is same as the one read from 3136c016485SSuriyan Ramasamimd5sum $addr \$filesize 3146c016485SSuriyan Ramasamisetenv filesize 3156c016485SSuriyan Ramasami# 31614678b3cSStefan Brüns 31714678b3cSStefan Brüns# Next test case checks writing a file whose dirent 31814678b3cSStefan Brüns# is the first in the block, which is always true for "." 31914678b3cSStefan Brüns# The write should fail, but the lookup should work 32014678b3cSStefan Brüns# Test Case 12 - Check directory traversal 32114678b3cSStefan Brüns${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}. 0x10 3222365a4b8SStefan Brüns 3232365a4b8SStefan Brüns# Read 1MB from small file 3242365a4b8SStefan Brüns${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL 3252365a4b8SStefan Brüns# Write it via "same directory", i.e. "." dirent 3262365a4b8SStefan Brüns# Test Case 13a - Check directory traversal 3272365a4b8SStefan Brüns${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}./${FILE_WRITE}2 \$filesize 3282365a4b8SStefan Brünsmw.b $addr 00 100 3292365a4b8SStefan Brüns${PREFIX}load host${SUFFIX} $addr ${FPATH}./${FILE_WRITE}2 3302365a4b8SStefan Brüns# Test Case 13b - Check md5 of written to is same as the one read from 3312365a4b8SStefan Brünsmd5sum $addr \$filesize 3322365a4b8SStefan Brünssetenv filesize 3332365a4b8SStefan Brünsmw.b $addr 00 100 3342365a4b8SStefan Brüns${PREFIX}load host${SUFFIX} $addr ${FPATH}${FILE_WRITE}2 3352365a4b8SStefan Brüns# Test Case 13c - Check md5 of written to is same as the one read from 3362365a4b8SStefan Brünsmd5sum $addr \$filesize 3372365a4b8SStefan Brünssetenv filesize 3382365a4b8SStefan Brüns# 3396c016485SSuriyan Ramasamireset 3406c016485SSuriyan Ramasami 3416c016485SSuriyan RamasamiEOF 3426c016485SSuriyan Ramasami} 3436c016485SSuriyan Ramasami 3446c016485SSuriyan Ramasami# 1st argument is the name of the image file. 3456c016485SSuriyan Ramasami# 2nd argument is the file where we generate the md5s of the files 3466c016485SSuriyan Ramasami# generated with the appropriate start and length that we use to test. 3476c016485SSuriyan Ramasami# It creates the necessary files in the image to test. 3486c016485SSuriyan Ramasami# $GB2p5 is the path of the big file (2.5 GB) 3496c016485SSuriyan Ramasami# $MB1 is the path of the small file (1 MB) 3506c016485SSuriyan Ramasami# $MOUNT_DIR is the path we can use to mount the image file. 3516c016485SSuriyan Ramasamifunction create_files() { 3526c016485SSuriyan Ramasami # Mount the image so we can populate it. 3536c016485SSuriyan Ramasami mkdir -p "$MOUNT_DIR" 3546c016485SSuriyan Ramasami sudo mount -o loop,rw "$1" "$MOUNT_DIR" 3556c016485SSuriyan Ramasami 3567c890f14STuomas Tynkkynen # Create a subdirectory. 3577c890f14STuomas Tynkkynen sudo mkdir -p "$MOUNT_DIR/SUBDIR" 3587c890f14STuomas Tynkkynen 3596c016485SSuriyan Ramasami # Create big file in this image. 3606c016485SSuriyan Ramasami # Note that we work only on the start 1MB, couple MBs in the 2GB range 3616c016485SSuriyan Ramasami # and the last 1 MB of the huge 2.5GB file. 3626c016485SSuriyan Ramasami # So, just put random values only in those areas. 3636c016485SSuriyan Ramasami if [ ! -f "${GB2p5}" ]; then 3646c016485SSuriyan Ramasami sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=1 \ 3656c016485SSuriyan Ramasami &> /dev/null 3666c016485SSuriyan Ramasami sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=2 seek=2047 \ 3676c016485SSuriyan Ramasami &> /dev/null 3686c016485SSuriyan Ramasami sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=1 seek=2499 \ 3696c016485SSuriyan Ramasami &> /dev/null 3706c016485SSuriyan Ramasami fi 3716c016485SSuriyan Ramasami 3726c016485SSuriyan Ramasami # Create a small file in this image. 3736c016485SSuriyan Ramasami if [ ! -f "${MB1}" ]; then 3746c016485SSuriyan Ramasami sudo dd if=/dev/urandom of="${MB1}" bs=1M count=1 \ 3756c016485SSuriyan Ramasami &> /dev/null 3766c016485SSuriyan Ramasami fi 3776c016485SSuriyan Ramasami 3782365a4b8SStefan Brüns # Delete the small file copies which possibly are written as part of a 3796c016485SSuriyan Ramasami # previous test. 3806c016485SSuriyan Ramasami sudo rm -f "${MB1}.w" 3812365a4b8SStefan Brüns sudo rm -f "${MB1}.w2" 3826c016485SSuriyan Ramasami 3836c016485SSuriyan Ramasami # Generate the md5sums of reads that we will test against small file 3846c016485SSuriyan Ramasami dd if="${MB1}" bs=1M skip=0 count=1 2> /dev/null | md5sum > "$2" 3856c016485SSuriyan Ramasami 3866c016485SSuriyan Ramasami # Generate the md5sums of reads that we will test against big file 3876c016485SSuriyan Ramasami # One from beginning of file. 3886c016485SSuriyan Ramasami dd if="${GB2p5}" bs=1M skip=0 count=1 \ 3896c016485SSuriyan Ramasami 2> /dev/null | md5sum >> "$2" 3906c016485SSuriyan Ramasami 3916c016485SSuriyan Ramasami # One from end of file. 3926c016485SSuriyan Ramasami dd if="${GB2p5}" bs=1M skip=2499 count=1 \ 3936c016485SSuriyan Ramasami 2> /dev/null | md5sum >> "$2" 3946c016485SSuriyan Ramasami 3956c016485SSuriyan Ramasami # One from the last 1MB chunk of 2GB 3966c016485SSuriyan Ramasami dd if="${GB2p5}" bs=1M skip=2047 count=1 \ 3976c016485SSuriyan Ramasami 2> /dev/null | md5sum >> "$2" 3986c016485SSuriyan Ramasami 3996c016485SSuriyan Ramasami # One from the start 1MB chunk from 2GB 4006c016485SSuriyan Ramasami dd if="${GB2p5}" bs=1M skip=2048 count=1 \ 4016c016485SSuriyan Ramasami 2> /dev/null | md5sum >> "$2" 4026c016485SSuriyan Ramasami 4036c016485SSuriyan Ramasami # One 1MB chunk crossing the 2GB boundary 4046c016485SSuriyan Ramasami dd if="${GB2p5}" bs=512K skip=4095 count=2 \ 4056c016485SSuriyan Ramasami 2> /dev/null | md5sum >> "$2" 4066c016485SSuriyan Ramasami 4076c016485SSuriyan Ramasami sync 4086c016485SSuriyan Ramasami sudo umount "$MOUNT_DIR" 4096c016485SSuriyan Ramasami rmdir "$MOUNT_DIR" 4106c016485SSuriyan Ramasami} 4116c016485SSuriyan Ramasami 4126c016485SSuriyan Ramasami# 1st parameter is the text to print 4136c016485SSuriyan Ramasami# if $? is 0 its a pass, else a fail 4146c016485SSuriyan Ramasami# As a side effect it shall update env variable PASS and FAIL 4156c016485SSuriyan Ramasamifunction pass_fail() { 4166c016485SSuriyan Ramasami if [ $? -eq 0 ]; then 4176c016485SSuriyan Ramasami echo pass - "$1" 4186c016485SSuriyan Ramasami PASS=$((PASS + 1)) 4196c016485SSuriyan Ramasami else 4206c016485SSuriyan Ramasami echo FAIL - "$1" 4216c016485SSuriyan Ramasami FAIL=$((FAIL + 1)) 4226c016485SSuriyan Ramasami fi 4236c016485SSuriyan Ramasami} 4246c016485SSuriyan Ramasami 4256c016485SSuriyan Ramasami# 1st parameter is the string which leads to an md5 generation 4266c016485SSuriyan Ramasami# 2nd parameter is the file we grep, for that string 4276c016485SSuriyan Ramasami# 3rd parameter is the name of the file which has md5s in it 4286c016485SSuriyan Ramasami# 4th parameter is the line # in the md5 file that we match it against 4296c016485SSuriyan Ramasami# This function checks if the md5 of the file in the sandbox matches 4306c016485SSuriyan Ramasami# that calculated while generating the file 4316c016485SSuriyan Ramasami# 5th parameter is the string to print with the result 4326c016485SSuriyan Ramasamicheck_md5() { 4336c016485SSuriyan Ramasami # md5sum in u-boot has output of form: 4346c016485SSuriyan Ramasami # md5 for 01000008 ... 01100007 ==> <md5> 4356c016485SSuriyan Ramasami # the 7th field is the actual md5 436d9554b7fSStefan Brüns md5_src=`grep -A2 "$1" "$2" | grep "md5 for" | tr -d '\r'` 4376c016485SSuriyan Ramasami md5_src=($md5_src) 4386c016485SSuriyan Ramasami md5_src=${md5_src[6]} 4396c016485SSuriyan Ramasami 4406c016485SSuriyan Ramasami # The md5 list, each line is of the form: 4416c016485SSuriyan Ramasami # - <md5> 4426c016485SSuriyan Ramasami # the 2nd field is the actual md5 4436c016485SSuriyan Ramasami md5_dst=`sed -n $4p $3` 4446c016485SSuriyan Ramasami md5_dst=($md5_dst) 4456c016485SSuriyan Ramasami md5_dst=${md5_dst[0]} 4466c016485SSuriyan Ramasami 4476c016485SSuriyan Ramasami # For a pass they should match. 4486c016485SSuriyan Ramasami [ "$md5_src" = "$md5_dst" ] 4496c016485SSuriyan Ramasami pass_fail "$5" 4506c016485SSuriyan Ramasami} 4516c016485SSuriyan Ramasami 4526c016485SSuriyan Ramasami# 1st parameter is the name of the output file to check 4536c016485SSuriyan Ramasami# 2nd parameter is the name of the file containing the md5 expected 4546c016485SSuriyan Ramasami# 3rd parameter is the name of the small file 4556c016485SSuriyan Ramasami# 4th parameter is the name of the big file 4566c016485SSuriyan Ramasami# 5th paramter is the name of the written file 4576c016485SSuriyan Ramasami# This function checks the output file for correct results. 4586c016485SSuriyan Ramasamifunction check_results() { 4596c016485SSuriyan Ramasami echo "** Start $1" 4606c016485SSuriyan Ramasami 4616c016485SSuriyan Ramasami PASS=0 4626c016485SSuriyan Ramasami FAIL=0 4636c016485SSuriyan Ramasami 4646c016485SSuriyan Ramasami # Check if the ls is showing correct results for 2.5 gb file 4657c890f14STuomas Tynkkynen grep -A7 "Test Case 1 " "$1" | egrep -iq "2621440000 *$4" 4666c016485SSuriyan Ramasami pass_fail "TC1: ls of $4" 4676c016485SSuriyan Ramasami 4686c016485SSuriyan Ramasami # Check if the ls is showing correct results for 1 mb file 4697c890f14STuomas Tynkkynen grep -A7 "Test Case 1 " "$1" | egrep -iq "1048576 *$3" 4706c016485SSuriyan Ramasami pass_fail "TC1: ls of $3" 4716c016485SSuriyan Ramasami 4726c016485SSuriyan Ramasami # Check size command on 1MB.file 4737c890f14STuomas Tynkkynen egrep -A3 "Test Case 2a " "$1" | grep -q "filesize=100000" 4746c016485SSuriyan Ramasami pass_fail "TC2: size of $3" 4757c890f14STuomas Tynkkynen # Check size command on 1MB.file via a path using '..' 4767c890f14STuomas Tynkkynen egrep -A3 "Test Case 2b " "$1" | grep -q "filesize=100000" 4777c890f14STuomas Tynkkynen pass_fail "TC2: size of $3 via a path using '..'" 4786c016485SSuriyan Ramasami 4796c016485SSuriyan Ramasami # Check size command on 2.5GB.file 4806c016485SSuriyan Ramasami egrep -A3 "Test Case 3 " "$1" | grep -q "filesize=9c400000" 4816c016485SSuriyan Ramasami pass_fail "TC3: size of $4" 4826c016485SSuriyan Ramasami 4836c016485SSuriyan Ramasami # Check read full mb of 1MB.file 484d9554b7fSStefan Brüns grep -A4 "Test Case 4a " "$1" | grep -q "filesize=100000" 4856c016485SSuriyan Ramasami pass_fail "TC4: load of $3 size" 4866c016485SSuriyan Ramasami check_md5 "Test Case 4b " "$1" "$2" 1 "TC4: load from $3" 4876c016485SSuriyan Ramasami 4886c016485SSuriyan Ramasami # Check first mb of 2.5GB.file 489d9554b7fSStefan Brüns grep -A4 "Test Case 5a " "$1" | grep -q "filesize=100000" 4906c016485SSuriyan Ramasami pass_fail "TC5: load of 1st MB from $4 size" 4916c016485SSuriyan Ramasami check_md5 "Test Case 5b " "$1" "$2" 2 "TC5: load of 1st MB from $4" 4926c016485SSuriyan Ramasami 4936c016485SSuriyan Ramasami # Check last mb of 2.5GB.file 494d9554b7fSStefan Brüns grep -A4 "Test Case 6a " "$1" | grep -q "filesize=100000" 4956c016485SSuriyan Ramasami pass_fail "TC6: load of last MB from $4 size" 4966c016485SSuriyan Ramasami check_md5 "Test Case 6b " "$1" "$2" 3 "TC6: load of last MB from $4" 4976c016485SSuriyan Ramasami 4986c016485SSuriyan Ramasami # Check last 1mb chunk of 2gb from 2.5GB file 499d9554b7fSStefan Brüns grep -A4 "Test Case 7a " "$1" | grep -q "filesize=100000" 5006c016485SSuriyan Ramasami pass_fail "TC7: load of last 1mb chunk of 2GB from $4 size" 5016c016485SSuriyan Ramasami check_md5 "Test Case 7b " "$1" "$2" 4 \ 5026c016485SSuriyan Ramasami "TC7: load of last 1mb chunk of 2GB from $4" 5036c016485SSuriyan Ramasami 5046c016485SSuriyan Ramasami # Check first 1mb chunk after 2gb from 2.5GB file 505d9554b7fSStefan Brüns grep -A4 "Test Case 8a " "$1" | grep -q "filesize=100000" 5066c016485SSuriyan Ramasami pass_fail "TC8: load 1st MB chunk after 2GB from $4 size" 5076c016485SSuriyan Ramasami check_md5 "Test Case 8b " "$1" "$2" 5 \ 5086c016485SSuriyan Ramasami "TC8: load 1st MB chunk after 2GB from $4" 5096c016485SSuriyan Ramasami 5106c016485SSuriyan Ramasami # Check 1mb chunk crossing the 2gb boundary from 2.5GB file 511d9554b7fSStefan Brüns grep -A4 "Test Case 9a " "$1" | grep -q "filesize=100000" 5126c016485SSuriyan Ramasami pass_fail "TC9: load 1MB chunk crossing 2GB boundary from $4 size" 5136c016485SSuriyan Ramasami check_md5 "Test Case 9b " "$1" "$2" 6 \ 5146c016485SSuriyan Ramasami "TC9: load 1MB chunk crossing 2GB boundary from $4" 5156c016485SSuriyan Ramasami 516e8de6d7bSTom Rini # Check 2mb chunk from the last 1MB of 2.5GB file loads 1MB 517d9554b7fSStefan Brüns grep -A5 "Test Case 10 " "$1" | grep -q "filesize=100000" 518e8de6d7bSTom Rini pass_fail "TC10: load 2MB from the last 1MB of $4 loads 1MB" 5196c016485SSuriyan Ramasami 5206c016485SSuriyan Ramasami # Check 1mb chunk write 521d9554b7fSStefan Brüns grep -A2 "Test Case 11a " "$1" | grep -q '1048576 bytes written' 52206806e38SStefan Brüns pass_fail "TC11: 1MB write to $3.w - write succeeded" 5236c016485SSuriyan Ramasami check_md5 "Test Case 11b " "$1" "$2" 1 \ 52406806e38SStefan Brüns "TC11: 1MB write to $3.w - content verified" 52514678b3cSStefan Brüns 52614678b3cSStefan Brüns # Check lookup of 'dot' directory 527e75996ceSAKASHI Takahiro grep -A4 "Test Case 12 " "$1" | grep -q 'Unable to write' 52814678b3cSStefan Brüns pass_fail "TC12: 1MB write to . - write denied" 5292365a4b8SStefan Brüns 5302365a4b8SStefan Brüns # Check directory traversal 5312365a4b8SStefan Brüns grep -A2 "Test Case 13a " "$1" | grep -q '1048576 bytes written' 5322365a4b8SStefan Brüns pass_fail "TC13: 1MB write to ./$3.w2 - write succeeded" 5332365a4b8SStefan Brüns check_md5 "Test Case 13b " "$1" "$2" 1 \ 5342365a4b8SStefan Brüns "TC13: 1MB read from ./$3.w2 - content verified" 5352365a4b8SStefan Brüns check_md5 "Test Case 13c " "$1" "$2" 1 \ 5362365a4b8SStefan Brüns "TC13: 1MB read from $3.w2 - content verified" 5372365a4b8SStefan Brüns 5386c016485SSuriyan Ramasami echo "** End $1" 5396c016485SSuriyan Ramasami} 5406c016485SSuriyan Ramasami 5416c016485SSuriyan Ramasami# Takes in one parameter which is "fs" or "nonfs", which then dictates 5426c016485SSuriyan Ramasami# if a fs test (size/load/save) or a nonfs test (fatread/extread) needs to 5436c016485SSuriyan Ramasami# be performed. 5446c016485SSuriyan Ramasamifunction test_fs_nonfs() { 5456c016485SSuriyan Ramasami echo "Creating files in $fs image if not already present." 5466c016485SSuriyan Ramasami create_files $IMAGE $MD5_FILE_FS 5476c016485SSuriyan Ramasami 54804812605SStephen Warren OUT_FILE="${OUT}.$1.${fs}.out" 5496c016485SSuriyan Ramasami test_image $IMAGE $fs $SMALL_FILE $BIG_FILE $1 "" \ 55004812605SStephen Warren > ${OUT_FILE} 2>&1 551d9554b7fSStefan Brüns # strip out noise from fs code 552d9554b7fSStefan Brüns grep -v -e "File System is consistent\|update journal finished" \ 553d9554b7fSStefan Brüns -e "reading .*\.file\|writing .*\.file.w" \ 554d9554b7fSStefan Brüns < ${OUT_FILE} > ${OUT_FILE}_clean 555d9554b7fSStefan Brüns check_results ${OUT_FILE}_clean $MD5_FILE_FS $SMALL_FILE \ 556d9554b7fSStefan Brüns $BIG_FILE 5576c016485SSuriyan Ramasami TOTAL_FAIL=$((TOTAL_FAIL + FAIL)) 5586c016485SSuriyan Ramasami TOTAL_PASS=$((TOTAL_PASS + PASS)) 5596c016485SSuriyan Ramasami echo "Summary: PASS: $PASS FAIL: $FAIL" 5606c016485SSuriyan Ramasami echo "--------------------------------------------" 5616c016485SSuriyan Ramasami} 5626c016485SSuriyan Ramasami 5636c016485SSuriyan Ramasami# ******************** 5646c016485SSuriyan Ramasami# * End of functions * 5656c016485SSuriyan Ramasami# ******************** 5666c016485SSuriyan Ramasami 5676c016485SSuriyan Ramasamicheck_clean "$1" 5686c016485SSuriyan Ramasamicheck_prereq 5696c016485SSuriyan Ramasamicompile_sandbox 5706c016485SSuriyan Ramasamiprepare_env 5716c016485SSuriyan Ramasami 5726c016485SSuriyan Ramasami# Track TOTAL_FAIL and TOTAL_PASS 5736c016485SSuriyan RamasamiTOTAL_FAIL=0 5746c016485SSuriyan RamasamiTOTAL_PASS=0 5756c016485SSuriyan Ramasami 5766c016485SSuriyan Ramasami# In each loop, for a given file system image, we test both the 5776c016485SSuriyan Ramasami# fs command, like load/size/write, the file system specific command 578*734e207cSTom Rini# like: ext4load/ext4size/ext4write and the host load/ls/save commands. 579edce588aSTuomas Tynkkynenfor fs in ext4 fat16 fat32; do 5806c016485SSuriyan Ramasami 5816c016485SSuriyan Ramasami echo "Creating $fs image if not already present." 5826c016485SSuriyan Ramasami IMAGE=${IMG}.${fs}.img 5836c016485SSuriyan Ramasami MD5_FILE_FS="${MD5_FILE}.${fs}" 5846c016485SSuriyan Ramasami create_image $IMAGE $fs 5856c016485SSuriyan Ramasami 586*734e207cSTom Rini # host commands test 5876c016485SSuriyan Ramasami echo "Creating files in $fs image if not already present." 5886c016485SSuriyan Ramasami create_files $IMAGE $MD5_FILE_FS 5896c016485SSuriyan Ramasami 590*734e207cSTom Rini # Lets mount the image and test host hostfs commands 5916c016485SSuriyan Ramasami mkdir -p "$MOUNT_DIR" 592edce588aSTuomas Tynkkynen case "$fs" in 593edce588aSTuomas Tynkkynen fat*) 5946c016485SSuriyan Ramasami uid="uid=`id -u`" 595edce588aSTuomas Tynkkynen ;; 596edce588aSTuomas Tynkkynen *) 5976c016485SSuriyan Ramasami uid="" 598edce588aSTuomas Tynkkynen ;; 599edce588aSTuomas Tynkkynen esac 6006c016485SSuriyan Ramasami sudo mount -o loop,rw,$uid "$IMAGE" "$MOUNT_DIR" 6016c016485SSuriyan Ramasami sudo chmod 777 "$MOUNT_DIR" 6026c016485SSuriyan Ramasami 6036c016485SSuriyan Ramasami OUT_FILE="${OUT}.sb.${fs}.out" 6046c016485SSuriyan Ramasami test_image $IMAGE $fs $SMALL_FILE $BIG_FILE sb `pwd`/$MOUNT_DIR \ 60504812605SStephen Warren > ${OUT_FILE} 2>&1 6066c016485SSuriyan Ramasami sudo umount "$MOUNT_DIR" 6076c016485SSuriyan Ramasami rmdir "$MOUNT_DIR" 6086c016485SSuriyan Ramasami 60906806e38SStefan Brüns check_results $OUT_FILE $MD5_FILE_FS $SMALL_FILE $BIG_FILE 6106c016485SSuriyan Ramasami TOTAL_FAIL=$((TOTAL_FAIL + FAIL)) 6116c016485SSuriyan Ramasami TOTAL_PASS=$((TOTAL_PASS + PASS)) 6126c016485SSuriyan Ramasami echo "Summary: PASS: $PASS FAIL: $FAIL" 6136c016485SSuriyan Ramasami echo "--------------------------------------------" 6146c016485SSuriyan Ramasami 6156c016485SSuriyan Ramasami test_fs_nonfs nonfs 6166c016485SSuriyan Ramasami test_fs_nonfs fs 6176c016485SSuriyan Ramasamidone 6186c016485SSuriyan Ramasami 6196c016485SSuriyan Ramasamiecho "Total Summary: TOTAL PASS: $TOTAL_PASS TOTAL FAIL: $TOTAL_FAIL" 6206c016485SSuriyan Ramasamiecho "--------------------------------------------" 6216c016485SSuriyan Ramasamiif [ $TOTAL_FAIL -eq 0 ]; then 6226c016485SSuriyan Ramasami echo "PASSED" 6236c016485SSuriyan Ramasami exit 0 6246c016485SSuriyan Ramasamielse 6256c016485SSuriyan Ramasami echo "FAILED" 6266c016485SSuriyan Ramasami exit 1 6276c016485SSuriyan Ramasamifi 628