test48: move can_use_network function to common code for reuse
Change-Id: I66a5f36f05fa4c4413b3b62c555fa58fbe5d73ea
This commit is contained in:
parent
c4182e08ab
commit
3433559c50
3 changed files with 22 additions and 17 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue