summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStafford Horne <shorne@gmail.com>2017-12-14 15:21:00 +0900
committerWaldemar Brodkorb <wbx@openadk.org>2017-12-16 21:06:06 +0100
commitd8953ce923ec3bee1b0e4459e737e315472ec808 (patch)
tree818b82d96d1a4989abf681827ebd97d07728b948
parenta710f82b67d690bf732f81ff652690d4b7b84d47 (diff)
tst-syscall*: Add tests for syscall() with varargs
Add tests in preparation for genericizing some of the architecture syscall() implementations. This was noticed when testing OR1K and found it had a broken syscall implementation. These tests try to cover the libc syscall() lqyer which has the purpose of passing the syscall number and arguments to the kernel. The actual kernel syscalls chosen have been selected for ease of testing. Signed-off-by: Stafford Horne <shorne@gmail.com>
-rw-r--r--test/misc/tst-syscall0.c15
-rw-r--r--test/misc/tst-syscall1.c18
-rw-r--r--test/misc/tst-syscall6.c61
3 files changed, 94 insertions, 0 deletions
diff --git a/test/misc/tst-syscall0.c b/test/misc/tst-syscall0.c
new file mode 100644
index 0000000..ebfca95
--- /dev/null
+++ b/test/misc/tst-syscall0.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+int main() {
+ int pid;
+
+ pid = syscall(SYS_getpid);
+ if (pid > 0) {
+ printf("syscall(SYS_getpid) says %d\n", pid);
+ return 0;
+ }
+
+ return 1;
+}
diff --git a/test/misc/tst-syscall1.c b/test/misc/tst-syscall1.c
new file mode 100644
index 0000000..e3b990e
--- /dev/null
+++ b/test/misc/tst-syscall1.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/utsname.h>
+
+int main() {
+ int ret;
+ struct utsname name;
+
+ ret = syscall(SYS_uname, &name);
+ if (ret == 0) {
+ printf("syscall(SYS_uname) says %s-%s\n", name.sysname,
+ name.release);
+ return 0;
+ }
+
+ return 1;
+}
diff --git a/test/misc/tst-syscall6.c b/test/misc/tst-syscall6.c
new file mode 100644
index 0000000..dad67d1
--- /dev/null
+++ b/test/misc/tst-syscall6.c
@@ -0,0 +1,61 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/uio.h>
+#include <sys/types.h>
+#include <linux/fs.h> /* for RWF_HIPRI */
+
+int main()
+{
+ char tmp[] = "/tmp/tst-preadv2-XXXXXX";
+ int fd;
+ struct iovec iov[2];
+ char *str0 = "hello ";
+ char *str1 = "world\n";
+ char input[16];
+ int nio;
+
+ fd = mkstemp (tmp);
+ if (fd == -1) {
+ puts ("mkstemp failed");
+ return 1;
+ }
+
+ iov[0].iov_base = str0;
+ iov[0].iov_len = strlen(str0);
+ iov[1].iov_base = str1;
+ iov[1].iov_len = strlen(str1) + 1; /* null terminator */
+
+ nio = syscall(SYS_pwritev2, fd, iov, 2, 0, 0, RWF_DSYNC);
+
+ if (nio <= 0) {
+ puts ("failed to write to fd");
+ return 1;
+ }
+
+ /* Read in the second string into the first buffer */
+ iov[0].iov_base = input;
+ iov[0].iov_len = strlen(str1) + 1; /* null terminator */
+ nio = syscall(SYS_preadv2, fd, iov, 1, strlen(str0), 0, RWF_HIPRI);
+ if (nio <= 0) {
+ printf ("failed to read fd %d\n", nio);
+ return 1;
+ }
+
+ if (strncmp(iov[0].iov_base, iov[1].iov_base, strlen(str1)) == 0)
+ printf ("syscall(SYS_preadv2) read %s", (char *) iov[0].iov_base);
+
+ if (close(fd) != 0) {
+ puts ("failed to close read fd");
+ return 1;
+ }
+
+ if (unlink(tmp) != 0) {
+ puts ("failed to unlink file");
+ return 1;
+ }
+
+ return 0;
+}