libstdc++: Fix ip::tcp::resolver test failure on Solaris
authorJonathan Wakely <jwakely@redhat.com>
Tue, 31 Aug 2021 12:08:23 +0000 (13:08 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 31 Aug 2021 16:36:11 +0000 (17:36 +0100)
Solaris 11 does not have "http" in /etc/services, which causes this test
to fail. Try some other services until we find one that works.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* testsuite/experimental/net/internet/resolver/ops/lookup.cc:
Try other service if "http" fails.

libstdc++-v3/testsuite/experimental/net/internet/resolver/ops/lookup.cc

index ca8f089..69be194 100644 (file)
@@ -30,13 +30,27 @@ test01()
   std::error_code ec;
   io_context ctx;
   ip::tcp::resolver resolv(ctx);
-  auto addrs = resolv.resolve("localhost", "http", ec);
+  auto hostname = "localhost", service = "http";
+  auto addrs = resolv.resolve(hostname, service, ec);
+  if (ec == ip::resolver_errc::service_not_found)
+  {
+    // Solaris doesn't have http in /etc/services, try some others.
+    for (auto serv : {"ftp", "telnet", "smtp"})
+    {
+      addrs = resolv.resolve(hostname, serv, ec);
+      if (!ec)
+      {
+       service = serv;
+       break;
+      }
+    }
+  }
   VERIFY( !ec );
   VERIFY( addrs.size() > 0 );
   VERIFY( addrs.begin() != addrs.end() );
   VERIFY( ! addrs.empty() );
 
-  auto addrs2 = resolv.resolve("localhost", "http");
+  auto addrs2 = resolv.resolve(hostname, service);
   VERIFY( addrs == addrs2 );
 }
 
@@ -68,7 +82,7 @@ test02()
 #if __cpp_exceptions
   bool caught = false;
   try {
-    resolv.resolve("localhost", "http", flags);
+    resolv.resolve("localhost", "42", flags);
   } catch (const std::system_error& e) {
     caught = true;
     VERIFY( e.code() == ec );