Re: [RFC v3 9/9] kmsg: selftests
On Mon, 2015-10-19 at 14:58 +0200, Paul Osmialowski wrote: > This patch adds selftests framework and four test scenarios for kmsg. > > The framework shape and code was inspired by similar selftests framework > for kdbus. > diff --git a/tools/testing/selftests/kmsg/Makefile > b/tools/testing/selftests/kmsg/Makefile > new file mode 100644 > index 000..b4ba892 > --- /dev/null > +++ b/tools/testing/selftests/kmsg/Makefile > @@ -0,0 +1,30 @@ > +CFLAGS += -I../../../../usr/include/ > +CFLAGS += -I../../../../samples/kmsg/ > +CFLAGS += -I../../../../include/uapi/ Please don't directly include the unexported kernel headers. > +CFLAGS += -std=gnu99 -Wall > +CFLAGS += -DKBUILD_MODNAME=\"kmsg\" -D_GNU_SOURCE Are you building userspace code here? I'm not sure why you need KBUILD_MODNAME. > +CFLAGS += -pthread > +LDLIBS += -pthread > + > +OBJS= \ > + kmsg-test.o \ > + test-buffer-add-del.o \ > + test-buffer-add-write-read-del.o\ > + test-buffer-buf-torture.o \ > + test-buffer-buf-multithreaded-torture.o > + > +all: kmsg-test > + > +include ../lib.mk > + > +%.o: %.c kmsg-test.h > + $(CC) $(CFLAGS) -c $< -o $@ > + > +kmsg-test: $(OBJS) > + $(CC) $(CFLAGS) $^ $(LDLIBS) -o $@ Those look the same as the implicit rules to me, so I don't think you need to spell them out. > + > +run_tests: > + ./kmsg-test --tap This should be giving you a warning about redefining run_tests. It sounds like you don't actually need to pass --tap, so you don't need to override run_tests. So you should just define: TEST_PROGS := kmsg-test Before you include lib.mk and then both the run and emit rules will work without any more work on your part. cheers -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC v3 9/9] kmsg: selftests
On Mon, 2015-10-19 at 14:58 +0200, Paul Osmialowski wrote: > This patch adds selftests framework and four test scenarios for kmsg. > > The framework shape and code was inspired by similar selftests framework > for kdbus. > diff --git a/tools/testing/selftests/kmsg/Makefile > b/tools/testing/selftests/kmsg/Makefile > new file mode 100644 > index 000..b4ba892 > --- /dev/null > +++ b/tools/testing/selftests/kmsg/Makefile > @@ -0,0 +1,30 @@ > +CFLAGS += -I../../../../usr/include/ > +CFLAGS += -I../../../../samples/kmsg/ > +CFLAGS += -I../../../../include/uapi/ Please don't directly include the unexported kernel headers. > +CFLAGS += -std=gnu99 -Wall > +CFLAGS += -DKBUILD_MODNAME=\"kmsg\" -D_GNU_SOURCE Are you building userspace code here? I'm not sure why you need KBUILD_MODNAME. > +CFLAGS += -pthread > +LDLIBS += -pthread > + > +OBJS= \ > + kmsg-test.o \ > + test-buffer-add-del.o \ > + test-buffer-add-write-read-del.o\ > + test-buffer-buf-torture.o \ > + test-buffer-buf-multithreaded-torture.o > + > +all: kmsg-test > + > +include ../lib.mk > + > +%.o: %.c kmsg-test.h > + $(CC) $(CFLAGS) -c $< -o $@ > + > +kmsg-test: $(OBJS) > + $(CC) $(CFLAGS) $^ $(LDLIBS) -o $@ Those look the same as the implicit rules to me, so I don't think you need to spell them out. > + > +run_tests: > + ./kmsg-test --tap This should be giving you a warning about redefining run_tests. It sounds like you don't actually need to pass --tap, so you don't need to override run_tests. So you should just define: TEST_PROGS := kmsg-test Before you include lib.mk and then both the run and emit rules will work without any more work on your part. cheers -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v3 9/9] kmsg: selftests
This patch adds selftests framework and four test scenarios for kmsg. The framework shape and code was inspired by similar selftests framework for kdbus. Signed-off-by: Paul Osmialowski --- samples/kmsg/kmsg-api.h| 44 +++ tools/testing/selftests/Makefile | 1 + tools/testing/selftests/kmsg/.gitignore| 1 + tools/testing/selftests/kmsg/Makefile | 30 ++ tools/testing/selftests/kmsg/kmsg-test.c | 329 + tools/testing/selftests/kmsg/kmsg-test.h | 34 +++ tools/testing/selftests/kmsg/test-buffer-add-del.c | 76 + .../kmsg/test-buffer-add-write-read-del.c | 161 ++ .../kmsg/test-buffer-buf-multithreaded-torture.c | 199 + .../selftests/kmsg/test-buffer-buf-torture.c | 139 + 10 files changed, 1014 insertions(+) create mode 100644 samples/kmsg/kmsg-api.h create mode 100644 tools/testing/selftests/kmsg/.gitignore create mode 100644 tools/testing/selftests/kmsg/Makefile create mode 100644 tools/testing/selftests/kmsg/kmsg-test.c create mode 100644 tools/testing/selftests/kmsg/kmsg-test.h create mode 100644 tools/testing/selftests/kmsg/test-buffer-add-del.c create mode 100644 tools/testing/selftests/kmsg/test-buffer-add-write-read-del.c create mode 100644 tools/testing/selftests/kmsg/test-buffer-buf-multithreaded-torture.c create mode 100644 tools/testing/selftests/kmsg/test-buffer-buf-torture.c diff --git a/samples/kmsg/kmsg-api.h b/samples/kmsg/kmsg-api.h new file mode 100644 index 000..9004acd --- /dev/null +++ b/samples/kmsg/kmsg-api.h @@ -0,0 +1,44 @@ +#ifndef KMSG_API_H +#define KMSG_API_H + +#include +#include +#include +#include + +static inline int kmsg_cmd_buffer_add(int fd, struct kmsg_cmd_buffer_add *cmd) +{ + int ret = ioctl(fd, KMSG_CMD_BUFFER_ADD, cmd); + + return (ret < 0) ? (errno > 0 ? -errno : -EINVAL) : 0; +} + +static inline int kmsg_cmd_buffer_del(int fd, int *minor) +{ + int ret = ioctl(fd, KMSG_CMD_BUFFER_DEL, minor); + + return (ret < 0) ? (errno > 0 ? -errno : -EINVAL) : 0; +} + +static inline int kmsg_cmd_get_buf_size(int fd, uint32_t *size) +{ + int ret = ioctl(fd, KMSG_CMD_GET_BUF_SIZE, size); + + return (ret < 0) ? (errno > 0 ? -errno : -EINVAL) : 0; +} + +static inline int kmsg_cmd_get_read_size_max(int fd, uint32_t *max_size) +{ + int ret = ioctl(fd, KMSG_CMD_GET_READ_SIZE_MAX, max_size); + + return (ret < 0) ? (errno > 0 ? -errno : -EINVAL) : 0; +} + +static inline int kmsg_cmd_clear(int fd) +{ + int ret = ioctl(fd, KMSG_CMD_CLEAR); + + return (ret < 0) ? (errno > 0 ? -errno : -EINVAL) : 0; +} + +#endif /* KMSG_API_H */ diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index bf4ece6..b7bdf58 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -7,6 +7,7 @@ TARGETS += ftrace TARGETS += futex TARGETS += kcmp TARGETS += kdbus +TARGETS += kmsg TARGETS += lib TARGETS += membarrier TARGETS += memfd diff --git a/tools/testing/selftests/kmsg/.gitignore b/tools/testing/selftests/kmsg/.gitignore new file mode 100644 index 000..687d517 --- /dev/null +++ b/tools/testing/selftests/kmsg/.gitignore @@ -0,0 +1 @@ +kmsg-test diff --git a/tools/testing/selftests/kmsg/Makefile b/tools/testing/selftests/kmsg/Makefile new file mode 100644 index 000..b4ba892 --- /dev/null +++ b/tools/testing/selftests/kmsg/Makefile @@ -0,0 +1,30 @@ +CFLAGS += -I../../../../usr/include/ +CFLAGS += -I../../../../samples/kmsg/ +CFLAGS += -I../../../../include/uapi/ +CFLAGS += -std=gnu99 -Wall +CFLAGS += -DKBUILD_MODNAME=\"kmsg\" -D_GNU_SOURCE +CFLAGS += -pthread +LDLIBS += -pthread + +OBJS= \ + kmsg-test.o \ + test-buffer-add-del.o \ + test-buffer-add-write-read-del.o\ + test-buffer-buf-torture.o \ + test-buffer-buf-multithreaded-torture.o + +all: kmsg-test + +include ../lib.mk + +%.o: %.c kmsg-test.h + $(CC) $(CFLAGS) -c $< -o $@ + +kmsg-test: $(OBJS) + $(CC) $(CFLAGS) $^ $(LDLIBS) -o $@ + +run_tests: + ./kmsg-test --tap + +clean: + rm -f *.o kmsg-test diff --git a/tools/testing/selftests/kmsg/kmsg-test.c b/tools/testing/selftests/kmsg/kmsg-test.c new file mode 100644 index 000..4f17b73 --- /dev/null +++ b/tools/testing/selftests/kmsg/kmsg-test.c @@ -0,0 +1,329 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kmsg-test.h" + +struct kmsg_test { + const char *name; + const char *desc; + int (*func)(const struct kmsg_test_args *args); +}; + +static const struct kmsg_test tests[] = { + { + .name = "buffer-add-del", + .desc = "create and delete kmsg devices", + .func = kmsg_test_buffer_add_del, +
[RFC v3 9/9] kmsg: selftests
This patch adds selftests framework and four test scenarios for kmsg. The framework shape and code was inspired by similar selftests framework for kdbus. Signed-off-by: Paul Osmialowski--- samples/kmsg/kmsg-api.h| 44 +++ tools/testing/selftests/Makefile | 1 + tools/testing/selftests/kmsg/.gitignore| 1 + tools/testing/selftests/kmsg/Makefile | 30 ++ tools/testing/selftests/kmsg/kmsg-test.c | 329 + tools/testing/selftests/kmsg/kmsg-test.h | 34 +++ tools/testing/selftests/kmsg/test-buffer-add-del.c | 76 + .../kmsg/test-buffer-add-write-read-del.c | 161 ++ .../kmsg/test-buffer-buf-multithreaded-torture.c | 199 + .../selftests/kmsg/test-buffer-buf-torture.c | 139 + 10 files changed, 1014 insertions(+) create mode 100644 samples/kmsg/kmsg-api.h create mode 100644 tools/testing/selftests/kmsg/.gitignore create mode 100644 tools/testing/selftests/kmsg/Makefile create mode 100644 tools/testing/selftests/kmsg/kmsg-test.c create mode 100644 tools/testing/selftests/kmsg/kmsg-test.h create mode 100644 tools/testing/selftests/kmsg/test-buffer-add-del.c create mode 100644 tools/testing/selftests/kmsg/test-buffer-add-write-read-del.c create mode 100644 tools/testing/selftests/kmsg/test-buffer-buf-multithreaded-torture.c create mode 100644 tools/testing/selftests/kmsg/test-buffer-buf-torture.c diff --git a/samples/kmsg/kmsg-api.h b/samples/kmsg/kmsg-api.h new file mode 100644 index 000..9004acd --- /dev/null +++ b/samples/kmsg/kmsg-api.h @@ -0,0 +1,44 @@ +#ifndef KMSG_API_H +#define KMSG_API_H + +#include +#include +#include +#include + +static inline int kmsg_cmd_buffer_add(int fd, struct kmsg_cmd_buffer_add *cmd) +{ + int ret = ioctl(fd, KMSG_CMD_BUFFER_ADD, cmd); + + return (ret < 0) ? (errno > 0 ? -errno : -EINVAL) : 0; +} + +static inline int kmsg_cmd_buffer_del(int fd, int *minor) +{ + int ret = ioctl(fd, KMSG_CMD_BUFFER_DEL, minor); + + return (ret < 0) ? (errno > 0 ? -errno : -EINVAL) : 0; +} + +static inline int kmsg_cmd_get_buf_size(int fd, uint32_t *size) +{ + int ret = ioctl(fd, KMSG_CMD_GET_BUF_SIZE, size); + + return (ret < 0) ? (errno > 0 ? -errno : -EINVAL) : 0; +} + +static inline int kmsg_cmd_get_read_size_max(int fd, uint32_t *max_size) +{ + int ret = ioctl(fd, KMSG_CMD_GET_READ_SIZE_MAX, max_size); + + return (ret < 0) ? (errno > 0 ? -errno : -EINVAL) : 0; +} + +static inline int kmsg_cmd_clear(int fd) +{ + int ret = ioctl(fd, KMSG_CMD_CLEAR); + + return (ret < 0) ? (errno > 0 ? -errno : -EINVAL) : 0; +} + +#endif /* KMSG_API_H */ diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index bf4ece6..b7bdf58 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -7,6 +7,7 @@ TARGETS += ftrace TARGETS += futex TARGETS += kcmp TARGETS += kdbus +TARGETS += kmsg TARGETS += lib TARGETS += membarrier TARGETS += memfd diff --git a/tools/testing/selftests/kmsg/.gitignore b/tools/testing/selftests/kmsg/.gitignore new file mode 100644 index 000..687d517 --- /dev/null +++ b/tools/testing/selftests/kmsg/.gitignore @@ -0,0 +1 @@ +kmsg-test diff --git a/tools/testing/selftests/kmsg/Makefile b/tools/testing/selftests/kmsg/Makefile new file mode 100644 index 000..b4ba892 --- /dev/null +++ b/tools/testing/selftests/kmsg/Makefile @@ -0,0 +1,30 @@ +CFLAGS += -I../../../../usr/include/ +CFLAGS += -I../../../../samples/kmsg/ +CFLAGS += -I../../../../include/uapi/ +CFLAGS += -std=gnu99 -Wall +CFLAGS += -DKBUILD_MODNAME=\"kmsg\" -D_GNU_SOURCE +CFLAGS += -pthread +LDLIBS += -pthread + +OBJS= \ + kmsg-test.o \ + test-buffer-add-del.o \ + test-buffer-add-write-read-del.o\ + test-buffer-buf-torture.o \ + test-buffer-buf-multithreaded-torture.o + +all: kmsg-test + +include ../lib.mk + +%.o: %.c kmsg-test.h + $(CC) $(CFLAGS) -c $< -o $@ + +kmsg-test: $(OBJS) + $(CC) $(CFLAGS) $^ $(LDLIBS) -o $@ + +run_tests: + ./kmsg-test --tap + +clean: + rm -f *.o kmsg-test diff --git a/tools/testing/selftests/kmsg/kmsg-test.c b/tools/testing/selftests/kmsg/kmsg-test.c new file mode 100644 index 000..4f17b73 --- /dev/null +++ b/tools/testing/selftests/kmsg/kmsg-test.c @@ -0,0 +1,329 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kmsg-test.h" + +struct kmsg_test { + const char *name; + const char *desc; + int (*func)(const struct kmsg_test_args *args); +}; + +static const struct kmsg_test tests[] = { + { + .name = "buffer-add-del", + .desc = "create and delete kmsg devices", + .func =