* [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase
@ 2012-08-08 9:26 Caspar Zhang
2012-08-08 9:26 ` [LTP] [PATCH 2/4] syscall/process_vm_readv03: " Caspar Zhang
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Caspar Zhang @ 2012-08-08 9:26 UTC (permalink / raw)
To: LTP List
[-- Attachment #1: Type: text/plain, Size: 730 bytes --]
This testcase is one of the simple CMA syscalls (process_vm_readv,
process_vm_writev) tests originally written by Chris Yeoh
<yeohc@au1.ibm.com>. I made some modifications to make it match the code
style in LTP.
Test Assertion and Strategy:
Fork two children, one child allocates memory and initializes it;
then the other one calls process_vm_readv and reads from the same
memory location, it then verifies if process_vm_readv returns
correct data.
Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
testcases/kernel/syscalls/cma/process_vm_readv02.c | 162 ++++++++++++++++++++
1 files changed, 162 insertions(+), 0 deletions(-)
create mode 100644 testcases/kernel/syscalls/cma/process_vm_readv02.c
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-syscall-process_vm_readv02-new-testcase.patch --]
[-- Type: text/x-patch; name="0001-syscall-process_vm_readv02-new-testcase.patch", Size: 4380 bytes --]
diff --git a/testcases/kernel/syscalls/cma/process_vm_readv02.c b/testcases/kernel/syscalls/cma/process_vm_readv02.c
new file mode 100644
index 0000000..db48312
--- /dev/null
+++ b/testcases/kernel/syscalls/cma/process_vm_readv02.c
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2012
+ * Copyright (c) Linux Test Project, 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
+#include "process_vm.h"
+
+char *TCID = "process_vm_readv02";
+int TST_TOTAL = 1;
+
+static char *tst_string = "THIS IS A TEST";
+static int len;
+static int pipe_fd[2];
+static pid_t pids[2];
+
+static void child_alloc(void);
+static void child_invoke(void);
+static void setup(void);
+static void cleanup(void);
+
+int main(int argc, char **argv)
+{
+ int lc, status;
+ char *msg;
+
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ Tst_count = 0;
+ len = strlen(tst_string);
+
+ if (pipe(pipe_fd) < 0)
+ tst_brkm(TBROK|TERRNO, cleanup, "pipe");
+
+ pids[0] = fork();
+ switch (pids[0]) {
+ case -1:
+ tst_brkm(TBROK|TERRNO, cleanup, "fork #0");
+ case 0:
+ child_alloc();
+ exit(0);
+ }
+
+ pids[1] = fork();
+ switch (pids[1]) {
+ case -1:
+ tst_brkm(TBROK|TERRNO, cleanup, "fork #0");
+ case 0:
+ child_invoke();
+ exit(0);
+ default:
+ if (waitpid(pids[1], &status, 0) == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ tst_resm(TFAIL, "child 1 returns %d", status);
+ }
+ if (kill(pids[0], SIGCONT) == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "kill");
+ }
+
+ cleanup();
+ tst_exit();
+}
+
+static void child_alloc(void)
+{
+ char *foo;
+ char buf[BUFSIZ];
+
+ foo = SAFE_MALLOC(tst_exit, len + 1);
+ strncpy(foo, tst_string, len);
+ foo[len] = '\0';
+ tst_resm(TINFO, "child 0: memory allocated and initialized.");
+
+ /* passing addr of string "foo" via pipe */
+ SAFE_CLOSE(tst_exit, pipe_fd[0]);
+ snprintf(buf, BUFSIZ, "%p", foo);
+ SAFE_WRITE(tst_exit, 1, pipe_fd[1], buf, strlen(buf));
+ SAFE_CLOSE(tst_exit, pipe_fd[1]);
+
+ if (raise(SIGSTOP) < 0)
+ tst_brkm(TBROK|TERRNO, tst_exit, "raise");
+}
+
+static void child_invoke(void)
+{
+ char *lp, *rp;
+ char buf[BUFSIZ];
+ struct iovec local, remote;
+
+ /* get addr from pipe */
+ SAFE_CLOSE(tst_exit, pipe_fd[1]);
+ SAFE_READ(tst_exit, 0, pipe_fd[0], buf, BUFSIZ);
+ SAFE_CLOSE(tst_exit, pipe_fd[0]);
+ if (sscanf(buf, "%p", &rp) != 1)
+ tst_brkm(TBROK|TERRNO, tst_exit, "sscanf");
+
+ lp = SAFE_MALLOC(tst_exit, len + 1);
+ local.iov_base = lp;
+ local.iov_len = len;
+ remote.iov_base = rp;
+ remote.iov_len = len;
+
+ tst_resm(TINFO, "child 1: reading string from same memory location.");
+ TEST(test_process_vm_readv(pids[0], &local, 1, &remote, 1, 0));
+ if (TEST_RETURN != len)
+ tst_brkm(TBROK|TERRNO, tst_exit, "process_vm_readv");
+ if (strcmp(lp, tst_string) != 0)
+ tst_brkm(TFAIL, tst_exit, "child 1: expected string: %s, "
+ "received string: %s", tst_string, lp);
+ else
+ tst_resm(TPASS, "expected string received.");
+
+ exit(0);
+}
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+
+#if !defined(__NR_process_vm_readv)
+ tst_brkm(TCONF, NULL, "process_vm_writev does not exist "
+ "on your system");
+#endif
+
+ TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+ TEST_CLEANUP;
+}
[-- Attachment #3: Type: text/plain, Size: 395 bytes --]
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
[-- Attachment #4: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 2/4] syscall/process_vm_readv03: new testcase
2012-08-08 9:26 [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase Caspar Zhang
@ 2012-08-08 9:26 ` Caspar Zhang
2012-08-08 9:26 ` [LTP] [PATCH 3/4] syscall/process_vm_writev02: " Caspar Zhang
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Caspar Zhang @ 2012-08-08 9:26 UTC (permalink / raw)
To: LTP List
[-- Attachment #1: Type: text/plain, Size: 889 bytes --]
This testcase is one of the simple CMA syscalls (process_vm_readv,
process_vm_writev) tests originally written by Chris Yeoh
<yeohc@au1.ibm.com>. I made some modifications to make it match the code
style in LTP.
Test Assertion and Strategy:
Fork two children, one child mallocs randomly sized trunks of memory
and initializes them; the other child calls process_vm_readv with
the remote iovecs initialized to the original process memory
locations and the local iovecs initialized to randomly sized and
allocated local memory locations. The second child then verifies
that the data copied is correct.
Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
testcases/kernel/syscalls/cma/process_vm_readv03.c | 272 ++++++++++++++++++++
1 files changed, 272 insertions(+), 0 deletions(-)
create mode 100644 testcases/kernel/syscalls/cma/process_vm_readv03.c
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-syscall-process_vm_readv03-new-testcase.patch --]
[-- Type: text/x-patch; name="0002-syscall-process_vm_readv03-new-testcase.patch", Size: 7099 bytes --]
diff --git a/testcases/kernel/syscalls/cma/process_vm_readv03.c b/testcases/kernel/syscalls/cma/process_vm_readv03.c
new file mode 100644
index 0000000..228a83b
--- /dev/null
+++ b/testcases/kernel/syscalls/cma/process_vm_readv03.c
@@ -0,0 +1,272 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2012
+ * Copyright (c) Linux Test Project, 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
+#include "process_vm.h"
+
+char *TCID = "process_vm_readv03";
+int TST_TOTAL = 1;
+
+#define NUM_LOCAL_VECS 4
+
+static int nflag, sflag;
+static char *nr_opt, *sz_opt;
+static option_t options[] = {
+ { "n:", &nflag, &nr_opt },
+ { "s:", &sflag, &sz_opt },
+ { NULL, NULL, NULL }
+};
+
+static int nr_iovecs;
+static long bufsz;
+static int pipe_fd[2];
+static pid_t pids[2];
+
+static void gen_random_arr(int *arr, int arr_sz);
+static void child_alloc(int *bufsz_arr);
+static void child_invoke(int *bufsz_arr);
+static long *fetch_remote_addrs(void);
+static void setup(void);
+static void cleanup(void);
+static void help(void);
+
+int main(int argc, char **argv)
+{
+ int lc, status;
+ char *msg;
+ int *bufsz_arr;
+
+ msg = parse_opts(argc, argv, options, &help);
+ if (msg != NULL)
+ tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s"
+ "use -help", msg);
+
+ setup();
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ Tst_count = 0;
+
+ if (pipe(pipe_fd) < 0)
+ tst_brkm(TBROK|TERRNO, cleanup, "pipe");
+
+ bufsz_arr = SAFE_MALLOC(cleanup, nr_iovecs * sizeof(int));
+ gen_random_arr(bufsz_arr, nr_iovecs);
+
+ pids[0] = fork();
+ switch (pids[0]) {
+ case -1:
+ tst_brkm(TBROK|TERRNO, cleanup, "fork #0");
+ case 0:
+ child_alloc(bufsz_arr);
+ exit(0);
+ }
+
+ pids[1] = fork();
+ switch (pids[1]) {
+ case -1:
+ tst_brkm(TBROK|TERRNO, cleanup, "fork #0");
+ case 0:
+ child_invoke(bufsz_arr);
+ exit(0);
+ default:
+ if (waitpid(pids[1], &status, 0) == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ tst_resm(TFAIL, "child 1 returns %d", status);
+ }
+ if (kill(pids[0], SIGCONT) == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "kill");
+
+ free(bufsz_arr);
+ }
+
+ cleanup();
+ tst_exit();
+}
+
+static void gen_random_arr(int *arr, int arr_sz)
+{
+ long bufsz_left, bufsz_single;
+ int i;
+
+ bufsz_left = bufsz;
+ for (i = 0; i < arr_sz - 1; i++) {
+ bufsz_single = rand() % (bufsz_left / 2) + 1;
+ arr[i] = bufsz_single;
+ bufsz_left -= bufsz_single;
+ }
+ arr[arr_sz-1] = bufsz_left;
+}
+
+static void child_alloc(int *bufsz_arr)
+{
+ char **foo;
+ int i, j;
+ char buf[BUFSIZ];
+ long count;
+
+ foo = SAFE_MALLOC(tst_exit, nr_iovecs * sizeof(char *));
+
+ count = 0;
+ for (i = 0; i < nr_iovecs; i++) {
+ foo[i] = SAFE_MALLOC(tst_exit, bufsz_arr[i]);
+ for (j = 0; j < bufsz_arr[i]; j++) {
+ foo[i][j] = count % 256;
+ count++;
+ }
+ }
+ tst_resm(TINFO, "child 0: %d iovecs allocated and initialized.",
+ nr_iovecs);
+
+ /* passing addr via pipe */
+ SAFE_CLOSE(tst_exit, pipe_fd[0]);
+ snprintf(buf, BUFSIZ, "%p", (void *)foo);
+ SAFE_WRITE(tst_exit, 1, pipe_fd[1], buf, strlen(buf));
+ SAFE_CLOSE(tst_exit, pipe_fd[1]);
+
+ if (raise(SIGSTOP) < 0)
+ tst_brkm(TBROK|TERRNO, tst_exit, "raise");
+}
+
+static long *fetch_remote_addrs(void)
+{
+ long *foo, *bar;
+ char buf[BUFSIZ];
+ long len;
+ struct iovec local, remote;
+
+ /* get addr from pipe */
+ SAFE_CLOSE(tst_exit, pipe_fd[1]);
+ SAFE_READ(tst_exit, 0, pipe_fd[0], buf, BUFSIZ);
+ SAFE_CLOSE(tst_exit, pipe_fd[0]);
+ if (sscanf(buf, "%p", &foo) != 1)
+ tst_brkm(TBROK|TERRNO, tst_exit, "sscanf");
+
+ len = nr_iovecs * sizeof(long);
+ bar = SAFE_MALLOC(tst_exit, len);
+ local.iov_base = bar;
+ local.iov_len = len;
+ remote.iov_base = foo;
+ remote.iov_len = len;
+
+ TEST(test_process_vm_readv(pids[0], &local, 1, &remote, 1, 0));
+ if (TEST_RETURN != len)
+ tst_brkm(TBROK|TERRNO, tst_exit, "process_vm_readv");
+
+ return local.iov_base;
+}
+
+static void child_invoke(int *bufsz_arr)
+{
+ int i, j, count, nr_error;
+ unsigned char expect, actual;
+ long *addrs;
+ struct iovec local[NUM_LOCAL_VECS], *remote;
+ int rcv_arr[NUM_LOCAL_VECS];
+
+ addrs = fetch_remote_addrs();
+
+ remote = SAFE_MALLOC(tst_exit, nr_iovecs * sizeof(struct iovec));
+ for (i = 0; i < nr_iovecs; i++) {
+ remote[i].iov_base = (void *)addrs[i];
+ remote[i].iov_len = bufsz_arr[i];
+ }
+ tst_resm(TINFO, "child 1: %d remote iovecs received.", nr_iovecs);
+
+ gen_random_arr(rcv_arr, NUM_LOCAL_VECS);
+ for (i = 0; i < NUM_LOCAL_VECS; i++) {
+ local[i].iov_base = SAFE_MALLOC(tst_exit, rcv_arr[i]);
+ local[i].iov_len = rcv_arr[i];
+ }
+ tst_resm(TINFO, "child 1: %d local iovecs initialized.",
+ NUM_LOCAL_VECS);
+
+ TEST(test_process_vm_readv(pids[0], local, NUM_LOCAL_VECS,
+ remote, nr_iovecs, 0));
+ if (TEST_RETURN != bufsz)
+ tst_brkm(TBROK|TERRNO, tst_exit, "process_vm_readv");
+
+ /* verify every byte */
+ count = 0;
+ nr_error = 0;
+ for (i = 0; i < NUM_LOCAL_VECS; i++) {
+ for (j = 0; j < local[i].iov_len; j++) {
+ expect = count % 256;
+ actual = ((unsigned char *)local[i].iov_base)[j];
+ if (expect != actual) {
+#if DEBUG
+ tst_resm(TFAIL, "child 1: expected %i, got %i "
+ "for byte seq %d",
+ expect, actual, count);
+#endif
+ nr_error++;
+ }
+ count++;
+ }
+ }
+ if (nr_error)
+ tst_brkm(TFAIL, tst_exit, "child 1: %d incorrect bytes "
+ "received.", nr_error);
+ else
+ tst_resm(TPASS, "child 1: all bytes are correctly received.");
+
+ exit(0);
+}
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+
+ nr_iovecs = nflag ? SAFE_STRTOL(NULL, nr_opt, 1, IOV_MAX) : 10;
+ bufsz = sflag ? SAFE_STRTOL(NULL, sz_opt, NUM_LOCAL_VECS, LONG_MAX)
+ : 100000;
+
+#if !defined(__NR_process_vm_readv)
+ tst_brkm(TCONF, NULL, "process_vm_writev does not exist "
+ "on your system");
+#endif
+
+ srand(time(NULL));
+
+ TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+ TEST_CLEANUP;
+}
+
+static void help(void)
+{
+ printf(" -n NUM Set the number of iovecs to be allocated.\n");
+ printf(" -s NUM Set the size of total buffer size.\n");
+}
[-- Attachment #3: Type: text/plain, Size: 395 bytes --]
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
[-- Attachment #4: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 3/4] syscall/process_vm_writev02: new testcase
2012-08-08 9:26 [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase Caspar Zhang
2012-08-08 9:26 ` [LTP] [PATCH 2/4] syscall/process_vm_readv03: " Caspar Zhang
@ 2012-08-08 9:26 ` Caspar Zhang
2012-08-08 9:26 ` [LTP] [PATCH 4/4] runtest/syscalls: add cma testcases Caspar Zhang
2012-08-08 10:52 ` [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase Jan Stancek
3 siblings, 0 replies; 6+ messages in thread
From: Caspar Zhang @ 2012-08-08 9:26 UTC (permalink / raw)
To: LTP List
[-- Attachment #1: Type: text/plain, Size: 719 bytes --]
This testcase is one of the simple CMA syscalls (process_vm_readv,
process_vm_writev) tests originally written by Chris Yeoh
<yeohc@au1.ibm.com>. I made some modifications to make it match the code
style in LTP.
Test Assertion and Strategy:
Fork two children, the first one allocates a chunk of memory and the
other one call process_vm_writev to write known data into the first
child. Then first child verifies that the data is as expected.
Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
.../kernel/syscalls/cma/process_vm_writev02.c | 202 ++++++++++++++++++++
1 files changed, 202 insertions(+), 0 deletions(-)
create mode 100644 testcases/kernel/syscalls/cma/process_vm_writev02.c
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-syscall-process_vm_writev02-new-testcase.patch --]
[-- Type: text/x-patch; name="0003-syscall-process_vm_writev02-new-testcase.patch", Size: 5112 bytes --]
diff --git a/testcases/kernel/syscalls/cma/process_vm_writev02.c b/testcases/kernel/syscalls/cma/process_vm_writev02.c
new file mode 100644
index 0000000..cfcb481
--- /dev/null
+++ b/testcases/kernel/syscalls/cma/process_vm_writev02.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2012
+ * Copyright (c) Linux Test Project, 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
+#include "process_vm.h"
+
+char *TCID = "process_vm_writev02";
+int TST_TOTAL = 1;
+
+#define PADDING_SIZE 10
+#define DEFAULT_CHAR 53
+
+static int sflag;
+static char *sz_opt;
+static option_t options[] = {
+ { "s:", &sflag, &sz_opt },
+ { NULL, NULL, NULL }
+};
+
+static long bufsz;
+static int pipe_fd[2];
+static pid_t pids[2];
+
+static void child_init_and_verify(void);
+static void child_write(void);
+static void setup(void);
+static void cleanup(void);
+static void help(void);
+
+int main(int argc, char **argv)
+{
+ int lc, status;
+ char *msg;
+
+ msg = parse_opts(argc, argv, options, &help);
+ if (msg != NULL)
+ tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ Tst_count = 0;
+
+ if (pipe(pipe_fd) < 0)
+ tst_brkm(TBROK|TERRNO, cleanup, "pipe");
+
+ pids[0] = fork();
+ switch (pids[0]) {
+ case -1:
+ tst_brkm(TBROK|TERRNO, cleanup, "fork #0");
+ case 0:
+ child_init_and_verify();
+ exit(0);
+ default:
+ break;
+ }
+
+ pids[1] = fork();
+ switch (pids[1]) {
+ case -1:
+ tst_brkm(TBROK|TERRNO, cleanup, "fork #1");
+ case 0:
+ child_write();
+ exit(0);
+ default:
+ break;
+ }
+ while (waitpid(-1, &status, 0) > 0)
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ tst_resm(TFAIL, "child 1 returns %d", status);
+ }
+
+ cleanup();
+ tst_exit();
+}
+
+static void child_init_and_verify(void)
+{
+ unsigned char *foo;
+ char buf[bufsz];
+ long i, nr_err;
+
+ foo = SAFE_MALLOC(tst_exit, bufsz);
+ for (i = 0; i < bufsz; i++)
+ foo[i] = DEFAULT_CHAR;
+ tst_resm(TINFO, "child 0: memory allocated.");
+
+ /* passing addr of string "foo" via pipe */
+ SAFE_CLOSE(tst_exit, pipe_fd[0]);
+ snprintf(buf, bufsz, "%p", foo);
+ SAFE_WRITE(tst_exit, 1, pipe_fd[1], buf, strlen(buf));
+ SAFE_CLOSE(tst_exit, pipe_fd[1]);
+
+ if (raise(SIGSTOP) < 0)
+ tst_brkm(TBROK|TERRNO, tst_exit, "raise");
+
+ nr_err = 0;
+ for (i = 0; i < bufsz; i++) {
+ if (foo[i] != i % 256) {
+#if DEBUG
+ tst_brkm(TFAIL, tst_exit, "child 0: expected string: "
+ "%s, received string: %s",
+ tst_string, lp);
+#endif
+ nr_err++;
+ }
+ }
+ if (nr_err)
+ tst_brkm(TFAIL, tst_exit, "child 0: got %ld incorrect bytes.",
+ nr_err);
+ else
+ tst_resm(TPASS, "child 0: all bytes are expected.");
+}
+
+static void child_write(void)
+{
+ unsigned char *lp, *rp;
+ char buf[bufsz];
+ struct iovec local, remote;
+ long i;
+
+ /* get addr from pipe */
+ SAFE_CLOSE(tst_exit, pipe_fd[1]);
+ SAFE_READ(tst_exit, 0, pipe_fd[0], buf, bufsz);
+ SAFE_CLOSE(tst_exit, pipe_fd[0]);
+ if (sscanf(buf, "%p", &rp) != 1)
+ tst_brkm(TBROK|TERRNO, tst_exit, "sscanf");
+
+ lp = SAFE_MALLOC(tst_exit, bufsz + PADDING_SIZE * 2);
+
+ for (i = 0; i < bufsz + PADDING_SIZE * 2; i++)
+ lp[i] = DEFAULT_CHAR;
+ for (i = 0; i < bufsz; i++)
+ lp[i+PADDING_SIZE] = i % 256;
+
+ local.iov_base = lp + PADDING_SIZE;
+ local.iov_len = bufsz;
+ remote.iov_base = rp;
+ remote.iov_len = bufsz;
+
+ tst_resm(TINFO, "child 2: write to the same memory location.");
+ TEST(test_process_vm_writev(pids[0], &local, 1, &remote, 1, 0));
+ if (TEST_RETURN != bufsz)
+ tst_brkm(TBROK|TERRNO, tst_exit, "process_vm_readv");
+
+ if (kill(pids[0], SIGCONT) == -1)
+ tst_brkm(TBROK|TERRNO, tst_exit, "kill");
+
+ exit(0);
+}
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+
+ bufsz = sflag ? SAFE_STRTOL(NULL, sz_opt, 1, LONG_MAX-PADDING_SIZE*2)
+ : 100000;
+
+#if !defined(__NR_process_vm_readv)
+ tst_brkm(TCONF, NULL, "process_vm_writev does not exist "
+ "on your system");
+#endif
+
+ TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+ TEST_CLEANUP;
+}
+
+static void help(void)
+{
+ printf(" -s NUM Set the size of total buffer size.\n");
+}
[-- Attachment #3: Type: text/plain, Size: 395 bytes --]
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
[-- Attachment #4: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 4/4] runtest/syscalls: add cma testcases
2012-08-08 9:26 [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase Caspar Zhang
2012-08-08 9:26 ` [LTP] [PATCH 2/4] syscall/process_vm_readv03: " Caspar Zhang
2012-08-08 9:26 ` [LTP] [PATCH 3/4] syscall/process_vm_writev02: " Caspar Zhang
@ 2012-08-08 9:26 ` Caspar Zhang
2012-08-08 10:52 ` [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase Jan Stancek
3 siblings, 0 replies; 6+ messages in thread
From: Caspar Zhang @ 2012-08-08 9:26 UTC (permalink / raw)
To: LTP List
[-- Attachment #1: Type: text/plain, Size: 264 bytes --]
adding the following testcases into runtest/syscalls:
process_vm_readv02
process_vm_readv03
process_vm_writev02
Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
runtest/syscalls | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0004-runtest-syscalls-add-cma-testcases.patch --]
[-- Type: text/x-patch; name="0004-runtest-syscalls-add-cma-testcases.patch", Size: 431 bytes --]
diff --git a/runtest/syscalls b/runtest/syscalls
index 7c4c9ca..edf6c1e 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -734,7 +734,10 @@ pread03_64 pread03_64
profil01 profil01
process_vm_readv01 process_vm01 -r
+process_vm_readv02 process_vm_readv02
+process_vm_readv03 process_vm_readv03
process_vm_writev01 process_vm01 -w
+process_vm_writev02 process_vm_writev02
pselect01 pselect01
pselect01_64 pselect01_64
[-- Attachment #3: Type: text/plain, Size: 395 bytes --]
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
[-- Attachment #4: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase
2012-08-08 9:26 [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase Caspar Zhang
` (2 preceding siblings ...)
2012-08-08 9:26 ` [LTP] [PATCH 4/4] runtest/syscalls: add cma testcases Caspar Zhang
@ 2012-08-08 10:52 ` Jan Stancek
2012-08-08 13:14 ` Jan Stancek
3 siblings, 1 reply; 6+ messages in thread
From: Jan Stancek @ 2012-08-08 10:52 UTC (permalink / raw)
To: Caspar Zhang; +Cc: LTP List
Hi Caspar,
+ if (TEST_RETURN != len)
+ tst_brkm(TBROK|TERRNO, tst_exit, "process_vm_readv");
Shouldn't this be TFAIL? Can it also print TEST_RETURN?
+ lp = SAFE_MALLOC(tst_exit, len + 1);
+ local.iov_base = lp;
+ local.iov_len = len;
+ remote.iov_base = rp;
+ remote.iov_len = len;
+
+ tst_resm(TINFO, "child 1: reading string from same memory location.");
+ TEST(test_process_vm_readv(pids[0], &local, 1, &remote, 1, 0));
+ if (TEST_RETURN != len)
+ tst_brkm(TBROK|TERRNO, tst_exit, "process_vm_readv");
+ if (strcmp(lp, tst_string) != 0)
+ tst_brkm(TFAIL, tst_exit, "child 1: expected string: %s, "
+ "received string: %s", tst_string, lp);
I think SAFE_MALLOC is not initialising memory. So if "lp[len] != 0"
strcmp will fail.
+#if !defined(__NR_process_vm_readv)
+ tst_brkm(TCONF, NULL, "process_vm_writev does not exist "
+ "on your system");
Message says "process_vm_writev", testcase is for "process_vm_readv".
Regards,
Jan
----- Original Message -----
> From: "Caspar Zhang" <caspar@casparzhang.com>
> To: "LTP List" <ltp-list@lists.sourceforge.net>
> Sent: Wednesday, 8 August, 2012 11:26:54 AM
> Subject: [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase
>
>
> This testcase is one of the simple CMA syscalls (process_vm_readv,
> process_vm_writev) tests originally written by Chris Yeoh
> <yeohc@au1.ibm.com>. I made some modifications to make it match the
> code
> style in LTP.
>
> Test Assertion and Strategy:
>
> Fork two children, one child allocates memory and initializes it;
> then the other one calls process_vm_readv and reads from the same
> memory location, it then verifies if process_vm_readv returns
> correct data.
>
> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
> ---
> testcases/kernel/syscalls/cma/process_vm_readv02.c | 162
> ++++++++++++++++++++
> 1 files changed, 162 insertions(+), 0 deletions(-)
> create mode 100644
> testcases/kernel/syscalls/cma/process_vm_readv02.c
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond.
> Discussions
> will include endpoint security, mobile security and the latest in
> malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase
2012-08-08 10:52 ` [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase Jan Stancek
@ 2012-08-08 13:14 ` Jan Stancek
0 siblings, 0 replies; 6+ messages in thread
From: Jan Stancek @ 2012-08-08 13:14 UTC (permalink / raw)
To: Caspar Zhang; +Cc: LTP List
----- Original Message -----
> From: "Jan Stancek" <jstancek@redhat.com>
> To: "Caspar Zhang" <caspar@casparzhang.com>
> Cc: "LTP List" <ltp-list@lists.sourceforge.net>
> Sent: Wednesday, 8 August, 2012 12:52:42 PM
> Subject: Re: [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase
>
> Hi Caspar,
>
> + if (TEST_RETURN != len)
> + tst_brkm(TBROK|TERRNO, tst_exit, "process_vm_readv");
> Shouldn't this be TFAIL? Can it also print TEST_RETURN?
>
> + lp = SAFE_MALLOC(tst_exit, len + 1);
> + local.iov_base = lp;
> + local.iov_len = len;
> + remote.iov_base = rp;
> + remote.iov_len = len;
> +
> + tst_resm(TINFO, "child 1: reading string from same memory
> location.");
> + TEST(test_process_vm_readv(pids[0], &local, 1, &remote, 1, 0));
> + if (TEST_RETURN != len)
> + tst_brkm(TBROK|TERRNO, tst_exit, "process_vm_readv");
> + if (strcmp(lp, tst_string) != 0)
> + tst_brkm(TFAIL, tst_exit, "child 1: expected string: %s, "
> + "received string: %s", tst_string, lp);
> I think SAFE_MALLOC is not initialising memory. So if "lp[len] != 0"
> strcmp will fail.
>
> +#if !defined(__NR_process_vm_readv)
> + tst_brkm(TCONF, NULL, "process_vm_writev does not exist "
> + "on your system");
> Message says "process_vm_writev", testcase is for "process_vm_readv".
+ tst_brkm(TBROK|TERRNO, cleanup, "fork #0");
Both messages about broken fork are "fork #0".
SIGSTOP/SIGCONT approach seems prone to races: if other child
is able to finish before first one raises SIGSTOP, then SIGCONT
arrives first. For example, let's put small sleep before SIGSTOP
in child_alloc() and child will never finish:
sleep(2);
if (raise(SIGSTOP) < 0)
tst_brkm(TBROK|TERRNO, tst_exit, "raise");
The testcase still gives PASS, but one of children is now hanging
in background:
5399 pts/0 T 0:00 ./process_vm_readv02
Regards,
Jan
>
> Regards,
> Jan
>
> ----- Original Message -----
> > From: "Caspar Zhang" <caspar@casparzhang.com>
> > To: "LTP List" <ltp-list@lists.sourceforge.net>
> > Sent: Wednesday, 8 August, 2012 11:26:54 AM
> > Subject: [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase
> >
> >
> > This testcase is one of the simple CMA syscalls (process_vm_readv,
> > process_vm_writev) tests originally written by Chris Yeoh
> > <yeohc@au1.ibm.com>. I made some modifications to make it match the
> > code
> > style in LTP.
> >
> > Test Assertion and Strategy:
> >
> > Fork two children, one child allocates memory and initializes
> > it;
> > then the other one calls process_vm_readv and reads from the
> > same
> > memory location, it then verifies if process_vm_readv returns
> > correct data.
> >
> > Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
> > ---
> > testcases/kernel/syscalls/cma/process_vm_readv02.c | 162
> > ++++++++++++++++++++
> > 1 files changed, 162 insertions(+), 0 deletions(-)
> > create mode 100644
> > testcases/kernel/syscalls/cma/process_vm_readv02.c
> >
> >
> > ------------------------------------------------------------------------------
> > Live Security Virtual Conference
> > Exclusive live event will cover all the ways today's security and
> > threat landscape has changed and how IT managers can respond.
> > Discussions
> > will include endpoint security, mobile security and the latest in
> > malware
> > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> > _______________________________________________
> > Ltp-list mailing list
> > Ltp-list@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/ltp-list
> >
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond.
> Discussions
> will include endpoint security, mobile security and the latest in
> malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-08-08 13:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-08 9:26 [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase Caspar Zhang
2012-08-08 9:26 ` [LTP] [PATCH 2/4] syscall/process_vm_readv03: " Caspar Zhang
2012-08-08 9:26 ` [LTP] [PATCH 3/4] syscall/process_vm_writev02: " Caspar Zhang
2012-08-08 9:26 ` [LTP] [PATCH 4/4] runtest/syscalls: add cma testcases Caspar Zhang
2012-08-08 10:52 ` [LTP] [PATCH 1/4] syscall/process_vm_readv02: new testcase Jan Stancek
2012-08-08 13:14 ` Jan Stancek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox