File: test_read_write_delta.sh

package info (click to toggle)
libewf 20140807-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 19,224 kB
  • sloc: ansic: 320,571; sh: 7,829; cpp: 3,819; makefile: 1,841; yacc: 1,104; python: 471; lex: 391; sed: 16
file content (213 lines) | stat: -rwxr-xr-x 5,101 bytes parent folder | download
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
#!/bin/bash
#
# Expert Witness Compression Format (EWF) library read/write testing script
#
# Copyright (c) 2006-2012, Joachim Metz <joachim.metz@gmail.com>
#
# Refer to AUTHORS for acknowledgements.
#
# This software is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this software.  If not, see <http://www.gnu.org/licenses/>.
#

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
EXIT_IGNORE=77;

INPUT="input";
TMP="tmp";

AWK="awk";
CUT="cut";
LS="ls";
TR="tr";

test_read_write_delta()
{ 
	MEDIA_SIZE=$1;
	CHUNK_SIZE=$2;
	COMPRESSION_LEVEL=$3;
	WRITE_OFFSET=$4;
	WRITE_SIZE=$5;

	shift 2;

	mkdir ${TMP};

	if test "${OSTYPE}" = "msys";
	then
		OUTPUT_FILE="${TMP}\\write";
	else
		OUTPUT_FILE="${TMP}/write";
	fi
	./${EWF_TEST_WRITE} -b ${CHUNK_SIZE} -B ${MEDIA_SIZE} -c `echo ${COMPRESSION_LEVEL} | ${CUT} -c 1` "${OUTPUT_FILE}";

	RESULT=$?;

	if [ ${RESULT} -eq ${EXIT_SUCCESS} ];
	then
		FILENAMES=`${LS} ${OUTPUT_FILE}.* | ${TR} '\n' ' '`;

		if test "${OSTYPE}" = "msys";
		then
			OUTPUT_FILE="${TMP}\\read_write";
		else
			OUTPUT_FILE="${TMP}/read_write";
		fi
		./${EWF_TEST_READ_WRITE_DELTA} -B ${WRITE_SIZE} -o ${WRITE_OFFSET} -t "${OUTPUT_FILE}" ${FILENAMES};

		RESULT=$?;
	fi

	if [ ${RESULT} -eq ${EXIT_SUCCESS} ];
	then
		if [ ${WRITE_OFFSET} -lt ${MEDIA_SIZE} ];
		then
			if [ -e ${OUTPUT_FILE}.d01 ];
			then
				FILESIZE=`${LS} -l ${OUTPUT_FILE}.d01 | ${AWK} '{ print $5 }'`;

				CHUNK_SIZE=`expr ${CHUNK_SIZE} \* 512`;

				if [ `expr ${WRITE_OFFSET} + ${WRITE_SIZE}` -gt ${MEDIA_SIZE} ];
				then
					WRITE_SIZE=`expr ${MEDIA_SIZE} - ${WRITE_OFFSET}`;
				fi

				NUMBER_OF_CHUNKS=`expr ${WRITE_SIZE} / ${CHUNK_SIZE}`;
				REMAINING_SIZE=`expr ${WRITE_SIZE} % ${CHUNK_SIZE}`;

				if [ ${REMAINING_SIZE} -gt 0 ];
				then
					# Check if the remaining size is part of the last chunk
					if [ `expr ${WRITE_OFFSET} + \( \( ${NUMBER_OF_CHUNKS} + 1 \) \* ${CHUNK_SIZE} \)` -le ${MEDIA_SIZE} ];
					then
						NUMBER_OF_CHUNKS=`expr ${NUMBER_OF_CHUNKS} + 1`;
						REMAINING_SIZE=0;
					fi
				fi

				CHUNK_OFFSET=`expr \( ${WRITE_OFFSET} / ${CHUNK_SIZE} \) \* ${CHUNK_SIZE}`;

				# Check if the written data passes a chunk boundary
				if [ ${WRITE_OFFSET} -gt ${CHUNK_OFFSET} ];
				then
					if [ `expr ${WRITE_OFFSET} + ${WRITE_SIZE}` -gt `expr ${CHUNK_OFFSET} + ${CHUNK_SIZE}` ];
					then
						NUMBER_OF_CHUNKS=`expr ${NUMBER_OF_CHUNKS} + 1`;
					fi
				fi

				if [ ${NUMBER_OF_CHUNKS} -gt 0 ];
				then
					# Add the section start, the delta chunk header and chunk checksum
					CALCULATED=`expr 76 + 18 + ${CHUNK_SIZE} + 4`;

					# Multiply by the amount of chunks altered
					CALCULATED=`expr ${CALCULATED} \* ${NUMBER_OF_CHUNKS}`;
				fi

				if [ ${REMAINING_SIZE} -gt 0 ];
				then
					# Add the section start, the delta chunk header and chunk checksum of the last chunk
					CALCULATED=`expr ${CALCULATED} + 76 + 18 + ${REMAINING_SIZE} + 4`;
				fi

				# Add the segment file header and the done or next section
				CALCULATED=`expr 13 + ${CALCULATED} + 76`;

				if [ ${FILESIZE} -eq ${CALCULATED} ];
				then
					RESULT=${EXIT_SUCCESS};
				else
					RESULT=${EXIT_FAILURE};
				fi
			else
				RESULT=${EXIT_FAILURE};
			fi
		else
			if [ -e ${OUTPUT_FILE}.d01 ];
			then
				RESULT=${EXIT_FAILURE};
			else
				RESULT=${EXIT_SUCCESS};
			fi
		fi
	fi

	rm -rf ${TMP};

	echo -n "Testing read/write with offset: ${WRITE_OFFSET} and size: ${WRITE_SIZE} and compression level: ${COMPRESSION_LEVEL} ";

	if test ${RESULT} -ne ${EXIT_SUCCESS};
	then
		echo " (FAIL)";
	else
		echo " (PASS)";
	fi
	return ${RESULT};
}

EWF_TEST_WRITE="ewf_test_write";

if ! test -x ${EWF_TEST_WRITE};
then
	EWF_TEST_WRITE="ewf_test_write.exe";
fi

if ! test -x ${EWF_TEST_WRITE};
then
	echo "Missing executable: ${EWF_TEST_WRITE}";

	exit ${EXIT_FAILURE};
fi

EWF_TEST_READ_WRITE_DELTA="ewf_test_read_write_delta";

if ! test -x ${EWF_TEST_READ_WRITE_DELTA};
then
	EWF_TEST_READ_WRITE_DELTA="ewf_test_read_write_delta.exe";
fi

if ! test -x ${EWF_TEST_READ_WRITE_DELTA};
then
	echo "Missing executable: ${EWF_TEST_READ_WRITE_DELTA}";

	exit ${EXIT_FAILURE};
fi

for COMPRESSION_LEVEL in none empty-block fast best;
do
	if ! test_read_write_delta 100000 64 ${COMPRESSION_LEVEL} 0 100000
	then
		exit ${EXIT_FAILURE};
	fi

	if ! test_read_write_delta 100000 64 ${COMPRESSION_LEVEL} 512 512
	then
		exit ${EXIT_FAILURE};
	fi

	if ! test_read_write_delta 100000 64 ${COMPRESSION_LEVEL} 32512 512
	then
		exit ${EXIT_FAILURE};
	fi

	if ! test_read_write_delta 100000 64 ${COMPRESSION_LEVEL} 32512 40000
	then
		exit ${EXIT_FAILURE};
	fi
done

exit ${EXIT_SUCCESS};