[RFC v1 14/14] bus1: basic user-space kselftests
From: Tom GundersenThis adds kselftests integration and provides some basic API tests for bus1. Signed-off-by: Tom Gundersen Signed-off-by: David Herrmann --- tools/testing/selftests/bus1/.gitignore | 2 + tools/testing/selftests/bus1/Makefile | 19 ++ tools/testing/selftests/bus1/bus1-ioctl.h | 111 +++ tools/testing/selftests/bus1/test-api.c | 532 ++ tools/testing/selftests/bus1/test-io.c| 198 +++ tools/testing/selftests/bus1/test.h | 114 +++ 6 files changed, 976 insertions(+) create mode 100644 tools/testing/selftests/bus1/.gitignore create mode 100644 tools/testing/selftests/bus1/Makefile create mode 100644 tools/testing/selftests/bus1/bus1-ioctl.h create mode 100644 tools/testing/selftests/bus1/test-api.c create mode 100644 tools/testing/selftests/bus1/test-io.c create mode 100644 tools/testing/selftests/bus1/test.h diff --git a/tools/testing/selftests/bus1/.gitignore b/tools/testing/selftests/bus1/.gitignore new file mode 100644 index 000..76ecb9c --- /dev/null +++ b/tools/testing/selftests/bus1/.gitignore @@ -0,0 +1,2 @@ +test-api +test-io diff --git a/tools/testing/selftests/bus1/Makefile b/tools/testing/selftests/bus1/Makefile new file mode 100644 index 000..cbcf689 --- /dev/null +++ b/tools/testing/selftests/bus1/Makefile @@ -0,0 +1,19 @@ +# Makefile for bus1 selftests + +CC = $(CROSS_COMPILE)gcc +CFLAGS += -D_FILE_OFFSET_BITS=64 -Wall -g -O2 +CFLAGS += -I../../../../include/uapi/ +CFLAGS += -I../../../../include/ +CFLAGS += -I../../../../usr/include/ + +TEST_PROGS := test-api test-io + +all: $(TEST_PROGS) + +%: %.c bus1-ioctl.h test.h ../../../../usr/include/linux/bus1.h + $(CC) $(CFLAGS) $< -o $@ + +include ../lib.mk + +clean: + $(RM) $(TEST_PROGS) diff --git a/tools/testing/selftests/bus1/bus1-ioctl.h b/tools/testing/selftests/bus1/bus1-ioctl.h new file mode 100644 index 000..552bd5d --- /dev/null +++ b/tools/testing/selftests/bus1/bus1-ioctl.h @@ -0,0 +1,111 @@ +#pragma once + +/* + * Copyright (C) 2013-2016 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +static inline int +bus1_ioctl(int fd, unsigned int cmd, void *arg) +{ + return (ioctl(fd, cmd, arg) >= 0) ? 0: -errno; +} + +static inline int +bus1_ioctl_peer_disconnect(int fd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_PEER_DISCONNECT) == sizeof(uint64_t), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_PEER_DISCONNECT, NULL); +} + +static inline int +bus1_ioctl_peer_query(int fd, struct bus1_cmd_peer_reset *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_PEER_QUERY) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_PEER_QUERY, cmd); +} + +static inline int +bus1_ioctl_peer_reset(int fd, struct bus1_cmd_peer_reset *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_PEER_RESET) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_PEER_RESET, cmd); +} + +static inline int +bus1_ioctl_handle_release(int fd, uint64_t *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_HANDLE_RELEASE) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_HANDLE_RELEASE, cmd); +} + +static inline int +bus1_ioctl_handle_transfer(int fd, struct bus1_cmd_handle_transfer *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_HANDLE_TRANSFER) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_HANDLE_TRANSFER, cmd); +} + +static inline int +bus1_ioctl_nodes_destroy(int fd, struct bus1_cmd_nodes_destroy *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_NODES_DESTROY) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_NODES_DESTROY, cmd); +} + +static inline int +bus1_ioctl_slice_release(int fd, uint64_t *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_SLICE_RELEASE) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_SLICE_RELEASE, cmd); +} + +static inline int +bus1_ioctl_send(int fd, struct bus1_cmd_send *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_SEND) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_SEND, cmd); +} + +static inline int +bus1_ioctl_recv(int fd, struct bus1_cmd_recv
[RFC v1 14/14] bus1: basic user-space kselftests
From: Tom Gundersen This adds kselftests integration and provides some basic API tests for bus1. Signed-off-by: Tom Gundersen Signed-off-by: David Herrmann --- tools/testing/selftests/bus1/.gitignore | 2 + tools/testing/selftests/bus1/Makefile | 19 ++ tools/testing/selftests/bus1/bus1-ioctl.h | 111 +++ tools/testing/selftests/bus1/test-api.c | 532 ++ tools/testing/selftests/bus1/test-io.c| 198 +++ tools/testing/selftests/bus1/test.h | 114 +++ 6 files changed, 976 insertions(+) create mode 100644 tools/testing/selftests/bus1/.gitignore create mode 100644 tools/testing/selftests/bus1/Makefile create mode 100644 tools/testing/selftests/bus1/bus1-ioctl.h create mode 100644 tools/testing/selftests/bus1/test-api.c create mode 100644 tools/testing/selftests/bus1/test-io.c create mode 100644 tools/testing/selftests/bus1/test.h diff --git a/tools/testing/selftests/bus1/.gitignore b/tools/testing/selftests/bus1/.gitignore new file mode 100644 index 000..76ecb9c --- /dev/null +++ b/tools/testing/selftests/bus1/.gitignore @@ -0,0 +1,2 @@ +test-api +test-io diff --git a/tools/testing/selftests/bus1/Makefile b/tools/testing/selftests/bus1/Makefile new file mode 100644 index 000..cbcf689 --- /dev/null +++ b/tools/testing/selftests/bus1/Makefile @@ -0,0 +1,19 @@ +# Makefile for bus1 selftests + +CC = $(CROSS_COMPILE)gcc +CFLAGS += -D_FILE_OFFSET_BITS=64 -Wall -g -O2 +CFLAGS += -I../../../../include/uapi/ +CFLAGS += -I../../../../include/ +CFLAGS += -I../../../../usr/include/ + +TEST_PROGS := test-api test-io + +all: $(TEST_PROGS) + +%: %.c bus1-ioctl.h test.h ../../../../usr/include/linux/bus1.h + $(CC) $(CFLAGS) $< -o $@ + +include ../lib.mk + +clean: + $(RM) $(TEST_PROGS) diff --git a/tools/testing/selftests/bus1/bus1-ioctl.h b/tools/testing/selftests/bus1/bus1-ioctl.h new file mode 100644 index 000..552bd5d --- /dev/null +++ b/tools/testing/selftests/bus1/bus1-ioctl.h @@ -0,0 +1,111 @@ +#pragma once + +/* + * Copyright (C) 2013-2016 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +static inline int +bus1_ioctl(int fd, unsigned int cmd, void *arg) +{ + return (ioctl(fd, cmd, arg) >= 0) ? 0: -errno; +} + +static inline int +bus1_ioctl_peer_disconnect(int fd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_PEER_DISCONNECT) == sizeof(uint64_t), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_PEER_DISCONNECT, NULL); +} + +static inline int +bus1_ioctl_peer_query(int fd, struct bus1_cmd_peer_reset *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_PEER_QUERY) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_PEER_QUERY, cmd); +} + +static inline int +bus1_ioctl_peer_reset(int fd, struct bus1_cmd_peer_reset *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_PEER_RESET) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_PEER_RESET, cmd); +} + +static inline int +bus1_ioctl_handle_release(int fd, uint64_t *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_HANDLE_RELEASE) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_HANDLE_RELEASE, cmd); +} + +static inline int +bus1_ioctl_handle_transfer(int fd, struct bus1_cmd_handle_transfer *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_HANDLE_TRANSFER) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_HANDLE_TRANSFER, cmd); +} + +static inline int +bus1_ioctl_nodes_destroy(int fd, struct bus1_cmd_nodes_destroy *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_NODES_DESTROY) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_NODES_DESTROY, cmd); +} + +static inline int +bus1_ioctl_slice_release(int fd, uint64_t *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_SLICE_RELEASE) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_SLICE_RELEASE, cmd); +} + +static inline int +bus1_ioctl_send(int fd, struct bus1_cmd_send *cmd) +{ + static_assert(_IOC_SIZE(BUS1_CMD_SEND) == sizeof(*cmd), + "ioctl is called with invalid argument size"); + + return bus1_ioctl(fd, BUS1_CMD_SEND, cmd); +} + +static inline int +bus1_ioctl_recv(int fd, struct bus1_cmd_recv *cmd) +{ +