Commit f6544dcd authored by Tiffany Yang's avatar Tiffany Yang Committed by Greg Kroah-Hartman
Browse files

binder: Convert binder_alloc selftests to KUnit



Convert the existing binder_alloc_selftest tests into KUnit tests. These
tests allocate and free an exhaustive combination of buffers with
various sizes and alignments. This change allows them to be run without
blocking or otherwise interfering with other processes in binder.

This test is refactored into more meaningful cases in the subsequent
patch.

Signed-off-by: default avatarTiffany Yang <ynaffit@google.com>
Acked-by: default avatarCarlos Llamas <cmllamas@google.com>
Link: https://lore.kernel.org/r/20250714185321.2417234-6-ynaffit@google.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5e024582
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -37,16 +37,6 @@ config ANDROID_BINDER_DEVICES
	  created. Each binder device has its own context manager, and is
	  therefore logically separated from the other devices.

config ANDROID_BINDER_IPC_SELFTEST
	bool "Android Binder IPC Driver Selftest"
	depends on ANDROID_BINDER_IPC
	help
	  This feature allows binder selftest to run.

	  Binder selftest checks the allocation and free of binder buffers
	  exhaustively with combinations of various buffer sizes and
	  alignments.

config ANDROID_BINDER_ALLOC_KUNIT_TEST
	tristate "KUnit Tests for Android Binder Alloc" if !KUNIT_ALL_TESTS
	depends on ANDROID_BINDER_IPC && KUNIT
+0 −1
Original line number Diff line number Diff line
@@ -3,5 +3,4 @@ ccflags-y += -I$(src) # needed for trace events

obj-$(CONFIG_ANDROID_BINDERFS)		+= binderfs.o
obj-$(CONFIG_ANDROID_BINDER_IPC)	+= binder.o binder_alloc.o
obj-$(CONFIG_ANDROID_BINDER_IPC_SELFTEST) += binder_alloc_selftest.o
obj-$(CONFIG_ANDROID_BINDER_ALLOC_KUNIT_TEST)	+= tests/
+0 −5
Original line number Diff line number Diff line
@@ -5709,11 +5709,6 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
	struct binder_thread *thread;
	void __user *ubuf = (void __user *)arg;

	/*pr_info("binder_ioctl: %d:%d %x %lx\n",
			proc->pid, current->pid, cmd, arg);*/

	binder_selftest_alloc(&proc->alloc);

	trace_binder_ioctl(cmd, arg);

	ret = wait_event_interruptible(binder_user_error_wait, binder_stop_on_user_error < 2);
+3 −0
Original line number Diff line number Diff line
@@ -697,6 +697,7 @@ struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc,
out:
	return buffer;
}
EXPORT_SYMBOL_IF_KUNIT(binder_alloc_new_buf);

static unsigned long buffer_start_page(struct binder_buffer *buffer)
{
@@ -875,6 +876,7 @@ void binder_alloc_free_buf(struct binder_alloc *alloc,
	binder_free_buf_locked(alloc, buffer);
	mutex_unlock(&alloc->mutex);
}
EXPORT_SYMBOL_IF_KUNIT(binder_alloc_free_buf);

/**
 * binder_alloc_mmap_handler() - map virtual address space for proc
@@ -1211,6 +1213,7 @@ enum lru_status binder_alloc_free_page(struct list_head *item,
err_mmget:
	return LRU_SKIP;
}
EXPORT_SYMBOL_IF_KUNIT(binder_alloc_free_page);

static unsigned long
binder_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
+0 −5
Original line number Diff line number Diff line
@@ -121,11 +121,6 @@ struct binder_alloc {
	bool oneway_spam_detected;
};

#ifdef CONFIG_ANDROID_BINDER_IPC_SELFTEST
void binder_selftest_alloc(struct binder_alloc *alloc);
#else
static inline void binder_selftest_alloc(struct binder_alloc *alloc) {}
#endif
enum lru_status binder_alloc_free_page(struct list_head *item,
				       struct list_lru_one *lru,
				       void *cb_arg);
Loading