fstat_02: Increase test coverage by creating hard links to file and validate using fstat
PATCH 1/1 fstat_02: Increase test coverage by creating hard links to file and validate using fstat
This patch creates a hard link for a file during setup and checks if number of hardlinks match with the expected number.
This is discussed here: https://github.com/linux-test-project/ltp/issues/517#issuecomment-533035589
Implements: #517
--- testcases/kernel/syscalls/fstat/fstat02.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
testcases/kernel/syscalls/fstat/fstat02.c +10 -0
@@ -17,8 +17,10 @@#include "tst_safe_macros.h" #define TESTFILE "test_file" +#define LINK_TESTFILE "link_test_file"#define FILE_SIZE 1024#define FILE_MODE 0644 +#define NLINK 2static struct stat stat_buf;static uid_t user_id;
@@ -61,6 +63,12 @@ static void run(void) fail++; } +if (stat_buf.st_nlink !=NLINK ) { +tst_res (TFAIL ,"stat_buf.st_nlink = %lu expected %o" , + (stat_buf.st_nlink),NLINK ); + fail++; + } +if (fail)return ;
@@ -78,6 +86,8 @@ static void setup(void)if (tst_fill_file (TESTFILE ,'a' ,FILE_SIZE ,1 ))tst_brk (TBROK ,"Could not fill Testfile!" ); + +SAFE_LINK (TESTFILE ,LINK_TESTFILE ); }static void cleanup (void )
Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 9 lines
#define TESTFILE "
test_file"testcases/kernel/syscalls/fstat/fstat02.c +2
-0+#define LINK_TESTFILE "link_test_file"#define FILE_SIZE 1024#define FILE_MODE 0644 +#define NLINK 2static struct stat stat_buf;static uid_t user_id;
testcases/kernel/syscalls/fstat/fstat02.c static void run(void) · line 67
Quoted 5 lines
testcases/kernel/syscalls/fstat/fstat02.c +2
-0@@ -61,6 +63,12 @@ static void run(void) fail++; } +if (stat_buf.st_nlink !=NLINK ) { + tst_res(TFAIL, "stat_buf.st_nlink = %lu expected %o",
^ Why %o?
testcases/kernel/syscalls/fstat/fstat02.c static void run(void) · line 68
Quoted 1 line
testcases/kernel/syscalls/fstat/fstat02.c +1
-0+ (stat_buf.st_nlink), NLINK);
^
this should be casted properly
Quoted 21 lines
testcases/kernel/syscalls/fstat/fstat02.c +5
-0+ fail++; + } +if (fail)return ;@@ -78,6 +86,8 @@ static void setup(void)if (tst_fill_file (TESTFILE ,'a' ,FILE_SIZE ,1 ))tst_brk (TBROK ,"Could not fill Testfile!" ); + +SAFE_LINK (TESTFILE ,LINK_TESTFILE ); }static void cleanup (void )Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp