From 455e42e5b953d80164ede19431551d7bd9db899a Mon Sep 17 00:00:00 2001 From: vcbchang Date: Mon, 28 Jun 2021 19:27:38 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=9D=80?= =?UTF-8?q?=E6=AD=BB=E6=8E=89hilog=E8=BF=9B=E7=A8=8B=E5=90=8ESecurityCapab?= =?UTF-8?q?ility=E9=97=A8=E7=A6=81=E7=94=A8=E4=BE=8B=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【背景】如果操作系统先执行kill hilog进程,然后再执行SecurityCapability,那么门禁用例将无法通过,原因是该用例先获取了hilog进程的id,但hilog进程已经杀掉了,所以报错 【修改方案】 1. 增加kill 0与错误码判断,如果发现进程已经被干掉的话将不执行相关内容 【影响】 无其它影响。 Signed-off-by: vcbchang Change-Id: Icdf357800175eff19acf1f92426469642a697386 --- .../capability/smoke/cap_test_001.cpp | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/testsuites/unittest/security/capability/smoke/cap_test_001.cpp b/testsuites/unittest/security/capability/smoke/cap_test_001.cpp index 95f6eb9f..f8887989 100644 --- a/testsuites/unittest/security/capability/smoke/cap_test_001.cpp +++ b/testsuites/unittest/security/capability/smoke/cap_test_001.cpp @@ -82,22 +82,38 @@ static int TestChild(VOID) capheader.pid = INVAILD_PID; ret = capget(&capheader, &capdatac[0]); ICUNIT_ASSERT_EQUAL(ret, -1, ret); + errno = 0; capheader.pid = 3; - ret = capget(&capheader, &capdatac[0]); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - printf("e %d,p %d\n", capdatac[0].effective, capdatac[0].permitted); + kill(capheader.pid, 0); + if (errno != ESRCH) { + ret = capget(&capheader, &capdatac[0]); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + printf("e %d,p %d\n", capdatac[0].effective, capdatac[0].permitted); + } + errno = 0; capheader.pid = 4; - ret = capget(&capheader, &capdatac[0]); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - printf("e %d,p %d\n", capdatac[0].effective, capdatac[0].permitted); + kill(capheader.pid, 0); + if (errno != ESRCH) { + ret = capget(&capheader, &capdatac[0]); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + printf("e %d,p %d\n", capdatac[0].effective, capdatac[0].permitted); + } + errno = 0; capheader.pid = 5; - ret = capget(&capheader, &capdatac[0]); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - printf("e %d,p %d\n", capdatac[0].effective, capdatac[0].permitted); + kill(capheader.pid, 0); + if (errno != ESRCH) { + ret = capget(&capheader, &capdatac[0]); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + printf("e %d,p %d\n", capdatac[0].effective, capdatac[0].permitted); + } + errno = 0; capheader.pid = 6; - ret = capget(&capheader, &capdatac[0]); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - printf("e %d,p %d\n", capdatac[0].effective, capdatac[0].permitted); + kill(capheader.pid, 0); + if (errno != ESRCH) { + ret = capget(&capheader, &capdatac[0]); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + printf("e %d,p %d\n", capdatac[0].effective, capdatac[0].permitted); + } capheader.pid = 0; int pid = fork(); -- GitLab