static void comparefiles( char *name2, char *name1 ) { int err; char buf1[IOSIZE]; char buf2[IOSIZE]; int fd1, fd2; ssize_t done1, done2; int i; diag_printf("<INFO>: compare files %s == %s\n",name2,name1); err = access( name1, F_OK ); if( err != 0 ) SHOW_RESULT( access, err ); err = access( name1, F_OK ); if( err != 0 ) SHOW_RESULT( access, err ); fd1 = open( name1, O_RDONLY ); if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); fd2 = open( name2, O_RDONLY ); if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); for(;;) { done1 = read( fd1, buf1, IOSIZE ); if( done1 < 0 ) SHOW_RESULT( read, done1 ); done2 = read( fd2, buf2, IOSIZE ); if( done2 < 0 ) SHOW_RESULT( read, done2 ); if( done1 != done2 ) diag_printf("Files different sizes\n"); if( done1 == 0 ) break; for( i = 0; i < done1; i++ ) if( buf1[i] != buf2[i] ) { diag_printf("buf1[%d](%02x) != buf1[%d](%02x)\n",i,buf1[i],i,buf2[i]); CYG_TEST_FAIL("Data in files not equal\n"); } } err = close( fd1 ); if( err < 0 ) SHOW_RESULT( close, err ); err = close( fd2 ); if( err < 0 ) SHOW_RESULT( close, err ); }
static DFBResult Test_ScaleWindow( IDirectFBDisplayLayer *layer, void *arg ) { int i; IDirectFBWindow *window; DFBWindowOptions opts; DFBDimension size; D_ASSERT( m_toplevel_id != 0 ); /* * Get the top level window */ _T( layer->GetWindow( layer, arg ? (unsigned long) arg : m_toplevel_id, &window ) ); window->GetSize( window, &size.w, &size.h ); /* * Enable scaling */ _T( window->GetOptions( window, &opts ) ); _T( window->SetOptions( window, opts | DWOP_SCALE ) ); /* * Scale the window */ { DFBDimension sizes[] = { { size.w + 40, size.h }, { size.w + 40, size.h + 40 }, { size.w, size.h + 40 }, { size.w + 40, size.h - 40 }, { size.w - 40, size.h + 40 }, { size.w, size.h } }; for (i=0; i<D_ARRAY_SIZE(sizes); i++) { SHOW_TEST( "Resize( %4d,%4d - [%02d] )...", sizes[i].w, sizes[i].h, i ); _T( window->Resize( window, sizes[i].w, sizes[i].h ) ); SHOW_RESULT( "...Resize( %4d,%4d - [%02d] ) done.", sizes[i].w, sizes[i].h, i ); } } /* * Restore options */ _T( window->SetOptions( window, opts ) ); window->Release( window ); return DFB_OK; }
static void checkfile( char *name ) { unsigned char buf[IOSIZE]; int fd; ssize_t done; int i; int err; off_t pos = 0; diag_printf("<INFO>: check file %s\n",name); err = access( name, F_OK ); if( err != 0 ) SHOW_RESULT( access, err ); fd = open( name, O_RDONLY ); if( fd < 0 ) SHOW_RESULT( open, fd ); for(;;) { done = read( fd, buf, IOSIZE ); if( done < 0 ) SHOW_RESULT( read, done ); if( done == 0 ) break; for( i = 0; i < done; i++ ) if( buf[i] != i%256 ) { diag_printf("buf[%ld+%d](%02x) != %02x\n", (unsigned long)pos,i,buf[i],i%256); CYG_TEST_FAIL("Data read not equal to data written\n"); } pos += done; } err = close( fd ); if( err < 0 ) SHOW_RESULT( close, err ); }
void checkcwd( const char *cwd ) { static char cwdbuf[PATH_MAX]; char *ret; ret = getcwd( cwdbuf, sizeof(cwdbuf)); if( ret == NULL ) SHOW_RESULT( getcwd, ret ); if( strcmp( cwdbuf, cwd ) != 0 ) { diag_printf( "cwdbuf %s cwd %s\n",cwdbuf, cwd ); CYG_TEST_FAIL( "Current directory mismatch"); } }
int main( int argc, char **argv ) { int err, iteration; struct mallinfo minfo ; CYG_TEST_INIT(); // -------------------------------------------------------------- CYG_TEST_INFO("mount /"); err = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" ); if( err < 0 ) SHOW_RESULT( mount, err ); chdir ("/"); iteration=0; create_file(iteration); while (iteration < ITERATIONS) { if (!(iteration % 1000)) { minfo = mallinfo(); diag_printf("<INFO> Iteration %07d fordblks = %7d\n", iteration, minfo.fordblks); } iteration++; create_file(iteration); check_file(iteration-1); delete_file(iteration-1); check_file(iteration); } CYG_TEST_INFO("umount /"); err = umount( "/" ); if( err < 0 ) SHOW_RESULT( umount, err ); CYG_TEST_PASS_FINISH("jffs2_3"); }
static void checkattrib(const char *name, const cyg_fs_attrib_t test_attrib ) { int err; cyg_fs_attrib_t file_attrib; diag_printf("<INFO>: check attrib %s\n",name); err = cyg_fs_get_attrib(name, &file_attrib); if( err != 0 ) SHOW_RESULT( stat, err ); if ( (file_attrib & S_FATFS_ATTRIB) != test_attrib ) diag_printf("<FAIL>: attrib %s incorrect\n\tExpected %x Was %x\n", name,test_attrib,(file_attrib & S_FATFS_ATTRIB)); }
static void copyfile( char *name2, char *name1 ) { int err; char buf[IOSIZE]; int fd1, fd2; ssize_t done, wrote; diag_printf("<INFO>: copy file %s -> %s\n",name2,name1); err = access( name1, F_OK ); if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); err = access( name2, F_OK ); if( err != 0 ) SHOW_RESULT( access, err ); fd1 = open( name1, O_WRONLY|O_CREAT ); if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); fd2 = open( name2, O_RDONLY ); if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); for(;;) { done = read( fd2, buf, IOSIZE ); if( done < 0 ) SHOW_RESULT( read, done ); if( done == 0 ) break; wrote = write( fd1, buf, done ); if( wrote != done ) SHOW_RESULT( write, wrote ); if( wrote != done ) break; } err = close( fd1 ); if( err < 0 ) SHOW_RESULT( close, err ); err = close( fd2 ); if( err < 0 ) SHOW_RESULT( close, err ); }
static DFBResult Test_MoveWindow( IDirectFBDisplayLayer *layer, void *arg ) { int i; DFBPoint pos; IDirectFBWindow *window; D_ASSERT( m_toplevel_id != 0 ); /* * Get the top level window */ _T( layer->GetWindow( layer, arg ? (unsigned long) arg : m_toplevel_id, &window ) ); window->GetPosition( window, &pos.x, &pos.y ); /* * Move the window */ { DFBPoint poss[] = { { pos.x - 40, pos.y - 40 }, { pos.x + 40, pos.y - 40 }, { pos.x + 40, pos.y + 40 }, { pos.x - 40, pos.y + 40 }, { pos.x , pos.y } }; for (i=0; i<D_ARRAY_SIZE(poss); i++) { SHOW_TEST( "MoveTo( %4d,%4d - [%02d] )...", poss[i].x, poss[i].y, i ); _T( window->MoveTo( window, poss[i].x, poss[i].y ) ); SHOW_RESULT( "...MoveTo( %4d,%4d - [%02d] ) done.", poss[i].x, poss[i].y, i ); } } window->Release( window ); return DFB_OK; }
void copyfile(char *name2, char *name1) { int err; char buf[IOSIZE]; int fd1, fd2; ssize_t done, wrote; fd1 = open(name1, O_WRONLY | O_CREAT, 0664); if (fd1 < 0) SHOW_RESULT(open, fd1); fd2 = open(name2, O_RDONLY); if (fd2 < 0) SHOW_RESULT(open, fd2); for (;; ) { done = read(fd2, buf, IOSIZE); if (done < 0) { SHOW_RESULT(read, done); break; } if (done == 0) break; wrote = write(fd1, buf, done); if (wrote != done) SHOW_RESULT(write, wrote); if (wrote != done) break; } err = close(fd1); if (err < 0) SHOW_RESULT(close, err); err = close(fd2); if (err < 0) SHOW_RESULT(close, err); }
/* utility fn to copy a directory */ void copydir(char *name, char *destdir) { int err; DIR *dirp; dirp = opendir(destdir); if (dirp==NULL) { mkdir(destdir, 0777); } else { err = closedir(dirp); } dirp = opendir(name); if( dirp == NULL ) SHOW_RESULT( opendir, -1 ); for (;;) { struct dirent *entry = readdir(dirp); if (entry == NULL) break; if (strcmp(entry->d_name, ".") == 0) continue; if (strcmp(entry->d_name, "..") == 0) continue; int isDir = 0; struct stat buf; char fullPath[PATH_MAX]; strncpy(fullPath, name, PATH_MAX); strcat(fullPath, "/"); strncat(fullPath, entry->d_name, PATH_MAX - strlen(fullPath)); if (stat(fullPath, &buf) == -1) { LOG_ERROR("unable to read status from %s", fullPath); break; } isDir = S_ISDIR(buf.st_mode) != 0; if (isDir) continue; // diag_printf("<INFO>: entry %14s",entry->d_name); char fullname[PATH_MAX]; char fullname2[PATH_MAX]; strcpy(fullname, name); strcat(fullname, "/"); strcat(fullname, entry->d_name); strcpy(fullname2, destdir); strcat(fullname2, "/"); strcat(fullname2, entry->d_name); // diag_printf("from %s to %s\n", fullname, fullname2); copyfile(fullname, fullname2); // diag_printf("\n"); } err = closedir(dirp); if( err < 0 ) SHOW_RESULT( stat, err ); }
int main( int argc, char **argv ) { int err; FILE *f; fpos_t fpos; int flibble = 4567; char *wibble = "abcdefghijk"; int flibble1; char wibble1[20]; CYG_TEST_INIT(); f = fopen("/foo", "w" ); if( f == NULL ) SHOW_RESULT( fopen, -1 ); err = fprintf(f, "flibble %d wibble %s\n", flibble, wibble ); if( err < 0 ) SHOW_RESULT( fprintf, err ); err = fprintf(f, "another flibble %d another wibble %s\n", flibble, wibble ); if( err < 0 ) SHOW_RESULT( fprintf, err ); err = fclose( f ); if( err == EOF ) SHOW_RESULT( fclose, -1 ); f = fopen("/foo", "r" ); if( f == NULL ) SHOW_RESULT( fopen, -1 ); err = fscanf(f, "flibble %d wibble %s\n", &flibble1, wibble1 ); if( err < 0 ) SHOW_RESULT( fscanf, err ); diag_printf("<INFO>: flibble1 %d wibble1 %s\n",flibble1,wibble1); CYG_TEST_CHECK( flibble1 == flibble , "Bad flibble result from fscanf"); CYG_TEST_CHECK( strcmp(wibble,wibble1) == 0, "Bad wibble result from fscanf"); err = fgetpos( f, &fpos ); if( err < 0 ) SHOW_RESULT( fgetpos, err ); err = fseek( f, 0, SEEK_SET ); if( err < 0 ) SHOW_RESULT( fseek, err ); err = fscanf(f, "flibble %d wibble %s\n", &flibble1, wibble1 ); if( err < 0 ) SHOW_RESULT( fscanf, err ); diag_printf("<INFO>: flibble1 %d wibble1 %s\n",flibble1,wibble1); CYG_TEST_CHECK( flibble1 == flibble , "Bad flibble result from fscanf"); CYG_TEST_CHECK( strcmp(wibble,wibble1) == 0, "Bad wibble result from fscanf"); err = fseek( f, 0, SEEK_END ); if( err < 0 ) SHOW_RESULT( fseek, err ); err = fsetpos( f, &fpos ); if( err < 0 ) SHOW_RESULT( fsetpos, err ); err = fscanf(f, "another flibble %d another wibble %s\n", &flibble1, wibble1 ); if( err < 0 ) SHOW_RESULT( fscanf, err ); diag_printf("<INFO>: flibble1 %d wibble1 %s\n",flibble1,wibble1); CYG_TEST_CHECK( flibble1 == flibble , "Bad flibble result from fscanf"); CYG_TEST_CHECK( strcmp(wibble,wibble1) == 0, "Bad wibble result from fscanf"); err = fclose( f ); CYG_TEST_PASS_FINISH("stdio"); return 0; }
void *pthread_entry1( void *arg) { int fd = 0; int err; fd_set rd, wr; sigset_t mask, oldmask; struct sigaction sigact; struct timespec ts; CYG_TEST_INFO( "Thread 1 running" ); FD_ZERO( &rd ); FD_ZERO( &wr ); sigfillset( &mask ); pthread_sigmask( SIG_SETMASK, &mask, &oldmask ); sigdelset( &mask, SIGUSR1 ); sigact.sa_mask = mask; sigact.sa_flags = SA_SIGINFO; sigact.sa_sigaction = sigusr1; err = sigaction( SIGUSR1, &sigact, NULL ); if( err < 0 ) SHOW_RESULT( sigact, err ); CYG_TEST_INFO( "Thread1: calling socket()"); fd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); if( fd < 0 ) SHOW_RESULT( socket, fd ); CYG_TEST_CHECK( fd >= 0, "socket() returned error"); CYG_TEST_INFO( "Thread1: calling bind()"); err = bind( fd, (struct sockaddr *)&sa, sizeof(sa)); if( err < 0 ) SHOW_RESULT( bind, err ); CYG_TEST_CHECK( err == 0, "bind() returned error"); CYG_TEST_INFO( "Thread1: calling listen()"); err = listen( fd, 3); if( err < 0 ) SHOW_RESULT( listen, err ); CYG_TEST_CHECK( err == 0, "listen() returned error"); FD_SET( fd, &rd ); ts.tv_sec = 0; ts.tv_nsec = 0; while( running ) { fd_set rd_res = rd; fd_set wr_res = wr; // ts.tv_nsec = 1000000 * (pselect_wakeups % 10); err = pselect( 8, &rd_res, &wr_res, NULL, &ts, &mask ); if( err < 0 ) { if( errno == EINTR ) pselect_eintr++; else SHOW_RESULT( pselect, err ); } if( err > 0 ) show_fdsets( "Thread1 result: ", 8, &rd_res, &wr_res, NULL ); pselect_wakeups++; } // If we were interrupted at just the wrong point above we may still // have a SIGUSR1 signal pending that we didn't handle, and so won't // have accounted for. So let's look... CYG_TEST_CHECK( 0 == sigpending( &mask ), "sigpending() returned error"); if (1 == sigismember(&mask, SIGUSR1) ) pselect_eintr++; pthread_sigmask( SIG_SETMASK, &oldmask, NULL ); pthread_exit(arg); }
static DFBResult Test_CreateSubWindow( IDirectFBDisplayLayer *layer, void *arg ) { IDirectFBWindow *window; DFBWindowID window_id; DFBDimension size = { m_desc_sub.width, m_desc_sub.height }; D_ASSERT( m_toplevel_id != 0 ); /* Write window ID of top level into description */ m_desc_sub.toplevel_id = m_toplevel_id; /* * Create a new sub window with 75% width/height and positioned at 20,20 within top level window */ SHOW_TEST( "CreateWindow( %d,%d - %dx%d %s + toplevel ID %u, options 0x%08x )...", m_desc_sub.posx, m_desc_sub.posy, m_desc_sub.width, m_desc_sub.height, dfb_pixelformat_name( m_desc_sub.pixelformat ), m_desc_sub.toplevel_id, m_desc_top.options ); _T( layer->CreateWindow( layer, &m_desc_sub, &window ) ); if (m_subcolor.valid) { DFBColor c = m_subcolor.color; SHOW_INFO( " - SetColor( 0x%02x, 0x%02x, 0x%02x, 0x%02x )...", c.r, c.g, c.b, c.a ); _T( window->SetColor( window, c.r, c.g, c.b, c.a ) ); } /* * Query its surface and clear it with light gray (if not input or color only) */ if (!(m_desc_sub.caps & (DWCAPS_INPUTONLY | DWCAPS_COLOR) )) { IDirectFBSurface *surface; SHOW_INFO( " - GetSurface()..." ); _T( window->GetSurface( window, &surface ) ); SHOW_INFO( " - Clear( 0xC0, 0xC0, 0xC0, 0xFF )..." ); _T( surface->Clear( surface, 0xC0, 0xC0, 0xC0, 0xFF ) ); _T( surface->DrawRectangle( surface, 0, 0, size.w, size.h ) ); _T( surface->FillRectangle( surface, size.w / 2, 1, 1, size.h - 2 ) ); _T( surface->FillRectangle( surface, 1, size.h / 2, size.w - 2, 1 ) ); surface->Release( surface ); } /* * Show the window */ SHOW_INFO( " - SetOpacity( 255 )..." ); _T( window->SetOpacity( window, 0xff ) ); /* * Query and print ID of new window */ SHOW_INFO( " - GetID()..." ); _T( window->GetID( window, &window_id ) ); /* * Set association of new window */ if (m_desc_sub.parent_id) { SHOW_INFO( " - SetAssociation( %u )...", m_desc_sub.parent_id ); _T( window->SetAssociation( window, m_desc_sub.parent_id ) ); } /* * Set top level window ID (user hasn't specified one) */ m_subwindow_id = window_id; m_subwindow = window; SHOW_RESULT( "...CreateWindow( %d,%d - %dx%d %s + toplevel ID %u ) done. => Sub Window ID %u", m_desc_sub.posx, m_desc_sub.posy, m_desc_sub.width, m_desc_sub.height, dfb_pixelformat_name( m_desc_sub.pixelformat ), m_desc_sub.toplevel_id, window_id ); return DFB_OK; }
void *pthread_entry2( void *arg) { #ifdef TEST_NET int fd; int netstate = 0; #endif #ifdef TEST_DEV int ser1; int serstate = 0; #endif #if defined(TEST_DEV) || defined(TEST_NET) int i; ssize_t done; #endif int netdone = 0; int serdone = 0; int err; fd_set rd, wr; CYG_TEST_INFO( "Thread 2 running" ); FD_ZERO( &rd ); FD_ZERO( &wr ); #ifdef TEST_NET CYG_TEST_INFO( "Thread2: calling socket()"); fd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); if( fd < 0 ) SHOW_RESULT( socket, fd ); CYG_TEST_CHECK( fd >= 0, "socket() returned error"); CYG_TEST_INFO( "Thread2: calling connect()"); err = connect( fd, (struct sockaddr *)&sa, sizeof(sa)); if( err < 0 ) SHOW_RESULT( connect, err ); CYG_TEST_CHECK( err == 0, "connect() returned error"); FD_SET( fd, &rd ); #else netdone = 1; #endif #ifdef TEST_DEV for( i = 0; i < TEST_BUFSIZE; i++ ) sbuf1[i] = i; CYG_TEST_INFO( "Thread2: calling open(/dev/ser1)"); ser1 = open("/dev/ser1", O_RDWR ); if( ser1 < 0 ) SHOW_RESULT( open, ser1 ); CYG_TEST_CHECK( ser1 >= 0, "open(/dev/ser1) returned error"); CYG_TEST_INFO( "Thread2: calling write(ser1)"); done = write( ser1, sbuf1, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( write, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "write() returned bad size"); FD_SET( ser1, &wr ); #else serdone = 1; #endif while(!(netdone && serdone)) { fd_set rd_res = rd; fd_set wr_res = wr; CYG_TEST_INFO( "Thread2: calling select()"); show_fdsets( "Thread2 request: ", 8, &rd_res, &wr_res, NULL ); err = select( 8, &rd_res, &wr_res, NULL, NULL ); if( err < 0 ) SHOW_RESULT( select, err ); CYG_TEST_CHECK( err >= 0, "select() returned error"); show_fdsets( "Thread2 result: ", 8, &rd_res, &wr_res, NULL ); #ifdef TEST_NET switch( netstate ) { case 0: CYG_TEST_INFO( "Thread2: netstate 0"); if( FD_ISSET( fd, &rd_res ) ) { CYG_TEST_INFO( "Thread2: calling read()"); done = read( fd, buf2, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( read, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "read() returned bad size"); for( i = 0; i < TEST_BUFSIZE; i++ ) if( buf1[i] != buf2[i] ) diag_printf("buf1[%d](%02x) != buf2[%d](%02x)\n",i,buf1[i],i,buf2[i]); netstate++; FD_CLR( fd, &rd ); FD_SET( fd, &wr ); } break; case 1: CYG_TEST_INFO( "Thread2: netstate 1"); if( FD_ISSET( fd, &wr_res ) ) { CYG_TEST_INFO( "Thread2: calling write()"); done = write( fd, buf2, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( write, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "write() returned bad size"); FD_CLR( fd, &wr ); netstate++; netdone = 1; CYG_TEST_INFO( "Thread2: netdone"); } break; } #endif #ifdef TEST_DEV switch( serstate ) { case 0: CYG_TEST_INFO( "Thread2: serstate 0"); if( FD_ISSET( ser1, &wr_res ) ) { FD_CLR( ser1, &wr ); FD_SET( ser1, &rd ); serstate++; } break; case 1: CYG_TEST_INFO( "Thread2: serstate 1"); if( FD_ISSET( ser1, &rd_res ) ) { CYG_TEST_INFO( "Thread2: calling read(ser1)"); done = read( ser1, sbuf3, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( read, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "read() returned bad size"); for( i = 0; i < TEST_BUFSIZE; i++ ) if( sbuf1[i] != sbuf3[i] ) diag_printf("sbuf1[%d](%02x) != sbuf3[%d](%02x)\n",i,sbuf1[i],i,sbuf3[i]); FD_CLR( ser1, &rd ); serstate++; serdone = 1; CYG_TEST_INFO( "Thread2: serdone"); } break; } #endif } #ifdef TEST_NET CYG_TEST_INFO( "Thread2: calling close(fd)"); err = close(fd); if( err < 0 ) SHOW_RESULT( close, err ); CYG_TEST_CHECK( err == 0, "close() returned error"); #endif #ifdef TEST_DEV CYG_TEST_INFO( "Thread2: calling close(ser1)"); err = close(ser1); if( err < 0 ) SHOW_RESULT( close, err ); CYG_TEST_CHECK( err == 0, "close(ser1) returned error"); #endif CYG_TEST_INFO( "Thread2: calling pthread_exit()"); pthread_exit( arg ); }
int main( int argc, char **argv ) { int err; //int i; int existingdirents=-1; CYG_TEST_INIT(); // -------------------------------------------------------------- err = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" ); if( err < 0 ) SHOW_RESULT( mount, err ); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); listdir( "/", true, -1, &existingdirents ); if ( existingdirents < 2 ) CYG_TEST_FAIL("Not enough dir entries\n"); // -------------------------------------------------------------- createfile( "/foo", 202 ); checkfile( "foo" ); copyfile( "foo", "fee"); checkfile( "fee" ); comparefiles( "foo", "/fee" ); diag_printf("<INFO>: mkdir bar\n"); err = mkdir( "/bar", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); listdir( "/" , true, existingdirents+3, NULL ); copyfile( "fee", "/bar/fum" ); checkfile( "bar/fum" ); comparefiles( "/fee", "bar/fum" ); diag_printf("<INFO>: cd bar\n"); err = chdir( "bar" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/bar" ); diag_printf("<INFO>: rename /foo bundy\n"); err = rename( "/foo", "bundy" ); if( err < 0 ) SHOW_RESULT( rename, err ); listdir( "/", true, existingdirents+2, NULL ); listdir( "" , true, 4, NULL ); checkfile( "/bar/bundy" ); comparefiles("/fee", "bundy" ); // -------------------------------------------------------------- createfile( LONGNAME1, 123 ); checkfile( LONGNAME1 ); copyfile( LONGNAME1, LONGNAME2 ); listdir( "", false, 6, NULL ); diag_printf("<INFO>: unlink " LONGNAME1 "\n"); err = unlink( LONGNAME1 ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink " LONGNAME2 "\n"); err = unlink( LONGNAME2 ); if( err < 0 ) SHOW_RESULT( unlink, err ); // -------------------------------------------------------------- diag_printf("<INFO>: unlink fee\n"); err = unlink( "/fee" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink fum\n"); err = unlink( "fum" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink /bar/bundy\n"); err = unlink( "/bar/bundy" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: cd /\n"); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); diag_printf("<INFO>: rmdir /bar\n"); err = rmdir( "/bar" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); listdir( "/", false, existingdirents, NULL ); // -------------------------------------------------------------- diag_printf("<INFO>: mount /jffs2 \n"); err = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/jffs2", "jffs2" ); if( err < 0 ) SHOW_RESULT( mount, err ); createfile( "/jffs2/tinky", 456 ); copyfile( "/jffs2/tinky", "/jffs2/laalaa" ); checkfile( "/jffs2/tinky"); checkfile( "/jffs2/laalaa"); comparefiles( "/jffs2/tinky", "/jffs2/laalaa" ); diag_printf("<INFO>: cd /jffs2\n"); err = chdir( "/jffs2" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2" ); diag_printf("<INFO>: mkdir noonoo\n"); err = mkdir( "noonoo", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); listdir( "." , true, existingdirents+3, NULL); diag_printf("<INFO>: cd noonoo\n"); err = chdir( "noonoo" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2/noonoo" ); createfile( "tinky", 678 ); checkfile( "tinky" ); createfile( "dipsy", 3456 ); checkfile( "dipsy" ); copyfile( "dipsy", "po" ); checkfile( "po" ); comparefiles( "dipsy", "po" ); /*for(i=0;i<2048;i++) { diag_printf("<INFO>: churningchurningchurning................................ITERATION = %d\n", i); createfile( "churningchurningchurning", 4096 ); diag_printf("<INFO>: unlink churningchurningchurning\n"); err = unlink( "churningchurningchurning" ); if( err < 0 ) SHOW_RESULT( unlink, err ); }*/ listdir( ".", true, 5, NULL ); listdir( "", true, 5, NULL ); listdir( "..", true, existingdirents+3, NULL ); // -------------------------------------------------------------- diag_printf("<INFO>: unlink tinky\n"); err = unlink( "tinky" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink dipsy\n"); err = unlink( "dipsy" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink po\n"); err = unlink( "po" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: cd ..\n"); err = chdir( ".." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2" ); diag_printf("<INFO>: rmdir noonoo\n"); err = rmdir( "noonoo" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); // -------------------------------------------------------------- err = mkdir( "x", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); err = mkdir( "x/y", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); err = mkdir( "x/y/z", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); err = mkdir( "x/y/z/w", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); diag_printf("<INFO>: cd /jffs2/x/y/z/w\n"); err = chdir( "/jffs2/x/y/z/w" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2/x/y/z/w" ); diag_printf("<INFO>: cd ..\n"); err = chdir( ".." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2/x/y/z" ); diag_printf("<INFO>: cd .\n"); err = chdir( "." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2/x/y/z" ); diag_printf("<INFO>: cd ../../y\n"); err = chdir( "../../y" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2/x/y" ); diag_printf("<INFO>: cd ../..\n"); err = chdir( "../.." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2" ); diag_printf("<INFO>: rmdir x/y/z/w\n"); err = rmdir( "x/y/z/w" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); diag_printf("<INFO>: rmdir x/y/z\n"); err = rmdir( "x/y/z" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); diag_printf("<INFO>: rmdir x/y\n"); err = rmdir( "x/y" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); diag_printf("<INFO>: rmdir x\n"); err = rmdir( "x" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); // -------------------------------------------------------------- diag_printf("<INFO>: unlink tinky\n"); err = unlink( "tinky" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink laalaa\n"); err = unlink( "laalaa" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: cd /\n"); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); diag_printf("<INFO>: umount /jffs2\n"); err = umount( "/jffs2" ); if( err < 0 ) SHOW_RESULT( umount, err ); diag_printf("<INFO>: umount /\n"); err = umount( "/" ); if( err < 0 ) SHOW_RESULT( umount, err ); CYG_TEST_PASS_FINISH("jffs2_1"); }
int main( int argc, char **argv ) { int err; int existingdirents=-1; #if defined(CYGSEM_FILEIO_BLOCK_USAGE) struct cyg_fs_block_usage usage; #endif CYG_TEST_INIT(); // -------------------------------------------------------------- err = mount( "/dev/disk0/1", "/", "fatfs" ); if( err < 0 ) SHOW_RESULT( mount, err ); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); listdir( "/", true, -1, &existingdirents ); // -------------------------------------------------------------- #if defined(CYGSEM_FILEIO_BLOCK_USAGE) err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage)); if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err ); diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n", usage.total_blocks, usage.total_blocks * usage.block_size); diag_printf("<INFO>: free size: %6lld blocks, %10lld bytes\n", usage.free_blocks, usage.free_blocks * usage.block_size); diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size); #endif // -------------------------------------------------------------- createfile( "/foo", 20257 ); checkfile( "foo" ); copyfile( "foo", "fee"); checkfile( "fee" ); comparefiles( "foo", "/fee" ); diag_printf("<INFO>: mkdir bar\n"); err = mkdir( "/bar", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); listdir( "/" , true, existingdirents+3, NULL ); copyfile( "fee", "/bar/fum" ); checkfile( "bar/fum" ); comparefiles( "/fee", "bar/fum" ); diag_printf("<INFO>: cd bar\n"); err = chdir( "bar" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/bar" ); diag_printf("<INFO>: rename /foo bundy\n"); err = rename( "/foo", "bundy" ); if( err < 0 ) SHOW_RESULT( rename, err ); listdir( "/", true, existingdirents+2, NULL ); listdir( "" , true, 4, NULL ); checkfile( "/bar/bundy" ); comparefiles("/fee", "bundy" ); #if defined(CYGSEM_FILEIO_BLOCK_USAGE) err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage)); if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err ); diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n", usage.total_blocks, usage.total_blocks * usage.block_size); diag_printf("<INFO>: free size: %6lld blocks, %10lld bytes\n", usage.free_blocks, usage.free_blocks * usage.block_size); diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size); #endif // -------------------------------------------------------------- diag_printf("<INFO>: unlink fee\n"); err = unlink( "/fee" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink fum\n"); err = unlink( "fum" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink /bar/bundy\n"); err = unlink( "/bar/bundy" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: cd /\n"); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); diag_printf("<INFO>: rmdir /bar\n"); err = rmdir( "/bar" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); listdir( "/", false, existingdirents, NULL ); // -------------------------------------------------------------- #if 0 diag_printf("<INFO>: mkdir disk2\n"); err = mkdir( "/disk2", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); #else diag_printf("<INFO>: mount /disk2\n"); err = mount( "/dev/disk0/2", "/disk2", "fatfs" ); if( err < 0 ) SHOW_RESULT( mount, err ); #endif listdir( "/disk2" , true, -1, &existingdirents); createfile( "/disk2/tinky", 4567 ); copyfile( "/disk2/tinky", "/disk2/laalaa" ); checkfile( "/disk2/tinky"); checkfile( "/disk2/laalaa"); comparefiles( "/disk2/tinky", "/disk2/laalaa" ); diag_printf("<INFO>: cd /disk2\n"); err = chdir( "/disk2" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2" ); diag_printf("<INFO>: mkdir noonoo\n"); err = mkdir( "noonoo", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); listdir( "/disk2" , true, existingdirents+3, NULL); diag_printf("<INFO>: cd noonoo\n"); err = chdir( "noonoo" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2/noonoo" ); createfile( "tinky", 6789 ); checkfile( "tinky" ); createfile( "dipsy", 34567 ); checkfile( "dipsy" ); copyfile( "dipsy", "po" ); checkfile( "po" ); comparefiles( "dipsy", "po" ); listdir( ".", true, 5, NULL ); listdir( "", true, 5, NULL ); listdir( "..", true, existingdirents+3, NULL ); // -------------------------------------------------------------- diag_printf("<INFO>: unlink tinky\n"); err = unlink( "tinky" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink dipsy\n"); err = unlink( "dipsy" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink po\n"); err = unlink( "po" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: cd ..\n"); err = chdir( ".." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2" ); diag_printf("<INFO>: rmdir noonoo\n"); err = rmdir( "noonoo" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); // -------------------------------------------------------------- err = mkdir( "x", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); err = mkdir( "x/y", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); err = mkdir( "x/y/z", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); err = mkdir( "x/y/z/w", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); diag_printf("<INFO>: cd /disk2/x/y/z/w\n"); err = chdir( "/disk2/x/y/z/w" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2/x/y/z/w" ); diag_printf("<INFO>: cd ..\n"); err = chdir( ".." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2/x/y/z" ); diag_printf("<INFO>: cd .\n"); err = chdir( "." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2/x/y/z" ); diag_printf("<INFO>: cd ../../y\n"); err = chdir( "../../y" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2/x/y" ); diag_printf("<INFO>: cd ../..\n"); err = chdir( "../.." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2" ); diag_printf("<INFO>: rmdir x/y/z/w\n"); err = rmdir( "x/y/z/w" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); diag_printf("<INFO>: rmdir x/y/z\n"); err = rmdir( "x/y/z" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); diag_printf("<INFO>: rmdir x/y\n"); err = rmdir( "x/y" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); diag_printf("<INFO>: rmdir x\n"); err = rmdir( "x" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); // -------------------------------------------------------------- checkcwd( "/disk2" ); diag_printf("<INFO>: unlink tinky\n"); err = unlink( "tinky" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink laalaa\n"); err = unlink( "laalaa" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: cd /\n"); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); listdir( "/disk2", true, -1, NULL ); #if 0 diag_printf("<INFO>: rmdir dir\n"); err = rmdir( "disk2" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); #else diag_printf("<INFO>: umount /disk2\n"); err = umount( "/disk2" ); if( err < 0 ) SHOW_RESULT( umount, err ); #endif #ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES // Create file diag_printf("<INFO>: create /foo\n"); createfile( "/foo", 20257 ); // Verify it is created with archive bit set checkattrib( "/foo", S_FATFS_ARCHIVE ); // Make it System diag_printf("<INFO>: attrib -A+S /foo\n"); err = cyg_fs_set_attrib( "/foo", S_FATFS_SYSTEM ); if( err < 0 ) SHOW_RESULT( chmod system , err ); // Verify it is now System checkattrib( "/foo", S_FATFS_SYSTEM ); // Make it Hidden diag_printf("<INFO>: attrib -S+H /foo\n"); err = cyg_fs_set_attrib( "/foo", S_FATFS_HIDDEN ); if( err < 0 ) SHOW_RESULT( chmod system , err ); // Verify it is now Hidden checkattrib( "/foo", S_FATFS_HIDDEN ); // Make it Read-only diag_printf("<INFO>: attrib -H+R /foo\n"); err = cyg_fs_set_attrib( "/foo", S_FATFS_RDONLY ); if( err < 0 ) SHOW_RESULT( chmod system , err ); // Verify it is now Read-only checkattrib( "/foo", S_FATFS_RDONLY ); // Verify we cannot unlink a read-only file diag_printf("<INFO>: unlink /foo\n"); err = unlink( "/foo" ); if( (err != -1) || (errno != EPERM) ) SHOW_RESULT( unlink, err ); // Verify we cannot rename a read-only file diag_printf("<INFO>: rename /foo bundy\n"); err = rename( "/foo", "bundy" ); if( (err != -1) || (errno != EPERM) ) SHOW_RESULT( rename, err ); // Verify we cannot open read-only file for writing int fd; diag_printf("<INFO>: create file /foo\n"); fd = open( "/foo", O_WRONLY ); if( (err != -1) || (errno != EACCES) ) SHOW_RESULT( open, err ); if( err > 0 ) close(fd); // Make it Normal diag_printf("<INFO>: attrib -H /foo\n"); err = cyg_fs_set_attrib( "/foo", 0 ); if( err < 0 ) SHOW_RESULT( chmod none , err ); // Verify it is now nothing checkattrib( "/foo", 0 ); // Now delete our test file diag_printf("<INFO>: unlink /foo\n"); err = unlink( "/foo" ); if( err < 0 ) SHOW_RESULT( unlink, err ); #endif // CYGCFG_FS_FAT_USE_ATTRIBUTES maxfile("file.max"); listdir( "/", true, -1, NULL ); diag_printf("<INFO>: unlink file.max\n"); err = unlink( "file.max" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: umount /\n"); err = umount( "/" ); if( err < 0 ) SHOW_RESULT( umount, err ); CYG_TEST_PASS_FINISH("fatfs1"); }
int main( int argc, char **argv ) { int err; char address[16]; #if defined(CYGSEM_FILEIO_BLOCK_USAGE) struct cyg_fs_block_usage usage; #endif CYG_TEST_INIT(); // -------------------------------------------------------------- diag_printf("<INFO>: ROMFS root follows\n"); listdir( "/", true ); diag_printf("<INFO>: cd /etc\n" ); err = chdir( "/etc" ); if ( err < 0 ) { SHOW_RESULT( chdir, err ); CYG_TEST_FAIL_FINISH("romfs1"); } diag_printf("<INFO>: ROMFS list of '' follows\n"); listdir( "", true ); diag_printf("<INFO>: ROMFS list of /etc follows\n"); listdir( "/etc", true ); diag_printf("<INFO>: ROMFS list of . follows\n"); listdir( ".", true ); #ifdef CYGPKG_FS_RAM err = mount( "", "/var", "ramfs" ); if( err < 0 ) SHOW_RESULT( mount, err ); copyfile( "/etc/passwd", "/var/passwd_copy" ); comparefiles( "/etc/passwd", "/var/passwd_copy" ); #endif diag_printf("<INFO>: ROMFS list of / follows\n"); #ifdef CYGPKG_FS_RAM diag_printf("<INFO>: Note that /var now gives stat() info for RAMFS\n"); #endif listdir( "/", true ); diag_printf("<INFO>: Mount ROMFS again onto /mnt\n"); sprintf( address, "%p", (void*)&filedata[0] ); err = mount( address, "/mnt", "romfs" ); if( err < 0 ) SHOW_RESULT( mount, err ); comparefiles( "/etc/passwd", "/mnt/etc/passwd" ); err = mkdir( "/foo", 0 ); CHKFAIL_TYPE( mkdir, err, EROFS ); err = rename( "/var", "/tmp" ); // RAMFS is mounted here #ifdef CYGPKG_FS_RAM CHKFAIL_TYPE( rename, err, EXDEV ); #else CHKFAIL_TYPE( rename, err, EROFS ); #endif err = rename( "/var/passwd_copy", "/mnt/etc/passwd_copy" ); CHKFAIL_TYPE( rename, err, EXDEV ); err = rename( "/etc", "/tmp" ); CHKFAIL_TYPE( rename, err, EROFS ); diag_printf("<INFO>: cd /etc\n"); err = chdir( "/etc" ); if( err < 0 ) SHOW_RESULT( chdir, err ); err = chdir( "/mnt/etc" ); if( err < 0 ) SHOW_RESULT( chdir, err ); listdir( ".", true ); diag_printf("<INFO>: unlink /tmp\n"); err = unlink( "/tmp" ); CHKFAIL_TYPE( unlink, err, EROFS ); diag_printf("<INFO>: mount random area\n"); sprintf(address, "%p", (void*)(&filedata[0] + 0x100)); err = mount( address, "/tmp", "romfs" ); CHKFAIL_TYPE( mount, err, ENOENT ); err = umount( "/mnt" ); if( err < 0 ) SHOW_RESULT( umount, err ); err = umount( "/var" ); #ifdef CYGPKG_FS_RAM if( err < 0 ) SHOW_RESULT( umount, err ); #else CHKFAIL_TYPE( umount, err, EINVAL ); #endif #if defined(CYGSEM_FILEIO_BLOCK_USAGE) err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage)); if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err ); diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n", usage.total_blocks, usage.total_blocks * usage.block_size); diag_printf("<INFO>: free size: %6lld blocks, %10lld bytes\n", usage.free_blocks, usage.free_blocks * usage.block_size); diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size); #endif // -------------------------------------------------------------- err = umount( "/" ); if( err < 0 ) SHOW_RESULT( umount, err ); CYG_TEST_PASS_FINISH("romfs1"); }
static void listdir( char *name, int statp, int numexpected, int *numgot ) { int err; DIR *dirp; int num=0; DBG("<INFO>: reading directory %s\n",name); dirp = opendir( name ); if( dirp == NULL ) SHOW_RESULT( opendir, -1 ); for(;;) { struct dirent *entry = readdir( dirp ); if( entry == NULL ) break; num++; DBG("<INFO>: entry %14s",entry->d_name); #ifdef CYGPKG_FS_FAT_RET_DIRENT_DTYPE DBG(" d_type %2x", entry->d_type); #endif if( statp ) { char fullname[PATH_MAX]; struct stat sbuf; if( name[0] ) { strcpy(fullname, name ); if( !(name[0] == '/' && name[1] == 0 ) ) strcat(fullname, "/" ); } else fullname[0] = 0; strcat(fullname, entry->d_name ); err = stat( fullname, &sbuf ); if( err < 0 ) { if( errno == ENOSYS ) DBG(" <no status available>"); else SHOW_RESULT( stat, err ); } else { DBG(" [mode %08x ino %08x nlink %d size %ld]", sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,(long)sbuf.st_size); } #ifdef CYGPKG_FS_FAT_RET_DIRENT_DTYPE if ((entry->d_type & S_IFMT) != (sbuf.st_mode & S_IFMT)) CYG_TEST_FAIL("File mode's don't match between dirent and stat"); #endif } DBG("\n"); } err = closedir( dirp ); if( err < 0 ) SHOW_RESULT( stat, err ); if (numexpected >= 0 && num != numexpected) CYG_TEST_FAIL("Wrong number of dir entries\n"); if ( numgot != NULL ) *numgot = num; }
int main( int argc, char **argv ) { int err; CYG_TEST_INIT(); // -------------------------------------------------------------- createfile( "/foo", 202 ); checkfile( "foo" ); copyfile( "foo", "fee"); checkfile( "fee" ); comparefiles( "foo", "/fee" ); err = mkdir( "/bar", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); listdir( "/" , false); copyfile( "fee", "/bar/fum" ); checkfile( "bar/fum" ); comparefiles( "/fee", "bar/fum" ); err = chdir( "bar" ); if( err < 0 ) SHOW_RESULT( chdir, err ); err = rename( "/foo", "bundy" ); if( err < 0 ) SHOW_RESULT( rename, err ); listdir( "/", true ); listdir( "" , true ); checkfile( "/bar/bundy" ); comparefiles("/fee", "bundy" ); testfs_dump(); // -------------------------------------------------------------- err = unlink( "/fee" ); if( err < 0 ) SHOW_RESULT( unlink, err ); err = unlink( "fum" ); if( err < 0 ) SHOW_RESULT( unlink, err ); err = unlink( "/bar/bundy" ); if( err < 0 ) SHOW_RESULT( unlink, err ); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); err = rmdir( "/bar" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); listdir( "/", false ); // -------------------------------------------------------------- err = mount( "", "/ram", "testfs" ); if( err < 0 ) SHOW_RESULT( mount, err ); createfile( "/ram/tinky", 456 ); copyfile( "/ram/tinky", "/ram/laalaa" ); checkfile( "/ram/tinky"); checkfile( "/ram/laalaa"); comparefiles( "/ram/tinky", "/ram/laalaa" ); err = chdir( "/ram" ); if( err < 0 ) SHOW_RESULT( chdir, err ); createfile( "tinky", 678 ); checkfile( "tinky" ); maxfile( "dipsy" ); checkfile( "dipsy" ); copyfile( "dipsy", "po" ); checkfile( "po" ); comparefiles( "dipsy", "po" ); testfs_dump(); // -------------------------------------------------------------- err = unlink( "tinky" ); if( err < 0 ) SHOW_RESULT( unlink, err ); err = unlink( "dipsy" ); if( err < 0 ) SHOW_RESULT( unlink, err ); err = unlink( "po" ); if( err < 0 ) SHOW_RESULT( unlink, err ); err = unlink( "laalaa" ); if( err < 0 ) SHOW_RESULT( unlink, err ); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); err = umount( "/ram" ); if( err < 0 ) SHOW_RESULT( umount, err ); CYG_TEST_PASS_FINISH("fileio1"); }
int main( int argc, char **argv ) { int err; FILE *stream; long pos; unsigned int i; char header[3]; CYG_TEST_INIT(); // -------------------------------------------------------------- CYG_TEST_INFO("mount /"); err = mount( "", "/", "ramfs" ); if( err < 0 ) SHOW_RESULT( mount, err ); CYG_TEST_INFO("creating /fseek"); stream = fopen("/fseek","w+"); if (!stream) { SHOW_RESULT( fopen, NULL); CYG_TEST_FAIL_FINISH("done"); \ } for (i = 0; i < sizeof(buf); i++) { buf[i] = i % 256; } CYG_TEST_INFO("writing test pattern"); err=fwrite(buf,sizeof(buf), 1, stream); if ( err < 0 ) SHOW_RESULT( fwrite, err ); pos = ftell(stream); if (pos < 0) SHOW_RESULT( ftell, pos ); if (pos != sizeof(buf)) diag_printf("<FAIL>: ftell is not telling the truth."); CYG_TEST_INFO("fseek()ing to 85"); err = fseek(stream, 85, SEEK_SET); if ( err < 0 ) SHOW_RESULT( fseek, err ); pos = ftell(stream); if (pos < 0) SHOW_RESULT( ftell, pos ); if (pos != 85) CYG_TEST_FAIL("ftell is not telling the truth"); err = fread(header,3,1,stream); if ( err < 0 ) SHOW_RESULT( fwrite, err ); if ((header[0] != 85) || (header[1] != 86) || (header[2] != 87)) CYG_TEST_FAIL("Read returned false data"); pos = ftell(stream); if (pos < 0) SHOW_RESULT( ftell, pos ); if (pos != 88) CYG_TEST_FAIL("ftell is not telling the truth"); for (i = 88; i < 161; i++) { buf[i] = 0x42; } CYG_TEST_INFO("writing"); err = fwrite(buf+88, 73, 1, stream); if ( err < 0 ) SHOW_RESULT( fwrite, err ); pos = ftell(stream); if (pos < 0) SHOW_RESULT( ftell, pos ); if (pos != 161) CYG_TEST_FAIL("ftell is not telling the truth"); CYG_TEST_INFO("closing file"); err = fclose(stream); if (err != 0) SHOW_RESULT( fclose, err ); CYG_TEST_INFO("open file /fseek"); stream = fopen("/fseek", "r+"); if (!stream) { SHOW_RESULT( fopen, NULL); CYG_TEST_FAIL_FINISH("done"); \ } CYG_TEST_INFO("Seeking to beginning of file"); err = fseek(stream, 0, SEEK_SET); if ( err < 0 ) SHOW_RESULT( fseek, err ); CYG_TEST_INFO("Reading buf1"); err = fread(buf1,sizeof(buf1),1, stream); if (err != 1) SHOW_RESULT( fread, err ); CYG_TEST_INFO("Comparing contents"); if (memcmp(buf, buf1, sizeof(buf1))) CYG_TEST_FAIL("File contents inconsistent"); CYG_TEST_INFO("closing file"); err = fclose(stream); if (err != 0) SHOW_RESULT( fclose, err ); CYG_TEST_INFO("umount /"); err = umount( "/" ); if( err < 0 ) SHOW_RESULT( umount, err ); CYG_TEST_PASS_FINISH("ramfs3"); }
void *pthread_entry1( void *arg) { #ifdef TEST_NET int fd = 0, fd2 = -1; struct sockaddr_in accsa; socklen_t accsa_len = sizeof(accsa); int netstate = 0; #endif #ifdef TEST_DEV int ser0; int serstate = 0; #endif #if defined(TEST_DEV) || defined(TEST_NET) int i; ssize_t done; #endif int netdone = 0; int serdone = 0; int err; fd_set rd, wr; CYG_TEST_INFO( "Thread 1 running" ); FD_ZERO( &rd ); FD_ZERO( &wr ); #ifdef TEST_DEV CYG_TEST_INFO( "Thread1: calling open()"); ser0 = open("/dev/ser0", O_RDWR ); if( ser0 < 0 ) SHOW_RESULT( open, ser0 ); CYG_TEST_CHECK( ser0 >= 0, "open(/dev/ser0) returned error"); FD_SET( ser0, &rd ); #else serdone = 1; #endif #ifdef TEST_NET for( i = 0; i < TEST_BUFSIZE; i++ ) buf1[i] = i; CYG_TEST_INFO( "Thread1: calling socket()"); fd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); if( fd < 0 ) SHOW_RESULT( socket, fd ); CYG_TEST_CHECK( fd >= 0, "socket() returned error"); CYG_TEST_INFO( "Thread1: calling bind()"); err = bind( fd, (struct sockaddr *)&sa, sizeof(sa)); if( err < 0 ) SHOW_RESULT( bind, err ); CYG_TEST_CHECK( err == 0, "bind() returned error"); CYG_TEST_INFO( "Thread1: calling listen()"); err = listen( fd, 3); if( err < 0 ) SHOW_RESULT( listen, err ); CYG_TEST_CHECK( err == 0, "listen() returned error"); FD_SET( fd, &rd ); #else netdone = 1; #endif while(!(netdone && serdone)) { fd_set rd_res = rd; fd_set wr_res = wr; CYG_TEST_INFO( "Thread1: calling select()"); show_fdsets( "Thread1 request: ", 8, &rd_res, &wr_res, NULL ); err = select( 8, &rd_res, &wr_res, NULL, NULL ); if( err < 0 ) SHOW_RESULT( select, err ); CYG_TEST_CHECK( err >= 0, "select() returned error"); show_fdsets( "Thread1 result: ", 8, &rd_res, &wr_res, NULL ); #ifdef TEST_NET switch( netstate ) { case 0: CYG_TEST_INFO( "Thread1: netstate 0"); if( FD_ISSET( fd, &rd_res ) ) { CYG_TEST_INFO( "Thread1: calling accept(fd)"); fd2 = accept( fd, (struct sockaddr *)&accsa, &accsa_len ); if( fd2 < 0 ) SHOW_RESULT( accept, fd2 ); CYG_TEST_CHECK( fd2 >= 0, "accept() returned error"); FD_CLR( fd, &rd ); FD_SET( fd2, &wr ); netstate++; } break; case 1: CYG_TEST_INFO( "Thread1: netstate 1"); if( FD_ISSET( fd2, &wr_res ) ) { CYG_TEST_INFO( "Thread1: calling write(fd2)"); done = write( fd2, buf1, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( write, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "write() returned bad size"); FD_CLR( fd2, &wr ); FD_SET( fd2, &rd ); netstate++; } break; case 2: CYG_TEST_INFO( "Thread1: netstate 2"); if( FD_ISSET( fd2, &rd_res ) ) { CYG_TEST_INFO( "Thread1: calling read(fd2)"); done = read( fd2, buf3, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( read, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "read() returned bad size"); for( i = 0; i < TEST_BUFSIZE; i++ ) if( buf1[i] != buf3[i] ) diag_printf("buf1[%d](%02x) != buf3[%d](%02x)\n",i,buf1[i],i,buf3[i]); FD_CLR( fd2, &rd ); netstate++; netdone = 1; CYG_TEST_INFO( "Thread1: netdone"); } break; } #endif #ifdef TEST_DEV switch( serstate ) { case 0: CYG_TEST_INFO( "Thread1: serstate 0"); if( FD_ISSET( ser0, &rd_res ) ) { CYG_TEST_INFO( "Thread1: calling read(ser0)"); done = read( ser0, sbuf2, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( read, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "read() returned bad size"); for( i = 0; i < TEST_BUFSIZE; i++ ) if( sbuf1[i] != sbuf2[i] ) diag_printf("buf1[%d](%02x) != buf2[%d](%02x)\n",i,sbuf1[i],i,sbuf2[i]); FD_CLR( ser0, &rd ); FD_SET( ser0, &wr ); serstate++; } break; case 1: CYG_TEST_INFO( "Thread1: serstate 1"); if( FD_ISSET( ser0, &wr_res ) ) { CYG_TEST_INFO( "Thread1: calling write(ser0)"); done = write( ser0, sbuf2, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( write, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "write() returned bad size"); FD_CLR( ser0, &wr ); serstate++; serdone = 1; CYG_TEST_INFO( "Thread1: serdone"); } else FD_SET( ser0, &wr ); break; } #endif } #ifdef TEST_NET CYG_TEST_INFO( "Thread1: calling close(fd)"); err = close(fd); if( err < 0 ) SHOW_RESULT( close, err ); CYG_TEST_CHECK( err == 0, "close() returned error"); if( fd2 >= 0 ) { CYG_TEST_INFO( "Thread1: calling close(fd2)"); err = close(fd2); if( err < 0 ) SHOW_RESULT( close, err ); CYG_TEST_CHECK( err == 0, "close() returned error"); } #endif #ifdef TEST_DEV CYG_TEST_INFO( "Thread1: calling close(ser0)"); err = close(ser0); if( err < 0 ) SHOW_RESULT( close, err ); CYG_TEST_CHECK( err == 0, "close() returned error"); #endif CYG_TEST_INFO( "Thread1: calling pthread_exit()"); pthread_exit( arg ); }