feat: 添加pid容器测试用例
Close #I69Z22 Signed-off-by: zhushengle <zhushengle@huawei.com> Change-Id: If2d737766f4cecef70a57be9574cf3785b6900a8
This commit is contained in:
54
testsuites/unittest/container/full/It_pid_container_001.cpp
Normal file
54
testsuites/unittest/container/full/It_pid_container_001.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return getpid();
|
||||
}
|
||||
|
||||
void ItPidContainer001(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, CONTAINER_FIRST_PID);
|
||||
}
|
||||
148
testsuites/unittest/container/full/It_pid_container_002.cpp
Normal file
148
testsuites/unittest/container/full/It_pid_container_002.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return getpid();
|
||||
}
|
||||
|
||||
static int ChildFunClone3(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int childPid;
|
||||
int status;
|
||||
int ret;
|
||||
pid_t pid = getpid();
|
||||
int childFunRet = (int)pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
pid_t parent_pid = getppid();
|
||||
if (parent_pid != CONTAINER_FIRST_PID) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, SIGCHLD, NULL);
|
||||
if (childPid == -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ret = WIFEXITED(status);
|
||||
ret = WEXITSTATUS(status);
|
||||
if (ret != CONTAINER_THIRD_PID) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_5;
|
||||
}
|
||||
|
||||
free(pstk);
|
||||
return childFunRet;
|
||||
}
|
||||
|
||||
static int ChildFunClone2(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int status;
|
||||
int ret;
|
||||
pid_t pid = getpid();
|
||||
int childFunRet = (int)pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
int childPid = clone(ChildFunClone3, (char *)pstk + STACK_SIZE, SIGCHLD, NULL);
|
||||
if (childPid == -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
ret = wait(&status);
|
||||
ret = WIFEXITED(status);
|
||||
ret = WEXITSTATUS(status);
|
||||
if (ret != CONTAINER_SECOND_PID) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
free(pstk);
|
||||
return childFunRet;
|
||||
}
|
||||
|
||||
static int ChildFunClone1(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int status;
|
||||
int ret;
|
||||
pid_t pid = getpid();
|
||||
int childFunRet = (int)pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
int childPid = clone(ChildFunClone2, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
if (childPid == -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ret = WIFEXITED(status);
|
||||
ret = WEXITSTATUS(status);
|
||||
if (ret != CONTAINER_FIRST_PID) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
free(pstk);
|
||||
return childFunRet;
|
||||
}
|
||||
|
||||
void ItPidContainer002(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFunClone1, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, CONTAINER_FIRST_PID);
|
||||
}
|
||||
102
testsuites/unittest/container/full/It_pid_container_003.cpp
Normal file
102
testsuites/unittest/container/full/It_pid_container_003.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return getpid();
|
||||
}
|
||||
|
||||
static int ChildFunClone2()
|
||||
{
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWUTS | SIGCHLD, NULL);
|
||||
|
||||
free(pstk);
|
||||
return childPid;
|
||||
}
|
||||
|
||||
static int ChildFunClone1(void *p)
|
||||
{
|
||||
(void)p;
|
||||
pid_t pid = getpid();
|
||||
const int COUNT = 1000;
|
||||
int childPid;
|
||||
int childFunRet = (int)pid;
|
||||
int processCount = 0;
|
||||
int ret;
|
||||
int status;
|
||||
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
childPid = ChildFunClone2();
|
||||
if (childPid != -1) {
|
||||
processCount++;
|
||||
} else {
|
||||
ret = wait(&status);
|
||||
if (ret > 0) {
|
||||
processCount--;
|
||||
} else {
|
||||
sleep(1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
while (processCount > 0) {
|
||||
ret = wait(&status);
|
||||
if (ret > 0) {
|
||||
processCount--;
|
||||
}
|
||||
}
|
||||
|
||||
return childFunRet;
|
||||
}
|
||||
|
||||
void ItPidContainer003(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFunClone1, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, CONTAINER_FIRST_PID);
|
||||
}
|
||||
100
testsuites/unittest/container/full/It_pid_container_004.cpp
Normal file
100
testsuites/unittest/container/full/It_pid_container_004.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return getpid();
|
||||
}
|
||||
|
||||
static int ChildFunClone2(void *p)
|
||||
{
|
||||
(void)p;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
if (childPid != -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
|
||||
free(pstk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ChildFunClone1(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret = 0;
|
||||
int status;
|
||||
pid_t pid = getpid();
|
||||
int childFunRet = (int)pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
int childPid = clone(ChildFunClone2, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
if (childPid == -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ret = WIFEXITED(status);
|
||||
ret = WEXITSTATUS(status);
|
||||
if (ret != 0) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
free(pstk);
|
||||
return childFunRet;
|
||||
}
|
||||
|
||||
void ItPidContainer004(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int status;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFunClone1, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, CONTAINER_FIRST_PID);
|
||||
}
|
||||
98
testsuites/unittest/container/full/It_pid_container_006.cpp
Normal file
98
testsuites/unittest/container/full/It_pid_container_006.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun1(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return getpid();
|
||||
}
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int status;
|
||||
int ret;
|
||||
pid_t pid = getpid();
|
||||
int childFunRet = (int)pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
int childPid = clone(ChildFun1, (char *)pstk + STACK_SIZE, SIGCHLD, NULL);
|
||||
if (childPid == -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ret = WIFEXITED(status);
|
||||
ret = WEXITSTATUS(status);
|
||||
if (ret != CONTAINER_SECOND_PID) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
childPid = clone(ChildFun1, (char *)pstk + STACK_SIZE, SIGCHLD, NULL);
|
||||
if (childPid == -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_5;
|
||||
}
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ret = WIFEXITED(status);
|
||||
ret = WEXITSTATUS(status);
|
||||
if (ret != CONTAINER_THIRD_PID) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_6;
|
||||
}
|
||||
|
||||
free(pstk);
|
||||
return childFunRet;
|
||||
}
|
||||
|
||||
void ItPidContainer006(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
pid_t parentPid = getpid();
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, CONTAINER_FIRST_PID);
|
||||
}
|
||||
72
testsuites/unittest/container/full/It_pid_container_007.cpp
Normal file
72
testsuites/unittest/container/full/It_pid_container_007.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
int status;
|
||||
int pid = getpid();
|
||||
if (pid != CONTAINER_FIRST_PID) {
|
||||
return -1;
|
||||
}
|
||||
ret = fork();
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
} else if (ret == 0) {
|
||||
if (getpid() != CONTAINER_SECOND_PID) {
|
||||
return -1;
|
||||
}
|
||||
exit(0);
|
||||
} else {
|
||||
wait(&status);
|
||||
}
|
||||
|
||||
exit(EXIT_CODE_ERRNO_5);
|
||||
}
|
||||
|
||||
void ItPidContainer007(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int status;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, EXIT_CODE_ERRNO_5);
|
||||
}
|
||||
85
testsuites/unittest/container/full/It_pid_container_008.cpp
Normal file
85
testsuites/unittest/container/full/It_pid_container_008.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
cpu_set_t initCpuset;
|
||||
|
||||
CPU_ZERO(&initCpuset);
|
||||
ret = sched_getaffinity(getpid(), sizeof(cpu_set_t), &initCpuset);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(1, &cpuset);
|
||||
ret = sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = sched_getaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
ret = (CPU_ISSET(0, &cpuset) > 0) ? 1 : 0;
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
ret = (CPU_ISSET(1, &cpuset) > 0) ? 1 : 0;
|
||||
if (ret != 1) {
|
||||
return EXIT_CODE_ERRNO_5;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer008(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
94
testsuites/unittest/container/full/It_pid_container_009.cpp
Normal file
94
testsuites/unittest/container/full/It_pid_container_009.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid;
|
||||
int count = 1000;
|
||||
int processCount = 0;
|
||||
|
||||
pid = getpid();
|
||||
if (pid != CONTAINER_FIRST_PID) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
sleep(5); /* delay 5s */
|
||||
exit(0);
|
||||
} else if (pid < 0) {
|
||||
if (errno != EAGAIN) {
|
||||
sleep(1);
|
||||
}
|
||||
ret = wait(&status);
|
||||
if (ret > 0) {
|
||||
processCount--;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
processCount++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
while (processCount > 0) {
|
||||
ret = wait(&status);
|
||||
if (ret > 0) {
|
||||
processCount--;
|
||||
} else {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
exit(EXIT_CODE_ERRNO_255);
|
||||
}
|
||||
|
||||
void ItPidContainer009(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int status;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, EXIT_CODE_ERRNO_255);
|
||||
}
|
||||
64
testsuites/unittest/container/full/It_pid_container_010.cpp
Normal file
64
testsuites/unittest/container/full/It_pid_container_010.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
int currGid = getpgrp();
|
||||
if (currGid != CONTAINER_FIRST_PID) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
ret = setpgid(getpid(), 0);
|
||||
if (ret == 0) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer010(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
54
testsuites/unittest/container/full/It_pid_container_011.cpp
Normal file
54
testsuites/unittest/container/full/It_pid_container_011.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return execl("/bin/toybox", "toybox", "ps", (char *)0);
|
||||
}
|
||||
|
||||
void ItPidContainer011(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
55
testsuites/unittest/container/full/It_pid_container_012.cpp
Normal file
55
testsuites/unittest/container/full/It_pid_container_012.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return execl("/bin/shell", "shell", "kill", "-9", "1", (char *)0);
|
||||
}
|
||||
|
||||
void ItPidContainer012(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
const int SIGNAL_NUM = 9;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ret = WTERMSIG(status);
|
||||
ASSERT_EQ(ret, SIGNAL_NUM);
|
||||
}
|
||||
67
testsuites/unittest/container/full/It_pid_container_013.cpp
Normal file
67
testsuites/unittest/container/full/It_pid_container_013.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
pid_t pid = getpid();
|
||||
if (pid != 1) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
struct timespec ts = { 0 };
|
||||
const int MIN_NSEC = 5000000;
|
||||
const int MAX_NSEC = 20000000;
|
||||
int ret = sched_rr_get_interval(pid, &ts);
|
||||
if ((ts.tv_nsec < MIN_NSEC) || (ts.tv_nsec > MAX_NSEC)) {
|
||||
if (ts.tv_nsec != -1) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ItPidContainer013(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
146
testsuites/unittest/container/full/It_pid_container_014.cpp
Normal file
146
testsuites/unittest/container/full/It_pid_container_014.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret = 0;
|
||||
int val, currPolicy;
|
||||
struct sched_param param = { 0 };
|
||||
const int DEFALUTE_PRIORITY = 31;
|
||||
int testProcessPri = 0;
|
||||
int currProcessPri = getpriority(PRIO_PROCESS, getpid());
|
||||
if ((currProcessPri > DEFALUTE_PRIORITY) || (currProcessPri < 0)) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
testProcessPri = currProcessPri + 1;
|
||||
currPolicy = sched_getscheduler(getpid());
|
||||
if (currPolicy != SCHED_RR) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
|
||||
val = getpriority(PRIO_PROCESS, 0);
|
||||
if (val != currProcessPri) {
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
ret = sched_getparam(0, ¶m);
|
||||
if ((ret != 0) || (param.sched_priority != currProcessPri)) {
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
val = sched_getscheduler(0);
|
||||
if (val != currPolicy) {
|
||||
return EXIT_CODE_ERRNO_5;
|
||||
}
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, 0, testProcessPri);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_6;
|
||||
}
|
||||
|
||||
ret = getpriority(PRIO_PROCESS, 0);
|
||||
if (ret != testProcessPri) {
|
||||
return EXIT_CODE_ERRNO_7;
|
||||
}
|
||||
|
||||
param.sched_priority = currProcessPri;
|
||||
ret = sched_setparam(0, ¶m);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_8;
|
||||
}
|
||||
|
||||
ret = getpriority(PRIO_PROCESS, getpid());
|
||||
if (ret != currProcessPri) {
|
||||
return EXIT_CODE_ERRNO_9;
|
||||
}
|
||||
|
||||
ret = sched_setscheduler(0, SCHED_FIFO, ¶m);
|
||||
if ((ret != -1) || (errno != EINVAL)) {
|
||||
return EXIT_CODE_ERRNO_10;
|
||||
}
|
||||
|
||||
ret = sched_setscheduler(0, SCHED_RR, ¶m);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_11;
|
||||
}
|
||||
|
||||
ret = sched_setscheduler(1, SCHED_FIFO, ¶m);
|
||||
if ((ret != -1) || (errno != EINVAL)) {
|
||||
return EXIT_CODE_ERRNO_12;
|
||||
}
|
||||
|
||||
ret = sched_setscheduler(2, SCHED_FIFO, ¶m); // 2, input the pid.
|
||||
if ((ret != -1) || (errno != ESRCH)) {
|
||||
return EXIT_CODE_ERRNO_13;
|
||||
}
|
||||
|
||||
ret = sched_setparam(1, ¶m);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_14;
|
||||
}
|
||||
|
||||
ret = sched_setparam(2, ¶m); // 2, set the param.
|
||||
if ((ret != -1) || (errno != ESRCH)) {
|
||||
return EXIT_CODE_ERRNO_15;
|
||||
}
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, 1, testProcessPri);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_16;
|
||||
}
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, 2, testProcessPri); // 2, Used to calculate priorities.
|
||||
if ((ret != -1) || (errno != ESRCH)) {
|
||||
return EXIT_CODE_ERRNO_255;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer014(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
58
testsuites/unittest/container/full/It_pid_container_015.cpp
Normal file
58
testsuites/unittest/container/full/It_pid_container_015.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret = execl("/bin/shell", "shell", "v2p", "1", "0x1000000", (char *)0);
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer015(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
58
testsuites/unittest/container/full/It_pid_container_016.cpp
Normal file
58
testsuites/unittest/container/full/It_pid_container_016.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret = execl("/bin/shell", "shell", "vmm", "1", (char *)0);
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer016(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
58
testsuites/unittest/container/full/It_pid_container_017.cpp
Normal file
58
testsuites/unittest/container/full/It_pid_container_017.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret = execl("/bin/shell", "shell", "cpup", "0", "1", (char *)0);
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer017(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
155
testsuites/unittest/container/full/It_pid_container_018.cpp
Normal file
155
testsuites/unittest/container/full/It_pid_container_018.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
const int TEST_COUNT = 5;
|
||||
const int TEST_PARENT_SLEEP_TIME = 2;
|
||||
const int TEST_CHILD_SLEEP_TIME = 5;
|
||||
static int ChildShell(void *p)
|
||||
{
|
||||
printf("\n###################### %s pid container process info ####################\n", (char *)p);
|
||||
int ret = execl("/bin/shell", "shell", "task", "-a", (char *)0);
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *PthreadFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Child2(void *p)
|
||||
{
|
||||
(void)p;
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int Child1(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
|
||||
ret = waitpid(pid, NULL, 0);
|
||||
if (ret != pid) {
|
||||
exit(EXIT_CODE_ERRNO_5);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
|
||||
pid_t pid1 = fork();
|
||||
if (pid1 == 0) {
|
||||
ret = Child1(NULL);
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
pid_t pid2 = fork();
|
||||
if (pid2 == 0) {
|
||||
(void)Child2(NULL);
|
||||
}
|
||||
|
||||
pid_t pid3 = fork();
|
||||
if (pid3 == 0) {
|
||||
ret = ChildShell(static_cast<void *>(const_cast<char*>("Child")));
|
||||
if (ret != 0) {
|
||||
exit(EXIT_CODE_ERRNO_1);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
|
||||
ret = waitpid(pid1, NULL, 0);
|
||||
if (ret != pid1) {
|
||||
exit(EXIT_CODE_ERRNO_2);
|
||||
}
|
||||
|
||||
ret = waitpid(pid2, NULL, 0);
|
||||
if (ret != pid2) {
|
||||
exit(EXIT_CODE_ERRNO_3);
|
||||
}
|
||||
|
||||
ret = waitpid(pid3, NULL, 0);
|
||||
if (ret != pid3) {
|
||||
exit(EXIT_CODE_ERRNO_4);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer018(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
pid_t pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
sleep(TEST_PARENT_SLEEP_TIME);
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ChildShell(static_cast<void *>(const_cast<char*>("Parent")));
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
120
testsuites/unittest/container/full/It_pid_container_019.cpp
Normal file
120
testsuites/unittest/container/full/It_pid_container_019.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
const int TEST_COUNT = 5;
|
||||
const int TEST_CMD_LEN = 20;
|
||||
const int TEST_PARENT_SLEEP_TIME = 2;
|
||||
const int TEST_CHILD_SLEEP_TIME = 5;
|
||||
static int ChildShell(void *p)
|
||||
{
|
||||
pid_t pid = (pid_t)(uintptr_t)p;
|
||||
char param[TEST_CMD_LEN] = {0};
|
||||
int ret = snprintf_s(param, TEST_CMD_LEN, TEST_CMD_LEN - 1, "-p %d", pid);
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
printf("\n###################### Pid %d thread info ####################\n", pid);
|
||||
ret = execl("/bin/shell", "shell", "task", param, (char *)0);
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *PthreadFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
|
||||
pthread_t pthread[TEST_COUNT] = {0};
|
||||
for (int count = 0; count < TEST_COUNT; count++) {
|
||||
pthread_create(&pthread[count], NULL, PthreadFunc, NULL);
|
||||
}
|
||||
|
||||
pid_t pid1 = fork();
|
||||
if (pid1 == 0) {
|
||||
ret = ChildShell(reinterpret_cast<void *>(getppid()));
|
||||
if (ret != 0) {
|
||||
exit(EXIT_CODE_ERRNO_1);
|
||||
}
|
||||
}
|
||||
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
|
||||
ret = waitpid(pid1, NULL, 0);
|
||||
if (ret != pid1) {
|
||||
exit(EXIT_CODE_ERRNO_2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer019(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
pid_t pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
sleep(TEST_PARENT_SLEEP_TIME);
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ChildShell((void *)childPid);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
115
testsuites/unittest/container/full/It_pid_container_020.cpp
Normal file
115
testsuites/unittest/container/full/It_pid_container_020.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
const int TEST_COUNT = 5;
|
||||
const int TEST_PARENT_SLEEP_TIME = 3;
|
||||
static int Child(void *p)
|
||||
{
|
||||
(void)p;
|
||||
pid_t pid1 = fork();
|
||||
if (pid1 == 0) {
|
||||
pid_t pid3 = fork();
|
||||
if (pid3 == 0) {
|
||||
sleep(TEST_PARENT_SLEEP_TIME);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sleep(TEST_PARENT_SLEEP_TIME);
|
||||
if (getppid() != 1) {
|
||||
exit(EXIT_CODE_ERRNO_3);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
pid_t pid2 = fork();
|
||||
if (pid2 == 0) {
|
||||
sleep(TEST_PARENT_SLEEP_TIME);
|
||||
|
||||
if (getppid() != 1) {
|
||||
exit(EXIT_CODE_ERRNO_4);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
int count = 2;
|
||||
int status = 0;
|
||||
|
||||
pid_t pid1 = fork();
|
||||
if (pid1 == 0) {
|
||||
(void)Child(NULL);
|
||||
}
|
||||
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
if ((ret != pid1) || (WIFEXITED(status) == 0)) {
|
||||
exit(EXIT_CODE_ERRNO_2);
|
||||
}
|
||||
if (WEXITSTATUS(status) != 0) {
|
||||
exit(WEXITSTATUS(status));
|
||||
}
|
||||
|
||||
while (count > 0) {
|
||||
ret = wait(&status);
|
||||
if ((ret < 0) || (WIFEXITED(status) == 0)) {
|
||||
exit(EXIT_CODE_ERRNO_3);
|
||||
}
|
||||
if (WEXITSTATUS(status) != 0) {
|
||||
exit(WEXITSTATUS(status));
|
||||
}
|
||||
count--;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer020(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
72
testsuites/unittest/container/full/It_pid_container_021.cpp
Normal file
72
testsuites/unittest/container/full/It_pid_container_021.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
struct timespec ts;
|
||||
clockid_t clockid;
|
||||
int ret;
|
||||
const int TEST_PID = 2;
|
||||
ret = clock_getcpuclockid(TEST_PID, &clockid);
|
||||
if (ret != EINVAL) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
ret = clock_getcpuclockid(getpid(), &clockid);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
ret = clock_gettime(clockid, &ts);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer021(void)
|
||||
{
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int ret;
|
||||
int status;
|
||||
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
64
testsuites/unittest/container/full/It_pid_container_022.cpp
Normal file
64
testsuites/unittest/container/full/It_pid_container_022.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
unsigned int cap;
|
||||
pid_t pid = getpid();
|
||||
|
||||
ret = ohos_capget(pid, &cap);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
ret = kill(pid, SIGKILL);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ItPidContainer022(void)
|
||||
{
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int ret;
|
||||
siginfo_t info = { 0 };
|
||||
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitid(P_PID, childPid, &info, WEXITED);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
81
testsuites/unittest/container/full/It_pid_container_024.cpp
Normal file
81
testsuites/unittest/container/full/It_pid_container_024.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
#include "sys/resource.h"
|
||||
#include "sys/wait.h"
|
||||
#include "pthread.h"
|
||||
#include "sched.h"
|
||||
|
||||
const int SLEEP_TIME_US = 1000;
|
||||
const int LOOP_NUM = 1000;
|
||||
|
||||
static int ChildFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
usleep(SLEEP_TIME_US);
|
||||
exit(EXIT_CODE_ERRNO_5);
|
||||
}
|
||||
|
||||
static int GroupProcess(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
int ret;
|
||||
int status = 0;
|
||||
|
||||
for (int i = 0; i < LOOP_NUM; i++) {
|
||||
int argTmp = CHILD_FUNC_ARG;
|
||||
auto pid = CloneWrapper(ChildFunc, CLONE_NEWPID, &argTmp);
|
||||
if (pid == -1) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
if (status != EXIT_CODE_ERRNO_5) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
}
|
||||
|
||||
exit(EXIT_CODE_ERRNO_5);
|
||||
}
|
||||
|
||||
void ItPidContainer024(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
int arg = CHILD_FUNC_ARG;
|
||||
auto pid = CloneWrapper(GroupProcess, CLONE_NEWPID, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
status = WEXITSTATUS(status);
|
||||
ASSERT_EQ(status, EXIT_CODE_ERRNO_5);
|
||||
}
|
||||
Reference in New Issue
Block a user