Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ANY.

Test basic synchronous functionality of NTSYNC_IOC_WAIT_ANY, when objects are
considered signaled or not signaled, and how they are affected by a successful
wait.

Signed-off-by: Elizabeth Figura <zfigura@codeweavers.com>
Link: https://lore.kernel.org/r/20241213193511.457338-19-zfigura@codeweavers.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Elizabeth Figura and committed by
Greg Kroah-Hartman
44554569 ae071aef

+114
+114
tools/testing/selftests/drivers/ntsync/ntsync.c
··· 329 329 close(fd); 330 330 } 331 331 332 + TEST(test_wait_any) 333 + { 334 + int objs[NTSYNC_MAX_WAIT_COUNT + 1], fd, ret; 335 + struct ntsync_mutex_args mutex_args = {0}; 336 + struct ntsync_sem_args sem_args = {0}; 337 + __u32 owner, index, count, i; 338 + struct timespec timeout; 339 + 340 + clock_gettime(CLOCK_MONOTONIC, &timeout); 341 + 342 + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); 343 + ASSERT_LE(0, fd); 344 + 345 + sem_args.count = 2; 346 + sem_args.max = 3; 347 + objs[0] = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); 348 + EXPECT_LE(0, objs[0]); 349 + 350 + mutex_args.owner = 0; 351 + mutex_args.count = 0; 352 + objs[1] = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); 353 + EXPECT_LE(0, objs[1]); 354 + 355 + ret = wait_any(fd, 2, objs, 123, &index); 356 + EXPECT_EQ(0, ret); 357 + EXPECT_EQ(0, index); 358 + check_sem_state(objs[0], 1, 3); 359 + check_mutex_state(objs[1], 0, 0); 360 + 361 + ret = wait_any(fd, 2, objs, 123, &index); 362 + EXPECT_EQ(0, ret); 363 + EXPECT_EQ(0, index); 364 + check_sem_state(objs[0], 0, 3); 365 + check_mutex_state(objs[1], 0, 0); 366 + 367 + ret = wait_any(fd, 2, objs, 123, &index); 368 + EXPECT_EQ(0, ret); 369 + EXPECT_EQ(1, index); 370 + check_sem_state(objs[0], 0, 3); 371 + check_mutex_state(objs[1], 1, 123); 372 + 373 + count = 1; 374 + ret = release_sem(objs[0], &count); 375 + EXPECT_EQ(0, ret); 376 + EXPECT_EQ(0, count); 377 + 378 + ret = wait_any(fd, 2, objs, 123, &index); 379 + EXPECT_EQ(0, ret); 380 + EXPECT_EQ(0, index); 381 + check_sem_state(objs[0], 0, 3); 382 + check_mutex_state(objs[1], 1, 123); 383 + 384 + ret = wait_any(fd, 2, objs, 123, &index); 385 + EXPECT_EQ(0, ret); 386 + EXPECT_EQ(1, index); 387 + check_sem_state(objs[0], 0, 3); 388 + check_mutex_state(objs[1], 2, 123); 389 + 390 + ret = wait_any(fd, 2, objs, 456, &index); 391 + EXPECT_EQ(-1, ret); 392 + EXPECT_EQ(ETIMEDOUT, errno); 393 + 394 + owner = 123; 395 + ret = ioctl(objs[1], NTSYNC_IOC_MUTEX_KILL, &owner); 396 + EXPECT_EQ(0, ret); 397 + 398 + ret = wait_any(fd, 2, objs, 456, &index); 399 + EXPECT_EQ(-1, ret); 400 + EXPECT_EQ(EOWNERDEAD, errno); 401 + EXPECT_EQ(1, index); 402 + 403 + ret = wait_any(fd, 2, objs, 456, &index); 404 + EXPECT_EQ(0, ret); 405 + EXPECT_EQ(1, index); 406 + 407 + close(objs[1]); 408 + 409 + /* test waiting on the same object twice */ 410 + 411 + count = 2; 412 + ret = release_sem(objs[0], &count); 413 + EXPECT_EQ(0, ret); 414 + EXPECT_EQ(0, count); 415 + 416 + objs[1] = objs[0]; 417 + ret = wait_any(fd, 2, objs, 456, &index); 418 + EXPECT_EQ(0, ret); 419 + EXPECT_EQ(0, index); 420 + check_sem_state(objs[0], 1, 3); 421 + 422 + ret = wait_any(fd, 0, NULL, 456, &index); 423 + EXPECT_EQ(-1, ret); 424 + EXPECT_EQ(ETIMEDOUT, errno); 425 + 426 + for (i = 1; i < NTSYNC_MAX_WAIT_COUNT + 1; ++i) 427 + objs[i] = objs[0]; 428 + 429 + ret = wait_any(fd, NTSYNC_MAX_WAIT_COUNT, objs, 123, &index); 430 + EXPECT_EQ(0, ret); 431 + EXPECT_EQ(0, index); 432 + 433 + ret = wait_any(fd, NTSYNC_MAX_WAIT_COUNT + 1, objs, 123, &index); 434 + EXPECT_EQ(-1, ret); 435 + EXPECT_EQ(EINVAL, errno); 436 + 437 + ret = wait_any(fd, -1, objs, 123, &index); 438 + EXPECT_EQ(-1, ret); 439 + EXPECT_EQ(EINVAL, errno); 440 + 441 + close(objs[0]); 442 + 443 + close(fd); 444 + } 445 + 332 446 TEST_HARNESS_MAIN