From: Zbigniew Jędrzejewski-Szmek Date: Wed, 21 Nov 2018 13:55:07 +0000 (+0100) Subject: test-resolved-etc-hosts: when parsing an external file, skip other tests X-Git-Tag: v240~102^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c65f788b9f60ee800ca9c364b79e13796c9e9028;p=thirdparty%2Fsystemd.git test-resolved-etc-hosts: when parsing an external file, skip other tests This makes timing tests much more useful. So let's simplify things, and just do the parsing of the external file when that is specified. --- diff --git a/src/resolve/test-resolved-etc-hosts.c b/src/resolve/test-resolved-etc-hosts.c index da10391d74e..08e178e7f63 100644 --- a/src/resolve/test-resolved-etc-hosts.c +++ b/src/resolve/test-resolved-etc-hosts.c @@ -9,6 +9,8 @@ static void test_parse_etc_hosts_system(void) { _cleanup_fclose_ FILE *f = NULL; + log_info("/* %s */", __func__); + f = fopen("/etc/hosts", "re"); if (!f) { assert_se(errno == -ENOENT); @@ -19,38 +21,32 @@ static void test_parse_etc_hosts_system(void) { assert_se(etc_hosts_parse(&hosts, f) == 0); } -static void test_parse_etc_hosts(const char *fname) { +static void test_parse_etc_hosts(void) { _cleanup_(unlink_tempfilep) char t[] = "/tmp/test-resolved-etc-hosts.XXXXXX"; + log_info("/* %s */", __func__); + int fd; _cleanup_fclose_ FILE *f; - if (fname) { - f = fopen(fname, "re"); - assert_se(f); - } else { - fd = mkostemp_safe(t); - assert_se(fd >= 0); - - f = fdopen(fd, "r+"); - assert_se(f); - fputs("1.2.3.4 some.where\n", f); - fputs("1.2.3.5 some.where\n", f); - fputs("::0 some.where some.other\n", f); - fputs("0.0.0.0 black.listed\n", f); - fputs("::5 some.where some.other foobar.foo.foo\n", f); - fputs(" \n", f); - fflush(f); - rewind(f); - } + fd = mkostemp_safe(t); + assert_se(fd >= 0); + + f = fdopen(fd, "r+"); + assert_se(f); + fputs("1.2.3.4 some.where\n", f); + fputs("1.2.3.5 some.where\n", f); + fputs("::0 some.where some.other\n", f); + fputs("0.0.0.0 black.listed\n", f); + fputs("::5 some.where some.other foobar.foo.foo\n", f); + fputs(" \n", f); + fflush(f); + rewind(f); _cleanup_(etc_hosts_free) EtcHosts hosts = {}; assert_se(etc_hosts_parse(&hosts, f) == 0); - if (fname) - return; - EtcHostsItemByName *bn; assert_se(bn = hashmap_get(hosts.by_name, "some.where")); assert_se(bn->n_addresses == 3); @@ -79,14 +75,26 @@ static void test_parse_etc_hosts(const char *fname) { assert_se(!set_contains(hosts.no_address, "foobar.foo.foo")); } +static void test_parse_file(const char *fname) { + _cleanup_(etc_hosts_free) EtcHosts hosts = {}; + _cleanup_fclose_ FILE *f; + + log_info("/* %s(\"%s\") */", __func__, fname); + + assert_se(f = fopen(fname, "re")); + assert_se(etc_hosts_parse(&hosts, f) == 0); +} + int main(int argc, char **argv) { log_set_max_level(LOG_DEBUG); log_parse_environment(); log_open(); - if (argc == 1) + if (argc == 1) { test_parse_etc_hosts_system(); - test_parse_etc_hosts(argv[1]); + test_parse_etc_hosts(); + } else + test_parse_file(argv[1]); return 0; }