diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-08-01 21:54:19 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-08-01 21:54:19 +0000 |
commit | a7c39d3d3fb4a529b29d432b81769617093965d8 (patch) | |
tree | d63d59fe676604f9095b3b742a1759c28d220f68 /testsuites/fstests/fstime | |
parent | 2011-08-01 Xiang Cui <medivhc@gmail.com> (diff) | |
download | rtems-a7c39d3d3fb4a529b29d432b81769617093965d8.tar.bz2 |
2011-08-01 Xiang Cui <medivhc@gmail.com>
* imfs_fslink/Makefile.am, imfs_fssymlink/Makefile.am,
mimfs_fslink/Makefile.am, mimfs_fssymlink/Makefile.am,
mrfs_fslink/Makefile.am, mrfs_fssymlink/Makefile.am,
mrfs_support/fs_config.h: Correcting from previous commit of
incorrect tarball.
* fserror/fserror.doc, fserror/test.c, fspatheval/patheval.doc,
fspatheval/test.c, fspermission/fspermission.doc,
fspermission/test.c, fsrdwr/fsrdwr.doc, fsrdwr/init.c,
fstime/fstime.doc, fstime/test.c, imfs_fserror/.cvsignore,
imfs_fserror/Makefile.am, imfs_fslink/.cvsignore,
imfs_fspatheval/.cvsignore, imfs_fspatheval/Makefile.am,
imfs_fspermission/.cvsignore, imfs_fspermission/Makefile.am,
imfs_fsrdwr/.cvsignore, imfs_fsrdwr/Makefile.am,
imfs_fssymlink/.cvsignore, imfs_fstime/.cvsignore,
imfs_fstime/Makefile.am, imfs_support/fs_supprot.h,
mdosfs_fserror/.cvsignore, mdosfs_fserror/Makefile.am,
mdosfs_fspatheval/.cvsignore, mdosfs_fspatheval/Makefile.am,
mdosfs_fsrdwr/.cvsignore, mdosfs_fsrdwr/Makefile.am,
mdosfs_fstime/.cvsignore, mdosfs_fstime/Makefile.am,
mimfs_fserror/.cvsignore, mimfs_fserror/Makefile.am,
mimfs_fslink/.cvsignore, mimfs_fspatheval/.cvsignore,
mimfs_fspatheval/Makefile.am, mimfs_fspermission/.cvsignore,
mimfs_fspermission/Makefile.am, mimfs_fsrdwr/.cvsignore,
mimfs_fsrdwr/Makefile.am, mimfs_fssymlink/.cvsignore,
mimfs_fstime/.cvsignore, mimfs_fstime/Makefile.am,
mrfs_fserror/.cvsignore, mrfs_fserror/Makefile.am,
mrfs_fslink/.cvsignore, mrfs_fspatheval/.cvsignore,
mrfs_fspatheval/Makefile.am, mrfs_fspermission/.cvsignore,
mrfs_fspermission/Makefile.am, mrfs_fsrdwr/.cvsignore,
mrfs_fsrdwr/Makefile.am, mrfs_fssymlink/.cvsignore,
mrfs_fstime/.cvsignore, mrfs_fstime/Makefile.am: New files.
Diffstat (limited to 'testsuites/fstests/fstime')
-rw-r--r-- | testsuites/fstests/fstime/fstime.doc | 28 | ||||
-rw-r--r-- | testsuites/fstests/fstime/test.c | 264 |
2 files changed, 292 insertions, 0 deletions
diff --git a/testsuites/fstests/fstime/fstime.doc b/testsuites/fstests/fstime/fstime.doc new file mode 100644 index 0000000000..b7b5ea05c9 --- /dev/null +++ b/testsuites/fstests/fstime/fstime.doc @@ -0,0 +1,28 @@ +# +# $Id$ +# +# COPYRIGHT (c) 1989-2009. +# On-Line Applications Research Corporation (OAR). +# +# The license and distribution terms for this file may be +# found in the file LICENSE in this distribution or at +# http://www.rtems.com/license/LICENSE. +# + +This file describes the directives and concepts tested by this test set. + +test set name: fstime + +directives: + ++ open ++ write ++ read ++ utime + + + +concepts: + ++ Check if the these directives update the time attribute + diff --git a/testsuites/fstests/fstime/test.c b/testsuites/fstests/fstime/test.c new file mode 100644 index 0000000000..a0e30d94a7 --- /dev/null +++ b/testsuites/fstests/fstime/test.c @@ -0,0 +1,264 @@ + +/* + * COPYRIGHT (c) 1989-2011. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id Exp $ + */ + +#include <sys/stat.h> +#include <limits.h> +#include <fcntl.h> +#include <errno.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <utime.h> +#include "fstest.h" + +void time_test01 (void) +{ + struct stat statbuf; + struct utimbuf timbuf; + int status = 0; + int fd; + time_t ctime1, mtime1; + time_t ctime2, mtime2; + char *readbuf; + char *databuf = "TEST"; + char *file01 = "test01"; + char *file02 = "test02"; + char *dir01 = "dir01"; + + int n; + int len = strlen (databuf); + + const char *wd = __func__; + mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; + /* + * Create a new directory and change to this + */ + status = mkdir (wd, mode); + rtems_test_assert (status == 0); + status = chdir (wd); + rtems_test_assert (status == 0); + + /* + * Create two files + */ + fd = open (file01, O_CREAT | O_WRONLY, mode); + n = write (fd, databuf, len); + rtems_test_assert (n == len); + status = close (fd); + rtems_test_assert (status == 0); + + fd = open (file02, O_CREAT | O_WRONLY, mode); + n = write (fd, databuf, len); + rtems_test_assert (n == len); + status = close (fd); + rtems_test_assert (status == 0); + /* + * If O_CREAT is set and the file did not previously exist, upon + * successful completion, open() shall mark for update the st_atime, + * st_ctime, and st_mtime fields of the file and the st_ctime and + * st_mtime fields of the parent directory. + */ + status = stat (file01, &statbuf); + rtems_test_assert (status == 0); + ctime1 = statbuf.st_ctime; + mtime1 = statbuf.st_mtime; + + status = stat (".", &statbuf); + rtems_test_assert (status == 0); + ctime2 = statbuf.st_ctime; + mtime2 = statbuf.st_mtime; + + /* + * Make sure they are the same + */ + + rtems_test_assert (TIME_EQUAL (ctime1, mtime1)); + rtems_test_assert (TIME_EQUAL (ctime1, mtime2)); + rtems_test_assert (TIME_EQUAL (ctime1, ctime2)); + + status = stat (file02, &statbuf); + rtems_test_assert (status == 0); + ctime1 = statbuf.st_ctime; + mtime1 = statbuf.st_mtime; + + status = stat (".", &statbuf); + rtems_test_assert (status == 0); + ctime2 = statbuf.st_ctime; + mtime2 = statbuf.st_mtime; + + /* + * Make sure they are the same + */ + rtems_test_assert (TIME_EQUAL (ctime1, mtime1)); + rtems_test_assert (TIME_EQUAL (ctime1, mtime2)); + rtems_test_assert (TIME_EQUAL (ctime1, ctime2)); + + /* + * Sleep a few seconds + */ + puts ("Sleep a few seconds"); + + sleep (TIME_PRECISION); + + /* + * Create an empty directory + */ + status = mkdir (dir01, mode); + rtems_test_assert (status == 0); + /* + * truncate file01 to len, so it does not changes the file size + */ + status = truncate (file01, len); + rtems_test_assert (status == 0); + + /* + *truncate file02 to len+1, it changes the file size + */ + status = truncate (file02, len + 1); + rtems_test_assert (status == 0); + + /* + * + * truncate shall not modify the file offset for any open file + * descriptions associated with the file. Upon successful completion, + * if the file size is changed, this function shall mark for update + * the st_ctime and st_mtime fields of the file + */ + + /* + * file01 shall not update + */ + status = stat (file01, &statbuf); + rtems_test_assert (status == 0); + ctime2 = statbuf.st_ctime; + mtime2 = statbuf.st_mtime; + + rtems_test_assert (TIME_EQUAL (ctime1, mtime2)); + rtems_test_assert (TIME_EQUAL (ctime1, ctime2)); + + /* + * file02 shall update + */ + status = stat (file02, &statbuf); + rtems_test_assert (status == 0); + ctime2 = statbuf.st_ctime; + mtime2 = statbuf.st_mtime; + + rtems_test_assert (TIME_EQUAL (ctime2, mtime2)); + rtems_test_assert (!TIME_EQUAL (ctime1, mtime2)); + rtems_test_assert (!TIME_EQUAL (ctime1, ctime2)); + + /* + * Upon successful completion, mkdir() shall mark for update the + * 5st_atime, st_ctime, and st_mtime fields of the directory. + * Also, the st_ctime and st_mtime fields of the directory that + * contains the new entry shall be marked for update. + */ + status = stat (dir01, &statbuf); + rtems_test_assert (status == 0); + ctime2 = statbuf.st_ctime; + mtime2 = statbuf.st_mtime; + rtems_test_assert (TIME_EQUAL (ctime2, mtime2)); + rtems_test_assert (!TIME_EQUAL (ctime1, mtime2)); + rtems_test_assert (!TIME_EQUAL (ctime1, ctime2)); + + status = stat (".", &statbuf); + rtems_test_assert (status == 0); + ctime2 = statbuf.st_ctime; + mtime2 = statbuf.st_mtime; + + rtems_test_assert (!TIME_EQUAL (ctime1, ctime2)); + rtems_test_assert (!TIME_EQUAL (ctime1, mtime2)); + + /* + * Upon successful completion, where nbyte is greater than 0, + * write() shall mark for update the st_ctime and st_mtime fields of the file + */ + + /* + * read file01, and this should not uptate st_mtime and st_ctime + */ + readbuf = (char *) malloc (len + 1); + fd = open (file01, O_RDONLY); + rtems_test_assert (fd != -1); + n = read (fd, readbuf, len); + rtems_test_assert (n == len); + status = fstat (fd, &statbuf); + + ctime2 = statbuf.st_ctime; + mtime2 = statbuf.st_mtime; + + rtems_test_assert (TIME_EQUAL (ctime1, ctime2)); + rtems_test_assert (TIME_EQUAL (ctime1, mtime2)); + + status = close (fd); + rtems_test_assert (status == 0); + /* + * write file01, and this should uptate st_mtime st_ctime + */ + readbuf = (char *) malloc (len + 1); + fd = open (file01, O_WRONLY); + rtems_test_assert (fd != -1); + n = write (fd, databuf, len); + rtems_test_assert (n == len); + status = fstat (fd, &statbuf); + + ctime2 = statbuf.st_ctime; + mtime2 = statbuf.st_mtime; + + rtems_test_assert (!TIME_EQUAL (ctime1, ctime2)); + rtems_test_assert (!TIME_EQUAL (ctime1, mtime2)); + status = close (fd); + rtems_test_assert (status == 0); + + /* + * The utime() function shall set the access and modification times + * of the file named by the path argument. + */ + timbuf.actime = ctime1; + timbuf.modtime = mtime1; + + status = utime (file01, &timbuf); + rtems_test_assert (status == 0); + + status = stat (file01, &statbuf); + ctime2 = statbuf.st_atime; + mtime2 = statbuf.st_mtime; + + rtems_test_assert (TIME_EQUAL (ctime1, ctime2)); + rtems_test_assert (TIME_EQUAL (ctime1, mtime2)); + + status = utime (dir01, &timbuf); + rtems_test_assert (status == 0); + + status = stat (dir01, &statbuf); + ctime2 = statbuf.st_atime; + mtime2 = statbuf.st_mtime; + + rtems_test_assert (TIME_EQUAL (ctime1, ctime2)); + rtems_test_assert (TIME_EQUAL (ctime1, mtime2)); + +} + +/* + * These tests only get time_t value, and test + * if they are changed. Thest tests don't check atime + */ +void test (void) +{ + + puts( "\n\n*** TIME TEST ***" ); + time_test01(); + puts( "*** END OF TIME TEST ***" ); +} |