]> git.proxmox.com Git - mirror_zfs.git/blobdiff - tests/zfs-tests/cmd/ctime.c
Linux 6.7 compat: zfs_setattr fix atime update
[mirror_zfs.git] / tests / zfs-tests / cmd / ctime.c
index cb2be72eedb9a1fb74e208e385d28bfaf920a948..5ff1cea8a869842c300144814fd18d9d59743084 100644 (file)
@@ -6,7 +6,7 @@
  * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
  * See the License for the specific language governing permissions
  * and limitations under the License.
  *
@@ -51,7 +51,7 @@
 
 typedef struct timetest {
        int     type;
-       char    *name;
+       const char      *name;
        int     (*func)(const char *pfile);
 } timetest_t;
 
@@ -260,7 +260,7 @@ static int
 do_xattr(const char *pfile)
 {
        int ret = 0;
-       char *value = "user.value";
+       const char *value = "user.value";
 
        if (pfile == NULL) {
                return (-1);
@@ -306,7 +306,7 @@ int
 main(void)
 {
        int i, ret, fd;
-       char *penv[] = {"TESTDIR", "TESTFILE0"};
+       const char *penv[] = {"TESTDIR", "TESTFILE0"};
 
        (void) atexit(cleanup);
 
@@ -327,7 +327,6 @@ main(void)
        if (access(tfile, F_OK) == 0) {
                (void) unlink(tfile);
        }
-       ret = 0;
        if ((fd = open(tfile, O_WRONLY | O_CREAT | O_TRUNC, ALL_MODE)) == -1) {
                (void) fprintf(stderr, "open(%s) failed: %d\n", tfile, errno);
                return (1);
@@ -363,12 +362,20 @@ main(void)
                        return (1);
                }
 
-               if (t1 == t2) {
-                       (void) fprintf(stderr, "%s: t1(%ld) == t2(%ld)\n",
+
+               /*
+                * Ideally, time change would be exactly two seconds, but allow
+                * a little slack in case of scheduling delays or similar.
+                */
+               long delta = (long)t2 - (long)t1;
+               if (delta < 2 || delta > 4) {
+                       (void) fprintf(stderr,
+                           "%s: BAD time change: t1(%ld), t2(%ld)\n",
                            timetest_table[i].name, (long)t1, (long)t2);
                        return (1);
                } else {
-                       (void) fprintf(stderr, "%s: t1(%ld) != t2(%ld)\n",
+                       (void) fprintf(stderr,
+                           "%s: good time change: t1(%ld), t2(%ld)\n",
                            timetest_table[i].name, (long)t1, (long)t2);
                }
        }