1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz> 4f08c3bdfSopenharmony_ci */ 5f08c3bdfSopenharmony_ci /* 6f08c3bdfSopenharmony_ci * This is basic test for pselect() returning without error. 7f08c3bdfSopenharmony_ci */ 8f08c3bdfSopenharmony_ci#include <stdio.h> 9f08c3bdfSopenharmony_ci#include <fcntl.h> 10f08c3bdfSopenharmony_ci#include <sys/select.h> 11f08c3bdfSopenharmony_ci#include <sys/time.h> 12f08c3bdfSopenharmony_ci#include <sys/types.h> 13f08c3bdfSopenharmony_ci#include <time.h> 14f08c3bdfSopenharmony_ci#include <unistd.h> 15f08c3bdfSopenharmony_ci#include <errno.h> 16f08c3bdfSopenharmony_ci 17f08c3bdfSopenharmony_ci#include "tst_test.h" 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_cistatic int fd; 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_cistatic void verify_pselect(void) 22f08c3bdfSopenharmony_ci{ 23f08c3bdfSopenharmony_ci fd_set readfds; 24f08c3bdfSopenharmony_ci struct timespec tv = {0}; 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci FD_ZERO(&readfds); 27f08c3bdfSopenharmony_ci FD_SET(fd, &readfds); 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_ci TEST(pselect(fd, &readfds, 0, 0, &tv, NULL)); 30f08c3bdfSopenharmony_ci if (TST_RET >= 0) 31f08c3bdfSopenharmony_ci tst_res(TPASS, "pselect() succeeded retval=%li", TST_RET); 32f08c3bdfSopenharmony_ci else 33f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "pselect() failed unexpectedly"); 34f08c3bdfSopenharmony_ci} 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_cistatic void setup(void) 37f08c3bdfSopenharmony_ci{ 38f08c3bdfSopenharmony_ci fd = SAFE_OPEN("pselect03_file", O_CREAT | O_RDWR, 0777); 39f08c3bdfSopenharmony_ci} 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_cistatic void cleanup(void) 42f08c3bdfSopenharmony_ci{ 43f08c3bdfSopenharmony_ci if (fd > 0) 44f08c3bdfSopenharmony_ci SAFE_CLOSE(fd); 45f08c3bdfSopenharmony_ci} 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_cistatic struct tst_test test = { 48f08c3bdfSopenharmony_ci .needs_tmpdir = 1, 49f08c3bdfSopenharmony_ci .setup = setup, 50f08c3bdfSopenharmony_ci .cleanup = cleanup, 51f08c3bdfSopenharmony_ci .test_all = verify_pselect, 52f08c3bdfSopenharmony_ci}; 53