All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] syscalls/ustat: convert to new lib, use direct syscall
@ 2019-02-02  0:17 Steve Muckle
  2019-02-04 12:55 ` Petr Vorel
  2019-02-07 10:18 ` [LTP] [PATCH] ustat: Fix EFAULT in 32bit compatability mode Richard Palethorpe
  0 siblings, 2 replies; 7+ messages in thread
From: Steve Muckle @ 2019-02-02  0:17 UTC (permalink / raw)
  To: ltp

Use direct syscall to expand test compatibility to Android.

Change-Id: I7c88e18990509458ca6066a09685d1d09b24907a
Signed-off-by: Steve Muckle <smuckle@google.com>
---
 include/lapi/ustat.h                      | 19 +++++
 testcases/kernel/syscalls/ustat/ustat01.c | 84 +++++----------------
 testcases/kernel/syscalls/ustat/ustat02.c | 92 +++++------------------
 3 files changed, 56 insertions(+), 139 deletions(-)
 create mode 100644 include/lapi/ustat.h

diff --git a/include/lapi/ustat.h b/include/lapi/ustat.h
new file mode 100644
index 000000000..b32749925
--- /dev/null
+++ b/include/lapi/ustat.h
@@ -0,0 +1,19 @@
+//SPDX-License-Identifier: GPL-2.0-or-later
+
+#ifndef LAPI_USTAT_H
+#define LAPI_USTAT_H
+
+#include <sys/types.h>
+
+#ifdef HAVE_SYS_USTAT_H
+# include <sys/ustat.h>
+#else
+struct ustat {
+	daddr_t f_tfree;
+	ino_t f_tinode;
+	char f_fname[6];
+	char f_fpack[6];
+};
+#endif
+
+#endif /* LAPI_USTAT_H */
diff --git a/testcases/kernel/syscalls/ustat/ustat01.c b/testcases/kernel/syscalls/ustat/ustat01.c
index 31d7f86dc..3f1186c49 100644
--- a/testcases/kernel/syscalls/ustat/ustat01.c
+++ b/testcases/kernel/syscalls/ustat/ustat01.c
@@ -1,21 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) Wipro Technologies Ltd, 2003.  All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-/*
  * Check that ustat() succeeds given correct parameters.
  */
 
@@ -24,71 +10,35 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include "config.h"
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "ustat01";
-
-#ifdef HAVE_USTAT
-# ifdef HAVE_SYS_USTAT_H
-#  include <sys/ustat.h>
-# endif
-
-static void setup(void);
-
-int TST_TOTAL = 1;
+#include "lapi/syscalls.h"
+#include "lapi/ustat.h"
+#include "tst_test.h"
 
 static dev_t dev_num;
-static struct ustat ubuf;
 
-int main(int argc, char *argv[])
+void run(void)
 {
-	int lc, i;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
+	struct ustat ubuf;
 
-	setup();
+	TEST(tst_syscall(__NR_ustat, dev_num, &ubuf));
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(ustat(dev_num, &ubuf));
-
-			if (TEST_RETURN == -1 && TEST_ERRNO == ENOSYS)
-				tst_brkm(TCONF, NULL, "ustat not supported");
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL, "ustat(2) failed and set"
-					 "the errno to %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TPASS, "ustat(2) passed");
-			}
-		}
-	}
-
-	tst_exit();
+	if (TST_RET == -1)
+		tst_res(TFAIL | TTERRNO, "ustat(2) failed");
+	else
+		tst_res(TPASS, "ustat(2) passed");
 }
 
 static void setup(void)
 {
 	struct stat buf;
 
-	tst_sig(NOFORK, DEF_HANDLER, NULL);
-
-	TEST_PAUSE;
-
 	/* Find a valid device number */
-	SAFE_STAT(NULL, "/", &buf);
+	SAFE_STAT("/", &buf);
 
 	dev_num = buf.st_dev;
 }
-#else
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "system doesn't have ustat() support");
-}
-#endif
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+};
diff --git a/testcases/kernel/syscalls/ustat/ustat02.c b/testcases/kernel/syscalls/ustat/ustat02.c
index fe644f9a9..9bbe4f3f5 100644
--- a/testcases/kernel/syscalls/ustat/ustat02.c
+++ b/testcases/kernel/syscalls/ustat/ustat02.c
@@ -1,21 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-/*
  * Test whether ustat(2) system call returns appropriate error number for
  * invalid dev_t parameter and for bad address paramater.
  */
@@ -25,18 +11,9 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include "config.h"
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "ustat02";
-
-#ifdef HAVE_USTAT
-# ifdef HAVE_SYS_USTAT_H
-#  include <sys/ustat.h>
-# endif
-
-static void setup(void);
+#include "lapi/syscalls.h"
+#include "lapi/ustat.h"
+#include "tst_test.h"
 
 static dev_t invalid_dev = -1;
 static dev_t root_dev;
@@ -57,59 +34,30 @@ static struct test_case_t {
 
 int TST_TOTAL = ARRAY_SIZE(tc);
 
-int main(int ac, char **av)
+void run(unsigned int test)
 {
-
-	int lc, i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(ustat(*tc[i].dev, tc[i].buf));
-
-			if (TEST_RETURN == -1 && TEST_ERRNO == ENOSYS)
-				tst_brkm(TCONF, NULL, "ustat not supported");
-
-			if ((TEST_RETURN == -1)
-			    && (TEST_ERRNO == tc[i].exp_errno)) {
-				tst_resm(TPASS,
-					 "ustat(2) expected failure;"
-					 " Got errno - %s : %s",
-					 tc[i].exp_errval, tc[i].err_desc);
-			} else {
-				tst_resm(TFAIL | TTERRNO,
-				         "ustat(2) failed to produce"
-					 " expected error; %d, errno"
-					 ": %s",
-					 tc[i].exp_errno, tc[i].exp_errval);
-			}
-		}
-	}
-
-	tst_exit();
+	TEST(tst_syscall(__NR_ustat, *tc[test].dev, tc[test].buf));
+
+	if ((TST_RET == -1) && (TST_ERR == tc[test].exp_errno))
+		tst_res(TPASS | TTERRNO, "ustat(2) expected failure");
+	else
+		tst_res(TFAIL | TTERRNO,
+			"ustat(2) failed to produce expected error; %d, errno"
+			": %s", tc[test].exp_errno, tc[test].exp_errval);
 }
 
 static void setup(void)
 {
 	struct stat buf;
 
-	tst_sig(NOFORK, DEF_HANDLER, NULL);
-
-	TEST_PAUSE;
-
 	/* Find a valid device number */
-	SAFE_STAT(NULL, "/", &buf);
+	SAFE_STAT("/", &buf);
 
 	root_dev = buf.st_dev;
 }
-#else
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "system doesn't have ustat() support");
-}
-#endif
+
+static struct tst_test test = {
+	.test = run,
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tc),
+};
-- 
2.20.1.611.gfbb209baf1-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2] syscalls/ustat: convert to new lib, use direct syscall
  2019-02-02  0:17 [LTP] [PATCH v2] syscalls/ustat: convert to new lib, use direct syscall Steve Muckle
@ 2019-02-04 12:55 ` Petr Vorel
  2019-02-07 10:18 ` [LTP] [PATCH] ustat: Fix EFAULT in 32bit compatability mode Richard Palethorpe
  1 sibling, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2019-02-04 12:55 UTC (permalink / raw)
  To: ltp

Hi Steve,

> Use direct syscall to expand test compatibility to Android.

thanks for your patch, merged.

> Change-Id: I7c88e18990509458ca6066a09685d1d09b24907a
I'm sorry, I removed your gerrit's Change-Id from commit message.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH] ustat: Fix EFAULT in 32bit compatability mode
  2019-02-02  0:17 [LTP] [PATCH v2] syscalls/ustat: convert to new lib, use direct syscall Steve Muckle
  2019-02-04 12:55 ` Petr Vorel
@ 2019-02-07 10:18 ` Richard Palethorpe
  2019-02-07 12:16   ` Jan Stancek
  2019-02-07 12:52   ` Petr Vorel
  1 sibling, 2 replies; 7+ messages in thread
From: Richard Palethorpe @ 2019-02-07 10:18 UTC (permalink / raw)
  To: ltp

This test fails with -m32 on Intel because the user land dev_num is too
large.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---

From looking at glibc, this test may also be broken on mips, but I am not sure
if that matters. AFAICT on all other platforms glibc always casts to uint
after performing a sanity check..

 testcases/kernel/syscalls/ustat/ustat01.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/ustat/ustat01.c b/testcases/kernel/syscalls/ustat/ustat01.c
index 3f1186c49..2e7dcc9d7 100644
--- a/testcases/kernel/syscalls/ustat/ustat01.c
+++ b/testcases/kernel/syscalls/ustat/ustat01.c
@@ -20,7 +20,7 @@ void run(void)
 {
 	struct ustat ubuf;
 
-	TEST(tst_syscall(__NR_ustat, dev_num, &ubuf));
+	TEST(tst_syscall(__NR_ustat, (unsigned int)dev_num, &ubuf));
 
 	if (TST_RET == -1)
 		tst_res(TFAIL | TTERRNO, "ustat(2) failed");
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH] ustat: Fix EFAULT in 32bit compatability mode
  2019-02-07 10:18 ` [LTP] [PATCH] ustat: Fix EFAULT in 32bit compatability mode Richard Palethorpe
@ 2019-02-07 12:16   ` Jan Stancek
  2019-02-07 13:07     ` Petr Vorel
  2019-02-07 12:52   ` Petr Vorel
  1 sibling, 1 reply; 7+ messages in thread
From: Jan Stancek @ 2019-02-07 12:16 UTC (permalink / raw)
  To: ltp



----- Original Message -----
> This test fails with -m32 on Intel because the user land dev_num is too
> large.
> 
> Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
> ---
> 
> From looking at glibc, this test may also be broken on mips, but I am not
> sure
> if that matters. AFAICT on all other platforms glibc always casts to uint
> after performing a sanity check..

LGTM, LTP is using only 0 (and -1 for errno tests), so it shouldn't matter.

What about ustat02? Are you planning on sending something similar for that test?

Regards,
Jan

> 
>  testcases/kernel/syscalls/ustat/ustat01.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/testcases/kernel/syscalls/ustat/ustat01.c
> b/testcases/kernel/syscalls/ustat/ustat01.c
> index 3f1186c49..2e7dcc9d7 100644
> --- a/testcases/kernel/syscalls/ustat/ustat01.c
> +++ b/testcases/kernel/syscalls/ustat/ustat01.c
> @@ -20,7 +20,7 @@ void run(void)
>  {
>  	struct ustat ubuf;
>  
> -	TEST(tst_syscall(__NR_ustat, dev_num, &ubuf));
> +	TEST(tst_syscall(__NR_ustat, (unsigned int)dev_num, &ubuf));
>  
>  	if (TST_RET == -1)
>  		tst_res(TFAIL | TTERRNO, "ustat(2) failed");
> --
> 2.20.1
> 
> 
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH] ustat: Fix EFAULT in 32bit compatability mode
  2019-02-07 10:18 ` [LTP] [PATCH] ustat: Fix EFAULT in 32bit compatability mode Richard Palethorpe
  2019-02-07 12:16   ` Jan Stancek
@ 2019-02-07 12:52   ` Petr Vorel
  1 sibling, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2019-02-07 12:52 UTC (permalink / raw)
  To: ltp

Hi Richard,

> This test fails with -m32 on Intel because the user land dev_num is too
> large.

Thanks for the fix, merged.


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH] ustat: Fix EFAULT in 32bit compatability mode
  2019-02-07 12:16   ` Jan Stancek
@ 2019-02-07 13:07     ` Petr Vorel
  2019-02-07 14:38       ` Richard Palethorpe
  0 siblings, 1 reply; 7+ messages in thread
From: Petr Vorel @ 2019-02-07 13:07 UTC (permalink / raw)
  To: ltp

Hi Jan,

> > From looking at glibc, this test may also be broken on mips, but I am not
> > sure
> > if that matters. AFAICT on all other platforms glibc always casts to uint
> > after performing a sanity check..

> LGTM, LTP is using only 0 (and -1 for errno tests), so it shouldn't matter.
I'm sorry I missed your mail, so pushed without your ack.

> What about ustat02? Are you planning on sending something similar for that test?
It's not needed for ustat02. Is it because *tc[test].dev in ustat02 is pointer?

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH] ustat: Fix EFAULT in 32bit compatability mode
  2019-02-07 13:07     ` Petr Vorel
@ 2019-02-07 14:38       ` Richard Palethorpe
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Palethorpe @ 2019-02-07 14:38 UTC (permalink / raw)
  To: ltp

Hello,

Petr Vorel <pvorel@suse.cz> writes:

> Hi Jan,
>
>> > From looking at glibc, this test may also be broken on mips, but I am not
>> > sure
>> > if that matters. AFAICT on all other platforms glibc always casts to uint
>> > after performing a sanity check..
>
>> LGTM, LTP is using only 0 (and -1 for errno tests), so it shouldn't matter.
> I'm sorry I missed your mail, so pushed without your ack.
>
>> What about ustat02? Are you planning on sending something similar for that test?
> It's not needed for ustat02. Is it because *tc[test].dev in ustat02 is
> pointer?

I don't think so, but AFAICT ustat02 is still valid because passing the
wrong data type still has the desired effect of creating an invalid
buffer pointer in the bad address test. On the invalid parameter test,
only the first 32bits of dev are checked before EINVAL is thrown, so
again, it doesn't matter.

So I won't send another patch, but I am not against adding the cast
either.

>
> Kind regards,
> Petr


--
Thank you,
Richard.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-02-07 14:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-02  0:17 [LTP] [PATCH v2] syscalls/ustat: convert to new lib, use direct syscall Steve Muckle
2019-02-04 12:55 ` Petr Vorel
2019-02-07 10:18 ` [LTP] [PATCH] ustat: Fix EFAULT in 32bit compatability mode Richard Palethorpe
2019-02-07 12:16   ` Jan Stancek
2019-02-07 13:07     ` Petr Vorel
2019-02-07 14:38       ` Richard Palethorpe
2019-02-07 12:52   ` Petr Vorel

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.