Skip several analyzer socket tests on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / fd-symbolic-socket.c
blob32264fd9701318d5c19fbaf0dd658cca74e10fbf
1 /* { dg-require-effective-target sockets } */
2 /* { dg-skip-if "" { hppa*-*-hpux* powerpc*-*-aix* } } */
4 #include <string.h>
5 #include <sys/socket.h>
6 #include <sys/un.h>
7 #include <unistd.h>
8 #include <errno.h>
9 #include "analyzer-decls.h"
11 void test_leak_socket (int type)
13 int fd = socket (AF_UNIX, type, 0); /* { dg-message "socket created here" } */
14 } /* { dg-warning "leak of file descriptor 'fd'" } */
16 void test_leak_socket_no_lhs (int type)
18 socket (AF_UNIX, type, 0); /* { dg-warning "leak of file descriptor" } */
21 void test_close_unchecked_socket (int type)
23 int fd = socket (AF_UNIX, type, 0);
24 close (fd);
27 void test_close_checked_socket (int type)
29 int fd = socket (AF_UNIX, type, 0);
30 if (fd == -1)
31 return;
32 close (fd);
35 void test_leak_checked_socket (int type)
37 int fd = socket (AF_UNIX, type, 0); /* { dg-message "socket created here" } */
38 if (fd == -1) /* { dg-warning "leak of file descriptor 'fd'" } */
39 return;
40 // TODO: strange location for leak message
43 void test_bind_on_checked_socket (int type, const char *sockname)
45 struct sockaddr_un addr;
46 int fd = socket (AF_UNIX, type, 0);
47 if (fd == -1)
48 return;
49 memset (&addr, 0, sizeof (addr));
50 addr.sun_family = AF_UNIX;
51 strncpy (addr.sun_path, sockname, sizeof(addr.sun_path) - 1);
52 bind (fd, (struct sockaddr *)&addr, sizeof (addr));
53 close (fd);
56 void test_bind_on_unchecked_socket (int type, const char *sockname)
58 struct sockaddr_un addr;
59 int fd = socket (AF_UNIX, type, 0); /* { dg-message "when 'socket' fails" } */
60 memset (&addr, 0, sizeof (addr));
61 addr.sun_family = AF_UNIX;
62 strncpy (addr.sun_path, sockname, sizeof(addr.sun_path) - 1);
63 bind (fd, (struct sockaddr *)&addr, sizeof (addr)); /* { dg-warning "'bind' on possibly invalid file descriptor 'fd'" } */
64 close (fd);
67 void test_leak_of_bound_socket (int type, const char *sockname)
69 struct sockaddr_un addr;
70 int fd = socket (AF_UNIX, type, 0); /* { dg-message "socket created here" } */
71 if (fd == -1)
72 return;
73 memset (&addr, 0, sizeof (addr));
74 addr.sun_family = AF_UNIX;
75 strncpy (addr.sun_path, sockname, sizeof(addr.sun_path) - 1);
76 bind (fd, (struct sockaddr *)&addr, sizeof (addr)); /* { dg-warning "leak of file descriptor 'fd'" } */
79 void test_listen_without_bind (int type)
81 int fd = socket (AF_UNIX, type, 0);
82 if (fd == -1)
83 return;
84 listen (fd, 5); /* { dg-warning "'listen' on file descriptor 'fd' in wrong phase" } */
85 /* { dg-message "'listen' expects a bound stream socket file descriptor but 'fd' has not yet been bound" "msg" { target *-*-* } .-1 } */
86 close (fd);
89 void test_listen_on_unchecked_bind (int type, const char *sockname)
91 struct sockaddr_un addr;
92 int fd = socket (AF_UNIX, type, 0);
93 if (fd == -1)
94 return;
95 memset (&addr, 0, sizeof (addr));
96 addr.sun_family = AF_UNIX;
97 strncpy (addr.sun_path, sockname, sizeof(addr.sun_path) - 1);
98 bind (fd, (struct sockaddr *)&addr, sizeof (addr)); /* { dg-message "when 'bind' fails" } */
99 listen (fd, 5); /* { dg-warning "'listen' on file descriptor 'fd' in wrong phase" "warning" } */
100 /* { dg-message "'listen' expects a bound stream socket file descriptor but 'fd' has not yet been bound" "msg" { target *-*-* } .-1 } */
101 close (fd);