mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nicholas Giunta <grahalt@google.com>
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Carlos Llamas" <cmllamas@google.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Shuah Khan" <shuah@kernel.org>
Cc: "Lyude Paul" <lyude@redhat.com>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org,
	"Nicholas Giunta" <grahalt@google.com>
Subject: [PATCH 4/4] selftests/binderfs: add idle timeout tests
Date: Fri, 04 Dec 2026 00:32:49 +0000	[thread overview]
Message-ID: <20261204-rust-binder-thread-spindown-v1-4-8702c42d4437@google.com> (raw)
In-Reply-To: <20261204-rust-binder-thread-spindown-v1-0-8702c42d4437@google.com>

Add kselftest coverage under FIXTURE(binderfs_idle) for Rust binder's
per-process idle thread timeout support (BINDER_SET_IDLE_TIMEOUT and
BR_FINISHED):

- ioctl_and_default_disabled: verify a fresh binder fd defaults to
  timeout=0 (disabled), validate BINDER_SET_IDLE_TIMEOUT argument bounds
  (-1 and INT64_MIN return EINVAL; INT64_MAX, 100, and 0 succeed), and
  verify resetting 100 -> 0 disables spin-down at runtime.
- spindown_and_respawn: verify BC_ENTER_LOOPER threads remain immune
  even with a peer in ready_threads, BC_REGISTER_LOOPER threads spin
  down with BR_FINISHED (without BR_SPAWN_LOOPER), and BINDER_THREAD_EXIT
  decrements started_thread_count so subsequent cycles spawn fresh
  looper threads.
- sole_ready_thread: verify the last remaining thread in ready_threads
  defers its idle timeout until a peer joins (then exits with
  BR_FINISHED), delivers BR_TRANSACTION rather than BR_FINISHED when
  woken by incoming work, and stays alive when BINDER_SET_IDLE_TIMEOUT(0)
  disables spin-down before a peer joins.

Probe BINDER_SET_IDLE_TIMEOUT(0) on a throwaway fd during fixture setup
so the tests skip cleanly on kernels without idle timeout support.

Assisted-by: Gemini
Signed-off-by: Nicholas Giunta <grahalt@google.com>
---
 .../selftests/filesystems/binderfs/binderfs_test.c | 487 +++++++++++++++++++++
 1 file changed, 487 insertions(+)

diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
index 7059bc9d25bd..39510117e395 100644
--- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
+++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
@@ -6,13 +6,16 @@
 #include <pthread.h>
 #include <sched.h>
 #include <stdbool.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/fsuid.h>
 #include <sys/ioctl.h>
+#include <sys/mman.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
+#include <sys/syscall.h>
 #include <sys/sysinfo.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -431,4 +434,488 @@ TEST(binderfs_test_unprivileged)
 	__do_binderfs_test(_metadata);
 }
 
+#define BINDER_MMAP_SIZE (128 * 1024)
+
+enum {
+	BR_SEEN_SPAWN    = 1,
+	BR_SEEN_FINISHED = 2,
+	BR_SEEN_TXN      = 4,
+	BR_SEEN_COMPLETE = 8,
+};
+
+struct looper_worker {
+	int fd;
+	__u32 cmd;
+	int tid;
+	int done;
+	int seen;
+};
+
+static int binder_wr(int fd, const void *wbuf, size_t wlen,
+		     void *rbuf, size_t rlen)
+{
+	struct binder_write_read bwr = {
+		.write_buffer = (binder_uintptr_t)(uintptr_t)wbuf,
+		.write_size = wlen,
+		.read_buffer = (binder_uintptr_t)(uintptr_t)rbuf,
+		.read_size = rlen,
+	};
+	int ret;
+
+	do {
+		ret = ioctl(fd, BINDER_WRITE_READ, &bwr);
+	} while (ret < 0 && errno == EINTR);
+
+	return ret < 0 ? -1 : (int)bwr.read_consumed;
+}
+
+static int binder_parse_read(const __u8 *buf, int len,
+			     binder_uintptr_t *txn_buf)
+{
+	size_t off = 0;
+	int seen = 0;
+
+	if (len < 0)
+		return -1;
+
+	while (off + sizeof(__u32) <= (size_t)len) {
+		__u32 cmd;
+
+		memcpy(&cmd, buf + off, sizeof(cmd));
+		off += sizeof(cmd);
+		if (cmd == BR_NOOP) {
+			continue;
+		} else if (cmd == BR_TRANSACTION_COMPLETE) {
+			seen |= BR_SEEN_COMPLETE;
+		} else if (cmd == BR_SPAWN_LOOPER) {
+			seen |= BR_SEEN_SPAWN;
+		} else if (cmd == BR_FINISHED) {
+			seen |= BR_SEEN_FINISHED;
+		} else if (cmd == BR_TRANSACTION) {
+			struct binder_transaction_data tr;
+
+			if (off + sizeof(tr) > (size_t)len)
+				return -1;
+			memcpy(&tr, buf + off, sizeof(tr));
+			off += sizeof(tr);
+			if (txn_buf)
+				*txn_buf = tr.data.ptr.buffer;
+			seen |= BR_SEEN_TXN;
+		} else {
+			return -1;
+		}
+	}
+
+	return off == (size_t)len ? seen : -1;
+}
+
+static int binder_free_buffer(int fd, binder_uintptr_t ptr)
+{
+	__u32 cmd = BC_FREE_BUFFER;
+	__u8 buf[sizeof(cmd) + sizeof(ptr)];
+
+	memcpy(buf, &cmd, sizeof(cmd));
+	memcpy(buf + sizeof(cmd), &ptr, sizeof(ptr));
+	return binder_wr(fd, buf, sizeof(buf), NULL, 0);
+}
+
+static int binder_send_oneway(int cfd)
+{
+	__u32 cmd = BC_TRANSACTION;
+	struct binder_transaction_data txn = { .flags = TF_ONE_WAY };
+	__u8 wbuf[sizeof(cmd) + sizeof(txn)], rbuf[128];
+	int n, seen;
+
+	memcpy(wbuf, &cmd, sizeof(cmd));
+	memcpy(wbuf + sizeof(cmd), &txn, sizeof(txn));
+	n = binder_wr(cfd, wbuf, sizeof(wbuf), rbuf, sizeof(rbuf));
+	seen = binder_parse_read(rbuf, n, NULL);
+	return (seen > 0 && (seen & BR_SEEN_COMPLETE)) ? 0 : -1;
+}
+
+static int binder_trigger_spawn(int sfd, int cfd)
+{
+	__u8 rbuf[512];
+	binder_uintptr_t txn_buf = 0;
+	int n, seen;
+
+	if (binder_send_oneway(cfd) < 0)
+		return -1;
+	n = binder_wr(sfd, NULL, 0, rbuf, sizeof(rbuf));
+	seen = binder_parse_read(rbuf, n, &txn_buf);
+	if (seen < 0 || !(seen & BR_SEEN_SPAWN))
+		return -1;
+	if ((seen & BR_SEEN_TXN) && binder_free_buffer(sfd, txn_buf) < 0)
+		return -1;
+	return 0;
+}
+
+static void *looper_worker_fn(void *arg)
+{
+	struct looper_worker *w = arg;
+	__u8 rbuf[512];
+	binder_uintptr_t txn_buf = 0;
+	__u32 exit_cmd = BC_EXIT_LOOPER;
+	__s32 zero = 0;
+	int n, seen;
+
+	__atomic_store_n(&w->tid, (int)syscall(SYS_gettid), __ATOMIC_RELEASE);
+	n = binder_wr(w->fd, &w->cmd, sizeof(w->cmd), rbuf, sizeof(rbuf));
+
+	seen = binder_parse_read(rbuf, n, &txn_buf);
+	if (seen > 0 && (seen & BR_SEEN_TXN) &&
+	    binder_free_buffer(w->fd, txn_buf) < 0)
+		seen = -1;
+	if (binder_wr(w->fd, &exit_cmd, sizeof(exit_cmd), NULL, 0) < 0 ||
+	    ioctl(w->fd, BINDER_THREAD_EXIT, &zero) < 0)
+		seen = -1;
+
+	w->seen = seen;
+	__atomic_store_n(&w->done, 1, __ATOMIC_RELEASE);
+	return NULL;
+}
+
+static int proc_read_file(const char *path, char *buf, size_t len)
+{
+	int pfd;
+	ssize_t n;
+
+	pfd = open(path, O_RDONLY | O_CLOEXEC);
+	if (pfd < 0)
+		return -1;
+	do {
+		n = read(pfd, buf, len - 1);
+	} while (n < 0 && errno == EINTR);
+	close(pfd);
+	if (n < 0)
+		return -1;
+	buf[n] = '\0';
+	return (int)n;
+}
+
+static int looper_start(pthread_t *thr, struct looper_worker *w,
+			int fd, __u32 cmd)
+{
+	char wpath[64], spath[64], buf[256], *p;
+	int i, tid, n;
+
+	memset(w, 0, sizeof(*w));
+	w->fd = fd;
+	w->cmd = cmd;
+	if (pthread_create(thr, NULL, looper_worker_fn, w) != 0)
+		return -1;
+
+	for (i = 0; i < 5000; i++) {
+		tid = __atomic_load_n(&w->tid, __ATOMIC_ACQUIRE);
+		if (tid || __atomic_load_n(&w->done, __ATOMIC_ACQUIRE))
+			break;
+		usleep(1000);
+	}
+	if (__atomic_load_n(&w->done, __ATOMIC_ACQUIRE))
+		return 0;
+	if (!tid)
+		return -1;
+
+	snprintf(wpath, sizeof(wpath), "/proc/self/task/%d/wchan", tid);
+	snprintf(spath, sizeof(spath), "/proc/self/task/%d/stat", tid);
+	for (i = 0; i < 5000; i++) {
+		if (__atomic_load_n(&w->done, __ATOMIC_ACQUIRE))
+			return 0;
+		n = proc_read_file(wpath, buf, sizeof(buf));
+		if (n > 0) {
+			if (strcmp(buf, "rust_binder_wait") == 0)
+				return 0;
+			if (strcmp(buf, "0") == 0 || strstr(buf, "futex")) {
+				usleep(1000);
+				continue;
+			}
+		}
+		n = proc_read_file(spath, buf, sizeof(buf));
+		if (n < 0)
+			return __atomic_load_n(&w->done, __ATOMIC_ACQUIRE) ? 0 : -1;
+		p = strrchr(buf, ')');
+		if (p && p[1] == ' ' && p[2] == 'S')
+			return 0;
+		usleep(1000);
+	}
+	return -1;
+}
+
+static int looper_join(pthread_t thr, struct looper_worker *w)
+{
+	int i;
+
+	for (i = 0; i < 5000; i++) {
+		if (__atomic_load_n(&w->done, __ATOMIC_ACQUIRE))
+			return pthread_join(thr, NULL);
+		usleep(1000);
+	}
+	return -1;
+}
+
+struct binderfs_idle_ctx {
+	char mntpt[sizeof(P_tmpdir "/binderfs_XXXXXX")];
+	int sfd;
+	int cfd;
+	void *smap;
+};
+
+FIXTURE(binderfs_idle) {
+	struct binderfs_idle_ctx ctx;
+};
+
+static void idle_cleanup(struct binderfs_idle_ctx *ctx)
+{
+	if (ctx->cfd >= 0) {
+		close(ctx->cfd);
+		ctx->cfd = -1;
+	}
+	if (ctx->smap && ctx->smap != MAP_FAILED) {
+		munmap(ctx->smap, BINDER_MMAP_SIZE);
+		ctx->smap = MAP_FAILED;
+	}
+	if (ctx->sfd >= 0) {
+		close(ctx->sfd);
+		ctx->sfd = -1;
+	}
+	binderfs_umount(ctx->mntpt);
+}
+
+FIXTURE_SETUP(binderfs_idle)
+{
+	char path[sizeof(self->ctx.mntpt) + 1 + BINDERFS_MAX_NAME];
+	__u32 max_threads = 1, enter = BC_ENTER_LOOPER;
+	__s64 probe_timeout = 0;
+	__s32 zero = 0;
+	int probe_fd, ret;
+
+	self->ctx.mntpt[0] = '\0';
+	self->ctx.sfd = -1;
+	self->ctx.cfd = -1;
+	self->ctx.smap = MAP_FAILED;
+
+	if (geteuid() != 0) {
+		ret = enter_userns();
+		if (ret < 0)
+			SKIP(return, "enter_userns() unsupported: %s",
+			     strerror(-ret));
+	}
+
+	change_mountns(_metadata);
+
+	ret = binderfs_mount(self->ctx.mntpt, sizeof(self->ctx.mntpt));
+	if (ret == -ENODEV)
+		SKIP(return, "binderfs missing");
+	ASSERT_EQ(ret, 0);
+
+	ASSERT_EQ(binderfs_add_device(self->ctx.mntpt, "my-binder", NULL), 0) {
+		idle_cleanup(&self->ctx);
+	}
+
+	snprintf(path, sizeof(path), "%s/my-binder", self->ctx.mntpt);
+
+	/* Probe ioctl on a throwaway fd so sfd keeps its default timeout. */
+	probe_fd = open(path, O_RDWR | O_CLOEXEC);
+	ASSERT_GE(probe_fd, 0) {
+		idle_cleanup(&self->ctx);
+	}
+	ret = ioctl(probe_fd, BINDER_SET_IDLE_TIMEOUT, &probe_timeout);
+	if (ret < 0 && (errno == EINVAL || errno == ENOTTY)) {
+		close(probe_fd);
+		idle_cleanup(&self->ctx);
+		SKIP(return, "BINDER_SET_IDLE_TIMEOUT not supported");
+	}
+	close(probe_fd);
+	ASSERT_EQ(ret, 0) {
+		idle_cleanup(&self->ctx);
+	}
+
+	self->ctx.sfd = open(path, O_RDWR | O_CLOEXEC);
+	ASSERT_GE(self->ctx.sfd, 0) {
+		idle_cleanup(&self->ctx);
+	}
+	self->ctx.smap = mmap(NULL, BINDER_MMAP_SIZE, PROT_READ, MAP_PRIVATE,
+			      self->ctx.sfd, 0);
+	ASSERT_NE(self->ctx.smap, MAP_FAILED) {
+		idle_cleanup(&self->ctx);
+	}
+	ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_MAX_THREADS, &max_threads), 0) {
+		idle_cleanup(&self->ctx);
+	}
+	ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_CONTEXT_MGR, &zero), 0) {
+		idle_cleanup(&self->ctx);
+	}
+	ASSERT_GE(binder_wr(self->ctx.sfd, &enter, sizeof(enter), NULL, 0), 0) {
+		idle_cleanup(&self->ctx);
+	}
+
+	self->ctx.cfd = open(path, O_RDWR | O_CLOEXEC);
+	ASSERT_GE(self->ctx.cfd, 0) {
+		idle_cleanup(&self->ctx);
+	}
+	ASSERT_EQ(binder_trigger_spawn(self->ctx.sfd, self->ctx.cfd), 0) {
+		idle_cleanup(&self->ctx);
+	}
+}
+
+FIXTURE_TEARDOWN(binderfs_idle)
+{
+	idle_cleanup(&self->ctx);
+}
+
+static void assert_no_spindown(struct __test_metadata *_metadata,
+			       int sfd, int cfd, useconds_t wait_us,
+			       bool *spawned)
+{
+	struct looper_worker w_reg, w_enter;
+	pthread_t t_reg, t_enter;
+
+	ASSERT_EQ(looper_start(&t_reg, &w_reg, sfd, BC_REGISTER_LOOPER), 0);
+	ASSERT_EQ(looper_start(&t_enter, &w_enter, sfd, BC_ENTER_LOOPER), 0);
+
+	usleep(wait_us);
+	EXPECT_FALSE(__atomic_load_n(&w_reg.done, __ATOMIC_ACQUIRE));
+	EXPECT_FALSE(__atomic_load_n(&w_enter.done, __ATOMIC_ACQUIRE));
+
+	ASSERT_EQ(binder_send_oneway(cfd), 0);
+	ASSERT_EQ(binder_send_oneway(cfd), 0);
+	ASSERT_EQ(looper_join(t_reg, &w_reg), 0);
+	ASSERT_EQ(looper_join(t_enter, &w_enter), 0);
+
+	EXPECT_GT(w_reg.seen, 0);
+	EXPECT_EQ(w_reg.seen & (BR_SEEN_TXN | BR_SEEN_FINISHED), BR_SEEN_TXN);
+	EXPECT_GT(w_enter.seen, 0);
+	EXPECT_EQ(w_enter.seen & (BR_SEEN_TXN | BR_SEEN_FINISHED), BR_SEEN_TXN);
+
+	if (spawned)
+		*spawned = (w_reg.seen > 0 && (w_reg.seen & BR_SEEN_SPAWN)) ||
+			   (w_enter.seen > 0 && (w_enter.seen & BR_SEEN_SPAWN));
+}
+
+TEST_F(binderfs_idle, ioctl_and_default_disabled)
+{
+	bool spawned = false;
+	__s64 timeout;
+
+	/* Default timeout is disabled (0); verify idle threads stay parked. */
+	assert_no_spindown(_metadata, self->ctx.sfd, self->ctx.cfd, 600 * 1000,
+			   &spawned);
+
+	timeout = -1;
+	EXPECT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), -1);
+	EXPECT_EQ(errno, EINVAL);
+
+	timeout = INT64_MIN;
+	EXPECT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), -1);
+	EXPECT_EQ(errno, EINVAL);
+
+	timeout = INT64_MAX;
+	EXPECT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), 0);
+
+	timeout = 100;
+	ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), 0);
+
+	/* Resetting 100 -> 0 must disable spin-down at runtime. */
+	timeout = 0;
+	ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), 0);
+	if (!spawned)
+		ASSERT_EQ(binder_trigger_spawn(self->ctx.sfd, self->ctx.cfd), 0);
+	assert_no_spindown(_metadata, self->ctx.sfd, self->ctx.cfd, 250 * 1000,
+			   NULL);
+}
+
+TEST_F(binderfs_idle, spindown_and_respawn)
+{
+	__s64 timeout = 100;
+	int cycle;
+
+	ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), 0);
+
+	/*
+	 * Two cycles with max_threads=1 prove:
+	 * 1. BC_ENTER_LOOPER is immune even with a peer (lead-wait on cycle 0
+	 *    would trigger deferred timeout + BR_FINISHED on w_reg arrival if
+	 *    Entered could time out).
+	 * 2. BC_REGISTER_LOOPER exits with BR_FINISHED (no BR_SPAWN_LOOPER).
+	 * 3. BINDER_THREAD_EXIT decrements started_thread_count so waking
+	 *    w_enter emits a fresh BR_SPAWN_LOOPER for the next cycle.
+	 */
+	for (cycle = 0; cycle < 2; cycle++) {
+		struct looper_worker w_enter, w_reg;
+		pthread_t t_enter, t_reg;
+
+		ASSERT_EQ(looper_start(&t_enter, &w_enter, self->ctx.sfd,
+				       BC_ENTER_LOOPER), 0);
+		if (cycle == 0)
+			usleep(200 * 1000);
+		ASSERT_EQ(looper_start(&t_reg, &w_reg, self->ctx.sfd,
+				       BC_REGISTER_LOOPER), 0);
+
+		ASSERT_EQ(looper_join(t_reg, &w_reg), 0);
+		EXPECT_EQ(w_reg.seen, BR_SEEN_FINISHED);
+		EXPECT_FALSE(__atomic_load_n(&w_enter.done, __ATOMIC_ACQUIRE));
+
+		ASSERT_EQ(binder_send_oneway(self->ctx.cfd), 0);
+		ASSERT_EQ(looper_join(t_enter, &w_enter), 0);
+		EXPECT_EQ(w_enter.seen, BR_SEEN_TXN | BR_SEEN_SPAWN);
+	}
+}
+
+TEST_F(binderfs_idle, sole_ready_thread)
+{
+	struct looper_worker w_reg, w_enter;
+	pthread_t t_reg, t_enter;
+	__s64 timeout = 100;
+
+	ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), 0);
+
+	/* Sole ready thread defers timeout, then exits once a peer joins. */
+	ASSERT_EQ(looper_start(&t_reg, &w_reg, self->ctx.sfd,
+			       BC_REGISTER_LOOPER), 0);
+	usleep(250 * 1000);
+	EXPECT_FALSE(__atomic_load_n(&w_reg.done, __ATOMIC_ACQUIRE));
+
+	ASSERT_EQ(looper_start(&t_enter, &w_enter, self->ctx.sfd,
+			       BC_ENTER_LOOPER), 0);
+	ASSERT_EQ(looper_join(t_reg, &w_reg), 0);
+	EXPECT_EQ(w_reg.seen, BR_SEEN_FINISHED);
+
+	ASSERT_EQ(binder_send_oneway(self->ctx.cfd), 0);
+	ASSERT_EQ(looper_join(t_enter, &w_enter), 0);
+	EXPECT_EQ(w_enter.seen, BR_SEEN_TXN | BR_SEEN_SPAWN);
+
+	/* Deferred timeout woken by work delivers BR_TRANSACTION, not BR_FINISHED. */
+	ASSERT_EQ(looper_start(&t_reg, &w_reg, self->ctx.sfd,
+			       BC_REGISTER_LOOPER), 0);
+	usleep(250 * 1000);
+	EXPECT_FALSE(__atomic_load_n(&w_reg.done, __ATOMIC_ACQUIRE));
+
+	ASSERT_EQ(binder_send_oneway(self->ctx.cfd), 0);
+	ASSERT_EQ(looper_join(t_reg, &w_reg), 0);
+	EXPECT_EQ(w_reg.seen, BR_SEEN_TXN);
+
+	/* Disabling timeout while deferred prevents BR_FINISHED when a peer joins. */
+	ASSERT_EQ(binder_trigger_spawn(self->ctx.sfd, self->ctx.cfd), 0);
+	ASSERT_EQ(looper_start(&t_reg, &w_reg, self->ctx.sfd,
+			       BC_REGISTER_LOOPER), 0);
+	usleep(250 * 1000);
+	EXPECT_FALSE(__atomic_load_n(&w_reg.done, __ATOMIC_ACQUIRE));
+
+	timeout = 0;
+	ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), 0);
+	ASSERT_EQ(looper_start(&t_enter, &w_enter, self->ctx.sfd,
+			       BC_ENTER_LOOPER), 0);
+	usleep(150 * 1000);
+	EXPECT_FALSE(__atomic_load_n(&w_reg.done, __ATOMIC_ACQUIRE));
+
+	ASSERT_EQ(binder_send_oneway(self->ctx.cfd), 0);
+	ASSERT_EQ(binder_send_oneway(self->ctx.cfd), 0);
+	ASSERT_EQ(looper_join(t_reg, &w_reg), 0);
+	ASSERT_EQ(looper_join(t_enter, &w_enter), 0);
+	EXPECT_GT(w_reg.seen, 0);
+	EXPECT_EQ(w_reg.seen & (BR_SEEN_TXN | BR_SEEN_FINISHED), BR_SEEN_TXN);
+	EXPECT_GT(w_enter.seen, 0);
+	EXPECT_EQ(w_enter.seen & (BR_SEEN_TXN | BR_SEEN_FINISHED), BR_SEEN_TXN);
+}
+
 TEST_HARNESS_MAIN

-- 
2.56.1.915.g69d5ec7298-goog


      parent reply	other threads:[~2026-12-04  0:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  0:32 [PATCH 0/4] rust_binder: add support for idle thread timeout Nicholas Giunta
2026-12-04  0:32 ` [PATCH 1/4] rust: sync: condvar: add wait_interruptible_freezable_timeout() Nicholas Giunta
2026-12-04  0:32 ` [PATCH 2/4] rust_binder: add support for thread timeout Nicholas Giunta
2026-12-04  0:32 ` [PATCH 3/4] selftests/binderfs: extract shared namespace and mount helpers Nicholas Giunta
2026-12-04  0:32 ` Nicholas Giunta [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204-rust-binder-thread-spindown-v1-4-8702c42d4437@google.com \
    --to=grahalt@google.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=brauner@kernel.org \
    --cc=cmllamas@google.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=tamird@kernel.org \
    --cc=tkjos@android.com \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®