csb_PL: Update month translations + add yesstr/nostr (bug 19485).
[glibc.git] / resolv / tst-resolv-res_ninit.c
blob46e72ab7ce5ca1f5456c06a4fe3b70f4fc8750ba
1 /* Test the creation of many struct __res_state objects.
2 Copyright (C) 2017-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <mcheck.h>
20 #include <resolv.h>
21 #include <resolv/resolv_context.h>
22 #include <stdlib.h>
23 #include <support/check.h>
25 /* Order the resolver states by their extended resolver state
26 index. */
27 static int
28 sort_res_state (const void *a, const void *b)
30 res_state left = (res_state) a;
31 res_state right = (res_state) b;
32 return memcmp (&left->_u._ext.__glibc_extension_index,
33 &right->_u._ext.__glibc_extension_index,
34 sizeof (left->_u._ext.__glibc_extension_index));
37 static int
38 do_test (void)
40 mtrace ();
42 enum { count = 100 * 1000 };
43 res_state array = calloc (count, sizeof (*array));
44 const struct resolv_conf *conf = NULL;
45 for (size_t i = 0; i < count; ++i)
47 TEST_VERIFY (res_ninit (array + i) == 0);
48 TEST_VERIFY (array[i].nscount > 0);
49 struct resolv_context *ctx = __resolv_context_get_override (array + i);
50 TEST_VERIFY_EXIT (ctx != NULL);
51 TEST_VERIFY (ctx->resp == array + i);
52 if (i == 0)
54 conf = ctx->conf;
55 TEST_VERIFY (conf != NULL);
57 else
58 /* The underyling configuration should be identical across all
59 res_state opjects because resolv.conf did not change. */
60 TEST_VERIFY (ctx->conf == conf);
62 qsort (array, count, sizeof (*array), sort_res_state);
63 for (size_t i = 1; i < count; ++i)
64 /* All extension indices should be different. */
65 TEST_VERIFY (sort_res_state (array + i - 1, array + i) < 0);
66 for (size_t i = 0; i < count; ++i)
67 res_nclose (array + i);
68 free (array);
70 TEST_VERIFY (res_init () == 0);
71 return 0;
74 #define TIMEOUT 50
75 #include <support/test-driver.c>