| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: t_stat.c,v 1.2 2011/10/16 08:28:10 jruoho Exp $ */ | | 1 | /* $NetBSD: t_stat.c,v 1.3 2012/03/06 10:32:15 jruoho Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2011 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Jukka Ruohonen. | | 8 | * by Jukka Ruohonen. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -19,31 +19,34 @@ | | | @@ -19,31 +19,34 @@ |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | #include <sys/cdefs.h> | | 31 | #include <sys/cdefs.h> |
32 | __RCSID("$NetBSD: t_stat.c,v 1.2 2011/10/16 08:28:10 jruoho Exp $"); | | 32 | __RCSID("$NetBSD: t_stat.c,v 1.3 2012/03/06 10:32:15 jruoho Exp $"); |
33 | | | 33 | |
34 | #include <sys/stat.h> | | 34 | #include <sys/stat.h> |
| | | 35 | #include <sys/socket.h> |
35 | #include <sys/types.h> | | 36 | #include <sys/types.h> |
36 | | | 37 | |
| | | 38 | #include <arpa/inet.h> |
| | | 39 | |
37 | #include <atf-c.h> | | 40 | #include <atf-c.h> |
38 | #include <errno.h> | | 41 | #include <errno.h> |
39 | #include <fcntl.h> | | 42 | #include <fcntl.h> |
40 | #include <fts.h> | | 43 | #include <fts.h> |
41 | #include <limits.h> | | 44 | #include <limits.h> |
42 | #include <string.h> | | 45 | #include <string.h> |
43 | #include <unistd.h> | | 46 | #include <unistd.h> |
44 | | | 47 | |
45 | #include <stdio.h> | | 48 | #include <stdio.h> |
46 | | | 49 | |
47 | static const char *path = "stat"; | | 50 | static const char *path = "stat"; |
48 | | | 51 | |
49 | ATF_TC_WITH_CLEANUP(stat_chflags); | | 52 | ATF_TC_WITH_CLEANUP(stat_chflags); |
| @@ -304,26 +307,71 @@ ATF_TC_BODY(stat_size, tc) | | | @@ -304,26 +307,71 @@ ATF_TC_BODY(stat_size, tc) |
304 | if (sb.st_size != sc.st_size) | | 307 | if (sb.st_size != sc.st_size) |
305 | atf_tc_fail("stat(2) and fstat(2) mismatch"); | | 308 | atf_tc_fail("stat(2) and fstat(2) mismatch"); |
306 | } | | 309 | } |
307 | | | 310 | |
308 | ATF_REQUIRE(close(fd) == 0); | | 311 | ATF_REQUIRE(close(fd) == 0); |
309 | ATF_REQUIRE(unlink(path) == 0); | | 312 | ATF_REQUIRE(unlink(path) == 0); |
310 | } | | 313 | } |
311 | | | 314 | |
312 | ATF_TC_CLEANUP(stat_size, tc) | | 315 | ATF_TC_CLEANUP(stat_size, tc) |
313 | { | | 316 | { |
314 | (void)unlink(path); | | 317 | (void)unlink(path); |
315 | } | | 318 | } |
316 | | | 319 | |
| | | 320 | ATF_TC(stat_socket); |
| | | 321 | ATF_TC_HEAD(stat_socket, tc) |
| | | 322 | { |
| | | 323 | atf_tc_set_md_var(tc, "descr", "Test fstat(2) with a socket"); |
| | | 324 | } |
| | | 325 | |
| | | 326 | ATF_TC_BODY(stat_socket, tc) |
| | | 327 | { |
| | | 328 | struct sockaddr_in addr; |
| | | 329 | struct stat st; |
| | | 330 | uint32_t iaddr; |
| | | 331 | int fd, flags; |
| | | 332 | |
| | | 333 | atf_tc_expect_fail("PR kern/46077"); |
| | | 334 | |
| | | 335 | (void)memset(&st, 0, sizeof(struct stat)); |
| | | 336 | (void)memset(&addr, 0, sizeof(struct sockaddr_in)); |
| | | 337 | |
| | | 338 | fd = socket(AF_INET, SOCK_STREAM, 0); |
| | | 339 | ATF_REQUIRE(fd >= 0); |
| | | 340 | |
| | | 341 | flags = fcntl(fd, F_GETFL); |
| | | 342 | |
| | | 343 | ATF_REQUIRE(flags != -1); |
| | | 344 | ATF_REQUIRE(fcntl(fd, F_SETFL, flags | O_NONBLOCK) != -1); |
| | | 345 | ATF_REQUIRE(inet_pton(AF_INET, "127.0.0.1", &iaddr) == 1); |
| | | 346 | |
| | | 347 | addr.sin_port = htons(42); |
| | | 348 | addr.sin_family = AF_INET; |
| | | 349 | addr.sin_addr.s_addr = iaddr; |
| | | 350 | |
| | | 351 | errno = 0; |
| | | 352 | |
| | | 353 | ATF_REQUIRE_ERRNO(EINPROGRESS, |
| | | 354 | connect(fd, (struct sockaddr *)&addr, |
| | | 355 | sizeof(struct sockaddr_in)) == -1); |
| | | 356 | |
| | | 357 | errno = 0; |
| | | 358 | |
| | | 359 | if (fstat(fd, &st) != 0 || errno != 0) |
| | | 360 | atf_tc_fail("fstat(2) failed for a EINPROGRESS socket"); |
| | | 361 | |
| | | 362 | (void)close(fd); |
| | | 363 | } |
| | | 364 | |
317 | ATF_TC_WITH_CLEANUP(stat_symlink); | | 365 | ATF_TC_WITH_CLEANUP(stat_symlink); |
318 | ATF_TC_HEAD(stat_symlink, tc) | | 366 | ATF_TC_HEAD(stat_symlink, tc) |
319 | { | | 367 | { |
320 | atf_tc_set_md_var(tc, "descr", "Test symbolic links with stat(2)"); | | 368 | atf_tc_set_md_var(tc, "descr", "Test symbolic links with stat(2)"); |
321 | } | | 369 | } |
322 | | | 370 | |
323 | ATF_TC_BODY(stat_symlink, tc) | | 371 | ATF_TC_BODY(stat_symlink, tc) |
324 | { | | 372 | { |
325 | const char *pathlink = "pathlink"; | | 373 | const char *pathlink = "pathlink"; |
326 | struct stat sa, sb; | | 374 | struct stat sa, sb; |
327 | int fd; | | 375 | int fd; |
328 | | | 376 | |
329 | (void)memset(&sa, 0, sizeof(struct stat)); | | 377 | (void)memset(&sa, 0, sizeof(struct stat)); |
| @@ -353,17 +401,18 @@ ATF_TC_CLEANUP(stat_symlink, tc) | | | @@ -353,17 +401,18 @@ ATF_TC_CLEANUP(stat_symlink, tc) |
353 | { | | 401 | { |
354 | (void)unlink(path); | | 402 | (void)unlink(path); |
355 | } | | 403 | } |
356 | | | 404 | |
357 | ATF_TP_ADD_TCS(tp) | | 405 | ATF_TP_ADD_TCS(tp) |
358 | { | | 406 | { |
359 | | | 407 | |
360 | ATF_TP_ADD_TC(tp, stat_chflags); | | 408 | ATF_TP_ADD_TC(tp, stat_chflags); |
361 | ATF_TP_ADD_TC(tp, stat_dir); | | 409 | ATF_TP_ADD_TC(tp, stat_dir); |
362 | ATF_TP_ADD_TC(tp, stat_err); | | 410 | ATF_TP_ADD_TC(tp, stat_err); |
363 | ATF_TP_ADD_TC(tp, stat_mtime); | | 411 | ATF_TP_ADD_TC(tp, stat_mtime); |
364 | ATF_TP_ADD_TC(tp, stat_perm); | | 412 | ATF_TP_ADD_TC(tp, stat_perm); |
365 | ATF_TP_ADD_TC(tp, stat_size); | | 413 | ATF_TP_ADD_TC(tp, stat_size); |
| | | 414 | ATF_TP_ADD_TC(tp, stat_socket); |
366 | ATF_TP_ADD_TC(tp, stat_symlink); | | 415 | ATF_TP_ADD_TC(tp, stat_symlink); |
367 | | | 416 | |
368 | return atf_no_error(); | | 417 | return atf_no_error(); |
369 | } | | 418 | } |