diff options
author | Chris Johns <chrisj@rtems.org> | 2013-08-08 08:09:51 +1000 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2013-08-08 08:11:57 +1000 |
commit | 2f9cef8819b5f07a36d7a29e3f928a89db38a817 (patch) | |
tree | 977f0ce9e81f5cc71998414e3c471c81acd180be /testsuites/fstests | |
parent | posix: Use _Objects_Put() for POSIX keys (diff) | |
download | rtems-2f9cef8819b5f07a36d7a29e3f928a89db38a817.tar.bz2 |
Check times with a no change truncate via open.
The open path should update the times even if the truncate does not
change the size.
Diffstat (limited to 'testsuites/fstests')
-rw-r--r-- | testsuites/fstests/fstime/test.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/testsuites/fstests/fstime/test.c b/testsuites/fstests/fstime/test.c index fb39d51d9c..df44a83d1b 100644 --- a/testsuites/fstests/fstime/test.c +++ b/testsuites/fstests/fstime/test.c @@ -37,6 +37,7 @@ static void time_test01 (void) char *databuf = "TEST"; char *file01 = "test01"; char *file02 = "test02"; + char *file03 = "test03"; char *dir01 = "dir01"; int n; @@ -53,7 +54,7 @@ static void time_test01 (void) rtems_test_assert (status == 0); /* - * Create two files + * Create the test files */ fd = open (file01, O_CREAT | O_WRONLY, mode); n = write (fd, databuf, len); @@ -66,6 +67,12 @@ static void time_test01 (void) rtems_test_assert (n == len); status = close (fd); rtems_test_assert (status == 0); + + /* A simple C version of touch */ + fd = open (file03, O_CREAT | O_WRONLY, mode); + 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, @@ -90,6 +97,7 @@ static void time_test01 (void) 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; @@ -119,6 +127,7 @@ static void time_test01 (void) */ status = mkdir (dir01, mode); rtems_test_assert (status == 0); + /* * truncate file01 to len, so it does not changes the file size */ @@ -132,11 +141,20 @@ static void time_test01 (void) rtems_test_assert (status == 0); /* + * Truncate an empty file which does not change the length. + */ + fd = open (file03, O_TRUNC | O_WRONLY, mode); + status = close (fd); + 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 + * + * open with O_TRUNC must update the file fields. */ /* @@ -163,6 +181,18 @@ static void time_test01 (void) rtems_test_assert (!TIME_EQUAL (ctime1, ctime2)); /* + * file03 shall update + */ + status = stat (file03, &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 |