All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xie Ziyao <xieziyao@huawei.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] syscalls/chown: format output and add testcases for chown05
Date: Wed, 9 Jun 2021 17:49:23 +0800	[thread overview]
Message-ID: <20210609094924.145262-2-xieziyao@huawei.com> (raw)
In-Reply-To: <20210609094924.145262-1-xieziyao@huawei.com>

1. Print values not variable names in TST_EXP_PASS().
2. Add testcases that -1 does not change the value after the chown
call.

Signed-off-by: Xie Ziyao <xieziyao@huawei.com>
---
 testcases/kernel/syscalls/chown/chown05.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/chown/chown05.c b/testcases/kernel/syscalls/chown/chown05.c
index ebb9e9b7c..44abdc750 100644
--- a/testcases/kernel/syscalls/chown/chown05.c
+++ b/testcases/kernel/syscalls/chown/chown05.c
@@ -2,6 +2,7 @@
 /*
  * Copyright (c) International Business Machines  Corp., 2001
  * 07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */

 /*\
@@ -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


  reply	other threads:[~2021-06-09  9:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-09  9:49 [LTP] [PATCH 0/2] syscalls/chown: Format output and add testcases for chown05 Xie Ziyao
2021-06-09  9:49 ` Xie Ziyao [this message]
2021-06-09  9:49 ` [LTP] [PATCH 2/2] syscalls/chown: format output and delete duplicate header files Xie Ziyao
2021-06-09 20:45 ` [LTP] [PATCH 0/2] syscalls/chown: Format output and add testcases for chown05 Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210609094924.145262-2-xieziyao@huawei.com \
    --to=xieziyao@huawei.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.