tools/testing/selftests/drivers/ntsync/ntsync.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/ntsync/ntsync.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/drivers/ntsync/ntsync.c- Extension
.c- Size
- 31944 bytes
- Lines
- 1344
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/ioctl.hsys/stat.hfcntl.htime.hpthread.hlinux/ntsync.hkselftest_harness.h
Detected Declarations
struct wake_argsstruct wait_argsfunction Copyrightfunction release_semfunction read_mutex_statefunction unlock_mutexfunction read_event_statefunction wait_objsfunction wait_anyfunction wait_allfunction wait_any_alertfunction wait_all_alertfunction get_abs_timeoutfunction wait_for_thread
Annotated Snippet
struct wake_args {
int fd;
int obj;
};
struct wait_args {
int fd;
unsigned long request;
struct ntsync_wait_args *args;
int ret;
int err;
};
static void *wait_thread(void *arg)
{
struct wait_args *args = arg;
args->ret = ioctl(args->fd, args->request, args->args);
args->err = errno;
return NULL;
}
static __u64 get_abs_timeout(unsigned int ms)
{
struct timespec timeout;
clock_gettime(CLOCK_MONOTONIC, &timeout);
return (timeout.tv_sec * 1000000000) + timeout.tv_nsec + (ms * 1000000);
}
static int wait_for_thread(pthread_t thread, unsigned int ms)
{
struct timespec timeout;
clock_gettime(CLOCK_REALTIME, &timeout);
timeout.tv_nsec += ms * 1000000;
timeout.tv_sec += (timeout.tv_nsec / 1000000000);
timeout.tv_nsec %= 1000000000;
return pthread_timedjoin_np(thread, NULL, &timeout);
}
TEST(wake_any)
{
struct ntsync_event_args event_args = {0};
struct ntsync_mutex_args mutex_args = {0};
struct ntsync_wait_args wait_args = {0};
struct ntsync_sem_args sem_args = {0};
struct wait_args thread_args;
__u32 count, index, signaled;
int objs[2], fd, ret;
pthread_t thread;
fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY);
ASSERT_LE(0, fd);
sem_args.count = 0;
sem_args.max = 3;
objs[0] = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args);
EXPECT_LE(0, objs[0]);
mutex_args.owner = 123;
mutex_args.count = 1;
objs[1] = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args);
EXPECT_LE(0, objs[1]);
/* test waking the semaphore */
wait_args.timeout = get_abs_timeout(1000);
wait_args.objs = (uintptr_t)objs;
wait_args.count = 2;
wait_args.owner = 456;
wait_args.index = 0xdeadbeef;
thread_args.fd = fd;
thread_args.args = &wait_args;
thread_args.request = NTSYNC_IOC_WAIT_ANY;
ret = pthread_create(&thread, NULL, wait_thread, &thread_args);
EXPECT_EQ(0, ret);
ret = wait_for_thread(thread, 100);
EXPECT_EQ(ETIMEDOUT, ret);
count = 1;
ret = release_sem(objs[0], &count);
EXPECT_EQ(0, ret);
EXPECT_EQ(0, count);
check_sem_state(objs[0], 0, 3);
ret = wait_for_thread(thread, 100);
EXPECT_EQ(0, ret);
EXPECT_EQ(0, thread_args.ret);
EXPECT_EQ(0, wait_args.index);
Annotation
- Immediate include surface: `sys/ioctl.h`, `sys/stat.h`, `fcntl.h`, `time.h`, `pthread.h`, `linux/ntsync.h`, `kselftest_harness.h`.
- Detected declarations: `struct wake_args`, `struct wait_args`, `function Copyright`, `function release_sem`, `function read_mutex_state`, `function unlock_mutex`, `function read_event_state`, `function wait_objs`, `function wait_any`, `function wait_all`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.