syscalls/chown: Format output and add testcases for chown05
cover syscalls/chown: Format output and add testcases for chown05
1. Format output and add testcases for chown05.
2. Delete duplicate header files.
Xie Ziyao (2):
syscalls/chown: format output and add testcases for chown05 syscalls/chown: format output and delete duplicate header files
testcases/kernel/syscalls/chown/chown01.c | 8 +------- testcases/kernel/syscalls/chown/chown02.c | 9 +++------ testcases/kernel/syscalls/chown/chown03.c | 9 --------- testcases/kernel/syscalls/chown/chown04.c | 20 +++++++++++--------- testcases/kernel/syscalls/chown/chown05.c | 22 +++++++++++++++------- 5 files changed, 30 insertions(+), 38 deletions(-)
--
2.17.1
PATCH 1/2 syscalls/chown: format output and add testcases for chown05
1. Print values not variable names in TST_EXP_PASS().
2. Add testcases that -1 does not change the value after the chown call.
--- testcases/kernel/syscalls/chown/chown05.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/chown/chown05.c +15 -7
@@ -2,6 +2,7 @@/* * Copyright (c) International Business Machines Corp., 2001 * 07/2001 Ported by Wayne Boyer +* Copyright (c) 2021 Xie Ziyao <[email protected]> */ /*\
@@ -20,24 +21,31 @@#define TESTFILE "testfile"struct test_case_t { +char *desc;uid_t uid;gid_t gid; } tc[] = { - {700 ,701 }, - {702 ,701 }, - {702 ,703 }, - {704 ,705 } + {"change owner/group ids" ,700 ,701 }, + {"change owner id only" ,702 ,-1 }, + {"change owner id only" ,703 ,701 }, + {"change group id only" ,-1 ,704 }, + {"change group id only" ,703 ,705 }, + {"no change" ,-1 ,-1 } };static void run (unsigned int i) {struct stat stat_buf; -TST_EXP_PASS (CHOWN (TESTFILE , tc[i].uid, tc[i].gid)); +uid_t expect_uid = tc[i].uid == (uid_t)-1 ? tc[i -1 ].uid : tc[i].uid; +gid_t expect_gid = tc[i].gid == (uid_t)-1 ? tc[i -1 ].gid : tc[i].gid; + +TST_EXP_PASS (CHOWN (TESTFILE , tc[i].uid, tc[i].gid),"chown(%s, %d, %d), %s" , +TESTFILE , tc[i].uid, tc[i].gid, tc[i].desc);SAFE_STAT (TESTFILE , &stat_buf); -if (stat_buf.st_uid != tc[i].uid || stat_buf.st_gid != tc[i].gid) { +if (stat_buf.st_uid != expect_uid || stat_buf.st_gid != expect_gid) {tst_res (TFAIL ,"%s: incorrect ownership set, expected %d %d" , -TESTFILE , tc[i].uid, tc[i].gid); +TESTFILE , expect_uid, expect_gid); } }
--
2.17.1
PATCH 2/2 syscalls/chown: format output and delete duplicate header files
In reply to Xie Ziyao1. Print values not variable names in the TST_EXP_PASS().
2. Delete duplicate header files.
--- testcases/kernel/syscalls/chown/chown01.c | 8 +------- testcases/kernel/syscalls/chown/chown02.c | 9 +++------ testcases/kernel/syscalls/chown/chown03.c | 9 --------- testcases/kernel/syscalls/chown/chown04.c | 20 +++++++++++--------- 4 files changed, 15 insertions(+), 31 deletions(-)
testcases/kernel/syscalls/chown/chown01.c +1 -7
@@ -3,6 +3,7 @@* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. * AUTHOR: William Roske * CO-PILOT: Dave Fenner +* Copyright (c) 2021 Xie Ziyao <[email protected]> */ /*\
@@ -11,13 +12,6 @@* Basic test for chown(). Calls chown() on a file and expects it to pass. */ -#include <stdio.h> -#include <sys/types.h> -#include <fcntl.h> -#include <errno.h> -#include <string.h> -#include <signal.h> -#include "tst_test.h" #include "compat_tst_16.h"
testcases/kernel/syscalls/chown/chown02.c +3 -6
@@ -2,6 +2,7 @@/* * Copyright (c) International Business Machines Corp., 2001 * 07/2001 Ported by Wayne Boyer +* Copyright (c) 2021 Xie Ziyao <[email protected]> */ /*\
@@ -12,11 +13,6 @@* - preserves setgid bit set on a non-group-executable file */ -#include <stdio.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include "tst_test.h" #include "compat_tst_16.h" #include "tst_safe_macros.h"
@@ -46,7 +42,8 @@ static void run(unsigned int i)SAFE_CHMOD (tc[i].filename, tc[i].set_mode); -TST_EXP_PASS (CHOWN (tc[i].filename, uid, gid)); +TST_EXP_PASS (CHOWN (tc[i].filename, uid, gid),"chown(%s, %d, %d)" , + tc[i].filename, uid, gid);struct stat stat_buf;SAFE_STAT (tc[i].filename, &stat_buf);
testcases/kernel/syscalls/chown/chown03.c +0 -9
@@ -17,15 +17,6 @@* Also verify that chown() clears the setuid/setgid bits set on the file. */ -#include <stdio.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include <string.h> -#include <signal.h> -#include <grp.h> #include <pwd.h> #include "tst_test.h"
testcases/kernel/syscalls/chown/chown04.c +11 -9
@@ -54,15 +54,16 @@ static char long_path[PATH_MAX + 2] = {[0 ... PATH_MAX + 1] = 'a'};static struct test_case_t {char *pathname;int exp_errno; +char *desc; } tc[] = { - {TEST_FILE1 ,EPERM }, - {TEST_FILE2 ,EACCES }, - {(char *)-1 ,EFAULT }, - {long_path,ENAMETOOLONG }, - {"" ,ENOENT }, - {TEST_FILE3 ,ENOTDIR }, - {TEST_FILE4 ,ELOOP }, - {TEST_FILE5 ,EROFS } + {TEST_FILE1 ,EPERM ,"without permissions" }, + {TEST_FILE2 ,EACCES ,"without full permissions of the path prefix" }, + {(char *)-1 ,EFAULT ,"with unaccessible pathname points" }, + {long_path,ENAMETOOLONG ,"when pathname is too long" }, + {"" ,ENOENT ,"when file does not exist" }, + {TEST_FILE3 ,ENOTDIR ,"when the path prefix is not a directory" }, + {TEST_FILE4 ,ELOOP ,"with too many symbolic links" }, + {TEST_FILE5 ,EROFS ,"when the named file resides on a read-only filesystem" } };static void run (unsigned int i)
@@ -73,7 +74,8 @@ static void run(unsigned int i)UID16_CHECK ((uid =geteuid ()),"chown" );GID16_CHECK ((gid =getegid ()),"chown" ); -TST_EXP_FAIL (CHOWN (tc[i].pathname, uid, gid), tc[i].exp_errno); +TST_EXP_FAIL (CHOWN (tc[i].pathname, uid, gid), tc[i].exp_errno, +"chown() %s" , tc[i].desc); }static void setup (void )
--
2.17.1
cover syscalls/chown: Format output and add testcases for chown05
In reply to Xie ZiyaoHi Ziyao,
Quoted 6 lines
1. Format output and add testcases for chown05.
2. Delete duplicate header files.Xie Ziyao (2):
syscalls/chown: format output and add testcases for chown05 syscalls/chown: format output and delete duplicate header files
Thanks a lot, merged!
Kind regards,
Petr