修复ppoll接口"[ERR]OsMemFree check error!"报错
【背景】 内核中释放用户空间指针报错:"[ERR]OsMemFree check error!" 【修改方案】 修改SysPpoll函数。 【影响】 对现有的产品编译不会有影响。 re #I47YWZ Change-Id: Id7f86036870d4f32be8fc438b9aad85cdda59546 Signed-off-by: pef <cyd1997@126.com>
This commit is contained in:
@@ -1,36 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_IO.h"
|
||||
#include "pthread.h"
|
||||
|
||||
#define BUF_SIZE 128
|
||||
#define DELAY_TIME 200
|
||||
const int BUF_SIZE = 128;
|
||||
const int DELAY_TIME = 200;
|
||||
|
||||
STATIC INT32 pipeFdPpoll[2];
|
||||
STATIC INT32 g_step = 1;
|
||||
STATIC CHAR strBuf[] = "hello world.";
|
||||
STATIC struct pollfd pfd;
|
||||
static INT32 pipeFdPpoll[2];
|
||||
static INT32 g_step = 1;
|
||||
static CHAR strBuf[] = "hello world.";
|
||||
static struct pollfd pfd;
|
||||
|
||||
STATIC VOID *pthread_01(VOID *arg)
|
||||
static void *pthread_01(void *arg)
|
||||
{
|
||||
INT32 retVal;
|
||||
CHAR buf[BUF_SIZE];
|
||||
const struct timespec timeout = {1000, 0};
|
||||
|
||||
/* 执行ppoll监视文件描述符*/
|
||||
while(g_step < 3) {
|
||||
/* 执行ppoll监视文件描述符 */
|
||||
while (g_step < 3) { /* 3, 3rd step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
g_step++;
|
||||
retVal = ppoll(&pfd, 1, NULL, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
|
||||
|
||||
while(g_step < 5) {
|
||||
while (g_step < 5) { /* 5, 5th step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
g_step++;
|
||||
|
||||
/* 判断revents*/
|
||||
/* 判断revents */
|
||||
if (pfd.revents & POLLIN) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset_s(buf, sizeof(buf), 0, sizeof(buf));
|
||||
retVal = read(pfd.fd, buf, BUF_SIZE);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
|
||||
|
||||
@@ -38,7 +68,7 @@ STATIC VOID *pthread_01(VOID *arg)
|
||||
ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal);
|
||||
}
|
||||
|
||||
while(g_step < 6) {
|
||||
while (g_step < 6) { /* 6, 6th step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
pthread_exit(NULL);
|
||||
@@ -49,28 +79,28 @@ STATIC UINT32 testcase(VOID)
|
||||
INT32 retVal;
|
||||
pthread_t tid;
|
||||
|
||||
/* 建立管道*/
|
||||
while(g_step < 1) {
|
||||
/* 建立管道 */
|
||||
while (g_step < 1) { /* 1, 1st step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
retVal = pipe(pipeFdPpoll);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
|
||||
g_step++;
|
||||
|
||||
/* 设置pfd*/
|
||||
pfd.fd = pipeFdPpoll[0];
|
||||
/* 设置pfd */
|
||||
pfd.fd = pipeFdPpoll[0];
|
||||
pfd.events = POLLIN;
|
||||
|
||||
/* 开辟线程执行 ppoll*/
|
||||
while(g_step < 2) {
|
||||
/* 开辟线程执行 ppoll */
|
||||
while (g_step < 2) { /* 2, 2nd step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
retVal = pthread_create(&tid, NULL, pthread_01, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(retVal, 0, retVal);
|
||||
g_step++;
|
||||
|
||||
/* 向管道写入数据*/
|
||||
while(g_step < 4) {
|
||||
/* 向管道写入数据 */
|
||||
while (g_step < 4) { /* 4, 4th step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
@@ -1,9 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_IO.h"
|
||||
#include "signal.h"
|
||||
#include "pthread.h"
|
||||
|
||||
#define BUF_SIZE 128
|
||||
#define DELAY_TIME 200
|
||||
const int BUF_SIZE = 128;
|
||||
const int DELAY_TIME = 200;
|
||||
|
||||
static int pipeFdPpoll[2];
|
||||
static int g_step = 1;
|
||||
@@ -17,7 +48,7 @@ static void *pthread_01(void *arg)
|
||||
const struct timespec timeout = {10000, 0};
|
||||
|
||||
/* 执行ppoll监视文件描述符 */
|
||||
while(g_step < 4) {
|
||||
while (g_step < 4) { /* 4, 4th step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
g_step++;
|
||||
@@ -26,14 +57,14 @@ static void *pthread_01(void *arg)
|
||||
|
||||
/* 判断revents */
|
||||
if (pfd.revents & POLLIN) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset_s(buf, sizeof(buf), 0, sizeof(buf));
|
||||
retVal = read(pfd.fd, buf, BUF_SIZE);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
|
||||
retVal = strcmp(strBuf, buf);
|
||||
ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal);
|
||||
}
|
||||
|
||||
while(g_step < 5) {
|
||||
while (g_step < 5) { /* 5, 5th step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
pthread_exit(NULL);
|
||||
@@ -45,7 +76,7 @@ static UINT32 testcase(VOID)
|
||||
pthread_t tid;
|
||||
|
||||
/* 建立管道 */
|
||||
while(g_step < 1) {
|
||||
while (g_step < 1) {
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
retVal = pipe(pipeFdPpoll);
|
||||
@@ -57,7 +88,7 @@ static UINT32 testcase(VOID)
|
||||
pfd.events = POLLIN;
|
||||
|
||||
/* 向管道写入数据 */
|
||||
while(g_step < 2) {
|
||||
while (g_step < 2) { /* 2, 2nd step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
sleep(1);
|
||||
@@ -67,7 +98,7 @@ static UINT32 testcase(VOID)
|
||||
g_step++;
|
||||
|
||||
/* 开辟线程执行 ppoll */
|
||||
while(g_step < 3) {
|
||||
while (g_step < 3) { /* 3, 3rd step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
retVal = pthread_create(&tid, NULL, pthread_01, NULL);
|
||||
@@ -76,7 +107,7 @@ static UINT32 testcase(VOID)
|
||||
|
||||
pthread_join(tid, NULL);
|
||||
|
||||
return LOS_OK;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID IO_TEST_PPOLL_002(VOID)
|
||||
|
||||
@@ -1,35 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_IO.h"
|
||||
#include "pthread.h"
|
||||
#include "signal.h"
|
||||
|
||||
#define BUF_SIZE 128
|
||||
#define DELAY_TIME 200
|
||||
const int BUF_SIZE = 128;
|
||||
const int DELAY_TIME = 200;
|
||||
|
||||
STATIC INT32 pipeFdPpoll[2];
|
||||
STATIC INT32 g_step = 1;
|
||||
STATIC CHAR strBuf[] = "hello world.";
|
||||
STATIC struct pollfd pfd;
|
||||
sigset_t sigMask;
|
||||
STATIC UINT32 count = 0;
|
||||
static INT32 pipeFdPpoll[2];
|
||||
static INT32 g_step = 1;
|
||||
static CHAR strBuf[] = "hello world.";
|
||||
static struct pollfd pfd;
|
||||
static sigset_t sigMask;
|
||||
static UINT32 count = 0;
|
||||
|
||||
STATIC VOID signalHandle(INT32 sigNum)
|
||||
static void signalHandle(INT32 sigNum)
|
||||
{
|
||||
//printf("Capture %d\n", sigNum);
|
||||
g_step++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC VOID *pthread_01(VOID *arg)
|
||||
static void *pthread_01(void *arg)
|
||||
{
|
||||
INT32 retVal;
|
||||
CHAR buf[BUF_SIZE];
|
||||
|
||||
signal(SIGUSR1, signalHandle);
|
||||
|
||||
(void)signal(SIGUSR1, signalHandle);
|
||||
|
||||
while (1) {
|
||||
/*执行ppoll监视文件描述符*/
|
||||
while (g_step < 2) {
|
||||
/* 执行ppoll监视文件描述符 */
|
||||
while (g_step < 2) { /* 2, 2nd step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
g_step++;
|
||||
@@ -37,9 +66,9 @@ STATIC VOID *pthread_01(VOID *arg)
|
||||
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
|
||||
|
||||
/*判断revents*/
|
||||
/* 判断revents */
|
||||
if (pfd.revents & POLLIN) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset_s(buf, sizeof(buf), 0, sizeof(buf));
|
||||
retVal = read(pfd.fd, buf, BUF_SIZE);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
|
||||
|
||||
@@ -50,72 +79,71 @@ STATIC VOID *pthread_01(VOID *arg)
|
||||
} else {
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(pfd.revents & POLLIN, 0, pfd.revents & POLLIN);
|
||||
}
|
||||
g_step++;
|
||||
g_step++;
|
||||
|
||||
if (g_step >= 7) {
|
||||
ICUNIT_ASSERT_EQUAL_NULL(count, 2, count);
|
||||
if (g_step >= 7) { /* 7, 7th step */
|
||||
ICUNIT_ASSERT_EQUAL_NULL(count, 2, count); /* 2, 2nd step */
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 testcase(VOID)
|
||||
static UINT32 testcase(VOID)
|
||||
{
|
||||
INT32 retVal;
|
||||
pthread_t tid;
|
||||
|
||||
/*建立管道*/
|
||||
|
||||
/* 建立管道 */
|
||||
while (g_step < 1) {
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
retVal = pipe(pipeFdPpoll);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
|
||||
|
||||
/*设置pfd sigmask*/
|
||||
pfd.fd = pipeFdPpoll[0];
|
||||
/* 设置pfd sigmask */
|
||||
pfd.fd = pipeFdPpoll[0];
|
||||
pfd.events = POLLIN;
|
||||
pfd.revents = 0x0;
|
||||
|
||||
sigemptyset(&sigMask);
|
||||
sigaddset(&sigMask, SIGUSR1);
|
||||
|
||||
/*开辟线程执行 ppoll*/
|
||||
|
||||
/* 开辟线程执行 ppoll */
|
||||
retVal = pthread_create(&tid, NULL, pthread_01, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(retVal, 0, retVal);
|
||||
g_step++;
|
||||
|
||||
/*向管道写入数据*/
|
||||
while (g_step < 3) {
|
||||
|
||||
/* 向管道写入数据 */
|
||||
while (g_step < 3) { /* 3, 3ed step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
sleep(1); /*保证先挂起再写入数据*/
|
||||
sleep(1); /* 保证先挂起再写入数据 */
|
||||
retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf));
|
||||
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
|
||||
|
||||
/*向线程发送信号*/
|
||||
while (g_step < 5) {
|
||||
/* 向线程发送信号 */
|
||||
while (g_step < 5) { /* 5, 5th step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
sleep(1); /*保证先挂起再发送信号*/
|
||||
sleep(1); /* 保证先挂起再发送信号 */
|
||||
retVal = pthread_kill(tid, SIGUSR1);
|
||||
ICUNIT_ASSERT_EQUAL(retVal, 0, retVal);
|
||||
|
||||
/*继续向管道写入数据*/
|
||||
ICUNIT_ASSERT_EQUAL(g_step, 5, g_step); /*判断挂起解除之前信号没有被处理*/
|
||||
/* 继续向管道写入数据 */
|
||||
ICUNIT_ASSERT_EQUAL(g_step, 5, g_step); /* 5, sth。判断挂起解除之前信号没有被处理 */
|
||||
retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf));
|
||||
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
|
||||
|
||||
while (g_step < 7) {
|
||||
while (g_step < 7) { /* 7, 7th step */
|
||||
usleep(DELAY_TIME);
|
||||
}
|
||||
ICUNIT_ASSERT_EQUAL(count, 2, count);
|
||||
/*等待退出*/
|
||||
ICUNIT_ASSERT_EQUAL(count, 2, count); /* 2, 2nd step */
|
||||
/* 等待退出 */
|
||||
pthread_join(tid, NULL);
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID IO_TEST_PPOLL_003(VOID)
|
||||
|
||||
Reference in New Issue
Block a user