From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] network/lib6/getaddrinfo01: rewrite with the new API + use static hostnames
Date: Tue, 18 May 2021 08:02:56 +0200 [thread overview]
Message-ID: <YKNYkNOqsmhv9kSJ@pevik> (raw)
In-Reply-To: <20210517085637.16866-1-aleksei.kodanev@bell-sw.com>
Hi Alexey,
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Moving everything to /etc/hosts based setup is a great idea
as we get rid of network setup related failures.
Do we lost any getaddrinfo() test coverage for bypassing DNS?
Just a few unimportant nits below (feel free to ignore them).
Again, I'd be for merging this before release.
> The test is now independent of various machine settings
> regarding the test host name as it adds predefined names
> and aliases to /etc/hosts file and restores it to its
> original state after completing the test.
> This should fix the following failures:
> * when gethostname() returns an alias name that doesn't
> match canonical name;
> * No AAAA record for the returned name from gethostname().
> Addresses and names added to /etc/hosts are more or less
> unique, so that there are no conflicts with the existing
> configuration.
We might want to put this into docparse documentation, e.g:
/*\
* [Description]
*
* Basic getaddrinfo() tests.
*
* Test use LTP specific addresses and names added to /etc/hosts to avoid
* problems with DNS and hostname setup or conflicts with existing
* configuration.
*/
> Also most of the duplicate code is now gone.
> Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
> ---
> testcases/network/lib6/getaddrinfo_01.c | 1140 +++++------------------
> 1 file changed, 235 insertions(+), 905 deletions(-)
> diff --git a/testcases/network/lib6/getaddrinfo_01.c b/testcases/network/lib6/getaddrinfo_01.c
> index db252a998..23a279ed1 100644
...
> +static void gaiv(void)
> +{
> + check_addrinfo(1, "basic lookup", hostname, 0, NULL, 0, 0, 0, NULL);
> + check_addrinfo_name("canonical name");
...
> + check_addrinfo(1, "host+service", hostname, 7, "echo", 0, 0, 0, NULL);
> +
> + check_addrinfo(1, "host+service, AI_PASSIVE", hostname, 9462, "9462",
> + AI_PASSIVE, SOCK_STREAM, 0, test_passive);
> +
> + check_addrinfo(0, "host+service, AI_NUMERICHOST", hostname, 7, "echo",
> + AI_NUMERICHOST, SOCK_STREAM, 0, NULL);
> + if (TST_RET != EAI_NONAME)
> + tst_brk(TFAIL, "AI_NUMERICHOST: ret %ld exp %d (EAI_NONAME)",
> + TST_RET, EAI_NONAME);
> + tst_res(TPASS, "AI_NUMERICHOST: exp %ld (EAI_NONAME)", TST_RET);
> +
> + check_addrinfo(1, "0+service, AI_PASSIVE", NULL, 9462, "9462",
> + AI_PASSIVE, SOCK_STREAM, 0, test_passive_no_host);
> +
> + check_addrinfo(0, "0+service", NULL, 9462, "9462",
> + 0, SOCK_STREAM, 0, test_loopback);
> + if (TST_RET == EAI_BADFLAGS) {
> + tst_res(TPASS, "0+service ('', '9462') returns %ld '%s'",
> + TST_RET, gai_strerror(TST_RET));
> + } else if (TST_RET) {
> + tst_brk(TFAIL, "0+service ('', '9462') returns %ld '%s'",
> + TST_RET, gai_strerror(TST_RET));
> }
nit: Maybe having check_addrinfo_badflags() which would do the verification
would safe few lines of code duplicity.
...
> - /* test 16, IPv6 host+service w/ AI_NUMERICHOST */
> - memset(&hints, 0, sizeof(hints));
> - strcpy(service, "echo");
> - servnum = 7;
> - hints.ai_family = AF_INET6;
> - hints.ai_flags = AI_NUMERICHOST;
> - TEST(getaddrinfo(hostname, service, &hints, &aires));
> - if (TEST_RETURN != EAI_NONAME) {
> - tst_resm(TFAIL, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname: "
> - "returns %ld expected %d (EAI_NONAME)",
> - TEST_RETURN, EAI_NONAME);
> - if (!TEST_RETURN)
> - freeaddrinfo(aires);
> - return;
> + check_addrinfo(0, "SOCK_STREAM/IPPROTO_UDP", NULL, 0, NULL, 0,
> + SOCK_STREAM, IPPROTO_UDP, NULL);
> + if (!TST_RET)
> + tst_brk(TFAIL, "SOCK_STREAM/IPPROTO_UDP: unexpected pass");
> + tst_res(TPASS, "SOCK_STREAM/IPPROTO_UDP: failed as expected");
> +
> + check_addrinfo(0, "socktype 0, 513", NULL, 513, "513", 0, 0, 0, NULL);
And here also check_addrinfo_badflags() (if implemented)
and nit: "socktype 0,513" (remove space)
> + if (TST_RET == EAI_BADFLAGS) {
> + tst_res(TPASS, "socktype 0,513 returns %ld '%s'",
> + TST_RET, gai_strerror(TST_RET));
> + } else if (TST_RET) {
> + tst_brk(TFAIL, "socktype 0,513 returns %ld '%s'",
> + TST_RET, gai_strerror(TST_RET));
> }
Kind regards,
Petr
next prev parent reply other threads:[~2021-05-18 6:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-17 8:56 [LTP] [PATCH] network/lib6/getaddrinfo01: rewrite with the new API + use static hostnames Alexey Kodanev
2021-05-17 19:57 ` Petr Vorel
2021-05-18 10:19 ` Alexey Kodanev
2021-05-18 9:59 ` Cyril Hrubis
2021-05-18 6:02 ` Petr Vorel [this message]
2021-05-18 8:30 ` Alexey Kodanev
2021-05-18 15:25 ` Petr Vorel
-- strict thread matches above, loose matches on Subject: below --
2021-05-18 9:14 Alexey Kodanev
2021-05-18 19:15 ` Petr Vorel
2021-05-19 7:32 ` Alexey Kodanev
2021-05-19 19:59 ` Petr Vorel
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=YKNYkNOqsmhv9kSJ@pevik \
--to=pvorel@suse.cz \
--cc=ltp@lists.linux.it \
/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