|
336
|
1 //========================================================================== |
|
|
2 // |
|
|
3 // yaffs5.c |
|
|
4 // |
|
|
5 // Test FAT filesystem |
|
|
6 // |
|
|
7 //========================================================================== |
|
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
|
9 // ------------------------------------------- |
|
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2006, 2007 Free Software Foundation, Inc. |
|
|
12 // Copyright (C) 2004, 2006, 2007 eCosCentric Limited |
|
|
13 // |
|
|
14 // eCos is free software; you can redistribute it and/or modify it under |
|
|
15 // the terms of the GNU General Public License as published by the Free |
|
|
16 // Software Foundation; either version 2 or (at your option) any later |
|
|
17 // version. |
|
|
18 // |
|
|
19 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
|
20 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
|
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
|
22 // for more details. |
|
|
23 // |
|
|
24 // You should have received a copy of the GNU General Public License |
|
|
25 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
|
26 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
|
27 // |
|
|
28 // As a special exception, if other files instantiate templates or use |
|
|
29 // macros or inline functions from this file, or you compile this file |
|
|
30 // and link it with other works to produce a work based on this file, |
|
|
31 // this file does not by itself cause the resulting work to be covered by |
|
|
32 // the GNU General Public License. However the source code for this file |
|
|
33 // must still be made available in accordance with section (3) of the GNU |
|
|
34 // General Public License v2. |
|
|
35 // |
|
|
36 // This exception does not invalidate any other reasons why a work based |
|
|
37 // on this file might be covered by the GNU General Public License. |
|
|
38 // ------------------------------------------- |
|
|
39 // ####ECOSGPLCOPYRIGHTEND#### |
|
|
40 //========================================================================== |
|
|
41 //#####DESCRIPTIONBEGIN#### |
|
|
42 // |
|
|
43 // Author(s): nickg |
|
|
44 // Contributors: nickg |
|
|
45 // Date: 2007-03-28 |
|
|
46 // Purpose: Test FAT system |
|
|
47 // Description: This test gets some performance figures from the |
|
|
48 // FAT filesystem. |
|
|
49 // |
|
|
50 //####DESCRIPTIONEND#### |
|
|
51 // |
|
|
52 //========================================================================== |
|
|
53 |
|
|
54 #include <pkgconf/hal.h> |
|
|
55 #include <pkgconf/kernel.h> |
|
|
56 #include <pkgconf/io_fileio.h> |
|
|
57 |
|
|
58 #include CYGDAT_DEVS_DISK_CFG // testing config defines |
|
|
59 |
|
|
60 #include <cyg/kernel/ktypes.h> // base kernel types |
|
|
61 #include <cyg/infra/cyg_trac.h> // tracing macros |
|
|
62 #include <cyg/infra/cyg_ass.h> // assertion macros |
|
|
63 |
|
|
64 #include <unistd.h> |
|
|
65 #include <fcntl.h> |
|
|
66 #include <sys/stat.h> |
|
|
67 #include <errno.h> |
|
|
68 #include <string.h> |
|
|
69 #include <dirent.h> |
|
|
70 #include <stdlib.h> |
|
|
71 |
|
|
72 #include <cyg/fileio/fileio.h> |
|
|
73 |
|
|
74 #include <cyg/infra/testcase.h> |
|
|
75 #include <cyg/infra/diag.h> // HAL polled output |
|
|
76 |
|
|
77 //========================================================================== |
|
|
78 // Config options |
|
|
79 |
|
|
80 #define TEST_DEVICE CYGDAT_DEVS_DISK_TEST_DEVICE |
|
|
81 |
|
|
82 #define TEST_MOUNTPOINT CYGDAT_DEVS_DISK_TEST_MOUNTPOINT |
|
|
83 |
|
|
84 #define TEST_DIRECTORY CYGDAT_DEVS_DISK_TEST_DIRECTORY |
|
|
85 |
|
|
86 #define TEST_FSTYPE "yaffs" |
|
|
87 |
|
|
88 #ifdef CYGDAT_DEVS_DISK_TEST_MOUNTPOINT2 |
|
|
89 |
|
|
90 #define TEST_DEVICE2 CYGDAT_DEVS_DISK_TEST_DEVICE2 |
|
|
91 |
|
|
92 #define TEST_MOUNTPOINT2 CYGDAT_DEVS_DISK_TEST_MOUNTPOINT2 |
|
|
93 |
|
|
94 #define TEST_DIRECTORY2 CYGDAT_DEVS_DISK_TEST_DIRECTORY2 |
|
|
95 |
|
|
96 #define TEST_FSTYPE2 "yaffs" |
|
|
97 |
|
|
98 #endif |
|
|
99 |
|
|
100 //========================================================================== |
|
|
101 |
|
|
102 #define SHOW_RESULT( _fn, _res ) \ |
|
|
103 { \ |
|
|
104 diag_printf("<FAIL>: " #_fn "() returned %ld %s\n", (long)_res, _res<0?strerror(errno):""); \ |
|
|
105 } |
|
|
106 |
|
|
107 //========================================================================== |
|
|
108 |
|
|
109 typedef struct |
|
|
110 { |
|
|
111 cyg_int64 ticks; |
|
|
112 cyg_int32 halticks; |
|
|
113 } timestamp; |
|
|
114 |
|
|
115 typedef struct |
|
|
116 { |
|
|
117 timestamp start; |
|
|
118 timestamp end; |
|
|
119 cyg_int64 interval; // In HAL ticks |
|
|
120 cyg_int64 us_interval; // Interval in microseconds |
|
|
121 } timing; |
|
|
122 |
|
|
123 static cyg_int64 ticks_overhead = 0; |
|
|
124 static cyg_int32 us_per_haltick = 0; |
|
|
125 static cyg_int32 halticks_per_us = 0; |
|
|
126 |
|
|
127 static cyg_int64 rtc_resolution[] = CYGNUM_KERNEL_COUNTERS_RTC_RESOLUTION; |
|
|
128 static cyg_int64 rtc_period = CYGNUM_KERNEL_COUNTERS_RTC_PERIOD; |
|
|
129 static cyg_int32 ticks_per_second; |
|
|
130 |
|
|
131 //========================================================================== |
|
|
132 |
|
|
133 static char date_string[] = __DATE__; |
|
|
134 static char time_string[] = __TIME__; |
|
|
135 |
|
|
136 cyg_uint32 timehash; |
|
|
137 |
|
|
138 //========================================================================== |
|
|
139 |
|
|
140 static void wait_for_tick( void ) |
|
|
141 { |
|
|
142 cyg_tick_count_t now = cyg_current_time(); |
|
|
143 |
|
|
144 while( cyg_current_time() == now ) |
|
|
145 continue; |
|
|
146 } |
|
|
147 |
|
|
148 static void get_timestamp( timestamp *ts ) |
|
|
149 { |
|
|
150 ts->ticks = cyg_current_time(); |
|
|
151 HAL_CLOCK_READ( (cyg_uint32 *)&ts->halticks ); |
|
|
152 } |
|
|
153 |
|
|
154 static cyg_int64 ticks_to_us( cyg_int64 ticks ) |
|
|
155 { |
|
|
156 cyg_int64 us; |
|
|
157 |
|
|
158 if( us_per_haltick != 0 ) |
|
|
159 us = ticks * us_per_haltick; |
|
|
160 else |
|
|
161 us = ticks / halticks_per_us; |
|
|
162 |
|
|
163 return us; |
|
|
164 } |
|
|
165 |
|
|
166 static void calculate_interval( timing *t ) |
|
|
167 { |
|
|
168 t->interval = t->end.halticks - t->start.halticks; |
|
|
169 |
|
|
170 t->interval += (t->end.ticks - t->start.ticks) * rtc_period; |
|
|
171 |
|
|
172 t->interval -= ticks_overhead; |
|
|
173 |
|
|
174 t->us_interval = ticks_to_us( t->interval ); |
|
|
175 } |
|
|
176 |
|
|
177 static void init_timing( void ) |
|
|
178 { |
|
|
179 timing t; |
|
|
180 |
|
|
181 ticks_per_second = (1000000000ULL*rtc_resolution[1])/rtc_resolution[0]; |
|
|
182 us_per_haltick = 1000000/(rtc_period * rtc_resolution[1]); |
|
|
183 halticks_per_us = (rtc_period * rtc_resolution[1])/1000000; |
|
|
184 |
|
|
185 wait_for_tick(); |
|
|
186 |
|
|
187 get_timestamp( &t.start ); |
|
|
188 get_timestamp( &t.end ); |
|
|
189 |
|
|
190 calculate_interval( &t ); |
|
|
191 |
|
|
192 ticks_overhead = t.interval; |
|
|
193 |
|
|
194 diag_printf("Timing overhead %lld ticks\n", ticks_overhead ); |
|
|
195 |
|
|
196 } |
|
|
197 |
|
|
198 //========================================================================== |
|
|
199 |
|
|
200 #ifndef CYGPKG_LIBC_STRING |
|
|
201 |
|
|
202 char *strcat( char *s1, const char *s2 ) |
|
|
203 { |
|
|
204 char *s = s1; |
|
|
205 while( *s1 ) s1++; |
|
|
206 while( (*s1++ = *s2++) != 0); |
|
|
207 return s; |
|
|
208 } |
|
|
209 |
|
|
210 #endif |
|
|
211 |
|
|
212 __externC int |
|
|
213 rename( const char * /* oldpath */, const char * /* newpath */ ) __THROW; |
|
|
214 |
|
|
215 //========================================================================== |
|
|
216 |
|
|
217 static void listdir( char *name, int statp, int numexpected, int *numgot ) |
|
|
218 { |
|
|
219 int err; |
|
|
220 DIR *dirp; |
|
|
221 int num=0; |
|
|
222 |
|
|
223 diag_printf("<INFO>: reading directory %s\n",name); |
|
|
224 |
|
|
225 // diag_printf("<INFO>: opendir(%s)\n",name); |
|
|
226 dirp = opendir( name ); |
|
|
227 if( dirp == NULL ) SHOW_RESULT( opendir, -1 ); |
|
|
228 |
|
|
229 for(;;) |
|
|
230 { |
|
|
231 struct dirent *entry = readdir( dirp ); |
|
|
232 |
|
|
233 if( entry == NULL ) |
|
|
234 break; |
|
|
235 num++; |
|
|
236 diag_printf("<INFO>: entry %14s",entry->d_name); |
|
|
237 if( statp ) |
|
|
238 { |
|
|
239 char fullname[PATH_MAX]; |
|
|
240 struct stat sbuf; |
|
|
241 |
|
|
242 if( name[0] ) |
|
|
243 { |
|
|
244 strcpy(fullname, name ); |
|
|
245 if( !(name[0] == '/' && name[1] == 0 ) ) |
|
|
246 strcat(fullname, "/" ); |
|
|
247 } |
|
|
248 else fullname[0] = 0; |
|
|
249 |
|
|
250 strcat(fullname, entry->d_name ); |
|
|
251 |
|
|
252 err = stat( fullname, &sbuf ); |
|
|
253 if( err < 0 ) |
|
|
254 { |
|
|
255 if( errno == ENOSYS ) |
|
|
256 diag_printf(" <no status available>"); |
|
|
257 else SHOW_RESULT( stat, err ); |
|
|
258 } |
|
|
259 else |
|
|
260 { |
|
|
261 diag_printf(" [mode %08x ino %08x nlink %d size %ld]", |
|
|
262 sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,sbuf.st_size); |
|
|
263 } |
|
|
264 } |
|
|
265 |
|
|
266 diag_printf("\n"); |
|
|
267 } |
|
|
268 |
|
|
269 // diag_printf("<INFO>: closedir(%s)\n",name); |
|
|
270 err = closedir( dirp ); |
|
|
271 if( err < 0 ) SHOW_RESULT( stat, err ); |
|
|
272 if (numexpected >= 0 && num != numexpected) |
|
|
273 CYG_TEST_FAIL("Wrong number of dir entries\n"); |
|
|
274 if ( numgot != NULL ) |
|
|
275 *numgot = num; |
|
|
276 } |
|
|
277 |
|
|
278 //========================================================================== |
|
|
279 |
|
|
280 static void createfile( char *name, size_t asize, size_t block_size ) |
|
|
281 { |
|
|
282 size_t size = asize; |
|
|
283 cyg_uint8 *buf; |
|
|
284 cyg_uint32 *b; |
|
|
285 int fd; |
|
|
286 ssize_t wrote; |
|
|
287 int i; |
|
|
288 int err; |
|
|
289 timing opent, writet; |
|
|
290 |
|
|
291 diag_printf("\n--------------------------------------------------------------------\n"); |
|
|
292 diag_printf("<INFO>: create file %s size %ld block_size %ld\n",name, (long)size, (long)block_size); |
|
|
293 |
|
|
294 buf = malloc( block_size ); |
|
|
295 if( buf == NULL ) |
|
|
296 { |
|
|
297 SHOW_RESULT( malloc, -1 ); |
|
|
298 return; |
|
|
299 } |
|
|
300 b = (cyg_uint32 *)buf; |
|
|
301 |
|
|
302 err = access( name, F_OK ); |
|
|
303 if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); |
|
|
304 |
|
|
305 i = 0; |
|
|
306 while( i < block_size/sizeof(cyg_uint32) ) |
|
|
307 { |
|
|
308 b[i] = i; |
|
|
309 i++; |
|
|
310 b[i++] = 0; |
|
|
311 b[i++] = timehash; |
|
|
312 b[i++] = 0x12345678; |
|
|
313 } |
|
|
314 |
|
|
315 |
|
|
316 get_timestamp( &opent.start ); |
|
|
317 fd = open( name, O_WRONLY|O_CREAT ); |
|
|
318 get_timestamp( &opent.end ); |
|
|
319 if( fd < 0 ) SHOW_RESULT( open, fd ); |
|
|
320 |
|
|
321 get_timestamp( &writet.start ); |
|
|
322 while( size > 0 ) |
|
|
323 { |
|
|
324 ssize_t len = size; |
|
|
325 if ( len > block_size ) len = block_size; |
|
|
326 |
|
|
327 b[1] = asize-size; |
|
|
328 b[block_size/sizeof(cyg_uint32)-3] = asize-size; |
|
|
329 wrote = write( fd, buf, len ); |
|
|
330 if( wrote != len ) SHOW_RESULT( write, wrote ); |
|
|
331 |
|
|
332 size -= wrote; |
|
|
333 } |
|
|
334 get_timestamp( &writet.end ); |
|
|
335 |
|
|
336 free( buf ); |
|
|
337 |
|
|
338 err = close( fd ); |
|
|
339 if( err < 0 ) SHOW_RESULT( close, err ); |
|
|
340 |
|
|
341 calculate_interval( &opent ); |
|
|
342 calculate_interval( &writet ); |
|
|
343 |
|
|
344 diag_printf("CreateFile Results: %s size %ld\n", name, (long)asize); |
|
|
345 diag_printf(" Open %8d.%03d ms\n", (int)(opent.us_interval/1000), (int)(opent.us_interval%1000) ); |
|
|
346 diag_printf(" Write %8d.%03d ms\n", (int)(writet.us_interval/1000), (int)(writet.us_interval%1000) ); |
|
|
347 diag_printf(" Data Rate %10lld KiB/s\n", (1000000LL*asize)/1024/writet.us_interval); |
|
|
348 } |
|
|
349 |
|
|
350 //========================================================================== |
|
|
351 |
|
|
352 static void checkfile( char *name, size_t block_size ) |
|
|
353 { |
|
|
354 cyg_uint8 *buf; |
|
|
355 cyg_uint32 *b; |
|
|
356 int fd; |
|
|
357 ssize_t done; |
|
|
358 int err; |
|
|
359 off_t pos = 0; |
|
|
360 timing opent, readt; |
|
|
361 |
|
|
362 diag_printf("\n--------------------------------------------------------------------\n"); |
|
|
363 diag_printf("<INFO>: check file %s\n",name); |
|
|
364 |
|
|
365 buf = malloc( block_size ); |
|
|
366 if( buf == NULL ) |
|
|
367 { |
|
|
368 SHOW_RESULT( malloc, -1 ); |
|
|
369 return; |
|
|
370 } |
|
|
371 b = (cyg_uint32 *)buf; |
|
|
372 |
|
|
373 err = access( name, F_OK ); |
|
|
374 if( err != 0 ) SHOW_RESULT( access, err ); |
|
|
375 |
|
|
376 get_timestamp( &opent.start ); |
|
|
377 fd = open( name, O_RDONLY ); |
|
|
378 get_timestamp( &opent.end ); |
|
|
379 if( fd < 0 ) SHOW_RESULT( open, fd ); |
|
|
380 |
|
|
381 get_timestamp( &readt.start ); |
|
|
382 for(;;) |
|
|
383 { |
|
|
384 done = read( fd, buf, block_size ); |
|
|
385 if( done < 0 ) SHOW_RESULT( read, done ); |
|
|
386 |
|
|
387 if( done == 0 ) break; |
|
|
388 |
|
|
389 // Check that this is the block we wrote |
|
|
390 if( b[0] != 0 ) |
|
|
391 diag_printf("b[%d] != %08x\n", 0, 0 ); |
|
|
392 |
|
|
393 if( b[1] != pos ) |
|
|
394 diag_printf("b[%d] != %08x\n", 1, (unsigned)pos ); |
|
|
395 |
|
|
396 if( b[2] != timehash ) |
|
|
397 diag_printf("b[%d] != %08x\n", 2, timehash ); |
|
|
398 |
|
|
399 if( b[3] != 0x12345678 ) |
|
|
400 diag_printf("b[%d] != %08x\n", 3, 0x12345678 ); |
|
|
401 |
|
|
402 if( b[(block_size/sizeof(cyg_uint32))-4] != (block_size/sizeof(cyg_uint32)-4) ) |
|
|
403 diag_printf("b[%lu](%08x) != %08x\n", (long)block_size/sizeof(cyg_uint32)-4, |
|
|
404 b[(block_size/sizeof(cyg_uint32))-4], |
|
|
405 (unsigned)(block_size/sizeof(cyg_uint32)-4) ); |
|
|
406 |
|
|
407 if( b[block_size/sizeof(cyg_uint32)-3] != pos ) |
|
|
408 diag_printf("b[%lu] != %08x\n", (long)block_size/sizeof(cyg_uint32)-3, (unsigned)pos ); |
|
|
409 |
|
|
410 if( b[block_size/sizeof(cyg_uint32)-2] != timehash ) |
|
|
411 diag_printf("b[%lu] != %08x\n", (long)block_size/sizeof(cyg_uint32)-2, timehash ); |
|
|
412 |
|
|
413 if( b[block_size/sizeof(cyg_uint32)-1] != 0x12345678 ) |
|
|
414 diag_printf("b[%lu] != %08x\n", (long)block_size/sizeof(cyg_uint32)-1, 0x12345678 ); |
|
|
415 |
|
|
416 pos += done; |
|
|
417 } |
|
|
418 get_timestamp( &readt.end ); |
|
|
419 |
|
|
420 free( buf ); |
|
|
421 |
|
|
422 err = close( fd ); |
|
|
423 if( err < 0 ) SHOW_RESULT( close, err ); |
|
|
424 |
|
|
425 calculate_interval( &opent ); |
|
|
426 calculate_interval( &readt ); |
|
|
427 |
|
|
428 diag_printf("CheckFile Results: %s size %ld\n", name, pos); |
|
|
429 diag_printf(" Open %8d.%03d ms\n", (int)(opent.us_interval/1000), (int)(opent.us_interval%1000) ); |
|
|
430 diag_printf(" Read %8d.%03d ms\n", (int)(readt.us_interval/1000), (int)(readt.us_interval%1000) ); |
|
|
431 diag_printf(" Data Rate %10lld KiB/s\n", (1000000LL*pos)/1024/readt.us_interval); |
|
|
432 } |
|
|
433 |
|
|
434 //========================================================================== |
|
|
435 |
|
|
436 #define TIME_DATA_MAX 20 |
|
|
437 |
|
|
438 static void checkfile1( char *name, size_t block_size ) |
|
|
439 { |
|
|
440 cyg_uint8 *buf; |
|
|
441 cyg_uint32 *b; |
|
|
442 int fd; |
|
|
443 ssize_t done; |
|
|
444 int err; |
|
|
445 off_t pos = 0; |
|
|
446 timing totalt; |
|
|
447 |
|
|
448 struct |
|
|
449 { |
|
|
450 int valid; |
|
|
451 timing mountt; |
|
|
452 timing opent; |
|
|
453 timing seekt; |
|
|
454 timing readt; |
|
|
455 timing closet; |
|
|
456 timing umountt; |
|
|
457 } time_data[TIME_DATA_MAX]; |
|
|
458 int td; |
|
|
459 |
|
|
460 for( td = 0; td < TIME_DATA_MAX; td++ ) |
|
|
461 time_data[td].valid = 0; |
|
|
462 td = 0; |
|
|
463 |
|
|
464 diag_printf("\n--------------------------------------------------------------------\n"); |
|
|
465 diag_printf("<INFO>: check file1 %s\n",name); |
|
|
466 |
|
|
467 buf = malloc( block_size ); |
|
|
468 if( buf == NULL ) |
|
|
469 { |
|
|
470 SHOW_RESULT( malloc, -1 ); |
|
|
471 return; |
|
|
472 } |
|
|
473 b = (cyg_uint32 *)buf; |
|
|
474 |
|
|
475 get_timestamp( &totalt.start ); |
|
|
476 for(;;) |
|
|
477 { |
|
|
478 get_timestamp( &time_data[td].mountt.start ); |
|
|
479 err = mount( TEST_DEVICE, TEST_MOUNTPOINT, TEST_FSTYPE ); |
|
|
480 get_timestamp( &time_data[td].mountt.end ); |
|
|
481 if( err < 0 ) SHOW_RESULT( mount, err ); |
|
|
482 |
|
|
483 get_timestamp( &time_data[td].opent.start ); |
|
|
484 fd = open( name, O_RDONLY ); |
|
|
485 get_timestamp( &time_data[td].opent.end ); |
|
|
486 if( fd < 0 ) SHOW_RESULT( open, fd ); |
|
|
487 |
|
|
488 get_timestamp( &time_data[td].seekt.start ); |
|
|
489 err = lseek( fd, pos, SEEK_SET ); |
|
|
490 get_timestamp( &time_data[td].seekt.end ); |
|
|
491 if( err < 0 ) SHOW_RESULT( lseek, err ); |
|
|
492 |
|
|
493 get_timestamp( &time_data[td].readt.start ); |
|
|
494 done = read( fd, buf, block_size ); |
|
|
495 get_timestamp( &time_data[td].readt.end ); |
|
|
496 if( done < 0 ) SHOW_RESULT( read, done ); |
|
|
497 |
|
|
498 get_timestamp( &time_data[td].closet.start ); |
|
|
499 err = close( fd ); |
|
|
500 get_timestamp( &time_data[td].closet.end ); |
|
|
501 if( err < 0 ) SHOW_RESULT( close, err ); |
|
|
502 |
|
|
503 get_timestamp( &time_data[td].umountt.start ); |
|
|
504 err = umount( TEST_MOUNTPOINT ); |
|
|
505 get_timestamp( &time_data[td].umountt.end ); |
|
|
506 if( err < 0 ) SHOW_RESULT( umount, err ); |
|
|
507 |
|
|
508 if( done == 0 ) break; |
|
|
509 |
|
|
510 // Check that this is the block we wrote |
|
|
511 if( b[0] != 0 ) |
|
|
512 diag_printf("b[%d] != %08x\n", 0, 0 ); |
|
|
513 |
|
|
514 if( b[1] != pos ) |
|
|
515 diag_printf("b[%d] != %08x\n", 1, (unsigned)pos ); |
|
|
516 |
|
|
517 // if( b[2] != timehash ) |
|
|
518 // diag_printf("b[%d] != %08x\n", 2, timehash ); |
|
|
519 |
|
|
520 if( b[3] != 0x12345678 ) |
|
|
521 diag_printf("b[%d] != %08x\n", 3, 0x12345678 ); |
|
|
522 |
|
|
523 if( b[(block_size/sizeof(cyg_uint32))-4] != (block_size/sizeof(cyg_uint32)-4) ) |
|
|
524 diag_printf("b[%lu](%08x) != %08x\n", (long)block_size/sizeof(cyg_uint32)-4, |
|
|
525 b[(block_size/sizeof(cyg_uint32))-4], |
|
|
526 (unsigned)(block_size/sizeof(cyg_uint32)-4) ); |
|
|
527 |
|
|
528 if( b[block_size/sizeof(cyg_uint32)-3] != pos ) |
|
|
529 diag_printf("b[%lu] != %08x\n", (long)block_size/sizeof(cyg_uint32)-3, (unsigned)pos ); |
|
|
530 |
|
|
531 // if( b[block_size/sizeof(cyg_uint32)-2] != timehash ) |
|
|
532 // diag_printf("b[%d] != %08x\n", block_size/sizeof(cyg_uint32)-2, timehash ); |
|
|
533 |
|
|
534 if( b[block_size/sizeof(cyg_uint32)-1] != 0x12345678 ) |
|
|
535 diag_printf("b[%lu] != %08x\n", (long)block_size/sizeof(cyg_uint32)-1, 0x12345678 ); |
|
|
536 |
|
|
537 pos += done; |
|
|
538 |
|
|
539 time_data[td].valid = 1; |
|
|
540 if( td < (TIME_DATA_MAX-1) ) |
|
|
541 td++; |
|
|
542 } |
|
|
543 get_timestamp( &totalt.end ); |
|
|
544 |
|
|
545 free( buf ); |
|
|
546 |
|
|
547 diag_printf("Block Mount Open Seek Read Close Umount\n"); |
|
|
548 |
|
|
549 for( td = 0; td < TIME_DATA_MAX; td++ ) |
|
|
550 { |
|
|
551 if( !time_data[td].valid ) |
|
|
552 continue; |
|
|
553 |
|
|
554 calculate_interval( &time_data[td].mountt ); |
|
|
555 calculate_interval( &time_data[td].opent ); |
|
|
556 calculate_interval( &time_data[td].seekt ); |
|
|
557 calculate_interval( &time_data[td].readt ); |
|
|
558 calculate_interval( &time_data[td].closet ); |
|
|
559 calculate_interval( &time_data[td].umountt ); |
|
|
560 |
|
|
561 diag_printf("%2d:", td); |
|
|
562 diag_printf(" %8d.%03d", (int)(time_data[td].mountt.us_interval/1000), (int)(time_data[td].mountt.us_interval%1000) ); |
|
|
563 diag_printf(" %8d.%03d", (int)(time_data[td].opent.us_interval/1000), (int)(time_data[td].opent.us_interval%1000) ); |
|
|
564 diag_printf(" %8d.%03d", (int)(time_data[td].seekt.us_interval/1000), (int)(time_data[td].seekt.us_interval%1000) ); |
|
|
565 diag_printf(" %8d.%03d", (int)(time_data[td].readt.us_interval/1000), (int)(time_data[td].readt.us_interval%1000) ); |
|
|
566 diag_printf(" %8d.%03d", (int)(time_data[td].closet.us_interval/1000), (int)(time_data[td].closet.us_interval%1000) ); |
|
|
567 diag_printf(" %8d.%03d", (int)(time_data[td].umountt.us_interval/1000), (int)(time_data[td].umountt.us_interval%1000) ); |
|
|
568 diag_printf("\n"); |
|
|
569 } |
|
|
570 |
|
|
571 calculate_interval( &totalt ); |
|
|
572 diag_printf("CheckFile1 Results: %s size %ld\n", name, pos); |
|
|
573 diag_printf(" Total %8d.%03d ms\n", (int)(totalt.us_interval/1000), (int)(totalt.us_interval%1000) ); |
|
|
574 diag_printf(" Data Rate %10lld KiB/s\n", (1000000LL*pos)/1024/totalt.us_interval); |
|
|
575 |
|
|
576 } |
|
|
577 |
|
|
578 //========================================================================== |
|
|
579 |
|
|
580 void checkcwd( const char *cwd ) |
|
|
581 { |
|
|
582 static char cwdbuf[PATH_MAX]; |
|
|
583 char *ret; |
|
|
584 |
|
|
585 ret = getcwd( cwdbuf, sizeof(cwdbuf)); |
|
|
586 if( ret == NULL ) SHOW_RESULT( getcwd, ret ); |
|
|
587 |
|
|
588 if( strcmp( cwdbuf, cwd ) != 0 ) |
|
|
589 { |
|
|
590 diag_printf( "cwdbuf %s cwd %s\n",cwdbuf, cwd ); |
|
|
591 CYG_TEST_FAIL( "Current directory mismatch"); |
|
|
592 } |
|
|
593 } |
|
|
594 |
|
|
595 //========================================================================== |
|
|
596 |
|
|
597 void fs_callback( cyg_int32 event, CYG_ADDRWORD data ) |
|
|
598 { |
|
|
599 #if 1 |
|
|
600 diag_printf("Filesystem %sSAFE\n", |
|
|
601 event==CYG_FS_CALLBACK_UNSAFE?"UN":""); |
|
|
602 #endif |
|
|
603 } |
|
|
604 |
|
|
605 |
|
|
606 //========================================================================== |
|
|
607 // main |
|
|
608 |
|
|
609 void yaffs5_main( CYG_ADDRESS id ) |
|
|
610 { |
|
|
611 int err; |
|
|
612 int existingdirents=-1; |
|
|
613 int i; |
|
|
614 timing mountt, umountt; |
|
|
615 |
|
|
616 #if defined(CYGSEM_FILEIO_BLOCK_USAGE) |
|
|
617 struct cyg_fs_block_usage usage; |
|
|
618 #endif |
|
|
619 // struct cyg_fs_callback_info callback; |
|
|
620 |
|
|
621 CYG_TEST_INIT(); |
|
|
622 |
|
|
623 init_timing(); |
|
|
624 |
|
|
625 for( i = 0 ; date_string[i] != 0 ; i++ ) |
|
|
626 timehash = (timehash<<1) ^ date_string[i]; |
|
|
627 for( i = 0 ; time_string[i] != 0 ; i++ ) |
|
|
628 timehash = (timehash<<1) ^ time_string[i]; |
|
|
629 |
|
|
630 // -------------------------------------------------------------- |
|
|
631 |
|
|
632 #if 1 |
|
|
633 #define DO_UMOUNT |
|
|
634 get_timestamp( &mountt.start ); |
|
|
635 err = mount( TEST_DEVICE, TEST_MOUNTPOINT, TEST_FSTYPE ); |
|
|
636 // err = mount( TEST_DEVICE, TEST_MOUNTPOINT, "yaffs:sync=write" ); |
|
|
637 // err = mount( TEST_DEVICE, TEST_MOUNTPOINT, "yaffs:sync=close" ); |
|
|
638 // err = mount( TEST_DEVICE, TEST_MOUNTPOINT, "yaffs:sync=data" ); |
|
|
639 get_timestamp( &mountt.end ); |
|
|
640 if( err < 0 ) { |
|
|
641 SHOW_RESULT( mount, err ); |
|
|
642 CYG_TEST_FAIL_FINISH("yaffs5"); |
|
|
643 } |
|
|
644 |
|
|
645 #if 0 |
|
|
646 callback.callback = fs_callback; |
|
|
647 callback.data = 0; |
|
|
648 err = cyg_fs_setinfo(TEST_MOUNTPOINT, FS_INFO_CALLBACK, |
|
|
649 &callback, sizeof(callback)); |
|
|
650 if( err < 0 ) SHOW_RESULT( cyg_fs_setinfo, err ); |
|
|
651 #endif |
|
|
652 |
|
|
653 calculate_interval( &mountt ); |
|
|
654 diag_printf(" Mount %8d.%03d ms\n", (int)(mountt.us_interval/1000), (int)(mountt.us_interval%1000) ); |
|
|
655 |
|
|
656 err = access( TEST_MOUNTPOINT TEST_DIRECTORY, F_OK ); |
|
|
657 if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); |
|
|
658 |
|
|
659 if( err < 0 && errno == EACCES ) |
|
|
660 { |
|
|
661 diag_printf("<INFO>: create %s\n", |
|
|
662 TEST_MOUNTPOINT TEST_DIRECTORY); |
|
|
663 err = mkdir( TEST_MOUNTPOINT TEST_DIRECTORY, 0 ); |
|
|
664 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
665 } |
|
|
666 |
|
|
667 err = chdir( TEST_MOUNTPOINT TEST_DIRECTORY ); |
|
|
668 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
669 |
|
|
670 checkcwd( TEST_MOUNTPOINT TEST_DIRECTORY ); |
|
|
671 |
|
|
672 listdir( TEST_MOUNTPOINT TEST_DIRECTORY, true, -1, &existingdirents ); |
|
|
673 |
|
|
674 // -------------------------------------------------------------- |
|
|
675 #if defined(CYGSEM_FILEIO_BLOCK_USAGE) |
|
|
676 err = cyg_fs_getinfo(TEST_MOUNTPOINT, FS_INFO_BLOCK_USAGE, |
|
|
677 &usage, sizeof(usage)); |
|
|
678 if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err ); |
|
|
679 diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n", |
|
|
680 usage.total_blocks, usage.total_blocks * usage.block_size); |
|
|
681 diag_printf("<INFO>: free size: %6lld blocks, %10lld bytes\n", |
|
|
682 usage.free_blocks, usage.free_blocks * usage.block_size); |
|
|
683 diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size); |
|
|
684 #endif |
|
|
685 // -------------------------------------------------------------- |
|
|
686 |
|
|
687 #endif |
|
|
688 |
|
|
689 #if 1 |
|
|
690 createfile( "yaffs5.0", 1024*1024, 16*1024 ); |
|
|
691 checkfile( "yaffs5.0",16*1024 ); |
|
|
692 err = unlink( "yaffs5.0" ); |
|
|
693 sync(); |
|
|
694 #endif |
|
|
695 |
|
|
696 #if 1 |
|
|
697 createfile( "yaffs5.0", 200*1024, 1024 ); |
|
|
698 checkfile( "yaffs5.0", 1024 ); |
|
|
699 err = unlink( "yaffs5.0" ); |
|
|
700 #endif |
|
|
701 |
|
|
702 #if 1 |
|
|
703 createfile( "yaffs5.1", 1024*1024, 1024 ); |
|
|
704 createfile( "yaffs5.2", 1024*1024, 4*1024 ); |
|
|
705 sync(); |
|
|
706 createfile( "yaffs5.3", 8*1024*1024, 32*1024 ); |
|
|
707 |
|
|
708 checkfile( "yaffs5.1", 1024 ); |
|
|
709 checkfile( "yaffs5.2", 4*1024 ); |
|
|
710 checkfile( "yaffs5.3", 32*1024 ); |
|
|
711 |
|
|
712 diag_printf("\n--------------------------------------------------------------------\n"); |
|
|
713 |
|
|
714 listdir( "." , true, existingdirents+3, NULL ); |
|
|
715 |
|
|
716 // -------------------------------------------------------------- |
|
|
717 |
|
|
718 diag_printf("<INFO>: unlink yaffs5.1\n"); |
|
|
719 err = unlink( "yaffs5.1" ); |
|
|
720 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
721 |
|
|
722 diag_printf("<INFO>: unlink yaffs5.2\n"); |
|
|
723 err = unlink( "yaffs5.2" ); |
|
|
724 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
725 |
|
|
726 diag_printf("<INFO>: unlink yaffs5.3\n"); |
|
|
727 err = unlink( "yaffs5.3" ); |
|
|
728 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
729 #endif |
|
|
730 |
|
|
731 // -------------------------------------------------------------- |
|
|
732 |
|
|
733 #if 1 && defined(DO_UMOUNT) |
|
|
734 |
|
|
735 diag_printf("<INFO>: unlink yaffs5.4\n"); |
|
|
736 err = unlink( "yaffs5.4" ); |
|
|
737 |
|
|
738 createfile( "yaffs5.4", 5*1024*1024, 32*1024 ); |
|
|
739 #endif |
|
|
740 |
|
|
741 // -------------------------------------------------------------- |
|
|
742 |
|
|
743 #ifdef DO_UMOUNT |
|
|
744 diag_printf("<INFO>: cd /\n"); |
|
|
745 err = chdir( "/" ); |
|
|
746 if( err == 0 ) |
|
|
747 { |
|
|
748 checkcwd( "/" ); |
|
|
749 |
|
|
750 diag_printf("<INFO>: umount %s\n",TEST_MOUNTPOINT); |
|
|
751 get_timestamp( &umountt.start ); |
|
|
752 err = umount( TEST_MOUNTPOINT ); |
|
|
753 get_timestamp( &umountt.end ); |
|
|
754 if( err < 0 ) SHOW_RESULT( umount, err ); |
|
|
755 |
|
|
756 calculate_interval( &umountt ); |
|
|
757 diag_printf(" Umount %8d.%03d ms\n", (int)(umountt.us_interval/1000), (int)(umountt.us_interval%1000) ); |
|
|
758 |
|
|
759 } |
|
|
760 #endif |
|
|
761 |
|
|
762 #if 1 |
|
|
763 |
|
|
764 diag_printf("<INFO>: syncing\n"); |
|
|
765 sync(); |
|
|
766 |
|
|
767 checkfile1(TEST_MOUNTPOINT TEST_DIRECTORY "/yaffs5.4", 32*1024 ); |
|
|
768 |
|
|
769 // Remount just to remove yaffs5.4 |
|
|
770 err = mount( TEST_DEVICE, TEST_MOUNTPOINT, TEST_FSTYPE ); |
|
|
771 if( err < 0 ) { |
|
|
772 SHOW_RESULT( mount, err ); |
|
|
773 CYG_TEST_FAIL_FINISH("yaffs5"); |
|
|
774 } |
|
|
775 err = unlink( TEST_MOUNTPOINT TEST_DIRECTORY "/yaffs5.4" ); |
|
|
776 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
777 err = umount( TEST_MOUNTPOINT ); |
|
|
778 if( err < 0 ) SHOW_RESULT( umount, err ); |
|
|
779 |
|
|
780 #endif |
|
|
781 |
|
|
782 diag_printf("<INFO>: syncing\n"); |
|
|
783 sync(); |
|
|
784 |
|
|
785 CYG_TEST_PASS_FINISH("yaffs5"); |
|
|
786 } |
|
|
787 |
|
|
788 // ------------------------------------------------------------------------- |
|
|
789 |
|
|
790 #include <cyg/kernel/kapi.h> |
|
|
791 |
|
|
792 static cyg_handle_t thread_handle; |
|
|
793 static cyg_thread thread; |
|
|
794 static char stack[CYGNUM_HAL_STACK_SIZE_TYPICAL+8*1024]; |
|
|
795 //static char stack[64*1024]; |
|
|
796 |
|
|
797 externC void |
|
|
798 cyg_start( void ) |
|
|
799 { |
|
|
800 cyg_thread_create(3, // Priority - just a number |
|
|
801 yaffs5_main, // entry |
|
|
802 0, // index |
|
|
803 0, // no name |
|
|
804 &stack[0], // Stack |
|
|
805 sizeof(stack), // Size |
|
|
806 &thread_handle, // Handle |
|
|
807 &thread // Thread data structure |
|
|
808 ); |
|
|
809 cyg_thread_resume(thread_handle); |
|
|
810 |
|
|
811 cyg_scheduler_start(); |
|
|
812 } |
|
|
813 |
|
|
814 // ------------------------------------------------------------------------- |
|
|
815 // EOF yaffs5.c |