!665 修复misc09用例因依赖hosts文件而失败

Merge pull request !665 from lnlan/sys_misc_test_fix
This commit is contained in:
openharmony_ci 2021-10-30 02:15:26 +00:00 committed by Gitee
commit 3074449c79
1 changed files with 19 additions and 4 deletions

View File

@ -30,14 +30,29 @@
*/ */
#include "It_test_misc.h" #include "It_test_misc.h"
static UINT32 TestCase(VOID) STATIC UINT32 TestCase(VOID)
{ {
long ret; INT32 ret;
CHAR *hostsFileStream = "127.0.0.1 localhost\n192.168.1.3 hisilicon\n::1 localhost\n";
CHAR *pathList[] = {"/etc/hosts"};
CHAR *streamList[] = {hostsFileStream};
INT32 streamLen[] = {strlen(hostsFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 1);
if (ret != 0) {
printf("error: need some env files, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 1);
return -1;
}
ret = gethostid(); ret = gethostid();
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, ERROUT);
(VOID)RecoveryFileEnv(pathList, 1);
return 0; return 0;
ERROUT:
(VOID)RecoveryFileEnv(pathList, 1);
return -1;
} }
VOID ItTestMisc009(VOID) VOID ItTestMisc009(VOID)