diff mbox

[U-Boot] fat: scripts for prepare and test read fat files

Message ID 1418399532-13502-1-git-send-email-p.marczak@samsung.com
State RFC
Headers show

Commit Message

Przemyslaw Marczak Dec. 12, 2014, 3:52 p.m. UTC
---------------------------------------------------------
mktest_files: script for generating random size long name files
---------------------------------------------------------
Usage:
./1_mktest_files.sh count

count - number of files to be generated

The output directory is: "./test_files"

---------------------------------------------------------
copy_files: copy the test_files/* into test partition mount point
---------------------------------------------------------
Usage:
./2_copy_files.sh mount_point

-----------------------------------------------------------
fat_test.sh: test fat read by write commands to the device console
----------------------------------------------------------
This script send commands to U-Boot console.
First specify few script variables, e.g:
- TTY="/dev/ttyS0"
- MMCDEV=0
- PARTITION=2
- LOAD_ADDR="0x40000000"

usage:
1. Target:
   run: ums 0 mmc 0
2. Run script 1 and 2 to make and copy the test files
   onto the test partition by UMS
3. This script:
   - set test device $PARTITION and other variables in the script,
     which is required for sending proper commands
   - set $TTY in the script
   run: ./3_fat_test.sh
4. Compare the crc results on the target and device consoles
   (sorry for the mess on the console)

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
---
 1_mktest_files.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2_copy_files.sh   | 20 ++++++++++++++
 3_fat_test.sh     | 38 ++++++++++++++++++++++++++
 3 files changed, 140 insertions(+)
 create mode 100755 1_mktest_files.sh
 create mode 100755 2_copy_files.sh
 create mode 100755 3_fat_test.sh

Comments

Przemyslaw Marczak Dec. 12, 2014, 3:54 p.m. UTC | #1
Hello,

On 12/12/2014 04:52 PM, Przemyslaw Marczak wrote:
> ---------------------------------------------------------
> mktest_files: script for generating random size long name files
> ---------------------------------------------------------
> Usage:
> ./1_mktest_files.sh count
>
> count - number of files to be generated
>
> The output directory is: "./test_files"
>
> ---------------------------------------------------------
> copy_files: copy the test_files/* into test partition mount point
> ---------------------------------------------------------
> Usage:
> ./2_copy_files.sh mount_point
>
> -----------------------------------------------------------
> fat_test.sh: test fat read by write commands to the device console
> ----------------------------------------------------------
> This script send commands to U-Boot console.
> First specify few script variables, e.g:
> - TTY="/dev/ttyS0"
> - MMCDEV=0
> - PARTITION=2
> - LOAD_ADDR="0x40000000"
>
> usage:
> 1. Target:
>     run: ums 0 mmc 0
> 2. Run script 1 and 2 to make and copy the test files
>     onto the test partition by UMS
> 3. This script:
>     - set test device $PARTITION and other variables in the script,
>       which is required for sending proper commands
>     - set $TTY in the script
>     run: ./3_fat_test.sh
> 4. Compare the crc results on the target and device consoles
>     (sorry for the mess on the console)
>
> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
> ---
>   1_mktest_files.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>   2_copy_files.sh   | 20 ++++++++++++++
>   3_fat_test.sh     | 38 ++++++++++++++++++++++++++
>   3 files changed, 140 insertions(+)
>   create mode 100755 1_mktest_files.sh
>   create mode 100755 2_copy_files.sh
>   create mode 100755 3_fat_test.sh
>

This is just for some quick test.
I will add something more pretty to the sandbox.

Best regards,
Simon Glass Dec. 16, 2014, 8:41 p.m. UTC | #2
Hi Przemyslaw,

On 12 December 2014 at 08:54, Przemyslaw Marczak <p.marczak@samsung.com> wrote:
>
> Hello,
>
>
> On 12/12/2014 04:52 PM, Przemyslaw Marczak wrote:
>>
>> ---------------------------------------------------------
>> mktest_files: script for generating random size long name files
>> ---------------------------------------------------------
>> Usage:
>> ./1_mktest_files.sh count
>>
>> count - number of files to be generated
>>
>> The output directory is: "./test_files"
>>
>> ---------------------------------------------------------
>> copy_files: copy the test_files/* into test partition mount point
>> ---------------------------------------------------------
>> Usage:
>> ./2_copy_files.sh mount_point
>>
>> -----------------------------------------------------------
>> fat_test.sh: test fat read by write commands to the device console
>> ----------------------------------------------------------
>> This script send commands to U-Boot console.
>> First specify few script variables, e.g:
>> - TTY="/dev/ttyS0"
>> - MMCDEV=0
>> - PARTITION=2
>> - LOAD_ADDR="0x40000000"
>>
>> usage:
>> 1. Target:
>>     run: ums 0 mmc 0
>> 2. Run script 1 and 2 to make and copy the test files
>>     onto the test partition by UMS
>> 3. This script:
>>     - set test device $PARTITION and other variables in the script,
>>       which is required for sending proper commands
>>     - set $TTY in the script
>>     run: ./3_fat_test.sh
>> 4. Compare the crc results on the target and device consoles
>>     (sorry for the mess on the console)
>>
>> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
>> ---
>>   1_mktest_files.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>   2_copy_files.sh   | 20 ++++++++++++++
>>   3_fat_test.sh     | 38 ++++++++++++++++++++++++++
>>   3 files changed, 140 insertions(+)
>>   create mode 100755 1_mktest_files.sh
>>   create mode 100755 2_copy_files.sh
>>   create mode 100755 3_fat_test.sh
>>
>
> This is just for some quick test.
> I will add something more pretty to the sandbox.

Perhaps this should be written in Python? We now have quite a few
tests and it's getting to the point where we might want to have a way
to run them all, check results, etc. That would be easier if we could
import them through some standard interface. For now, perhaps we
should avoid shell scripts except for really trivial things.

You can bring in the patman libraries (we could break these out into
another dir but it doesn't seem important):

import os
import sys

# Bring in the patman libraries
our_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(our_path, 'tools/patman'))

import command

The, for example:
print command.Output('ls', '-l')

Regards,
Simon
Przemyslaw Marczak Dec. 17, 2014, 8:53 a.m. UTC | #3
Hello Simon,

On 12/16/2014 09:41 PM, Simon Glass wrote:
> Hi Przemyslaw,
>
> On 12 December 2014 at 08:54, Przemyslaw Marczak <p.marczak@samsung.com> wrote:
>>
>> Hello,
>>
>>
>> On 12/12/2014 04:52 PM, Przemyslaw Marczak wrote:
>>>
>>> ---------------------------------------------------------
>>> mktest_files: script for generating random size long name files
>>> ---------------------------------------------------------
>>> Usage:
>>> ./1_mktest_files.sh count
>>>
>>> count - number of files to be generated
>>>
>>> The output directory is: "./test_files"
>>>
>>> ---------------------------------------------------------
>>> copy_files: copy the test_files/* into test partition mount point
>>> ---------------------------------------------------------
>>> Usage:
>>> ./2_copy_files.sh mount_point
>>>
>>> -----------------------------------------------------------
>>> fat_test.sh: test fat read by write commands to the device console
>>> ----------------------------------------------------------
>>> This script send commands to U-Boot console.
>>> First specify few script variables, e.g:
>>> - TTY="/dev/ttyS0"
>>> - MMCDEV=0
>>> - PARTITION=2
>>> - LOAD_ADDR="0x40000000"
>>>
>>> usage:
>>> 1. Target:
>>>      run: ums 0 mmc 0
>>> 2. Run script 1 and 2 to make and copy the test files
>>>      onto the test partition by UMS
>>> 3. This script:
>>>      - set test device $PARTITION and other variables in the script,
>>>        which is required for sending proper commands
>>>      - set $TTY in the script
>>>      run: ./3_fat_test.sh
>>> 4. Compare the crc results on the target and device consoles
>>>      (sorry for the mess on the console)
>>>
>>> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
>>> ---
>>>    1_mktest_files.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>>    2_copy_files.sh   | 20 ++++++++++++++
>>>    3_fat_test.sh     | 38 ++++++++++++++++++++++++++
>>>    3 files changed, 140 insertions(+)
>>>    create mode 100755 1_mktest_files.sh
>>>    create mode 100755 2_copy_files.sh
>>>    create mode 100755 3_fat_test.sh
>>>
>>
>> This is just for some quick test.
>> I will add something more pretty to the sandbox.
>
> Perhaps this should be written in Python? We now have quite a few
> tests and it's getting to the point where we might want to have a way
> to run them all, check results, etc. That would be easier if we could
> import them through some standard interface. For now, perhaps we
> should avoid shell scripts except for really trivial things.
>
> You can bring in the patman libraries (we could break these out into
> another dir but it doesn't seem important):
>
> import os
> import sys
>
> # Bring in the patman libraries
> our_path = os.path.dirname(os.path.realpath(__file__))
> sys.path.append(os.path.join(our_path, 'tools/patman'))
>
> import command
>
> The, for example:
> print command.Output('ls', '-l')
>
> Regards,
> Simon
>

The patch fixes the issue with the "hidden" files, so for looking the 
issue on some other cases I made some simple script. I understand that 
this is not good for a U-Boot tests, and I agree that better is to write 
something automated in the Python for the sandbox.
I think that the fix should be merged.
I can write the test for the sandbox in a free time, but it will take a 
moment, because now I would like to focus on the pmic framework.
The pmic was on hold for too long.

Best regards,
diff mbox

Patch

diff --git a/1_mktest_files.sh b/1_mktest_files.sh
new file mode 100755
index 0000000..e9f4e26
--- /dev/null
+++ b/1_mktest_files.sh
@@ -0,0 +1,82 @@ 
+#!/bin/bash
+#
+# Copyright (C) 2014 Samsung Electronics
+# Przemyslaw Marczak <p.marczak@samsung.com>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+F_CNT=${1}
+OUT_DIR="./test_files"
+# File max: 100k
+f_max_size=255
+
+# Minimal len of long name -> len+"xxxk.bin"
+LONG_NAME_LEN=20
+
+if [ ${#1} -eq 0 ]
+	then
+	echo "Bad arg!"
+	echo "usage:"
+	echo "./mktest_files.sh count"
+	exit
+else
+	if [ -d $OUT_DIR ]
+		then
+		echo "Directory: \"$OUT_DIR\" exists - cleanup"
+		rm $OUT_DIR/*
+	else
+		echo "Test files directory: \"$OUT_DIR\""
+		mkdir $OUT_DIR
+	fi
+	echo "Generating $1 files:"
+fi
+
+######
+# 1. # Generate random size for the files
+######
+
+i=0
+for val in `rand -M $f_max_size -N $F_CNT -u`
+	do
+	f_size_list[$i]=$val
+#	echo "Size[$i]: ${f_size_list[$i]}"
+	i=$(($i+1))
+done
+
+######
+# 2. #  Prepare the long name
+######
+CHAR="_"
+
+for I in `seq 1 1 $LONG_NAME_LEN`; do
+	LONG_NAME="$LONG_NAME""$CHAR"
+done
+
+######
+# 3. # Generate files with random data
+######
+i=0
+# Set fat16 file extension (dot + 3 characters)
+EXT=".bin"
+for len_k in ${f_size_list[@]}
+	do
+
+	prefix="$len_k""k"
+
+	prefix_len=${#prefix}
+	long_name_len=${#LONG_NAME}
+	ext_len=${#EXT}
+	name=`echo "$prefix""$LONG_NAME" | head -c $long_name_len`
+	name=$name$EXT
+#	echo Name: $name len: ${#name}
+
+	echo "$i Prefix: $prefix name len: ${#name} chars:"
+	full_name="$OUT_DIR/$name"
+
+	echo "$full_name"
+
+	dd if=/dev/urandom of=${full_name} bs=1k count=$len_k 2>/dev/null
+
+	i=$(($i+1))
+done
diff --git a/2_copy_files.sh b/2_copy_files.sh
new file mode 100755
index 0000000..6bfefc6
--- /dev/null
+++ b/2_copy_files.sh
@@ -0,0 +1,20 @@ 
+#!/bin/bash
+#
+# Copyright (C) 2014 Samsung Electronics
+# Przemyslaw Marczak <p.marczak@samsung.com>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+#MOUNT_POINT - for the fat16 partition,
+#              e.g. target partition using ums command
+
+MOUNT_POINT=$1
+DIR="test_files"
+
+for I in `ls -1 -S $DIR/`; do
+	echo Copying "$DIR/$I" to $DEV
+	cp "$DIR/$I" $MOUNT_POINT
+done
+
+sync
\ No newline at end of file
diff --git a/3_fat_test.sh b/3_fat_test.sh
new file mode 100755
index 0000000..07222a0
--- /dev/null
+++ b/3_fat_test.sh
@@ -0,0 +1,38 @@ 
+#!/bin/sh
+#
+# Copyright (C) 2014 Samsung Electronics
+# Przemyslaw Marczak <p.marczak@samsung.com>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+TTY="/dev/ttyS0"
+MMCDEV=0
+PARTITION=2
+LOAD_ADDR="0x40000000"
+
+DIR="test_files"
+
+SPACE="_____________________________ "
+CMD_1_2="setenv t \"fatload mmc $MMCDEV:$PARTITION $LOAD_ADDR '\$F';"
+CMD_2_2="echo $SPACE File: '\$F'; crc $LOAD_ADDR '\$S'\""
+CMD="$CMD_1_2""$CMD_2_2"
+
+# Set command for loading DIR
+echo "$CMD" > $TTY
+
+for I in `ls -1 -S $DIR`;
+	do
+	FILE="$DIR"/"$I"
+	# Hex size:
+	SIZE=`ls -l $FILE | awk '{printf("%#x\n", $5)}'`
+	CRC=`crc32 $FILE`
+
+	echo
+	echo "File: $I"
+	echo "  ==> $CRC"
+
+	CMD="setenv F \'$I\'; setenv S $SIZE; run t;"
+	echo "echo" > $TTY
+	echo $CMD > $TTY
+done