testsuite: Add filter for target socket support
authorDimitar Dimitrov <dimitar@dinux.eu>
Fri, 18 Nov 2022 19:59:42 +0000 (21:59 +0200)
committerDimitar Dimitrov <dimitar@dinux.eu>
Mon, 21 Nov 2022 16:13:53 +0000 (18:13 +0200)
The new analyzer tests for sockets are failing on embedded targets.
The newlib and avr-libc C libraries do not support sockets.

Testing done:
  - No changes in gcc.sum for x86_64-pc-linux-gnu, with or without this
    patch.
  - Filtered cases are now UNSUPPORTED instead of failing on AVR and PRU
    backends.

gcc/ChangeLog:

* doc/sourcebuild.texi (sockets): Document new check.

gcc/testsuite/ChangeLog:

* gcc.dg/analyzer/fd-accept.c: Require sockets.
* gcc.dg/analyzer/fd-bind.c: Ditto.
* gcc.dg/analyzer/fd-connect.c: Ditto.
* gcc.dg/analyzer/fd-datagram-socket.c: Ditto.
* gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c:
Ditto.
* gcc.dg/analyzer/fd-glibc-byte-stream-socket.c: Ditto.
* gcc.dg/analyzer/fd-glibc-datagram-client.c: Ditto.
* gcc.dg/analyzer/fd-glibc-datagram-socket.c: Ditto.
* gcc.dg/analyzer/fd-listen.c: Ditto.
* gcc.dg/analyzer/fd-manpage-getaddrinfo-client.c: Ditto.
* gcc.dg/analyzer/fd-mappage-getaddrinfo-server.c: Ditto.
* gcc.dg/analyzer/fd-socket-meaning.c: Ditto.
* gcc.dg/analyzer/fd-socket-misuse.c: Ditto.
* gcc.dg/analyzer/fd-stream-socket-active-open.c: Ditto.
* gcc.dg/analyzer/fd-stream-socket-passive-open.c: Ditto.
* gcc.dg/analyzer/fd-stream-socket.c: Ditto.
* gcc.dg/analyzer/fd-symbolic-socket.c: Ditto.
* lib/target-supports.exp (check_effective_target_sockets): New
check.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
19 files changed:
gcc/doc/sourcebuild.texi
gcc/testsuite/gcc.dg/analyzer/fd-accept.c
gcc/testsuite/gcc.dg/analyzer/fd-bind.c
gcc/testsuite/gcc.dg/analyzer/fd-connect.c
gcc/testsuite/gcc.dg/analyzer/fd-datagram-socket.c
gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c
gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-socket.c
gcc/testsuite/gcc.dg/analyzer/fd-glibc-datagram-client.c
gcc/testsuite/gcc.dg/analyzer/fd-glibc-datagram-socket.c
gcc/testsuite/gcc.dg/analyzer/fd-listen.c
gcc/testsuite/gcc.dg/analyzer/fd-manpage-getaddrinfo-client.c
gcc/testsuite/gcc.dg/analyzer/fd-mappage-getaddrinfo-server.c
gcc/testsuite/gcc.dg/analyzer/fd-socket-meaning.c
gcc/testsuite/gcc.dg/analyzer/fd-socket-misuse.c
gcc/testsuite/gcc.dg/analyzer/fd-stream-socket-active-open.c
gcc/testsuite/gcc.dg/analyzer/fd-stream-socket-passive-open.c
gcc/testsuite/gcc.dg/analyzer/fd-stream-socket.c
gcc/testsuite/gcc.dg/analyzer/fd-symbolic-socket.c
gcc/testsuite/lib/target-supports.exp

index 7662669..ffe69d6 100644 (file)
@@ -2666,6 +2666,9 @@ Target can compile using @code{pthread.h} with no errors or warnings.
 @item pthread_h
 Target has @code{pthread.h}.
 
+@item sockets
+Target can compile using @code{sys/socket.h} with no errors or warnings.
+
 @item run_expensive_tests
 Expensive testcases (usually those that consume excessive amounts of CPU
 time) should be run on this target.  This can be enabled by setting the
index 36cc7af..5426063 100644 (file)
@@ -1,3 +1,5 @@
+/* { dg-require-effective-target sockets } */
+
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
index 6f91bc4..c34803f 100644 (file)
@@ -1,3 +1,5 @@
+/* { dg-require-effective-target sockets } */
+
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
index 1ab54d0..7bf687e 100644 (file)
@@ -1,3 +1,5 @@
+/* { dg-require-effective-target sockets } */
+
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
index 045bdfa..5850857 100644 (file)
@@ -1,3 +1,5 @@
+/* { dg-require-effective-target sockets } */
+
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
index 1ff9028..5a1a6f5 100644 (file)
@@ -1,4 +1,5 @@
 /* Example from glibc manual (16.9.7).  */
+/* { dg-require-effective-target sockets } */
 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
 
 #include <stdio.h>
index f96da81..806bb24 100644 (file)
@@ -1,4 +1,5 @@
 /* Example from glibc manual (16.9.6).  */
+/* { dg-require-effective-target sockets } */
 
 #include <stdio.h>
 #include <string.h>
index 888c751..072ac4c 100644 (file)
@@ -1,4 +1,5 @@
 /* Example from the glibc manual (16.10.4).  */
+/* { dg-require-effective-target sockets } */
 
 #include <stdio.h>
 #include <errno.h>
index b8b6876..d417828 100644 (file)
@@ -1,4 +1,5 @@
 /* Example from glibc manual (16.10.3).  */
+/* { dg-require-effective-target sockets } */
 
 #include <stdio.h>
 #include <errno.h>
index 1f54a8f..becf469 100644 (file)
@@ -1,3 +1,5 @@
+/* { dg-require-effective-target sockets } */
+
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
index d9c3ff0..ee627de 100644 (file)
@@ -26,6 +26,7 @@ Formatted or processed versions of this manual, if unaccompanied by
 the source, must acknowledge the copyright and authors of this work.
 */
 
+/* { dg-require-effective-target sockets } */
 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
 
 #include <sys/types.h>
index 66398e8..d2e39eb 100644 (file)
@@ -26,6 +26,8 @@ Formatted or processed versions of this manual, if unaccompanied by
 the source, must acknowledge the copyright and authors of this work.
 */
 
+/* { dg-require-effective-target sockets } */
+
 #include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
index 5bfb57f..82a199f 100644 (file)
@@ -1,3 +1,4 @@
+/* { dg-require-effective-target sockets } */
 /* { dg-additional-options "-fanalyzer-verbose-state-changes" } */
 
 #include <sys/socket.h>
index 4ff08d5..628f5e4 100644 (file)
@@ -1,5 +1,7 @@
 /* Various operations done on sockets in the wrong phase.  */
 
+/* { dg-require-effective-target sockets } */
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
index 7fde0ef..841894c 100644 (file)
@@ -1,3 +1,5 @@
+/* { dg-require-effective-target sockets } */
+
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
index c31e5b5..a610911 100644 (file)
@@ -2,6 +2,8 @@
    either from scratch, or when various phases are assumed to already
    be done.  */
 
+/* { dg-require-effective-target sockets } */
+
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
index 3a292d0..e51f0f0 100644 (file)
@@ -1,3 +1,5 @@
+/* { dg-require-effective-target sockets } */
+
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
index 83400c1..ad1f989 100644 (file)
@@ -1,3 +1,5 @@
+/* { dg-require-effective-target sockets } */
+
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
index 01cf17e..65ba33b 100644 (file)
@@ -1176,6 +1176,20 @@ proc check_effective_target_pthread {} {
     } "-pthread"]
 }
 
+# Return 1 if the target supports both Unix and internet sockets, 0 otherwise.
+proc check_effective_target_sockets {} {
+    return [check_no_compiler_messages socket executable {
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+int main (void) {
+    socket(AF_UNIX, SOCK_STREAM, 0);
+    socket(AF_INET, SOCK_DGRAM, 0);
+    return 0;
+}
+    } ""]
+}
+
 # Return 1 if compilation with -mpe-aligned-commons is error-free
 # for trivial code, 0 otherwise.