xref: /minix/minix/tests/t40g.c (revision 433d6423)
1 /* t40g.c
2  *
3  * Test select on character driver that does not support select
4  *
5  * We use /dev/zero for this right now.  If the memory driver ever implements
6  * select support, this test should be changed to use another character driver.
7  */
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <sys/types.h>
13 #include <sys/select.h>
14 #include <sys/wait.h>
15 #include <sys/time.h>
16 #include <time.h>
17 #include <errno.h>
18 #include <string.h>
19 #include <signal.h>
20 #include <fcntl.h>
21 
22 #include "common.h"
23 
24 int
main(int argc,char ** argv)25 main(int argc, char **argv)
26 {
27 	fd_set set;
28 	int fd, retval;
29 
30 	/* Get subtest number */
31 	if (argc != 2 || sscanf(argv[1], "%d", &subtest) != 1) {
32 		printf("Usage: %s subtest_no\n", argv[0]);
33 		exit(-2);
34 	}
35 
36 	/*
37 	 * Do a select on /dev/zero, with the expectation that it will fail
38 	 * with an EBADF error code.
39 	 */
40 	fd = open("/dev/zero", O_RDONLY);
41 	if (fd < 0) em(1, "unable to open /dev/zero");
42 
43 	FD_ZERO(&set);
44 	FD_SET(fd, &set);
45 
46 	retval = select(fd + 1, &set, NULL, NULL, NULL);
47 	if (retval != -1) em(2, "select call was expected to fail");
48 	if (errno != EBADF) em(3, "error code other than EBADF returned");
49 	if (!FD_ISSET(fd, &set)) em(4, "file descriptor set was modified");
50 
51 	exit(errct);
52 }
53