Message ID | 20210607080742.21377-1-xieziyao@huawei.com |
---|---|
State | Accepted |
Headers | show |
Series | syscalls/fchown: Make output nicer and add checks before SAFE_CLOSE(fd) | expand |
Xie Ziyao <xieziyao@huawei.com> wrote: > 1. Print values not variable names in TST_EXP_PASS(). > 2. Check if the fd has been opened in cleanup(). I helped tweak the format and pushed, thanks!
diff --git a/testcases/kernel/syscalls/fchown/fchown01.c b/testcases/kernel/syscalls/fchown/fchown01.c index 77913ce32..16e1f677b 100644 --- a/testcases/kernel/syscalls/fchown/fchown01.c +++ b/testcases/kernel/syscalls/fchown/fchown01.c @@ -28,7 +28,7 @@ static gid_t gid; static void run(void) { - TST_EXP_PASS(FCHOWN(fd, uid, gid)); + TST_EXP_PASS(FCHOWN(fd, uid, gid), "fchown(%i, %i, %i)", fd, uid, gid); } static void setup(void) diff --git a/testcases/kernel/syscalls/fchown/fchown02.c b/testcases/kernel/syscalls/fchown/fchown02.c index d541f0450..ec04b5c01 100644 --- a/testcases/kernel/syscalls/fchown/fchown02.c +++ b/testcases/kernel/syscalls/fchown/fchown02.c @@ -53,7 +53,7 @@ static void run(unsigned int i) SAFE_CHMOD(tc[i].filename, tc[i].set_mode); - TST_EXP_PASS(FCHOWN(*tc[i].fd, uid, gid)); + TST_EXP_PASS(FCHOWN(*tc[i].fd, uid, gid), "fchown(%i, %i, %i)", *tc[i].fd, uid, gid); SAFE_STAT(tc[i].filename, &stat_buf); @@ -78,8 +78,10 @@ static void cleanup(void) { unsigned int i; - for (i = 0; i < ARRAY_SIZE(tc); i++) - SAFE_CLOSE(*tc[i].fd); + for (i = 0; i < ARRAY_SIZE(tc); i++) { + if (*tc[i].fd > 0) + SAFE_CLOSE(*tc[i].fd); + } } static struct tst_test test = { diff --git a/testcases/kernel/syscalls/fchown/fchown03.c b/testcases/kernel/syscalls/fchown/fchown03.c index 752d9c394..97d6c9d34 100644 --- a/testcases/kernel/syscalls/fchown/fchown03.c +++ b/testcases/kernel/syscalls/fchown/fchown03.c @@ -85,7 +85,9 @@ static void cleanup(void) { SAFE_SETEGID(0); SAFE_SETEUID(0); - SAFE_CLOSE(fd); + + if (fd > 0) + SAFE_CLOSE(fd); } static struct tst_test test = {
1. Print values not variable names in TST_EXP_PASS(). 2. Check if the fd has been opened in cleanup(). Signed-off-by: Xie Ziyao <xieziyao@huawei.com> --- testcases/kernel/syscalls/fchown/fchown01.c | 2 +- testcases/kernel/syscalls/fchown/fchown02.c | 8 +++++--- testcases/kernel/syscalls/fchown/fchown03.c | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) -- 2.17.1