MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / test_errors

Function test_errors

test/core/test_select_blocking.c:216–237  ·  view source on GitHub ↗

Check if select handles error returns and errno correctly

Source from the content-addressed store, hash-verified

214
215// Check if select handles error returns and errno correctly
216void test_errors() {
217 printf("test_errors\n");
218 struct timeval tv = {0, 0};
219 fd_set readfds;
220
221 // Negative nfds should fail with EINVAL
222 FD_ZERO(&readfds);
223 errno = 0;
224 assert(select(-1, &readfds, NULL, NULL, &tv) == -1);
225 assert(errno == EINVAL);
226
227 // Closed / invalid fd should fail with EBADF
228 int pipe_fds[2];
229 assert(pipe(pipe_fds) == 0);
230 close(pipe_fds[0]); // close read end
231 FD_ZERO(&readfds);
232 FD_SET(pipe_fds[0], &readfds);
233 errno = 0;
234 assert(select(pipe_fds[0] + 1, &readfds, NULL, NULL, &tv) == -1);
235 assert(errno == EBADF);
236 close(pipe_fds[1]);
237}
238
239int main() {
240 test_select_in_threads();

Callers 1

mainFunction · 0.85

Calls 5

printfFunction · 0.85
selectFunction · 0.85
pipeFunction · 0.85
assertFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected