Skip to content

Commit

Permalink
enable kunit to call agnocast function
Browse files Browse the repository at this point in the history
  • Loading branch information
sykwer committed Jan 29, 2025
1 parent 945d734 commit c6497b5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kmod/Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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


Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions kmod/agnocast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions kmod/agnocast.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 2 additions & 0 deletions kmod/agnocast_kunit.c → kmod/agnocast_kunit_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit c6497b5

Please sign in to comment.