aboutgitcodelistschat:MatrixIRC
path: root/tests-utils/test-syscalls.c
diff options
context:
space:
mode:
authorAlice Frosi <afrosi@redhat.com>2022-12-21 15:17:46 +0100
committerAlice Frosi <afrosi@redhat.com>2023-02-15 11:31:46 +0100
commitb47cde4553f31b033cd3d096552c0a5646cdc88d (patch)
treeacbef878efcfdf3c9a3847db25705b7cd0ec0d1d /tests-utils/test-syscalls.c
parent4d80c91ea37b6903ca6d5cdb788db6b2f0b44b09 (diff)
downloadseitan-b47cde4553f31b033cd3d096552c0a5646cdc88d.tar
seitan-b47cde4553f31b033cd3d096552c0a5646cdc88d.tar.gz
seitan-b47cde4553f31b033cd3d096552c0a5646cdc88d.tar.bz2
seitan-b47cde4553f31b033cd3d096552c0a5646cdc88d.tar.lz
seitan-b47cde4553f31b033cd3d096552c0a5646cdc88d.tar.xz
seitan-b47cde4553f31b033cd3d096552c0a5646cdc88d.tar.zst
seitan-b47cde4553f31b033cd3d096552c0a5646cdc88d.zip
Create test utils for testing different syscall
For now, just testing the connect syscalls with a client/server small test program. Signed-off-by: Alice Frosi <afrosi@redhat.com>
Diffstat (limited to 'tests-utils/test-syscalls.c')
-rw-r--r--tests-utils/test-syscalls.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests-utils/test-syscalls.c b/tests-utils/test-syscalls.c
new file mode 100644
index 0000000..d017df5
--- /dev/null
+++ b/tests-utils/test-syscalls.c
@@ -0,0 +1,47 @@
+#include <sys/un.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static int test_connect()
+{
+ struct sockaddr_un addr;
+ char data[256] = "test connection";
+ int fd;
+ if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ perror("creating socket");
+ return 1;
+ }
+ memset(&addr, 0, sizeof(addr));
+ strcpy(addr.sun_path, "/tmp/test.sock");
+ addr.sun_family = AF_UNIX;
+ if (connect(fd, (struct sockaddr *)&addr, sizeof(addr.sun_path)) < 0) {
+ perror("connect error");
+ return 1;
+ }
+ if (write(fd, data, strlen(data) + 1) < 0) {
+ perror("writing data");
+ return 1;
+ }
+ close(fd);
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ int ret;
+ if (argc < 2) {
+ perror("missing syscall to test");
+ exit(EXIT_FAILURE);
+ }
+ printf("Test syscall: %s \n", argv[1]);
+ if (strcmp(argv[1], "connect") == 0)
+ ret = test_connect();
+ else {
+ perror("syscall not supported");
+ exit(EXIT_FAILURE);
+ }
+ if (ret != 0)
+ exit(EXIT_FAILURE);
+}