public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: Joseph Myers <joseph@codesourcery.com>,
	Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	Florian Weimer <fweimer@redhat.com>, DJ Delorie <dj@redhat.com>
Cc: Paul Eggert <eggert@cs.ucla.edu>,
	Alistair Francis <alistair23@gmail.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Alistair Francis <alistair.francis@wdc.com>,
	GNU C Library <libc-alpha@sourceware.org>,
	Carlos O'Donell <carlos@redhat.com>,
	Florian Weimer <fw@deneb.enyo.de>,
	Zack Weinberg <zackw@panix.com>,
	libc-help@sourceware.org, Lukasz Majewski <lukma@denx.de>
Subject: [RFC PATCH] tst: Add test for gai_suspend
Date: Fri, 12 Mar 2021 16:49:58 +0100	[thread overview]
Message-ID: <20210312154958.13842-1-lukma@denx.de> (raw)

---
 resolv/Makefile          |  2 ++
 resolv/tst-gai_suspend.c | 53 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
 create mode 100644 resolv/tst-gai_suspend.c

diff --git a/resolv/Makefile b/resolv/Makefile
index 1047bb6ae5..e7e66fe903 100644
--- a/resolv/Makefile
+++ b/resolv/Makefile
@@ -60,6 +60,7 @@ tests += \
   tst-resolv-res_init-multi \
   tst-resolv-search \
   tst-resolv-trailing \
+  tst-gai_suspend \
 
 # This test calls __res_context_send directly, which is not exported
 # from libresolv.
@@ -209,3 +210,4 @@ $(objpfx)tst-ns_name_compress: $(objpfx)libresolv.so
 $(objpfx)tst-ns_name_pton: $(objpfx)libresolv.so
 $(objpfx)tst-res_hnok: $(objpfx)libresolv.so
 $(objpfx)tst-p_secstodate: $(objpfx)libresolv.so
+$(objpfx)tst-gai_suspend: $(objpfx)libanl.so
diff --git a/resolv/tst-gai_suspend.c b/resolv/tst-gai_suspend.c
new file mode 100644
index 0000000000..bbafd13fc4
--- /dev/null
+++ b/resolv/tst-gai_suspend.c
@@ -0,0 +1,53 @@
+/* Test for gai_suspend timeout
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <time.h>
+#include <netdb.h>
+#include <errno.h>
+#include <string.h>
+#include <support/check.h>
+#include <support/xtime.h>
+#include <support/timespec.h>
+
+static int
+do_test (void)
+{
+  struct timespec ts;
+  xclock_gettime (CLOCK_REALTIME, &ts);
+  struct timespec timeout = make_timespec (1, 0);
+  ts = timespec_add (ts, timeout);
+
+  /* Ignore gaicb content - just wait for timeout.  */
+  struct addrinfo result;
+
+  struct gaicb gai = { "foo.baz", "0", NULL, &result };
+  const struct gaicb * const gai_s[] = { &gai };
+  struct gaicb *gai_p = &gai;
+
+  int ret = getaddrinfo_a (GAI_NOWAIT, &gai_p, 1, NULL);
+  if (ret != 0)
+    FAIL_EXIT1 ("getaddrinfo_a failed: %m\n");
+
+  ret = gai_suspend (gai_s, 1, &timeout);
+  TEST_COMPARE (ret, EAI_AGAIN);
+  TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
-- 
2.20.1


             reply	other threads:[~2021-03-12 15:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12 15:49 Lukasz Majewski [this message]
2021-03-12 16:09 ` Lukasz Majewski
2021-03-12 16:41   ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210312154958.13842-1-lukma@denx.de \
    --to=lukma@denx.de \
    --cc=adhemerval.zanella@linaro.org \
    --cc=alistair.francis@wdc.com \
    --cc=alistair23@gmail.com \
    --cc=arnd@arndb.de \
    --cc=carlos@redhat.com \
    --cc=dj@redhat.com \
    --cc=eggert@cs.ucla.edu \
    --cc=fw@deneb.enyo.de \
    --cc=fweimer@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=libc-help@sourceware.org \
    --cc=zackw@panix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).