aboutsummaryrefslogtreecommitdiff
path: root/ubi-utils/sort-me-out/ubi_tools_test.sh
blob: 7f121f134db7d64df13d6b76c6611b6c7a1ce788 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/bin/sh
#
# UBI Volume creation/deletion/write/read test script.
# Uses our flash update tools and the associated toolchain for flash
# image creation.
#
# Written in shell language to reduce dependencies to more sophisticated 
# interpreters, which may not be available on some stupid platforms.
#
# Author: Frank Haverkamp <haver@vnet.ibm.com>
#
# 1.0 Initial version
#

VERSION="1.0"

export PATH=$PATH:~/bin:/usr/local/bin:/home/dedekind/work/prj/ubi/tools/flashutils/bin/

UBIMKVOL=ubimkvol
UBIRMVOL=ubirmvol
UBIWRITEVOL=ubiupdatevol
PFIFLASH=pfiflash
CMP=cmp

MAXVOL=32

test_pfi=test_complete.pfi
real_pfi=example_complete.pfi

# 128 KiB 131072
# 256 KiB 262144
# 512 KiB 524288

#
# To have a standardized output I define the following function to be
# used when a test was ok or when it failed.
#
failed () 
{
    echo "FAILED"
}

passed ()
{
    echo "PASSED"
}

#
# Print sucess message. Consider to exit with zero as return code.
#
exit_success ()
{
    echo "SUCCESS"
    exit 0
}

#
# Print failure message. Consider to exit with non zero return code.
#
exit_failure ()
{
    echo "FAILED"
    exit 1
}

###############################################################################
#
# START
#
###############################################################################

fix_sysfs_issue ()
{
    echo -n "*** Fixing the sysfs issue with the /dev nodes ... "

    minor=0
    major=`grep ubi0 /proc/devices | sed -e 's/\(.*\) ubi0/\1/'`

    rm -rf /dev/ubi0
    mknod /dev/ubi0 c $major 0

    for minor in `seq 0 $MAXVOL`; do
	### echo " mknod /dev/ubi0_$minor c $major $(($minor + 1))"
        rm -rf /dev/ubi0_$minor
        mknod /dev/ubi0_$minor c $major $(($minor + 1))
    done
    passed
}

# delete_volume - Delete a volume. If it does not exist, do not try
#                 to delete it.
# @id:     volume id
#
delete_volume ()
{
    volume=$1

    ### FIXME broken sysfs!!!!
    if [ -e /sys/class/ubi/$volume -o -e /sys/class/ubi/ubi0/$volume -o -e /sys/class/ubi/ubi0_$volume ]; then

	echo -n "*** Truncate volume if it exists ... "
	$UBIWRITEVOL -d0 -n$volume -t
	if [ $? -ne "0" ] ; then
	    exit_failure
	fi
	passed

	echo -n "*** Delete volume if it exists ... "
	$UBIRMVOL -d0 -n$volume
	if [ $? -ne "0" ] ; then
	    exit_failure
	fi
	passed
    fi
}

echo "***********************************************************************"
echo "*           UBI Tools Testing starts now ...                          *"
echo "*                                 Good luck!                          *"
echo "***********************************************************************"

# Set to zero if not running on example hardware
grep ubi /proc/devices > /dev/null
if [ $? -ne "0" ]; then
    echo "No UBI found in /proc/devices! I am broken!"
    exit_failure
fi

# Set to zero if not running on example hardware
grep 1142 /proc/cpuinfo > /dev/null
if [ $? -eq "0" ]; then
    echo "Running on example hardware"
    mount -o remount,rw / /
    sleep 1
    fix_sysfs_issue
else
    echo "Running on other hardware"
fi

### Test basic stuff
pfiflash_basic ()
{
    echo "Calling pfiflash with test-data ... "
    echo "    $PFIFLASH $test_pfi"
    $PFIFLASH $test_pfi
    if [ $? -ne "0" ]; then
	echo "Uhhh something went wrong!"
	exit_failure
    fi
    passed
    
    echo "Testing if data is correct 10 and 11 ... "
    $CMP /dev/ubi0_10 /dev/ubi0_11
    if [ $? -ne "0" ]; then
	echo "Mirrored volumes not equal!"
	exit_failure
    fi
    passed
    
    echo "Comparing against original data ... "
    $CMP /dev/ubi0_10 test_u-boot.bin
    if [ $? -ne "0" ]; then
	echo "Compared volume not equal!"
	exit_failure
    fi
    passed
    
    echo "Testing if data is correct 12 and 13 ... "
    $CMP /dev/ubi0_12 /dev/ubi0_13
    if [ $? -ne "0" ]; then
	echo "Mirrored volumes not equal!"
	exit_failure
    fi
    passed
    
    echo "Comparing against original data ... "
    $CMP /dev/ubi0_12 test_vmlinux.bin
    if [ $? -ne "0" ]; then
	echo "Compared volume not equal!"
	exit_failure
    fi
    passed
    
    echo "Testing if data is correct 14 and 15 ... "
    $CMP /dev/ubi0_14 /dev/ubi0_15
    if [ $? -ne "0" ]; then
	echo "Mirrored volumes not equal!"
	exit_failure
    fi
    passed
}

### Test each and everything
pfiflash_advanced ()
{
    if [ -e  example_complete.pfi ]; then
	echo "Calling pfiflash with real data ... "
	$PFIFLASH -p overwrite --complete example_complete.pfi
	if [ $? -ne "0" ]; then
	    echo "Uhhh something went wrong!"
	    exit_failure
	fi
	passed
	
	echo "Testing if data is correct 2 and 3 ... "
	$CMP /dev/ubi0_2 /dev/ubi0_3
	if [ $? -ne "0" ]; then
	    echo "Mirrored volumes not equal!"
	    exit_failure
	fi
	passed
	
	echo "Comparing against original data ... "
	$CMP /dev/ubi0_2 u-boot.bin
	if [ $? -ne "0" ]; then
	    echo "Compared volume not equal!"
	    exit_failure
	fi
	passed
	
	echo "Testing if data is correct 6 and 7 ... "
	$CMP /dev/ubi0_6 /dev/ubi0_7
	if [ $? -ne "0" ]; then
	    echo "Mirrored volumes not equal!"
	    exit_failure
	fi
	passed
	
	echo "Comparing against original data ... "
	$CMP /dev/ubi0_6 vmlinux.bin
	if [ $? -ne "0" ]; then
	    echo "Compared volume not equal!"
	    exit_failure
	fi
	passed
    fi
}

echo "***********************************************************************"
echo "*                Testing pfiflash ...                                 *"
echo "***********************************************************************"
echo "VERSION: $VERSION"

pfiflash_basic
pfiflash_advanced
    
echo "***********************************************************************"
echo "*               Congratulations, no errors found!                     *"
echo "*              Have fun with your cool UBI system!                    *"
echo "***********************************************************************"

exit_success