diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-08-02 14:24:59 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-08-02 14:24:59 +0000 |
commit | 6fed43eabc0e78606cf80439c536a00be18fd743 (patch) | |
tree | f74fea0e1e6b46a7acea595ad70131a6b25f34df /testsuites/fstests/fsrdwr | |
parent | 2011-08-02 Ricardo Aguirre <el.mastin@ymail.com> (diff) | |
download | rtems-6fed43eabc0e78606cf80439c536a00be18fd743.tar.bz2 |
2011-08-02 Xiang Cui <medivhc@gmail.com>
* configure.ac, fserror/test.c, fslink/test.c, fspermission/test.c,
fsrdwr/init.c, fssymlink/test.c, fstime/test.c,
mdosfs_support/fs_config.h, mdosfs_support/fs_support.c,
mimfs_support/fs_support.c, mrfs_support/fs_config.h,
support/fstest.h, support/fstest_support.c,
support/ramdisk_support.c, support/ramdisk_support.h: Perform first
phase of clean up.
Diffstat (limited to 'testsuites/fstests/fsrdwr')
-rw-r--r-- | testsuites/fstests/fsrdwr/init.c | 437 |
1 files changed, 221 insertions, 216 deletions
diff --git a/testsuites/fstests/fsrdwr/init.c b/testsuites/fstests/fsrdwr/init.c index 6565eb9415..7464277e2f 100644 --- a/testsuites/fstests/fsrdwr/init.c +++ b/testsuites/fstests/fsrdwr/init.c @@ -21,12 +21,13 @@ #include "fstest.h" const char *databuf = - "Happy days are here again. Happy days are here again.1Happy " - "days are here again.2Happy days are here again.3Happy days are here again." - "4Happy days are here again.5Happy days are here again.6Happy days are here " - "again.7Happy days are here again."; + "Happy days are here again. Happy days are here again.1Happy " + "days are here again.2Happy days are here again.3Happy days are here again." + "4Happy days are here again.5Happy days are here again.6Happy days are here " + "again.7Happy days are here again."; -void read_write_test (void) +void +read_write_test (void) { int fd; @@ -42,15 +43,15 @@ void read_write_test (void) mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; - const char* wd=__func__; + const char *wd = __func__; /* * Create a new directory and change the current directory to this */ - status=mkdir(wd,mode); - rtems_test_assert(status==0); - status=chdir(wd); - rtems_test_assert(status==0); + status = mkdir (wd, mode); + rtems_test_assert (status == 0); + status = chdir (wd); + rtems_test_assert (status == 0); /* * Create an empty file */ @@ -142,7 +143,7 @@ void read_write_test (void) rtems_test_assert (status == 0); /* - * Open the file using O_TRUNC + * Open the file using O_TRUNC */ fd = open (name01, O_WRONLY | O_TRUNC); @@ -173,347 +174,351 @@ void read_write_test (void) /* * Go back to parent directory */ - status=chdir(".."); - rtems_test_assert(status==0); + status = chdir (".."); + rtems_test_assert (status == 0); } -void truncate_test03(void ) +void +truncate_test03 (void) { - int fd; - int status; - char *name01="name01"; + int fd; + int status; + char *name01 = "name01"; struct stat statbuf; - char data; - int n; - int i; + char data; + int n; + int i; - size_t len = strlen(databuf); + size_t len = strlen (databuf); char *readbuf; - off_t good_size=100; - mode_t mode = S_IRWXU|S_IRWXG|S_IRWXO; + off_t good_size = 100; + mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; - const char* wd=__func__; + const char *wd = __func__; /* * Create a new directory and change the current directory to this */ - status=mkdir(wd,mode); - rtems_test_assert(status==0); - status=chdir(wd); - rtems_test_assert(status==0); + status = mkdir (wd, mode); + rtems_test_assert (status == 0); + status = chdir (wd); + rtems_test_assert (status == 0); /* * Create an empty file */ - fd=creat(name01,mode); - status=close(fd); - rtems_test_assert(status==0); + fd = creat (name01, mode); + status = close (fd); + rtems_test_assert (status == 0); /* * Truncate it to a valid size */ - status=truncate(name01,good_size); - rtems_test_assert(status==0); + status = truncate (name01, good_size); + rtems_test_assert (status == 0); /* * Verify the size and the data */ - status=stat(name01,&statbuf); - rtems_test_assert(status==0); - rtems_test_assert(good_size==statbuf.st_size); + status = stat (name01, &statbuf); + rtems_test_assert (status == 0); + rtems_test_assert (good_size == statbuf.st_size); - fd=open(name01,O_RDONLY); - while ((n=read(fd,&data,1))>0) { - rtems_test_assert(data==0); + fd = open (name01, O_RDONLY); + while ((n = read (fd, &data, 1)) > 0) { + rtems_test_assert (data == 0); } - status=close(fd); - rtems_test_assert(status==0); + status = close (fd); + rtems_test_assert (status == 0); /* * Fill a file with data */ - fd=open(name01,O_WRONLY); - rtems_test_assert(fd!=-1); - n=write(fd,databuf,len); - rtems_test_assert(n==len); + fd = open (name01, O_WRONLY); + rtems_test_assert (fd != -1); + n = write (fd, databuf, len); + rtems_test_assert (n == len); /* - * Truncate it to the half size + * Truncate it to the half size */ - status=truncate(name01,len/2); - status=truncate(name01,len); + status = truncate (name01, len / 2); + status = truncate (name01, len); /* * verify the data */ - readbuf = (char *)malloc(len/2); - rtems_test_assert( readbuf ); - fd=open(name01,O_RDONLY); - rtems_test_assert(fd!=-1); - n=read(fd,readbuf,len/2); - rtems_test_assert(n==len/2); - rtems_test_assert(!strncmp(databuf,readbuf,len/2)); - n=read(fd,readbuf,len/2); - rtems_test_assert(n==len/2); - for (i=0;i<len/2;i++){ - rtems_test_assert(readbuf[i]==0); + readbuf = (char *) malloc (len / 2); + rtems_test_assert (readbuf); + fd = open (name01, O_RDONLY); + rtems_test_assert (fd != -1); + n = read (fd, readbuf, len / 2); + rtems_test_assert (n == len / 2); + rtems_test_assert (!strncmp (databuf, readbuf, len / 2)); + n = read (fd, readbuf, len / 2); + rtems_test_assert (n == len / 2); + for (i = 0; i < len / 2; i++) { + rtems_test_assert (readbuf[i] == 0); } - status=close(fd); - rtems_test_assert( status==0 ); + status = close (fd); + rtems_test_assert (status == 0); /* * Go back to parent directory */ - status=chdir(".."); - rtems_test_assert(status==0); + status = chdir (".."); + rtems_test_assert (status == 0); } -void lseek_test(void) +void +lseek_test (void) { - int fd; - int status; - char *name01="test_name01"; + int fd; + int status; + char *name01 = "test_name01"; struct stat statbuf; - int n; - int i; + int n; + int i; - size_t len = strlen(databuf); + size_t len = strlen (databuf); off_t pos; - int total_written=0; + int total_written = 0; char *readbuf; - mode_t mode = S_IRWXU|S_IRWXG|S_IRWXO; + mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; - const char* wd=__func__; + const char *wd = __func__; /* * Create a new directory and change the current directory to this */ - status=mkdir(wd,mode); - rtems_test_assert(status==0); - status=chdir(wd); - rtems_test_assert(status==0); + status = mkdir (wd, mode); + rtems_test_assert (status == 0); + status = chdir (wd); + rtems_test_assert (status == 0); /* * Create a file and fill with the data. */ - puts("Create a new file"); - fd=creat(name01,mode); - rtems_test_assert(fd!=-1); + puts ("Create a new file"); + fd = creat (name01, mode); + rtems_test_assert (fd != -1); + + pos = lseek (fd, 0, SEEK_CUR); + rtems_test_assert (pos == 0); - pos=lseek(fd,0,SEEK_CUR); - rtems_test_assert(pos==0); + pos = lseek (fd, 0, SEEK_END); + rtems_test_assert (pos == 0); - pos=lseek(fd,0,SEEK_END); - rtems_test_assert(pos==0); - - pos=lseek(fd,0,SEEK_SET); - rtems_test_assert(pos==0); - + pos = lseek (fd, 0, SEEK_SET); + rtems_test_assert (pos == 0); - printf( "Writing %d bytes to file\n", len * 10 ); - for (i=0; i<10; i++) { - n = write(fd, databuf, len); - rtems_test_assert( n != -1 ); + + printf ("Writing %d bytes to file\n", len * 10); + for (i = 0; i < 10; i++) { + n = write (fd, databuf, len); + rtems_test_assert (n != -1); total_written += n; } - printf("Successfully wrote %d\n", total_written); + printf ("Successfully wrote %d\n", total_written); /* * Check the current position */ - puts("Check the current position"); - pos=lseek(fd,0,SEEK_CUR); - rtems_test_assert(pos==total_written); + puts ("Check the current position"); + pos = lseek (fd, 0, SEEK_CUR); + rtems_test_assert (pos == total_written); - pos=lseek(fd,0,SEEK_END); - rtems_test_assert(pos==total_written); + pos = lseek (fd, 0, SEEK_END); + rtems_test_assert (pos == total_written); /* * ftruncate shall not change the posistion */ - status=ftruncate(fd,total_written+1); - rtems_test_assert(status==0); + status = ftruncate (fd, total_written + 1); + rtems_test_assert (status == 0); - pos=lseek(fd,0,SEEK_CUR); - rtems_test_assert(pos==total_written); + pos = lseek (fd, 0, SEEK_CUR); + rtems_test_assert (pos == total_written); - pos=lseek(fd,0,SEEK_END); - printf("%jd\n",(intmax_t)pos); - rtems_test_assert(pos==total_written+1); + pos = lseek (fd, 0, SEEK_END); + printf ("%jd\n", (intmax_t) pos); + rtems_test_assert (pos == total_written + 1); - status=ftruncate(fd,total_written); - rtems_test_assert(status==0); - - pos=lseek(fd,0,SEEK_CUR); - rtems_test_assert(pos==total_written+1); + status = ftruncate (fd, total_written); + rtems_test_assert (status == 0); + pos = lseek (fd, 0, SEEK_CUR); + rtems_test_assert (pos == total_written + 1); - status=close(fd); - rtems_test_assert(status==0); + + status = close (fd); + rtems_test_assert (status == 0); /* * Check the file size */ - status=stat(name01,&statbuf); - rtems_test_assert(statbuf.st_size==total_written); + status = stat (name01, &statbuf); + rtems_test_assert (statbuf.st_size == total_written); /* * Open the file with O_RDONLY and check the lseek */ - readbuf=(char*)malloc(len); - fd=open(name01,O_RDONLY); - pos=lseek(fd,len,SEEK_CUR); - rtems_test_assert(pos==len); - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - rtems_test_assert(!strncmp(databuf,readbuf,len)); - - pos=lseek(fd,len,SEEK_CUR); - rtems_test_assert(pos==3*len); - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - rtems_test_assert(!strncmp(databuf,readbuf,len)); - - pos=lseek(fd,-len,SEEK_CUR); - rtems_test_assert(pos==3*len); - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - rtems_test_assert(!strncmp(databuf,readbuf,len)); - - pos=lseek(fd,4*len,SEEK_SET); - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - rtems_test_assert(!strncmp(databuf,readbuf,len)); - - - pos=lseek(fd,10,SEEK_SET); - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - rtems_test_assert(strncmp(databuf,readbuf,len)!=0); - - pos=lseek(fd,-len,SEEK_END); - n=read(fd,readbuf,2*len); - rtems_test_assert(n==len); - rtems_test_assert(!strncmp(databuf,readbuf,len)); - - status=close(fd); - rtems_test_assert(status==0); + readbuf = (char *) malloc (len); + fd = open (name01, O_RDONLY); + pos = lseek (fd, len, SEEK_CUR); + rtems_test_assert (pos == len); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + rtems_test_assert (!strncmp (databuf, readbuf, len)); + + pos = lseek (fd, len, SEEK_CUR); + rtems_test_assert (pos == 3 * len); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + rtems_test_assert (!strncmp (databuf, readbuf, len)); + + pos = lseek (fd, -len, SEEK_CUR); + rtems_test_assert (pos == 3 * len); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + rtems_test_assert (!strncmp (databuf, readbuf, len)); + + pos = lseek (fd, 4 * len, SEEK_SET); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + rtems_test_assert (!strncmp (databuf, readbuf, len)); + + + pos = lseek (fd, 10, SEEK_SET); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + rtems_test_assert (strncmp (databuf, readbuf, len) != 0); + + pos = lseek (fd, -len, SEEK_END); + n = read (fd, readbuf, 2 * len); + rtems_test_assert (n == len); + rtems_test_assert (!strncmp (databuf, readbuf, len)); + + status = close (fd); + rtems_test_assert (status == 0); /* * Open the file withe O_RDWR and check the lseek */ - fd=open(name01,O_RDWR); + fd = open (name01, O_RDWR); - pos=lseek(fd,len,SEEK_CUR); - rtems_test_assert(pos==len); - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - rtems_test_assert(!strncmp(databuf,readbuf,len)); + pos = lseek (fd, len, SEEK_CUR); + rtems_test_assert (pos == len); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + rtems_test_assert (!strncmp (databuf, readbuf, len)); - pos=lseek(fd,len,SEEK_CUR); - rtems_test_assert(pos==3*len); - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - rtems_test_assert(!strncmp(databuf,readbuf,len)); + pos = lseek (fd, len, SEEK_CUR); + rtems_test_assert (pos == 3 * len); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + rtems_test_assert (!strncmp (databuf, readbuf, len)); - pos=lseek(fd,-len,SEEK_CUR); - rtems_test_assert(pos==3*len); - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - rtems_test_assert(!strncmp(databuf,readbuf,len)); + pos = lseek (fd, -len, SEEK_CUR); + rtems_test_assert (pos == 3 * len); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + rtems_test_assert (!strncmp (databuf, readbuf, len)); - pos=lseek(fd,4*len,SEEK_SET); - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - rtems_test_assert(!strncmp(databuf,readbuf,len)); + pos = lseek (fd, 4 * len, SEEK_SET); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + rtems_test_assert (!strncmp (databuf, readbuf, len)); /* - * Go to the wrong position, so the data is not the same + * Go to the wrong position, so the data is not the same */ - pos=lseek(fd,10,SEEK_SET); - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - rtems_test_assert(strncmp(databuf,readbuf,len)!=0); + pos = lseek (fd, 10, SEEK_SET); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + rtems_test_assert (strncmp (databuf, readbuf, len) != 0); /* - * Use SEEK_END + * Use SEEK_END */ - pos=lseek(fd,-len,SEEK_END); - n=read(fd,readbuf,2*len); - rtems_test_assert(n==len); - rtems_test_assert(!strncmp(databuf,readbuf,len)); + pos = lseek (fd, -len, SEEK_END); + n = read (fd, readbuf, 2 * len); + rtems_test_assert (n == len); + rtems_test_assert (!strncmp (databuf, readbuf, len)); - memset(readbuf,0,len); + memset (readbuf, 0, len); /* * Write the zero to the end of file. */ - pos=lseek(fd,-len,SEEK_END); - rtems_test_assert(pos==total_written-len); - n=write(fd,readbuf,len); - rtems_test_assert(n==len); + pos = lseek (fd, -len, SEEK_END); + rtems_test_assert (pos == total_written - len); + n = write (fd, readbuf, len); + rtems_test_assert (n == len); /* - * Verify it + * Verify it */ - pos=lseek(fd,total_written-len,SEEK_SET); - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - for (i=0;i<n;i++){ - rtems_test_assert(readbuf[i]==0); + pos = lseek (fd, total_written - len, SEEK_SET); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + for (i = 0; i < n; i++) { + rtems_test_assert (readbuf[i] == 0); } /* * Write the zero to the beginning of file. */ - pos=lseek(fd,-total_written,SEEK_END); - rtems_test_assert(pos==0); - n=write(fd,readbuf,len); - rtems_test_assert(n==len); + pos = lseek (fd, -total_written, SEEK_END); + rtems_test_assert (pos == 0); + n = write (fd, readbuf, len); + rtems_test_assert (n == len); /* * Verify it */ - pos=lseek(fd,0,SEEK_SET); - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - for (i=0;i<n;i++){ - rtems_test_assert(readbuf[i]==0); + pos = lseek (fd, 0, SEEK_SET); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + for (i = 0; i < n; i++) { + rtems_test_assert (readbuf[i] == 0); } - n=read(fd,readbuf,len); - rtems_test_assert(n==len); - rtems_test_assert(strncmp(databuf,readbuf,len)==0); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + rtems_test_assert (strncmp (databuf, readbuf, len) == 0); /* * Call ftruncate to decrease the file and the position not change */ - status=ftruncate(fd,len); - rtems_test_assert(status==0); - pos=lseek(fd,0,SEEK_CUR); - rtems_test_assert(pos==len*2); + status = ftruncate (fd, len); + rtems_test_assert (status == 0); + pos = lseek (fd, 0, SEEK_CUR); + rtems_test_assert (pos == len * 2); - status=close(fd); - rtems_test_assert(status==0); + status = close (fd); + rtems_test_assert (status == 0); /* * Go back to parent directory */ - status=chdir(".."); - rtems_test_assert(status==0); + status = chdir (".."); + rtems_test_assert (status == 0); } -void test(void ) + +void +test (void) { - read_write_test(); - lseek_test(); + read_write_test (); + lseek_test (); } |