From f2f5c5fdc3202610de173e7046adab4df5e59142 Mon Sep 17 00:00:00 2001 From: lnlan Date: Thu, 28 Oct 2021 02:06:08 +0000 Subject: [PATCH] =?UTF-8?q?fix(test):=20misc09=E7=94=A8=E4=BE=8B=E5=9B=A0?= =?UTF-8?q?=E4=BE=9D=E8=B5=96hosts=E6=96=87=E4=BB=B6=E8=80=8C=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【背景】 1.etc/hosts文件不存在,misc09依赖hosts文件而失败 【修改方案】 1.用例执行前检查是否存在这些配置文件,不存在就跳过该用例 re#I48IZ0 Change-Id: I193cb03770932c1f681cd726ceb383816aa2257a Signed-off-by: lnlan Change-Id: I3fb7ca1ed5f8cc79a56cd1872f3b303ab325a7a9 --- .../unittest/misc/full/misc_test_009.cpp | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/testsuites/unittest/misc/full/misc_test_009.cpp b/testsuites/unittest/misc/full/misc_test_009.cpp index c8dcf10e..cc4c6518 100644 --- a/testsuites/unittest/misc/full/misc_test_009.cpp +++ b/testsuites/unittest/misc/full/misc_test_009.cpp @@ -30,14 +30,29 @@ */ #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(); - ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); - + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, ERROUT); + (VOID)RecoveryFileEnv(pathList, 1); return 0; + +ERROUT: + (VOID)RecoveryFileEnv(pathList, 1); + return -1; } VOID ItTestMisc009(VOID)