diff --git a/kmod/Makefile b/kmod/Makefile index b514ded1..4392050a 100644 --- a/kmod/Makefile +++ b/kmod/Makefile @@ -1,11 +1,11 @@ obj-m := agnocast.o CFLAGS_agnocast.o := -Wall -Werror +CFLAGS_agnocast_kunit.o := -Wall -Werror KERNEL_VERSION := $(shell uname -r) KERNEL_MAJOR := $(shell echo $(KERNEL_VERSION) | cut -d '.' -f 1) KERNEL_MINOR := $(shell echo $(KERNEL_VERSION) | cut -d '.' -f 2) - # In Linux kernel v5.17 and earlier, the top-level Linux Makefile specifies -std=gnu89, # so it is necessary to declare the variable used as the iterator in the for loop beforehand. # For example: @@ -16,6 +16,7 @@ KERNEL_MINOR := $(shell echo $(KERNEL_VERSION) | cut -d '.' -f 2) # Therefore, add -std=gnu11 to suppress this error. ifeq ($(shell expr $(KERNEL_MAJOR) \< 5 \| $(KERNEL_MAJOR) = 5 \& $(KERNEL_MINOR) \<= 17), 1) CFLAGS_agnocast.o += -std=gnu11 + CFLAGS_agnocast_kunit.o += -std=gnu11 endif @@ -25,12 +26,15 @@ endif # this, we should add -Wno-declaration-after-statement. ifeq ($(shell expr $(KERNEL_MAJOR) \< 6 \| $(KERNEL_MAJOR) = 6 \& $(KERNEL_MINOR) \<= 4), 1) CFLAGS_agnocast.o += -Wno-declaration-after-statement + CFLAGS_agnocast_kunit.o += -Wno-declaration-after-statement endif # For KUnit ifeq ($(CONFIG_KUNIT),y) obj-m += agnocast_kunit.o + agnocast_kunit-m := agnocast_kunit_main.o agnocast.o endif + ifeq ($(CONFIG_GCOV_KERNEL),y) CFLAGS_agnocast.o += -fprofile-arcs -ftest-coverage CFLAGS_agnocast_kunit.o += -fprofile-arcs -ftest-coverage diff --git a/kmod/agnocast.c b/kmod/agnocast.c index 2ab10842..bc8aafae 100644 --- a/kmod/agnocast.c +++ b/kmod/agnocast.c @@ -1690,6 +1690,13 @@ static struct kprobe kp = { // ========================================= +void tmp_func(void) +{ + printk("tmp_func"); +} + +EXPORT_SYMBOL(tmp_func); + static int agnocast_init(void) { mutex_init(&global_mutex); diff --git a/kmod/agnocast.h b/kmod/agnocast.h index f9b6b780..3a32efca 100644 --- a/kmod/agnocast.h +++ b/kmod/agnocast.h @@ -143,3 +143,5 @@ union ioctl_get_subscriber_num_args { #define AGNOCAST_TAKE_MSG_CMD _IOW('M', 5, union ioctl_take_msg_args) #define AGNOCAST_NEW_SHM_CMD _IOW('I', 1, union ioctl_new_shm_args) #define AGNOCAST_GET_SUBSCRIBER_NUM_CMD _IOW('G', 1, union ioctl_get_subscriber_num_args) + +void tmp_func(void); diff --git a/kmod/agnocast_kunit.c b/kmod/agnocast_kunit_main.c similarity index 93% rename from kmod/agnocast_kunit.c rename to kmod/agnocast_kunit_main.c index 7cef1e48..c091e481 100644 --- a/kmod/agnocast_kunit.c +++ b/kmod/agnocast_kunit_main.c @@ -6,6 +6,8 @@ MODULE_LICENSE("Dual BSD/GPL"); static void agnocast_sample_test_case(struct kunit * test) { + printk("hoge"); + tmp_func(); KUNIT_EXPECT_EQ(test, 1 + 1, 2); }