Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
78a50aff
K
Kernel Liteos A
项目概览
OpenHarmony
/
Kernel Liteos A
9 个月 前同步成功
通知
450
Star
414
Fork
55
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos A
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
78a50aff
编写于
7月 13, 2021
作者:
O
openharmony_ci
提交者:
Gitee
7月 13, 2021
浏览文件
操作
浏览文件
下载
差异文件
!396 修复signal中的关于pipe部分的用例问题
Merge pull request !396 from phchang/fix_pipebug
上级
7240fe3b
fd6f91bc
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
105 addition
and
49 deletion
+105
-49
testsuites/unittest/signal/full/It_ipc_fdclr_001.cpp
testsuites/unittest/signal/full/It_ipc_fdclr_001.cpp
+1
-1
testsuites/unittest/signal/full/It_ipc_fdset_001.cpp
testsuites/unittest/signal/full/It_ipc_fdset_001.cpp
+1
-1
testsuites/unittest/signal/full/It_ipc_fdzero_001.cpp
testsuites/unittest/signal/full/It_ipc_fdzero_001.cpp
+1
-1
testsuites/unittest/signal/full/It_ipc_pipe_002.cpp
testsuites/unittest/signal/full/It_ipc_pipe_002.cpp
+15
-2
testsuites/unittest/signal/full/It_ipc_pipe_003.cpp
testsuites/unittest/signal/full/It_ipc_pipe_003.cpp
+17
-4
testsuites/unittest/signal/full/pipe_test_005.cpp
testsuites/unittest/signal/full/pipe_test_005.cpp
+32
-30
testsuites/unittest/signal/signal_test.cpp
testsuites/unittest/signal/signal_test.cpp
+11
-0
testsuites/unittest/signal/smoke/It_ipc_fdisset_001.cpp
testsuites/unittest/signal/smoke/It_ipc_fdisset_001.cpp
+1
-1
testsuites/unittest/signal/smoke/pipe_test_002.cpp
testsuites/unittest/signal/smoke/pipe_test_002.cpp
+26
-9
未找到文件。
testsuites/unittest/signal/full/It_ipc_fdclr_001.cpp
浏览文件 @
78a50aff
...
...
@@ -46,7 +46,7 @@ static UINT32 Testcase(VOID)
ret
=
pipe
(
pipeFd
[
i
]);
ICUNIT_GOTO_EQUAL
(
ret
,
0
,
ret
,
EXIT
);
fdmax
=
pipeFd
[
i
][
1
]
>
fdmax
?
pipeFd
[
i
][
1
]
:
fdmax
;
ret
=
write
(
pipeFd
[
i
][
1
],
"
hello
world"
,
TAR_STR_LEN
);
ret
=
write
(
pipeFd
[
i
][
1
],
"
aloha
world"
,
TAR_STR_LEN
);
printf
(
"write first status: %d
\n
"
,
ret
);
ICUNIT_GOTO_EQUAL
(
ret
,
TAR_STR_LEN
,
ret
,
EXIT
);
}
...
...
testsuites/unittest/signal/full/It_ipc_fdset_001.cpp
浏览文件 @
78a50aff
...
...
@@ -49,7 +49,7 @@ static UINT32 Testcase(VOID)
ICUNIT_GOTO_EQUAL
(
ret
,
0
,
ret
,
EXIT
);
fdmax
=
pipeFd
[
i
][
1
]
>
fdmax
?
pipeFd
[
i
][
1
]
:
fdmax
;
fdmax
=
pipeFd
[
i
][
0
]
>
fdmax
?
pipeFd
[
i
][
0
]
:
fdmax
;
ret
=
write
(
pipeFd
[
i
][
1
],
"
hello w
orld"
,
TAR_STR_LEN
);
ret
=
write
(
pipeFd
[
i
][
1
],
"
Aloha W
orld"
,
TAR_STR_LEN
);
printf
(
"write first status: %d
\n
"
,
ret
);
ICUNIT_GOTO_EQUAL
(
ret
,
TAR_STR_LEN
,
ret
,
EXIT
);
}
...
...
testsuites/unittest/signal/full/It_ipc_fdzero_001.cpp
浏览文件 @
78a50aff
...
...
@@ -48,7 +48,7 @@ static UINT32 Testcase(VOID)
ret
=
pipe
(
pipeFd
[
i
]);
ICUNIT_GOTO_EQUAL
(
ret
,
0
,
ret
,
EXIT
);
fdmax
=
pipeFd
[
i
][
1
]
>
fdmax
?
pipeFd
[
i
][
1
]
:
fdmax
;
ret
=
write
(
pipeFd
[
i
][
1
],
"
hello
world"
,
TAR_STR_LEN
);
ret
=
write
(
pipeFd
[
i
][
1
],
"
Aloha
world"
,
TAR_STR_LEN
);
printf
(
"write first status: %d
\n
"
,
ret
);
ICUNIT_GOTO_EQUAL
(
ret
,
TAR_STR_LEN
,
ret
,
EXIT
);
}
...
...
testsuites/unittest/signal/full/It_ipc_pipe_002.cpp
浏览文件 @
78a50aff
...
...
@@ -29,28 +29,41 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "it_test_signal.h"
#include "sys/shm.h"
static
UINT32
Testcase
(
VOID
)
{
int
pipeFd
[
2
],
ret
,
spid
;
// 2, pipe return 2 file descripter
char
buffer
[
20
];
// 20, target buffer size
int
*
sharedflag
=
NULL
;
int
shmid
;
ret
=
pipe
(
pipeFd
);
ICUNIT_GOTO_EQUAL
(
ret
,
0
,
ret
,
EXIT1
);
shmid
=
shmget
((
key_t
)
IPC_PRIVATE
,
sizeof
(
int
),
0666
|
IPC_CREAT
);
// 0666 the authority of the shm
ICUNIT_ASSERT_NOT_EQUAL
(
shmid
,
-
1
,
shmid
);
sharedflag
=
(
int
*
)
shmat
(
shmid
,
NULL
,
0
);
*
sharedflag
=
0
;
spid
=
fork
();
ICUNIT_GOTO_NOT_EQUAL
(
spid
,
-
1
,
spid
,
EXIT1
);
if
(
spid
==
0
)
{
sharedflag
=
(
int
*
)
shmat
(
shmid
,
NULL
,
0
);
close
(
pipeFd
[
0
]);
sleep
(
10
);
// 10, sleep 10 second.
ret
=
write
(
pipeFd
[
1
],
"hello world"
,
12
);
// 12, "hello world" length and '\0'
printf
(
"write first status: %d
\n
"
,
ret
);
if
(
ret
!=
12
)
{
// 12, "hello world" length and '\0'
exit
(
11
);
// 11, the value of son process unexpect exit, convenient to debug
}
*
sharedflag
=
1
;
close
(
pipeFd
[
1
]);
exit
(
RED_FLAG
);
}
close
(
pipeFd
[
1
]);
// waitting for the sub process has written the sentence
while
(
*
sharedflag
!=
1
)
{
usleep
(
1
);
}
ret
=
read
(
pipeFd
[
0
],
buffer
,
12
);
// 12, "hello world" length and '\0'
ICUNIT_GOTO_EQUAL
(
ret
,
12
,
ret
,
EXIT
);
// 12, "hello world" length and '\0'
ret
=
strcmp
(
buffer
,
"hello world"
);
...
...
testsuites/unittest/signal/full/It_ipc_pipe_003.cpp
浏览文件 @
78a50aff
...
...
@@ -29,7 +29,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "it_test_signal.h"
#include "sys/shm.h"
static
const
int
TAR_STR_LEN
=
12
;
...
...
@@ -37,25 +37,38 @@ static UINT32 Testcase(VOID)
{
int
pipeFd
[
2
],
ret
,
spid
;
// 2, pipe return 2 file descripter
char
buffer
[
20
];
// 20, target buffer size
int
*
sharedflag
=
NULL
;
int
shmid
;
ret
=
pipe
(
pipeFd
);
ICUNIT_GOTO_EQUAL
(
ret
,
0
,
ret
,
EXIT1
);
shmid
=
shmget
((
key_t
)
IPC_PRIVATE
,
sizeof
(
int
),
0666
|
IPC_CREAT
);
// 0666 the authority of the shm
ICUNIT_ASSERT_NOT_EQUAL
(
shmid
,
-
1
,
shmid
);
sharedflag
=
(
int
*
)
shmat
(
shmid
,
NULL
,
0
);
*
sharedflag
=
0
;
spid
=
fork
();
ICUNIT_GOTO_NOT_EQUAL
(
spid
,
-
1
,
spid
,
EXIT1
);
if
(
spid
==
0
)
{
sharedflag
=
(
int
*
)
shmat
(
shmid
,
NULL
,
0
);
close
(
pipeFd
[
0
]);
ret
=
write
(
pipeFd
[
1
],
"
h
ello world"
,
TAR_STR_LEN
);
ret
=
write
(
pipeFd
[
1
],
"
H
ello world"
,
TAR_STR_LEN
);
printf
(
"write first status: %d
\n
"
,
ret
);
if
(
ret
!=
TAR_STR_LEN
)
{
exit
(
11
);
// 11, the value of son process unexpect exit, convenient to debug
}
*
sharedflag
=
1
;
close
(
pipeFd
[
1
]);
exit
(
RED_FLAG
);
}
close
(
pipeFd
[
1
]);
sleep
(
2
);
// 2, sleep 2 second
// waitting for the sub process has written the sentence
while
(
*
sharedflag
!=
1
)
{
usleep
(
1
);
}
ret
=
read
(
pipeFd
[
0
],
buffer
,
TAR_STR_LEN
);
ICUNIT_GOTO_EQUAL
(
ret
,
TAR_STR_LEN
,
ret
,
EXIT
);
ret
=
strcmp
(
buffer
,
"
h
ello world"
);
ret
=
strcmp
(
buffer
,
"
H
ello world"
);
ICUNIT_GOTO_EQUAL
(
ret
,
0
,
ret
,
EXIT
);
printf
(
"read pipe success: %s
\n
"
,
buffer
);
wait
(
&
ret
);
...
...
testsuites/unittest/signal/full/pipe_test_005.cpp
浏览文件 @
78a50aff
...
...
@@ -28,6 +28,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "sys/shm.h"
#include "it_test_signal.h"
#include "signal.h"
...
...
@@ -41,58 +42,59 @@ static int PipecommonWrite()
int
pipefd
[
2
];
// 2, array subscript
pid_t
pid
;
int
retValue
=
-
1
;
retValue
=
pipe
(
pipefd
);
ICUNIT_ASSERT_EQUAL
(
retValue
,
0
,
retValue
);
signal
(
SIGPIPE
,
SigPrint
);
int
*
sharedflag
=
NULL
;
int
shmid
;
int
*
readFd
=
&
pipefd
[
0
];
int
*
writeFd
=
&
pipefd
[
1
];
char
sentence
[]
=
"Hello World"
;
char
readbuffer
[
100
];
int
status
,
ret
;
retValue
=
pipe
(
pipefd
);
ICUNIT_ASSERT_EQUAL
(
retValue
,
0
,
retValue
);
if
(
signal
(
SIGPIPE
,
SigPrint
)
==
SIG_ERR
)
{
printf
(
"signal error
\n
"
);
}
shmid
=
shmget
((
key_t
)
IPC_PRIVATE
,
sizeof
(
int
),
0666
|
IPC_CREAT
);
// 0666 the authority of the shm
ICUNIT_ASSERT_NOT_EQUAL
(
shmid
,
-
1
,
shmid
);
sharedflag
=
(
int
*
)
shmat
(
shmid
,
NULL
,
0
);
*
sharedflag
=
0
;
pid
=
fork
();
if
(
pid
==
-
1
)
{
printf
(
"Fork Error!
\n
"
);
return
-
1
;
}
else
if
(
pid
==
0
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
// 3, Number of cycles
close
(
*
readFd
);
retValue
=
write
(
*
writeFd
,
sentence
,
strlen
(
sentence
)
+
1
);
if
(
i
==
0
)
{
if
(
retValue
!=
strlen
(
sentence
)
+
1
)
{
exit
(
retValue
);
}
}
else
{
if
(
retValue
!=
-
1
)
{
exit
(
retValue
);
}
if
(
errno
!=
EPIPE
)
{
exit
(
errno
);
}
}
usleep
(
150000
);
// 150000, Used to calculate the delay time.
sharedflag
=
(
int
*
)
shmat
(
shmid
,
NULL
,
0
);
close
(
*
readFd
);
retValue
=
write
(
*
writeFd
,
sentence
,
strlen
(
sentence
)
+
1
);
ICUNIT_ASSERT_EQUAL
(
retValue
,
strlen
(
sentence
)
+
1
,
retValue
);
*
sharedflag
=
1
;
// 2 waitting for the father process close the pipe's read port
while
(
*
sharedflag
!=
2
)
{
usleep
(
1
);
}
retValue
=
write
(
*
writeFd
,
sentence
,
strlen
(
sentence
)
+
1
);
ICUNIT_ASSERT_EQUAL
(
retValue
,
-
1
,
retValue
);
ICUNIT_ASSERT_EQUAL
(
errno
,
EPIPE
,
errno
);
exit
(
0
);
}
else
{
usleep
(
10000
);
// 10000, Used to calculate the delay time.
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
// 3, Number of cycles
close
(
*
readFd
);
close
(
*
writeFd
);
// 1 waitting for the sub process has written the sentence first
while
(
*
sharedflag
!=
1
)
{
usleep
(
1
);
}
close
(
*
readFd
);
// 2 father process close the pipe's read port
*
sharedflag
=
2
;
ret
=
waitpid
(
pid
,
&
status
,
0
);
ICUNIT_ASSERT_EQUAL
(
ret
,
pid
,
ret
);
ICUNIT_ASSERT_EQUAL
(
WEXITSTATUS
(
status
),
0
,
WEXITSTATUS
(
status
));
}
close
(
*
readFd
);
close
(
*
writeFd
);
return
0
;
}
void
ItPosixPipe005
(
void
)
{
TEST_ADD_CASE
(
__FUNCTION__
,
PipecommonWrite
,
TEST_POSIX
,
TEST_MEM
,
TEST_LEVEL0
,
TEST_FUNCTION
);
...
...
testsuites/unittest/signal/signal_test.cpp
浏览文件 @
78a50aff
...
...
@@ -627,6 +627,17 @@ HWTEST_F(SignalTest, ItPosixPipe003, TestSize.Level0)
ItPosixPipe003
();
}
/* *
* @tc.name: ItPosixPipe004
* @tc.desc: function for SignalTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F
(
SignalTest
,
ItPosixPipe004
,
TestSize
.
Level0
)
{
ItPosixPipe004
();
}
/* *
* @tc.name: ItPosixPipe005
* @tc.desc: function for SignalTest
...
...
testsuites/unittest/signal/smoke/It_ipc_fdisset_001.cpp
浏览文件 @
78a50aff
...
...
@@ -39,7 +39,7 @@ static UINT32 Testcase(VOID)
fd_set
reads
;
ret
=
pipe
(
pipeFd
);
ICUNIT_GOTO_EQUAL
(
ret
,
0
,
ret
,
EXIT
);
ret
=
write
(
pipeFd
[
1
],
"
hello w
orld"
,
TAR_STR_LEN
);
ret
=
write
(
pipeFd
[
1
],
"
Hello W
orld"
,
TAR_STR_LEN
);
printf
(
"write first status: %d
\n
"
,
ret
);
ICUNIT_GOTO_EQUAL
(
ret
,
TAR_STR_LEN
,
ret
,
EXIT
);
FD_ZERO
(
&
reads
);
...
...
testsuites/unittest/signal/smoke/pipe_test_002.cpp
浏览文件 @
78a50aff
...
...
@@ -31,6 +31,7 @@
#include "it_test_signal.h"
#include "signal.h"
#include "fcntl.h"
#include "sys/shm.h"
static
int
TestPipeMultiProcess
()
{
...
...
@@ -42,46 +43,62 @@ static int TestPipeMultiProcess()
int
*
readFd
=
&
pipefd
[
0
];
int
*
writeFd
=
&
pipefd
[
1
];
char
readbuffer
[
100
];
char
readbuffer
[
100
]
=
{
0
};
int
status
,
ret
;
int
totalNum
=
3
;
int
*
sharedflag
=
NULL
;
int
shmid
;
int
flag
=
fcntl
(
*
readFd
,
F_GETFL
);
fcntl
(
*
readFd
,
F_SETFL
,
flag
|
O_NONBLOCK
);
shmid
=
shmget
((
key_t
)
IPC_PRIVATE
,
sizeof
(
int
),
0666
|
IPC_CREAT
);
// 0666 the authority of the shm
ICUNIT_ASSERT_NOT_EQUAL
(
shmid
,
-
1
,
shmid
);
sharedflag
=
(
int
*
)
shmat
(
shmid
,
NULL
,
0
);
*
sharedflag
=
0
;
pid
=
fork
();
if
(
pid
==
-
1
)
{
printf
(
"Fork Error!
\n
"
);
return
-
1
;
}
else
if
(
pid
==
0
)
{
sharedflag
=
(
int
*
)
shmat
(
shmid
,
NULL
,
0
);
close
(
pipefd
[
0
]);
for
(
int
i
=
0
;
i
<
totalNum
;
i
++
)
{
errno
=
0
;
char
sentence1
[
15
]
=
"Hello World"
;
char
a
[
4
]
=
{
0
};
char
a
[
2
]
=
{
0
};
sprintf
(
a
,
"%d"
,
i
);
strcat
(
sentence1
,
a
);
int
ret
=
write
(
*
writeFd
,
sentence1
,
strlen
(
sentence1
)
+
1
);
ICUNIT_ASSERT_EQUAL
(
ret
,
strlen
(
sentence1
)
+
1
,
ret
);
usleep
(
10000
);
// 10000, Used to calculate the delay time.
}
*
sharedflag
=
1
;
ret
=
close
(
pipefd
[
1
]);
ICUNIT_ASSERT_EQUAL
(
ret
,
0
,
ret
);
exit
(
0
);
}
else
{
close
(
pipefd
[
1
]);
// waitting for the sub process has written the sentence first
while
(
*
sharedflag
!=
1
)
{
usleep
(
1
);
}
for
(
int
i
=
0
;
i
<
totalNum
;
i
++
)
{
printf
(
"read
\n
"
);
char
sentence1
[
15
]
=
"Hello World"
;
char
a
[
4
]
=
{
0
};
char
a
[
2
]
=
{
0
};
sprintf
(
a
,
"%d"
,
i
);
strcat
(
sentence1
,
a
);
memset
(
readbuffer
,
0
,
sizeof
(
readbuffer
));
retValue
=
read
(
*
readFd
,
readbuffer
,
s
izeof
(
readbuffer
)
);
printf
(
"Receive %d bytes data : %s,%d
\n
"
,
retValue
,
readbuffer
,
errno
);
ICUNIT_ASSERT_SIZE_STRING_EQUAL
(
readbuffer
,
readbuffer
,
strlen
(
sentence1
),
errno
);
retValue
=
read
(
*
readFd
,
readbuffer
,
s
trlen
(
sentence1
)
+
1
);
printf
(
"Receive %d bytes data : %s,
errno :
%d
\n
"
,
retValue
,
readbuffer
,
errno
);
ICUNIT_ASSERT_SIZE_STRING_EQUAL
(
readbuffer
,
sentence1
,
strlen
(
sentence1
),
errno
);
}
}
ret
=
waitpid
(
pid
,
&
status
,
0
);
ICUNIT_ASSERT_EQUAL
(
ret
,
pid
,
ret
);
ret
=
close
(
pipefd
[
0
]);
ICUNIT_ASSERT_EQUAL
(
ret
,
0
,
ret
);
ret
=
close
(
pipefd
[
1
]);
ICUNIT_ASSERT_EQUAL
(
ret
,
0
,
ret
);
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录