From: Erik van der Kouwe Date: Wed, 8 Jul 2015 07:30:15 +0000 (+0200) Subject: test48: move can_use_network function to common code for reuse X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=refs%2Fchanges%2F23%2F3023%2F1;p=minix.git test48: move can_use_network function to common code for reuse Change-Id: I66a5f36f05fa4c4413b3b62c555fa58fbe5d73ea --- diff --git a/minix/tests/common.c b/minix/tests/common.c index 986858f22..8da406896 100644 --- a/minix/tests/common.c +++ b/minix/tests/common.c @@ -183,3 +183,23 @@ void getmem(uint32_t *total, uint32_t *free, uint32_t *cached) fclose(f); } +static int get_setting(const char *name, int def) +{ + const char *value; + + value = getenv(name); + if (!value || !*value) return def; + if (strcmp(value, "yes") == 0) return 1; + if (strcmp(value, "no") == 0) return 0; + + fprintf(stderr, "warning: invalid $%s value: %s\n", name, value); + return 0; +} + +int get_setting_use_network(void) +{ + /* set $USENETWORK to "yes" or "no" to indicate whether + * an internet connection is to be expected; defaults to "no" + */ + return get_setting("USENETWORK", 0); +} diff --git a/minix/tests/common.h b/minix/tests/common.h index 1290883d2..f4593d0bb 100644 --- a/minix/tests/common.h +++ b/minix/tests/common.h @@ -23,5 +23,6 @@ void rm_rf_dir(int test_nr); void rm_rf_ppdir(int test_nr); void start(int test_nr); void getmem(uint32_t *total, uint32_t *free, uint32_t *cached); +int get_setting_use_network(void); extern int common_test_nr, errct, subtest; diff --git a/minix/tests/test48.c b/minix/tests/test48.c index 697bd9459..73294c33b 100644 --- a/minix/tests/test48.c +++ b/minix/tests/test48.c @@ -575,29 +575,13 @@ static void test_getnameinfo_all(void) } } -static int can_use_network(void) -{ - const char *usenet; - - /* set $USENETWORK to "yes" or "no" to indicate whether - * an internet connection is to be expected; defaults to "no" - */ - usenet = getenv("USENETWORK"); - if (!usenet || !*usenet) return 0; /* default: disable network */ - if (strcmp(usenet, "yes") == 0) return 1; /* network enabled */ - if (strcmp(usenet, "no") == 0) return 0; /* network disabled */ - - fprintf(stderr, "warning: invalid $USENETWORK value: %s\n", usenet); - return 0; -} - int main(void) { int use_network; start(48); - use_network = can_use_network(); + use_network = get_setting_use_network(); test_getaddrinfo_all(use_network); test_getnameinfo_all();