All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [COMMITTED] [PATCH 1/4] getrandom01: Convert to the new library.
@ 2017-02-08 15:08 Cyril Hrubis
  2017-02-08 15:08 ` [LTP] [COMMITTED] [PATCH 2/4] getrandom02: " Cyril Hrubis
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Cyril Hrubis @ 2017-02-08 15:08 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/getrandom/getrandom01.c | 40 +++++++++--------------
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/testcases/kernel/syscalls/getrandom/getrandom01.c b/testcases/kernel/syscalls/getrandom/getrandom01.c
index 103748a..7c7ed94 100644
--- a/testcases/kernel/syscalls/getrandom/getrandom01.c
+++ b/testcases/kernel/syscalls/getrandom/getrandom01.c
@@ -28,33 +28,25 @@
 
 #include "lapi/getrandom.h"
 #include "linux_syscall_numbers.h"
-#include "test.h"
+#include "tst_test.h"
 
-char *TCID = "getrandom01";
-static int modes[] = { 0, GRND_RANDOM, GRND_NONBLOCK,
-		       GRND_RANDOM | GRND_NONBLOCK };
+static int modes[] = {0, GRND_RANDOM, GRND_NONBLOCK,
+		      GRND_RANDOM | GRND_NONBLOCK};
 
-int TST_TOTAL = ARRAY_SIZE(modes);
-
-int main(int ac, char **av)
+static void verify_getrandom(unsigned int n)
 {
-	int lc, i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	TEST(tst_syscall(__NR_getrandom, NULL, 100, modes[n]));
 
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(ltp_syscall(__NR_getrandom, NULL, 100, modes[i]));
-			if (TEST_RETURN == -1) {
-				tst_resm(TPASS, "getrandom returned %ld",
-						TEST_RETURN);
-			} else {
-				tst_resm(TFAIL | TTERRNO, "getrandom failed");
-			}
-		}
+	if (TEST_RETURN == -1) {
+		tst_res(TPASS | TTERRNO, "getrandom returned %ld",
+			TEST_RETURN);
+	} else {
+		tst_res(TFAIL | TTERRNO, "getrandom failed");
 	}
-	tst_exit();
 }
+
+static struct tst_test test = {
+	.tid = "getrandom01",
+	.tcnt = ARRAY_SIZE(modes),
+	.test = verify_getrandom,
+};
-- 
2.10.2


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

* [LTP] [COMMITTED] [PATCH 2/4] getrandom02: Convert to the new library.
  2017-02-08 15:08 [LTP] [COMMITTED] [PATCH 1/4] getrandom01: Convert to the new library Cyril Hrubis
@ 2017-02-08 15:08 ` Cyril Hrubis
  2017-02-08 15:08 ` [LTP] [COMMITTED] [PATCH 3/4] getrandom03: " Cyril Hrubis
  2017-02-08 15:08 ` [LTP] [COMMITTED] [PATCH 4/4] getrandom04: " Cyril Hrubis
  2 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2017-02-08 15:08 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/getrandom/getrandom02.c | 69 ++++++++---------------
 1 file changed, 25 insertions(+), 44 deletions(-)

diff --git a/testcases/kernel/syscalls/getrandom/getrandom02.c b/testcases/kernel/syscalls/getrandom/getrandom02.c
index ec19f0f..ac20d79 100644
--- a/testcases/kernel/syscalls/getrandom/getrandom02.c
+++ b/testcases/kernel/syscalls/getrandom/getrandom02.c
@@ -29,54 +29,12 @@
 
 #include "lapi/getrandom.h"
 #include "linux_syscall_numbers.h"
-#include "test.h"
+#include "tst_test.h"
 
-char *TCID = "getrandom02";
 static int modes[] = { 0, GRND_RANDOM, GRND_NONBLOCK,
 		       GRND_RANDOM | GRND_NONBLOCK };
 
-int TST_TOTAL = ARRAY_SIZE(modes);
-
-static unsigned char buf[256];
-static size_t size = 256;
-
-static void fill(void);
-static int check_content(int nb);
-
-int main(int ac, char **av)
-{
-	int lc, i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			fill();
-
-			do {
-				TEST(ltp_syscall(__NR_getrandom, buf, size,
-					modes[i]));
-			} while ((modes[i] & GRND_NONBLOCK) && TEST_RETURN == -1
-				&& TEST_ERRNO == EAGAIN);
-
-			if (!check_content(TEST_RETURN))
-				tst_resm(TFAIL | TTERRNO, "getrandom failed");
-			else
-				tst_resm(TPASS, "getrandom returned %ld",
-						TEST_RETURN);
-		}
-	}
-	tst_exit();
-}
-
-static void fill(void)
-{
-	memset(buf, '\0', sizeof(buf));
-}
-
-static int check_content(int nb)
+static int check_content(unsigned char *buf, int nb)
 {
 	int table[256];
 	int i, index, max;
@@ -96,3 +54,26 @@ static int check_content(int nb)
 	}
 	return 1;
 }
+
+static void verify_getrandom(unsigned int n)
+{
+	unsigned char buf[256];
+
+	memset(buf, 0, sizeof(buf));
+
+	do {
+		TEST(tst_syscall(__NR_getrandom, buf, sizeof(buf), modes[n]));
+	} while ((modes[n] & GRND_NONBLOCK) && TEST_RETURN == -1
+		  && TEST_ERRNO == EAGAIN);
+
+	if (!check_content(buf, TEST_RETURN))
+		tst_res(TFAIL | TTERRNO, "getrandom failed");
+	else
+		tst_res(TPASS, "getrandom returned %ld", TEST_RETURN);
+}
+
+static struct tst_test test = {
+	.tid = "getrandom02",
+	.tcnt = ARRAY_SIZE(modes),
+	.test = verify_getrandom,
+};
-- 
2.10.2


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

* [LTP] [COMMITTED] [PATCH 3/4] getrandom03: Convert to the new library.
  2017-02-08 15:08 [LTP] [COMMITTED] [PATCH 1/4] getrandom01: Convert to the new library Cyril Hrubis
  2017-02-08 15:08 ` [LTP] [COMMITTED] [PATCH 2/4] getrandom02: " Cyril Hrubis
@ 2017-02-08 15:08 ` Cyril Hrubis
  2017-02-08 15:08 ` [LTP] [COMMITTED] [PATCH 4/4] getrandom04: " Cyril Hrubis
  2 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2017-02-08 15:08 UTC (permalink / raw)
  To: ltp

Also use hardcoded table of sizes instead of random().

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/getrandom/getrandom03.c | 47 +++++++++++++----------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/testcases/kernel/syscalls/getrandom/getrandom03.c b/testcases/kernel/syscalls/getrandom/getrandom03.c
index 03950e0..e754ca3 100644
--- a/testcases/kernel/syscalls/getrandom/getrandom03.c
+++ b/testcases/kernel/syscalls/getrandom/getrandom03.c
@@ -32,33 +32,38 @@
 
 #include "lapi/getrandom.h"
 #include "linux_syscall_numbers.h"
-#include "test.h"
+#include "tst_test.h"
 
 #define MAX_SIZE 256
 
-char *TCID = "getrandom03";
-int TST_TOTAL = 5;
+static unsigned int sizes[] = {
+	1,
+	2,
+	3,
+	7,
+	8,
+	15,
+	22,
+	64,
+	127,
+};
 
-static char buf[256];
-
-int main(int ac, char **av)
+static void verify_getrandom(unsigned int n)
 {
-	int lc, i;
-	long size;
+	char buf[MAX_SIZE];
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	TEST(tst_syscall(__NR_getrandom, buf, sizes[n], 0));
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		for (i = 0; i < TST_TOTAL; i++) {
-			size = random() % MAX_SIZE;
-			TEST(ltp_syscall(__NR_getrandom, buf, size, 0));
-			if (TEST_RETURN != size)
-				tst_resm(TFAIL | TTERRNO, "getrandom failed");
-			else
-				tst_resm(TPASS, "getrandom returned %ld",
-					TEST_RETURN);
-		}
+	if (TEST_RETURN != sizes[n]) {
+		tst_res(TFAIL | TTERRNO, "getrandom returned %li, expected %u",
+			TEST_RETURN, sizes[n]);
+	} else {
+		tst_res(TPASS, "getrandom returned %ld", TEST_RETURN);
 	}
-	tst_exit();
 }
+
+static struct tst_test test = {
+	.tid = "getrandom03",
+	.tcnt = ARRAY_SIZE(sizes),
+	.test = verify_getrandom,
+};
-- 
2.10.2


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

* [LTP] [COMMITTED] [PATCH 4/4] getrandom04: Convert to the new library.
  2017-02-08 15:08 [LTP] [COMMITTED] [PATCH 1/4] getrandom01: Convert to the new library Cyril Hrubis
  2017-02-08 15:08 ` [LTP] [COMMITTED] [PATCH 2/4] getrandom02: " Cyril Hrubis
  2017-02-08 15:08 ` [LTP] [COMMITTED] [PATCH 3/4] getrandom03: " Cyril Hrubis
@ 2017-02-08 15:08 ` Cyril Hrubis
  2 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2017-02-08 15:08 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/getrandom/getrandom04.c | 36 +++++++++++------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/testcases/kernel/syscalls/getrandom/getrandom04.c b/testcases/kernel/syscalls/getrandom/getrandom04.c
index 10ab44b..0eae031 100644
--- a/testcases/kernel/syscalls/getrandom/getrandom04.c
+++ b/testcases/kernel/syscalls/getrandom/getrandom04.c
@@ -33,30 +33,28 @@
 #include <sys/resource.h>
 #include "lapi/getrandom.h"
 #include "linux_syscall_numbers.h"
-#include "test.h"
+#include "tst_test.h"
 
-char *TCID = "getrandom04";
-int TST_TOTAL = 1;
-static char buf[128];
-
-int main(int ac, char **av)
+static void verify_getrandom(void)
 {
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	int r;
-
-	struct rlimit lim = {3, 3};
+	char buf[128];
+	struct rlimit lold, lnew;
 
-	r = setrlimit(RLIMIT_NOFILE, &lim);
+	SAFE_GETRLIMIT(RLIMIT_NOFILE, &lold);
+	lnew.rlim_max = lold.rlim_max;
+	lnew.rlim_cur = 3;
+	SAFE_SETRLIMIT(RLIMIT_NOFILE, &lnew);
 
-	if (r == -1)
-		tst_brkm(TBROK | TTERRNO, NULL, "setrlimit failed");
-
-	TEST(ltp_syscall(__NR_getrandom, buf, 100, 0));
+	TEST(tst_syscall(__NR_getrandom, buf, 100, 0));
 	if (TEST_RETURN == -1)
-		tst_resm(TFAIL | TTERRNO, "getrandom failed");
+		tst_res(TFAIL | TTERRNO, "getrandom failed");
 	else
-		tst_resm(TPASS, "getrandom returned %ld", TEST_RETURN);
+		tst_res(TPASS, "getrandom returned %ld", TEST_RETURN);
 
-	tst_exit();
+	SAFE_SETRLIMIT(RLIMIT_NOFILE, &lold);
 }
+
+static struct tst_test test = {
+	.tid = "getrandom04",
+	.test_all = verify_getrandom,
+};
-- 
2.10.2


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

end of thread, other threads:[~2017-02-08 15:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-08 15:08 [LTP] [COMMITTED] [PATCH 1/4] getrandom01: Convert to the new library Cyril Hrubis
2017-02-08 15:08 ` [LTP] [COMMITTED] [PATCH 2/4] getrandom02: " Cyril Hrubis
2017-02-08 15:08 ` [LTP] [COMMITTED] [PATCH 3/4] getrandom03: " Cyril Hrubis
2017-02-08 15:08 ` [LTP] [COMMITTED] [PATCH 4/4] getrandom04: " Cyril Hrubis

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.