[RFC PATCH] tst: Add test for gai_suspend
Lukasz Majewski
lukma@denx.de
Fri Mar 12 15:49:58 GMT 2021
---
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
More information about the Libc-alpha
mailing list