-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This test has been extracted from symlink01 test and it verifies that utime() is working correctly on symlink() generated files. Link: https://lore.kernel.org/ltp/[email protected]/ Reviewed-by: Avinesh Kumar <[email protected]> Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Andrea Cervesato <[email protected]> [ pvorel: extend doc ] Signed-off-by: Petr Vorel <[email protected]>
- Loading branch information
Showing
4 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
/utime04 | ||
/utime05 | ||
/utime06 | ||
/utime07 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. | ||
* Authors: David Fenner, Jon Hendrickson | ||
* Copyright (C) 2024 Andrea Cervesato <[email protected]> | ||
*/ | ||
|
||
/*\ | ||
* [Description] | ||
* | ||
* This test verifies that utime() is working correctly on symlink() | ||
* generated files. | ||
* | ||
* Also verify if utime() fails with: | ||
* | ||
* - ENOENT when symlink points to nowhere | ||
* - ELOOP when symlink is looping | ||
*/ | ||
|
||
#include <utime.h> | ||
#include "tst_test.h" | ||
|
||
#define TIME_DIFF 100 | ||
|
||
static void create_symlink(const char *path, const char *symname) | ||
{ | ||
struct stat asymlink; | ||
|
||
SAFE_SYMLINK(path, symname); | ||
SAFE_LSTAT(symname, &asymlink); | ||
|
||
if ((asymlink.st_mode & S_IFMT) != S_IFLNK) { | ||
tst_brk(TBROK, "symlink generated a non-symbolic link %s to %s", | ||
symname, path); | ||
} | ||
} | ||
|
||
static void test_utime(void) | ||
{ | ||
char *symname = "my_symlink0"; | ||
struct stat oldsym_stat; | ||
struct stat newsym_stat; | ||
|
||
tst_res(TINFO, "Test if utime() changes access time"); | ||
|
||
create_symlink(tst_get_tmpdir(), symname); | ||
SAFE_STAT(symname, &oldsym_stat); | ||
|
||
struct utimbuf utimes = { | ||
.actime = oldsym_stat.st_atime + TIME_DIFF, | ||
.modtime = oldsym_stat.st_mtime + TIME_DIFF | ||
}; | ||
|
||
TST_EXP_PASS(utime(symname, &utimes)); | ||
SAFE_STAT(symname, &newsym_stat); | ||
|
||
TST_EXP_EQ_LI(newsym_stat.st_atime - oldsym_stat.st_atime, TIME_DIFF); | ||
TST_EXP_EQ_LI(newsym_stat.st_mtime - oldsym_stat.st_mtime, TIME_DIFF); | ||
|
||
SAFE_UNLINK(symname); | ||
} | ||
|
||
static void test_utime_no_path(void) | ||
{ | ||
char *symname = "my_symlink1"; | ||
struct utimbuf utimes; | ||
|
||
tst_res(TINFO, "Test if utime() raises ENOENT when symlink points to nowhere"); | ||
|
||
create_symlink("bc+eFhi!k", symname); | ||
TST_EXP_FAIL(utime(symname, &utimes), ENOENT); | ||
|
||
SAFE_UNLINK(symname); | ||
} | ||
|
||
static void test_utime_loop(void) | ||
{ | ||
char *symname = "my_symlink2"; | ||
struct utimbuf utimes; | ||
|
||
tst_res(TINFO, "Test if utime() raises ELOOP when symlink is looping"); | ||
|
||
create_symlink(symname, symname); | ||
TST_EXP_FAIL(utime(symname, &utimes), ELOOP); | ||
|
||
SAFE_UNLINK(symname); | ||
} | ||
|
||
static void run(void) | ||
{ | ||
test_utime(); | ||
test_utime_no_path(); | ||
test_utime_loop(); | ||
} | ||
|
||
static struct tst_test test = { | ||
.test_all = run, | ||
.needs_tmpdir = 1, | ||
}; |