您的当前位置:首页正文

测试规格说明书 1.7.6

来源:个人技术集锦


Linux进程通信- 测试规格说明书

SY1306110 琚午阳 SY1306120 童飞飞 SY1306115 李逍逍 SY1306223 常兵

版本提交记录表:

提交版本 测试规格说明书1.6.1 测试规格说明书1.6.2 测试规格说明书1.6.3 测试规格说明书1.7.1 测试规格说明书1.7.2 测试规格说明书1.7.3 测试规格说明书1.7.4 测试规格说明书1.7.5 测试规格说明书1.7.6 时间(2014年) 6-22 ~ 6-28 7-2 7-2 7-2 7-2 7-2 7-2 7-2 7-2 修改人员 全体组员 琚午阳, 常兵 童飞飞 李逍逍 童飞飞 常兵 琚午阳 李逍逍 童飞飞

[在此处键入]

1编写目的.................................................................................................. 1 2测试团队构成 ......................................................................................... 1 2.1职责 .................................................................................................... 1 2.2职责划分 ........................................................................................... 1 3工作流程及规范 ..................................................................................... 1 3.1计划与设计阶段 ............................................................................... 1 3.1.1测试团队...................................................................................... 1 3.1.2编写测试计划文档 ..................................................................... 2 3.1.3设计测试用例 ............................................................................. 2 3.1.4测试用例与设计需求对应关系表 ............................................. 2 3.1.5各模块测试需求用例设计 ......................................................... 3 3.1.5.1 管道及有名管道 ................................................................... 3 3.1.5.2 消息队列 ............................................................................. 10 3.1.5.3 共享内存 ............................................................................. 23 3.1.5.4 信号...................................................................................... 27 3.2实施测试阶段 ................................................................................. 31 3.3总结阶段 ......................................................................................... 50

测试规格说明书

1编写目的

本文档主要明确了本次测试的主要内容和测试小组各成员的分工,并对测试用例进行了初步的设计。测试技术和策略等问题不在本文档描述范围内。

2测试团队构成

2.1职责

测试是软件开发过程中的重要组成部分,肩负着如下责任:  编写合理的测试计划,并与需求分析相对应。  编写覆盖率高的测试用例。

 针对测试需求进行相关测试技术的研究。  认真仔细地实施测试工作,并提交测试报告。  撰写工作进度日志。

2.2职责划分

成员 琚午阳 李逍逍 童飞飞 常兵 琚午阳、李逍逍、 撰写测试规格说明书 童飞飞、常兵 相关主要责任  根据管道及有名管道相关需求及代码做测试需求分析  根据共享内存相关需求及代码做测试需求分析  根据消息队列相关需求及代码做测试需求分析  根据信号相关需求及代码做测试需求分析 3工作流程及规范

3.1计划与设计阶段

3.1.1测试团队

本测试团队与需求分析团队成员相同

1

测试规格说明书

3.1.2编写测试计划文档

需求分析文档确立后,测试组需要编写测试计划文档,为后续的测试工作提供直接的指导 过程要点 输入条件 详细说明 项目需求文档建立 根据项目的需求文档,按照测试计划文档模板编写测试计划。测试计划中应该至少包括以下关键内容:  根据已有的需求文档终稿,明确相应的测试用例,包括四大部分的测试用例模块。  具体设计各大模块的测试用例,设计完成后进行评审工作。 工作内容  根据评审后的测试用例编写测试代码  部署环境,具体测试各模块功能,记录测试数据及结果。  结合需求文档终稿,对测试结果进行分析。  完成整个测试需求文档,由评审组完成最终评审。 测试计划编写完毕后,必须提交给项目组全体成员,并由项目组组中各成员联合评审。 退出标准 责任人 3.1.3设计测试用例

在需求分析文档确立基线以后,测试组需要针对项目的测试需求编写测试用例,在实际的测试中,测试用例将是唯一实施标准。在用例的编写过程中,具体的任务和责任人如下: 过程要点 输入条件 工作内容 退出标准 责任人 详细说明 测试需求明确,测试计划明确 根据每一步测试计划编写全部的测试用例 测试用例需要覆盖大部分测试需求 测试组  测试获得预期成果。  测试由评审组评审通过. 测试团队 3.1.4测试用例与设计需求对应关系表

2

测试规格说明书

此次测试用例的编写没有额外考虑结构流程很相似的一些需求用例,主要以主干的一些功能需求为目标分析测试。 模块名称 所含需求 CreateAndOpenPipe WriteDataToPipe ReadDataFromPipe ClosePipe CreateAndOpenNamedPipe WriteDataToNamedPipe ReadDataFromNamedPipe CloseNamedPipe GetSharedMemory ReadSharedMemory WriteSharedMemory ControlSharedMemory ReleaseSharedMemory CreateNewMessageQueue OpenExistingMessageQueue 消息队列 SendMessage ReceiveMessage GetMessageQueueStatus SetMessageQueueProperties RemoveMessageQueue GenerateSignal SendSignal ReceiveSignal 信号 CancleSignal RunFunction ManageShieldCollection ManageBlockCollection 所选测试用例 Test create and open pipe Test write data to pipe Test read data from pipe Test close pipe —— —— —— —— Test get shared memory —— Test write shared memory Test control shared memory Test release shared memory Test create new message queue Test open existing message queue Test send message Test receive message —— —— —— Generate Signal Send Signal Receive Signal Shield Signal 管道与有名管道 共享内存 —— —— —— —— 3.1.5各模块测试需求用例设计

3.1.5.1 管道及有名管道

Name Brief Description Test Case Specification Test create and open pipe The test specification aims to test the behavior when parent process and child process create and open a pipe. 3

测试规格说明书

Precondition Tester Dependency Test Setup The kernel is running. The processes have relatives. None None Name Create parent process Description This test setup aims to create the parent process in the test environment. Basic Flow Steps (Test Setup) 1 The test system creates the parent process. Postcondition The parent process is created. (Test Oracle) Basic Flow Steps (Test Sequence) 1 The test system VALIDATES THAT the number of file descriptors the parent process uses is under the OS limit. 2 The test system VALIDATES THAT the OS limit on the total number of open files is not reached. 3 The parent process INVOKES API pipe() to create a duplex communication channel. 4 The parent process INVOKES API fork() to create its child process. 5 IF the pipe is used for parent-child communication THEN 6 The parent process and the child process INVOKES API close() to close one ends of the communication channel respectively to make the channel unidirectional. 7 ELSEIF the pipe is used for brother processes’ communication THEN 8 The child process A and the child process B INVOKES API close() to close one ends of the communication channel respectively to make the channel unidirectional. 9 ENDIF Postcondition The flow of creating and opening a pipe for two (Test Oracle) kinds of communications are tested, including normal condition and error handling. Specific RFS 1 Alternative 1 The test system receives an error code when Flows pipe() is invoked. (Test Sequence) 2 ABORT Postcondition The handling of an error condition is tested. (Test Sequence) 4

测试规格说明书

Specific RFS 2 Alternative 1 Flows (Test Sequence) 2 Postcondition (Test Sequence) Oracle RFS 3 Verification 1 Flow The test system receives an error code when pipe() is invoked. ABORT The handling of an error condition is tested. Oracle Verification Flow Oracle Verification Flow The test system VALIDATES THAT the file descriptor. Postcondition The result of normal condition is tested. (Test Oracle) RFS 6 1 The test system VALIDATES THAT the file descriptor of the end is not valid anymore. Postcondition The result of normal condition is tested. (Test Oracle) RFS 8 1 The test system VALIDATES THAT the file descriptor of the end is not valid anymore. Postcondition The result of normal condition is tested. (Test Oracle) Name Brief Description Precondition Tester Dependency Test Setup 1 Test Case Specification Test write data to pipe The test specification aims to test the behavior when process of writing message writes data to pipe. The kernel is running. The processes have relatives. None None Name Create and open a parent-child communication pipe Description This test setup aims to create and open a pipe used for parent-child communication in the test environment. Steps 1 The parent process INVOKES API pipe() to create a duplex communication channel. 2 The parent process INVOKES API fork() to create its child process. 3 The parent process and the child process INVOKES API close() to close one ends of the Basic Flow (Test Setup) 5

测试规格说明书

communication channel respectively to make the channel unidirectional. Postcondition The parent-child communication pipe is created (Test Oracle) and opened. Test Setup 2 Name Create and open a brother communication pipe Description This test setup aims to create and open a pipe used for brother processes’ communication in the test environment. Basic Flow Steps (Test Setup) 1 The parent process INVOKES API pipe() to create a duplex communication channel. 2 The parent process INVOKES API fork() to create its child process. 3 The child process A and the child process B INVOKES API close() to close one ends of the communication channel respectively to make the channel unidirectional. Postcondition The brother processes’ communication pipe is (Test Oracle) created and opened. Basic Flow Steps (Test Sequence) 1 The process of writing message formats the message to a proper type. 2 The test system VALIDATES THAT the pipe buffer is unlocked. 3 The test system VALIDATES THAT the read end of the pipe is open. 4 The process of writing message locks the pipe buffer. 5 The process of writing message INVOKES API write() to write message to the pipe by the file descriptor of the write end. 6 The process of writing message unlocks the pipe buffer. Postcondition The flow of writing data to a pipe for two kinds (Test Oracle) of communication are tested, including normal condition and error handling. Specific RFS 2 Alternative 1 DO process of writing message is sleep UNTIL the Flows system awakes the process of sending data in a (Test Sequence) proper time. 2 RESUME STEP 3 Postcondition The handling of an exception is tested. (Test Sequence) 6

测试规格说明书

Specific RFS 3 Alternative 1 Flows (Test Sequence) 2 Postcondition (Test Sequence) Oracle RFS 5 Verification 1 Flow The test system receives an error code when write() is invoked. ABORT The handling of an error condition is tested. The tester VERIFIES THAT the message is completely and correctly written to the pipe buffer. Postcondition The result of normal condition is tested. (Test Oracle) Name Brief Description Precondition Tester Dependency Test Setup 1 Test Case Specification Test read data from pipe The test specification aims to test the behavior when process of reading message reads message from pipe. The kernel is running. The processes have relatives. None None Name Create and open a parent-child communication pipe and write data to it Description This test setup aims to create and open a pipe used for parent-child communication in the test environment. Steps 1 The parent process INVOKES API pipe() to create a duplex communication channel. 2 The parent process INVOKES API fork() to create its child process. 3 The parent process and the child process INVOKES API close() to close one ends of the communication channel respectively to make the channel unidirectional. 4 The process of writing message INVOKES API write() to write message to the pipe by the file descriptor of the write end. Postcondition The flow of reading data to a pipe for two kinds (Test Oracle) of communication are tested, including normal condition and error handling. Name Create and open a brother communication pipe Basic Flow (Test Setup) Test Setup 2 7

测试规格说明书

Description This test setup aims to create and open a pipe used for brother processes’ communication in the test environment. Basic Flow (Test Setup) The parent process INVOKES API pipe() to create a duplex communication channel. 2 The parent process INVOKES API fork() to create its child process. 3 The child process A and the child process B INVOKES API close() to close one ends of the communication channel respectively to make the channel unidirectional. 4 The process of writing message INVOKES API write() to write message to the pipe by the file descriptor of the write end. Postcondition The brother processes’ communication pipe is (Test Oracle) created and opened, some message is written to it. Basic Flow Steps (Test Sequence) 1 The test system VALIDATES THAT the pipe buffer is unlocked. 2 The process of reading message locks the pipe buffer. 3 The process of reading message INVOKES API read() to read message from the pipe buffer by the file descriptor of the read end. 4 The process of reading message unlocks the pipe buffer. Postcondition The flow of reading data to a pipe for two kinds (Test Oracle) of communication are tested, including normal condition and error handling. Specific RFS 1 Alternative 1 DO process of reading message is sleep UNTIL the Flows system awakes the process of sending data in a (Test Sequence) proper time. 2 RESUME STEP 2 Postcondition The handling of an exception is tested. (Test Sequence) Oracle RFS 3 Verification 1 The tester VERIFIES THAT the message is Flow completely and correctly read. Postcondition The result of normal condition is tested. (Test Oracle) 8

Steps 1 测试规格说明书

Test Case Specification Name Test close pipe Brief The test specification aims to test the behavior when process Description closes a pipe. Precondition The kernel is running. The processes have relatives. Tester None Dependency None Test Setup 1 Name Create and open a parent-child communication pipe Description This test setup aims to create and open a pipe used for parent-child communication in the test environment. Basic Flow Steps (Test Setup) 1 The parent process INVOKES API pipe() to create a duplex communication channel. 2 The parent process INVOKES API fork() to create its child process. 3 The parent process and the child process INVOKES API close() to close one ends of the communication channel respectively to make the channel unidirectional. Postcondition The parent-child communication pipe is created (Test Oracle) and opened. Test Setup 2 Name Create and open a brother communication pipe Description This test setup aims to create and open a pipe used for brother processes’ communication in the test environment. Basic Flow Steps (Test Setup) 1 The parent process INVOKES API pipe() to create a duplex communication channel. 2 The parent process INVOKES API fork() to create its child process. 3 The child process A and the child process B INVOKES API close() to close one ends of the communication channel respectively to make the channel unidirectional. Postcondition The brother processes’ communication pipe is (Test Oracle) created and opened. Basic Flow Steps (Test Sequence) 1 The test system VALIDATES THAT the file descriptor of the write end is valid. 9

测试规格说明书

The process of writing message INVOKES API close() to close the write end and start waiting. 3 The test system VALIDATES THAT the file descriptor of the read end is valid. 4 The process of reading message reads all the message and INVOKES API close() to close the read end. 5 The process of reading message awakes the process of writing message. 6 The process of reading message and the process of writing message release their resource of the pipe. Postcondition The flow of closing a pipe for two kinds of (Test Oracle) communication are tested, including normal condition and error handling. Specific RFS 1 Alternative 1 The test system receives an error code when Flows close() is invoked. (Test Sequence) 2 ABORT Postcondition The handling of an error condition is tested. (Test Sequence) Specific RFS 3 Alternative 1 The test system receives an error code when Flows close() is invoked. (Test Sequence) 2 ABORT Postcondition The handling of an error condition is tested. (Test Sequence) Oracle RFS 2 Verification 1 The test system VALIDATES THAT the file Flow descriptor of the end is not valid anymore. Postcondition The result of normal condition is tested. (Test Oracle) Oracle RFS 4 Verification 1 The test system VALIDATES THAT the file Flow descriptor of the end is not valid anymore. Postcondition The result of normal condition is tested. (Test Oracle)

3.1.5.2 消息队列

2 1)获取消息队列

10

测试规格说明书

sys_msgget(key_t,int msgflag)

当创建一个新的消息队列,调用函数newque()来创建和初始化,并且把新建队列的1D返回给调用者。对于已经存在的消息队列,提供一个键值key。在全局消息队列描述符队列(msgids.entries)中,调用函数ipc_ findkey()查找相关的索引。在返回消息队列的ID之前,要对调用者的参数和权限进行校验。在查询操作与校验之前,还必须对全局消息队列自

旋锁 (msg_ids.ary)上锁。 简单框图如图1所示。

图1 sys_msgget的简单框图

Name Brief Description Precondition Tester Dependency Test Setup Test Case Specification CreateNewMessageQueueTest The test specification aims to test the behavior when the sender process get a new message queue with the msgflg containing IPC_PRIVATE. The kernel is idle. None None Name Create a sender process Description This test setup aims to creates a sender process in the test environment. Steps 1 The test system creates a sender process. Postcondition The sender process is created. (Test Oracle) Steps 11

Basic Flow (Test Setup) Basic Flow 测试规格说明书

(Test Sequence) 1 The test system VALIDATES THAT the number of file descriptors the parent process uses is under the OS limit. 2 The test system VALIDATES THAT the OS limit on the total number of open files is not reached. 3 DO 4 The test system INVOKES API ipc_findkey() to check that the key value does not exists. 5 UNTIL return value == 0 6 The sender process INVOKES API msgget () to create a private messsage queue. 7 The test system VALIDATES THAT the message queue identity descriptor > 0. 8 The test system INVOKES API ipcs() to check the message queue state. 9 The test system release the message queue memory and kill the sender process. Postcondition The test system returns the messsage queue (Test Oracle) sequence number. Specific RFS 1 Alternative 1 The test system returns an error to the tester. Flows 2 ABORT (Test Sequence) Postcondition The handling of an error condition is tested. (Test Sequence) Specific RFS 2 Alternative 1 The test system returns an error to the tester. Flows 2 ABORT (Test Sequence) Postcondition The handling of an error condition is tested. (Test Sequence) Oracle RFS 4 Verification 1 The test system VALIDATES THAT the key value Flow queue is locked. Postcondition (Test Oracle) Specific RFS 7 Alternative 1 IF the message queue identity descriptor == -1 Flows THEN (Test Sequence) 2 The message queue is failed to be created 3 ELSE 4 The test system returns an error to the tester. 5 ENDIF 12

测试规格说明书

6 ABORT Postcondition The handling of an error condition is tested. (Test Sequence) Test Case Specification Name OpenExistingMessageQueueTest Brief The test specification aims to test the behavior when the sender Description or receiver process open a existing message queue. Precondition The kernel is idle. Tester None Dependency None Test Setup Name Create a sender process Description This test setup aims to creates a the sender or receiver process in the test environment. Basic Flow Steps (Test Setup) 1 The test system creates a sender or receiver process. Postcondition The test system reutns the process identifier of (Test Oracle) the sender or receiver process. Basic Flow Steps (Test Sequence) 1 The test system VALIDATES THAT the number of file descriptors the parent process uses is under the OS limit. 2 The test system VALIDATES THAT the OS limit on the total number of open files is not reached. 3 The test system INVOKES API ipcperms() to check the sender or receiver process access mode. 4 DO 5 The test system INVOKES API ipc_findkey() to check that the key value does not exists. 6 UNTIL return value ==1 7 The sender process INVOKES API msgget() to open a existing messsage queue. 8 The test system VALIDATES THAT the message queue identity descriptor > 0. 9 The test system INVOKES API ipcs() to check the message queue state. 10 The test system release the message queue memory and kill the sender process. Postcondition The existing messsage queue is open. (Test Oracle) 13

测试规格说明书

Specific Alternative Flows (Test Sequence) RFS 1 1 2 Postcondition (Test Sequence) Specific RFS 2 Alternative 1 Flows 2 (Test Sequence) Postcondition (Test Sequence) Oracle RFS 4 Verification 1 Flow The test system returns an error to the tester. ABORT The handling of an error condition is tested. The test system returns an error to the tester. ABORT The handling of an error condition is tested. The test system VALIDATES THAT the key value queue is locked. Postcondition (Test Oracle) Specific RFS 7 Alternative 1 IF the message queue identity descriptor == -1 Flows THEN (Test Sequence) 2 The message queue is failed to be created 3 ELSE 4 The test system returns an error to the tester. 5 ENDIF 6 ABORT Postcondition The handling of an error condition is tested. (Test Sequence) 2)发送消息

sys_msgsnd(int msgid, struct msgbuf *msgp, size_t msgsz,int msgflg)

sys_ msgsnd()接收的参数有消息队列的1D(msgid),指向缓冲区的指针struct msg_msg类型(msgp),发送消息的大小(msgsz),说明等待或者不等待的标志(msgflg)。向msgid代

表的消息队列发送一个消息,即将发送的消息存储在msgp指向的msgbuf结构中。如果在接收消息等待的队列中有一个进程正在等待这个消息,消息则直接被传给接收的进程,接收进程被唤醒。没有等待消息的进程,如果在消息等待队列中有足够的空间,消息被保存在这个队列中。下面将详细介绍sys_msgsnd():

1) 使缓存地址和消息类型有效,需要调用load_msg()把用户消息加载到一个临时的

msg类型struct msg_msg。初始化消息的类型和消息的大小。

2) 把全局消息队列的自旋锁锁定,并且得到消息队列的描述符和消息队列ID。如果没

有符合要求的消息队列,则返回EINVAL。

3) 调用ipc_checkid()(通过msg_checkid())检查调用进程ID是否有效,ipcperms()

来检查调用进程的访问权限。

14

测试规格说明书

4) 检查消息的大小和消息等待队列的剩余空间,检查是否有足够的空闻来存储消息。

如果没有足够的空间,则必须按不同情况返回。

5) 调用pipeline_send()直接发送消息给等待接收进程。

6) 如果没有接收进程等待这条消息,则把这条消息(msg)编入消息等待队列

(msq->q_messages)。更新消息队列属性q_cbytes和q_qnum,更新全局变量msq_bytes和msq_hdrs,前者是整个消息字节的大小,后者是整个消息系统的大小。 7) 如果消息被成功地发送或者是入队列,则需要更新消息队列的q_Ispid和q_stime,

并且释放全局消息队列的自旋锁。 简单框图如图2所示。

图2 sys_msgsnd的框图

Name Brief Description Precondition Tester Dependency Test Setup Test Case Specification SendMessageTest The test specification aims to test the behavior when the sender process write a message into the opening message queue. The kernel is idle. None None Name Create a sender process Description This test setup aims to creates a sender process in the test environment. 15

测试规格说明书

Basic Flow (Test Setup) Test Setup Steps 1 Postcondition (Test Oracle) Name Description Steps 1 The test system creates a sender process. The sender process is created. Create a message queue This test setup aims to creates a new message queue in the test environment. Basic Flow (Test Setup) INCLUDE TEST CASE SPECIFICATION CreateNewMessageQueueTest. Postcondition The new message queue is created. (Test Oracle) Test Setup Name Create a message Description This test setup aims to creates a new message in the test environment. Basic Flow Steps (Test Setup) 1 Define a message struct variable 2 The test system INVOKES API load_msg() to load the message into the message struct variable. 3 The message type is set with sender processs id. 4 set the message length with specified value. Basic Flow Steps (Test Sequence) 1 The test system VALIDATES THAT the number of file descriptors the parent process uses is under the OS limit. 2 The test system VALIDATES THAT the OS limit on the total number of open files is not reached. 3 The test system locks the message queue with a spinlock. 4 The test system VALIDATES THAT the message queue descriptor with the message queue id exists. 5 The test system INVOKES API ipc_checkid() to check the sender process id. 6 The test system INVOKES API ipcperms() to check the sender process access mode. 7 The test system INVOKES API msgctl() to check the message queue space. 8 The test system INVOKES API msgsnd() to write the message into the messsage queue. 9 The test system INVOKES API msgctl() to update the message queue properties. 10 The test system unlocks the message queue. 11 The test system release the message queue memory 16

测试规格说明书

and kill the sender process. Postcondition The sender process write the message into the (Test Oracle) specified message queue. Specific RFS 1 Alternative 1 The test system returns an error to the tester. Flows 2 ABORT (Test Sequence) Postcondition The handling of an error condition is tested. (Test Sequence) Specific RFS 2 Alternative 1 The test system returns an error to the tester. Flows 2 ABORT (Test Sequence) Postcondition The handling of an error condition is tested. (Test Sequence) Specific RFS 2 Alternative 1 The test system returns an error named EINVAL. Flows 2 ABORT (Test Sequence) Postcondition The handling of an error condition is tested. (Test Sequence) Oracle RFS 5 Verification 1 The test system VALIDATES THAT the sender Flow process id is valid. Postcondition (Test Oracle) Oracle RFS 6 Verification 1 The test system VALIDATES THAT the sender Flow process access mode is valid. Postcondition (Test Oracle) Oracle RFS 7 Verification 1 The test system VALIDATES THAT the message queue Flow is not full. Postcondition (Test Oracle) Oracle RFS 8 Verification 1 The test system VALIDATES THAT return value==0. Flow Postcondition (Test Oracle) 3)接收消息

sys_msgrcv(int msqid,struct msgbuf *msgp,size_t msgsz,long msgtyp,int msgflg)

17

测试规格说明书

函数sys_msgrcv()接收的参数有:消息队列的ID(msqid),指向缓冲区的指针msg_msg类型(msgp),期望接收消息的大小(msgsz),消息类型(msgtyp)和标志符(msgflg)o函数首先根据消息队列ID搜寻消息等待队列,找到第1个符合要求的类型,把它拷贝到用户空间。如果没有找到,则请求进程被编入消息接收等待队列中,直到需要的消息出现。下面详细介绍函数sys_m sgrcv():

1) 首先,根据msgtype调用函数convert_mode()启动搜寻模式。函数sys_m sgrcv()

锁定全局消息队列自旋锁,并且根据消息队列的ID获得消息队列的描述符。如果没有符合的消息队列,则返回EINVAL. 2) 检查当前进程访问消息队列的权限。

3) 从消息等待队列的第1条消息开始,调用testmsg()检查是否有符合要求的消息存

在。sys_msgrcv()会持续检查到符合的消息或者整个队列都检查完毕。如果查找模式是SEARCH_LESSEQUAL,也就是该消息的类型值小于或者等于作为参数传过来的msgtyp,则找到队列中第1个满足的消息,而且一旦发现就不用再往下找了。 4) 如果找到了消息,如果消息大小大于期望值,并且标识符msgflg声明不允许错误,

返回E2BIG。唤醒新的发送进程。

5) 如果在消息等待队列中没有符合接收的消息,则检查标识符msgflg。如果是

IPC_NOWAIT,则全局消息队列的自旋锁解锁,并且返回ENOMSG。否者,接收进程进入消息等待队列。

6) 当接收进程被唤醒后,检查msr的属性r_msq。这个属性是用来存储管道消息或者

错误信息。如果属性r_msq被消息填满,跳到最后一步。否则全局消息队列自旋锁被再次上锁。

7) 在获得自旋锁后,重新检查属性r_msq,看是否接收到消息。如果接收到消息,则

跳转到最后一步。

8) 如果属性r_msq还没有变化,这时被要求重试唤醒进程。在这种情况下,msr出列。

如果有信号等待这个进程,则解锁全局消息队列的自旋锁,返回EINTR。否则必须返回,函数重载。

9) 如果在睡眠状态下属性r_msq返回错误,全局消息队列的自旋锁解锁并且返回错误。 10) 在确认用户缓存地址的有效性后,消息类型被载入msp的mtype属性,并且调用函

数store_msg()拷贝捎息内容给msp的mtext。调用函数free_msg()释放消息空间。 简单框图如图3所示。

18

测试规格说明书

图3 sys_msgrcv的框图

Test Case Specification ReceiveMessageTest The test specification aims to test the behavior when the receiver process reads a message from the opening message queue. The kernel is idle. None None Name Create a sender process Description This test setup aims to creates a sender process in the test environment. Steps 1 The test system creates a sender process. Postcondition The sender process is created. (Test Oracle) Name Create a message queue Description This test setup aims to creates a new message 19

Name Brief Description Precondition Tester Dependency Test Setup Basic Flow (Test Setup) Test Setup 测试规格说明书

queue in the test environment. Basic Flow (Test Setup) INCLUDE TEST CASE SPECIFICATION CreateNewMessageQueueTest. Postcondition The new message queue is created. (Test Oracle) Test Setup Name Create messages Description This test setup aims to creates a new message in the test environment. Basic Flow Steps (Test Setup) 1 Define a message struct variable 2 The test system INVOKES API load_msg() to load the message into the message struct variable. 3 The message type is set with sender processs id. 4 set the message length with specified value. Postcondition The new messages were created. (Test Oracle) Test Setup Name send messages into the message queue Description This test setup aims to send messages into the message queue in the test environment. Basic Flow Steps (Test Setup) 1 INCLUDE TEST CASE SPECIFICATION SendMessageTest. Postcondition Messages were written into the message queue (Test Oracle) and the q_qnum increments. Basic Flow Steps (Test Sequence) 1 The test system VALIDATES THAT the number of file descriptors the parent process uses is under the OS limit. 2 The test system VALIDATES THAT the OS limit on the total number of open files is not reached. 3 The test system INVOKES API convert_mode() to start the search. 4 The test system locks the global message queue with a spinlock. 5 The test system VALIDATES THAT the message queue descriptor with the message queue id exists. 6 The test system INVOKES API ipcperms() to check the receiver process access mode. 7 The test system VALIDATES THAT the search mode is not equal to SEARCH_LESSEQUAL. 8 DO Steps 1 20

测试规格说明书

9 Specific Alternative Flows (Test Sequence) Specific Alternative Flows (Test Sequence) Specific Alternative Flows (Test Sequence) Oracle Verification Flow Specific Alternative Flows (Test Sequence) The test system INVOKES API testmsg() to check whether the specified message exists in the message queue or not. 9 UNTIL the first specified msgtyp message is found or the whole message queue has been checked 10 The test system VALIDATES THAT msgp!=null. 11 The test system VALIDATES THAT msgp.msgsz==msgsz. 12 The test system INVOKES API store_msg() to copy the message content to the msg.mtext. 13 The test system INVOKES API free_msg() to free the message space. Postcondition The receiver process reads msg.mtext to the (Test Oracle) process space. RFS 1 1 The test system returns an error to the tester. 2 ABORT Postcondition The handling of an error condition is tested. (Test Sequence) RFS 2 1 The test system returns an error to the tester. 2 ABORT Postcondition The handling of an error condition is tested. (Test Sequence) RFS 5 1 The test system returns an error named EINVAL. 2 ABORT Postcondition The handling of an error condition is tested. (Test Sequence) RFS 6 1 The test system VALIDATES THAT the receiver process access mode is valid. Postcondition (Test Oracle) RFS 7 1 DO 2 The test system INVOKES API testmsg() to check whether the specified message exists in the message queue or not. 21

测试规格说明书

UNTIL the message type parameter ≤msgtyp or the whole message queue has been checked 4 RESUME STEP 10 Postcondition The message search have done. (Test Sequence) Specific RFS 10 Alternative 1 IF the msgflg==IPC_NOWAIT THEN Flows 2 The test system unlocks the global message (Test Sequence) queue spinlock. 3 The test system returns an error code ENOMSG. 4 ELSE 5 The test system inserts the receiver process into the wait_queue. 6 DO 7 The test system INVOKES API wait_event() to check if the specified message comes. 8 UNTIL msgp!=null 9 ENDIF 10 RESUME STEP 11 Postcondition The specified message is found. (Test Sequence) Specific RFS 11 Alternative 1 IF the msgflg declares that does not allow the Flows error THEN (Test Sequence) 2 The test system returns an error code E2BIG. 3 The test system INVOKES API _wake_up() to wakeup the new sender process. 4 ENDIF 5 ABORT Postcondition The test system start to send new messages. (Test Sequence) 4)控制消息队列

sys_msgctl(int msqid,int cmd,struct msqid_ds *but)

传递给sys_msgctl()的参数是:消息队列的ID(msqid),命令码(cmd),指向用户空间缓存的指针msgi_ds类型(buf)。该系统调用对由msqid标识的消息队列执行cmd操作。函数中的6个命令码是:IPC_INFO 3, MSG_INFO 12,IPC_STAT 2,MSG_STAT 11,IPC_SET 1和IPC_RMIDO。消息队列的ID与命令码的参数必须是有效的;命令码(cmd)的作用如下:

1) IPC_INFO(或MSG_INFO)

该命令将全局消息队列信息拷贝到用户的空间。

22

3 测试规格说明书

2) IPC_STAT(或MSG_STAT)

该命令用来获取消息队列信息,返回的信息存储在buf指向的msqid结构中。 3) IPC_SET

该命令用来设置消息队列的属性。 4) IPC_RMID

删除msqid标识的消息队列。使用freeque()来释放和消息队列ID相关的资源。 简单框图如图4所示。

图4 sys_msgctl简单框图

3.1.5.3 共享内存

进程获取共享内存模块测试用例:

进程在将内享共存区映射到自己的虚拟空间之前,必须创建一个共享内存区或访问已创建的共享内存区以获得该内存区的ID标识(shmid)。系统调用shmget()可以创建或访问一个共享内存区。 Test Case Specification Name Brief Description Precondition Tester Dependency Test Setup Test get shared memory The test specification aims to test the behavior when the process call for a shared memory. The kernel is running normally. The process is created. None None Name Description Basic Flow (Test Setup) Steps 1 2 The test system creates the process. The process has the key of the shared memory. Get the shared memory This test setup aims to get a shared memory in the test environment. 23

测试规格说明书

Postcondition (Test Oracle) Basic Flow (Test Sequence) Steps IF the shared memory with specified key is not created (key=IPC_PRIVATE ||key ==0 && shmflg.IPC_CREAT == on)THEN 1 2 The test system VALIDATES THAT the parameter size is not more than SHMMAX and not less than SHMMIN. The test system VALIDATES THAT the available space for shared memory is not less than the specified shared memory’s size. The test system creates the new shared memory and set its default property. The test system VALIDATES THAT the process has the shared memory’s access right. The process INVOKES API shmget() to get the specified shared memory’s id. The kernel INVOKES API shmat() to attach the shared memory. MEANWHILE the process can get the shared memory space’s address pointer to access it like the normal memory. The process get the shared memory’s access right. The process is created. 3 ENDIF 4 5 6 Postcondition (Test Oracle) Specific Alternative Flows (Test Sequence) RFS 1,2 1 2 The test system returns an error code EINVAL to the tester. ABORT Postcondition Process fails to creat and get a shared memory. (Test Sequence) Specific Alternative Flows (Test Sequence) RFS 4 1 2 The test system returns an error code EACCES to the tester. ABORT Postcondition Process fails to get a shared memory. (Test Sequence) Oracle Verification Flow RFS 1,2,4 1 Postcondition (Test Oracle) Tester VERIFIES THAT get the corresponding error. None

进程写入共享内存模块测试用例:

24

测试规格说明书

Test Case Specification Name Brief Description Precondition Tester Dependency Test Setup Test write shared memory The test specification aims to test the behavior when the process write message to the shared memory. The kernel is running normally. The process and is created. None None Name Description Basic Flow (Test Setup) Steps 1 2 3 4 Postcondition (Test Oracle) Basic Flow (Test Sequence) Steps 1 2 3 The test system VALIDATES THAT the process’id is in the shared memory’s struct ipc_perm. The test system VALIDATES THAT the shared memory is not read or writen now. The test system VALIDATES THAT the available space for the shared memory is not less than the message need to send. The test system INVOKES API sem_post() to add semaphore. The test system INVOKES API copy_from_user() to copy the process’ message to the shared memory. The test system INVOKES API shmdt() to disattach the shared memory. The process succeed writing the shared memory. The test system creates the process. The process has the message need to send. The shared memory exists. The test system INVOKES API shmat() to attach the shared memory . The process is created. The shared memory is created and attached. Write to the shared memory This test setup aims to write message to the shared memory in the test environment. 4 5 6 Postcondition (Test Oracle) Bounded Alternative Flows (Test Sequence) RFS 2 1 2 The test system INVOKES API sem_wait() wait to access the shared memory. RESUME STEP 2 Postcondition The test continues the exclusively detection. (Test Sequence) Specific Alternative Flows RFS 1,3 1 The test system returns an error code to the tester. 25

测试规格说明书

(Test Sequence) 2 ABORT Postcondition The process fails to write the shared memory. (Test Sequence) Oracle Verification Flow RFS 4 INCLUDE TEST CASE SPECIFICATION ReadSharedMemory 1 Postcondition (Test Oracle) Oracle Verification Flow RFS 6 1 Tester VERIFIES THAT the shared memory is not read or writen by other process now.(Its semaphore is greater than one) The process is the only one to write the shared memory. Tester VERIFIES THAT the message from the shared memory is same to the sent message. The process succeed writing the shared memory. Postcondition (Test Oracle)

释放共享内存模块测试用例: Test Case Specification Name Brief Description Precondition Tester Dependency Test Setup Test write shared memory The test specification aims to test the behavior when the process write message to the shared memory. The kernel is running normally. The process and is created. None None Name Description Basic Flow (Test Setup) Steps 1 3 4 Postcondition (Test Oracle) Basic Flow (Test Sequence) Steps 1 2 Postcondition (Test Oracle) The test system VALIDATES THAT the process’id is in the shared memory’s struct ipc_perm. The test system INVOKES API shm_release() to release the shared memory and free its space. The process succeed release the shared memory. The test system creates the process. The shared memory exists. The test system INVOKES API shmdt() to disattach the shared memory . The process is created. The shared memory is created and disattached. Release the shared memory This test setup aims to release the shared memory in the test environment. 26

测试规格说明书

Specific Alternative Flows (Test Sequence)

3.1.5.4 信号

RFS 2 1 RESUME STEP 2 Postcondition The test continues the exclusively detection. (Test Sequence)

信号注册功能模块测试用例 Test Case Specification Name Register Signal Brief Description The test specification aims to test the behavior of the IPC system when test registers a signal to the goal process Precondition 1 The process B Status.exit=YES (Test Data 2 The process A Status.sigqueue.return==1 Specification) Tester None Dependency INCLUE TEST CASE SPECIFICATION Shield Signal Name SetParameters Description This test setup aims to provide the Test Setup necessary parameters which will be using in signal registering Steps 1 The test system provides the necessary Basic Flow parameters(SignalD=xx, Act=xx, OldAct=xx) (Test Setup) Postcondition The signal is ready to be registered (Test Oracle) Basic Flow Steps (Test Sequence) 1 The test system VALIDATES THAT Status.list.exit==YES 2 The test system VALIDATES THAT Status. UnresolveCollection. exit==YES 3 The test system VALIDATES THAT the signal is not shielded 4 The test system VALIDATES THAT Status.signal.real=YES 27

测试规格说明书

5 The test system INVOKES API Sigaction() to register the signal Postcondition The signal is registered (Test Oracle) Specific Alternative RFS 1 Flows 1 The kernel creates an empty list (Test Sequence) 2 RESUME STEP 2 Postcondition Status.list.exit==YES (Test Oracle) Specific RFS 2 Alternative Flows 1 The kernel creates an empty unresolvecollection (Test Sequence) 2 RESUME STEP 3 Postcondition Status.unresolvecollection.exit==YES (Test Oracle) Specific Alternative RFS 3 Flows 1 The test system puts the signal into (Test Sequence) blockcollection 2 ABORT Postcondition The signal is blocked (Test Oracle) Specific Alternative RFS 4 Flows 1 IF The test system checks Status. (Test Sequence) unresolvecollection. signal.exit==YES , THEN 2 ABORT 3 ELSE RESUME STEP 5 Postcondition The signal is registered (Test Oracle) Oracle Verification RFS 5 Flows 1 Tester VERFIES THAT the signal is in the (Test Sequence) unresolvedcollection 2 Tester VERFIES THAT the message of the signal in the the list Postcondition None (Test Oracle) 采用信号方式通信的整体测试用例 Test Case Specification 28

测试规格说明书

Name Brief Description Precondition (Test Specification) Tester Dependency Test Setup Use Signal The test specification aims to test the behavior of the IPC system by using the way of signal 1 Process A Status.life==ACTIVE Data 2 Process B Status.life==ACTIVE None None Name CreateProcess Description This test setup aims to create two processes which are used to communicate by signal Steps 1 The test system creates a process A(AID=XX) 2 The test system creates a process B(BID=XX) Postcondition Process A is created (Test Oracle) Process B is created Steps 1 Process A generates a signal(SID=xx) 2 Process A INVOKES API sigqueue(BID,SID ,union struct) to send the signal to Process B 3 The test system VALIDATES THAT process A invokes API successfully 4 The test system INVOKES API Sigaction(SlD=xx, Act=xx, OldAct=xx) to register the signal to process B 5 The test system calls Process B to run 6 Process B VALIDATES THAT Status. Unresolvedcollection. empty==NO 7 Process B gets a signal S from Unresolvedcollection 8 The test system INVOKES API sigpending() to get blockcollection 9 The test system VALIDATES THAT signal S is not in the blockcollection 10 The test system VALIDATES THAT signal S is a real signal 11 The test system VALIDATES THAT S Status.getnumber>1 12 The test system removes message struct from message list 13 S Status.getnumber+1 29

Basic Flow (Test Setup) Basic Flow (Test Sequence) 测试规格说明书

14 The test system VALIDATES THAT Act!=null 15 Process B run function Act 16 The test system VALIDATES THAT Act.return ==0 17 Process B finishs handling signal S Postcondition Process B keeps running (Test Oracle) Process A keeps running Specific Alternative RFS 3 Flows 1 Process A fails to send signal to process B (Test Sequence) 2 ABORT Postcondition Process A returns an error (Test Oracle) Specific Alternative RFS 6 Flows 1 Process B keep running (Test Sequence) 2 ABORT Postcondition Process B keeps running (Test Oracle) Process A keeps running Specific Alternative RFS 9 Flows 1 Process B gives up handling this signal (Test Sequence) 2 ABORT Postcondition Process B keeps running (Test Oracle) Process A keeps running Specific Alternative RFS 10 Flows 1 The test system removes the signal from the (Test Sequence) unresolvedcollecton 2 RESUME STEP 11 Postcondition Process B keeps running (Test Oracle) Process A keeps running Specific Alternative RFS 11 Flows 1 The test system removes the message struct from the (Test Sequence) message list 2 The test system removes the signal from the unresolvedcollecton 3 RESUME STEP 12 Postcondition Process B keeps running (Test Oracle) Process A keeps running Specific Alternative RFS 14 Flows 1 IF OldAct!=null THEN 30

测试规格说明书

(Test Sequence) 2 Process B runs function OldAct 3 RESUME STEP 15 3 ELSE ABORT Postcondition Process B keeps running (Test Oracle) Process A keeps running Specific Alternative RFS 16 Flows 1 Process B fails to handle the signal (Test Sequence) 2 ABORT Postcondition Process B keeps running (Test Oracle) Process A keeps running Oracle Verification RFS 4 Flows 1 Tester VERFIES THAT the signal is in the (Test Sequence) unresolvedcollection 2 Tester VERFIES THAT the message struct of the signal in the the message list Postcondition None (Test Oracle) Oracle Verification RFS 12 Flows 1 Tester VERFIES THAT the message struct is not in (Test Sequence) the message list anymore Postcondition None (Test Oracle)

3.2实施测试阶段

3.2.1 管道与有名管道测试过程:

3.2.1.1 Test create and open pipe

结果说明

1) Normal condition of parent-child pipe

正常情况下所有流程都无错误,父子进程间创建管道成功。 2) Test basic flow step 1 of parent-child pipe

31

测试规格说明书

由于将进程可使用的文件描述符个数调得很低,导致不能为管道分配两个文件描述符,调用pipe()时报错,成功测试了basic flow step 1中的错误情况。 3) Test basic flow step 2 of parent-child pipe

由于将系统可打开的个数调得很低,并且测试时主动打开了大量文件,导致不能为管道分配两个文件描述符,调用pipe()时报错,成功测试了basic flow step 2中的错误情况。

4) Normal condition of brothers’ pipe

正常情况下所有流程都无错误,兄弟进程间创建管道成功。 5) Test basic flow step 1 of brothers’ pipe

由于将进程可使用的文件描述符个数调得很低,导致不能为管道分配两个文件描述符,调用pipe()时报错,成功测试了basic flow step 1中的错误情况。 6) Test basic flow step 2 of brothers’ pipe

由于将系统可打开的个数调得很低,并且测试时主动打开了大量文件,导致不能为管道分配两个文件描述符,调用pipe()时报错,,成功测试了basic flow step 2中的错误情况。

3.2.1.2 Test write data to pipe

结果说明

1) Normal condition of writing to parent-child pipe

正常情况下所有流程都无错误,向管道写入数据成功,内容无误。 2) Test basic flow step 2 of writing to parent-child pipe

32

测试规格说明书

验证了管道文件使用的是阻塞式I/O,即验证了basic flow step 2中的异常情况。 3) Test basic flow step 3 of writing to parent-child pipe

先将读端关闭,此时若有写入操作则会报错,验证了basic flow step 3中的错误情况。 4) Normal condition of writing to brothers’ pipe

正常情况下所有流程都无错误,向管道写入数据成功,内容无误。 5) Test basic flow step 2 of writing to brothers’ pipe

验证了管道文件使用的是阻塞式I/O,即验证了basic flow step 2中的异常情况。 6) Test basic flow step 3 of writing to brothers’ pipe

先将读端关闭,此时若有写入操作则会报错,验证了basic flow step 3中的错误情况。

3.2.1.3 Test read data from pipe

结果说明

1) Normal condition of reading from parent-child pipe

正常情况下所有流程都无错误,从管道读出数据成功,内容无误。 2) Test basic flow step 1 of reading from parent-child pipe

验证了管道文件使用的是阻塞式I/O,即验证了basic flow step 1中的异常情况。 3) Normal condition of reading from brothers’ pipe

33

测试规格说明书

正常情况下所有流程都无错误,从管道读出数据成功,内容无误。 4) Test basic flow step 1 of reading from brothers’ pipe

验证了管道文件使用的是阻塞式I/O,即验证了basic flow step 1中的异常情况。

3.2.1.4 Test close pipe

结果说明

1.Normal condition of closing parent-child pipe

正常情况下所有流程都无错误,从管道被成功关闭,占用的资源释放。 2.Test basic flow step 1 of closing parent-child pipe

由于使得写端的文件描述符不可用,在关闭写端时会报错,验证了basic flow step 1中的错误情况。

3.Test basic flow step 3 of closing parent-child pipe

由于使得读端的文件描述符不可用,在关闭读端时会报错,验证了basic flow step 3中的错误情况。

4.Normal condition of closing brothers’ pipe

正常情况下所有流程都无错误,从管道被成功关闭,占用的资源释放。 5.Test basic flow step 1 of closing brothers’ pipe

由于使得写端的文件描述符不可用,在关闭写端时会报错,验证了basic flow step 1中的错误情况。

6.Test basic flow step 3 of closing brothers’ pipe

由于使得读端的文件描述符不可用,在关闭读端时会报错,验证了basic flow step 3中的错误情况。

3.2.2 消息队列测试过程:

3.2.2.1创建消息队列

测试使用msgget函数创建一个队列,函数中参数falgs指定为IPC_CREAT|0666,说明新建一个权限为0666的消息队列,其中组用户、当前用户以及其他用户拥有读写的权限。并在程序的最后使用shell命令ipcs –q来查看系统IPC的状态。 程序代码:

34

测试规格说明书

在程序中使用了系统命令ipcs,命令参数-q说明只查看消息队列的状态。注意在输出消息中,key段标明的是IPC的key值,msqid为该队列的ID值,perms为执行权限。

在shell中运行该程序如下:

3.2.2.2发送消息

程序中创建了一个消息的模板结构体,并对声明变量做初始化。使用msgget函数创建了一个消息队列,使用msgsnd函数向该队列中发送了一条消息。

snd_msg.c 调用msgsnd函数向队列中发送消息:

35

测试规格说明书

上述程序中,先定义了一个消息的结构体。该结构体中包含两个成员,long类型成员msg_types是消息的类型,注意,在消息队列中是以消息类型做索引值来进行检索的。char类型数组存放消息。在程序中先声明了一个消息的结构体变量,并做相应初始化,然后使用了msgget函数创建一个消息队列,并将该消息发送到此消息队列中。

在shell中运行该程序如下:

3.2.2.3接收消息测试

在程序的开始部分,判断用户是否输入了目标消息队列ID,如果没有,则打印命令的帮助信息;如果用户输入了队列的ID,则从队列中取出该消息,并输出到标准输出。

rcv_msg.c 使用msgrcv函数从指定队列中读出消息:

36

测试规格说明书

该程序中声明了一个消息的结构体类型变量,并从命令行中得到所要操作的消息队列,然后使用函数msgrcv从指定消息队列中读取队列中最上面的一条消息(函数的第4个参数等于0,说明根据先进先出规则,应从队列的最上面读取一条消息),并将该消息输出到标准输出。在发送消息的程序中,消息类型字段指定的是发送消息进程的ID,可以使用该内容来判断信息的来源。

在shell中运行该程序如下:

37

测试规格说明书

3.2.3 共享内存测试过程:

此次测试在Linux环境下编写测试代码,调用存在的库头文件执行测试用例,得到程序结果。首先对共享内存基本功能性进行了测试, 然后选择了两个典型的异常处理子用例测试。

测试代码文件图:

3.2.3.1共享内存正常用例流

38

测试规格说明书

整体测试代码shm_basic_flow.c:

程序结果:

测试过程说明:

39

测试规格说明书

此程序考虑各子用例正常运作的情况测试。

3.2.3.2创建共享内存异常子用例 主要测试代码:

程序结果:

测试过程说明:

当创建共享内存时未给明它的权限属性,进程无法正确访问共享内存。 3.2.3.3释放共享内存子用例 主要测试代码:

40

测试规格说明书

程序结果:

测试过程说明:

删除该共享内存时,如果区段已经做了删除标记(在前面以IPC-RMID指令调用shmctl(),而当前挂接数已经变为0, 这个区段就会被移除。

此时当前挂接数为1, 这个区段不会被移除,返回” Shared memory remove failed”。

3.2.4 信号测试过程:

3.2.4.1 信号产生测试

信号产生需求用例

信号产生功能模块测试用例 Test Case Specification 41

测试规格说明书

Name Brief Description GenerateSignal The test specification aims to test the behavior of the IPC system when hardware generates a signal to a process Precondition 1 The kernel is running (Test Data 2 The goal process is running Specification) Tester Dependency Name Test Setup Steps Basic Flow (Test Setup) 1 2 The test system creates a process The test system creates a function The process is created. The function is created. CreateProcessAndHandleFunction Description This test setup aims to create a goal process and a function to respond to the signal None None Postcondition (Test Oracle) Steps 1 2 3 4 5 6 Basic Flow (Test Sequence) The test system makes sentences printed The tester presses CTRL+C The test system Status.function.run=YES The test system makes sentences printed The tester presses CTRL+C The goal process finishes Postcondition The goal process finishes (Test Oracle) Oracle Verification RFS 1 3 4 Flows 1 Tester VERFIES THAT the goal process finishes (Test Sequence) Postcondition None (Test Oracle) 测试代码:

42

测试规格说明书

运行结果:

运行结果分析:

开始时,主进程main循环产生“Hello World!”,当第一次按下“CTRL+C”时,产生了一个信号sig,但该信号的处理函数已经被更改为ouch,所以进程接收到该信号后,转向执行函数ouch而不是结束该进程,在ouch函数的结尾,把信号的处理方式又改成了默认的方式,所以当再一次按下“CTRL+C”时进程就终止了 3.2.4.2 信号发送测试

信号发送的需求用例

信号发送的测试用例

43

测试规格说明书

Test Case Specification Name Brief Description SendSignal The test specification aims to test the behavior of the IPC system when process A send a signal to process B Precondition 1 The kernel is running (Test Data 2 Process A exits Specification) 3 Process B exits Tester Dependency Name Test Setup Steps Basic Flow (Test Setup) 1 2 The test system creates process A The test system creates process B Process A exits Process B exits CreateProcess Description This test setup aims to create process A and Process B None None Postcondition (Test Oracle) Steps 1 2 Basic Flow (Test Sequence) The test system INVOKES API sigqueue() to send a signal The test system VALIDATES THAT sigqueue.return==0 The signal is sent Postcondition (Test Oracle) Global Alternative IF sigqueue.return==-1 Flows 1 Print \"send error\" (Test Sequence) 2 ABORT Postcondition Process A fails to send signal to process (Test Oracle) B

测试代码

44

测试规格说明书

正常运行结果

异常运行结果

运行结果分析:

因为存在ID为5902的进程,所以信号发送就会成功;ID为7263的进程不存在,所以信号发送失败

3.2.4.3 信号接收测试

信号接收模块需求用例

45

测试规格说明书

针对信号接收模块的需求用例,分两部分测试用例进行测试,第一部分为纯接收测试,不考虑信号屏蔽的情况,第二部分为信号屏蔽测试

接收测试 Test Case Specification Name Brief Description ReceiveSignal The test specification aims to test the behavior of the IPC system when process B receives a signal from process A Precondition 1 The kernel is running (Test Data 2 Process A exits Specification) 3 Process B exits 4 Process A sends a signal to process B Tester Dependency Name Test Setup CreateProcessAndSendASignal Description This test setup aims to create process A and Process B. Also,process A sends a signal to process B Steps 1 Basic Flow (Test Setup) 2 3 The test system creates process A The test system creates process B Process A sends a signal to process B Process A exits Process B exits Process A sends a signal to process B None None Postcondition (Test Oracle)

46

测试规格说明书

Basic Flow (Test Sequence) Steps 1 2 The test system INVOKES API sigaction() to receive a signal The test system VALIDATES THAT sigaction.return>=0 The signal is received Postcondition (Test Oracle)

Global Alternative IF sigqueue.return<0 Flows 1 Print \"install signal error\" (Test Sequence) 2 ABORT Postcondition Process B fails to install the signal (Test Oracle) 测试代码:

正常运行结果

异常运行结果

运行结果分析

从正常运行结果可以看出,sigaction()函数正常运行,接收进程可以接收到发送进程传

47

测试规格说明书

来的数据;当sigaction()运行错误时,系统返回错误提示 3.2.4.4 信号屏蔽测试

信号屏蔽测试用例 Test Case Specification Name Brief Description ShieldSignal The test specification aims to test the behavior of the IPC system when the signal is shielded by process A Precondition 1 The kernel is running (Test Data 2 Process A exits Specification) 4 Process A receives a signal Tester Dependency Name Test Setup Steps Basic Flow (Test Setup) 1 3 The test system creates process A Process A receives a signal(SIGINT) Process A exits Process A receives a signal SIGINT CreateProcess Description This test setup aims to create process A and Process B. Also,process A receives a signal None None Postcondition (Test Oracle) Steps 1 2 3 4 5 Basic Flow (Test Sequence) Process A receives a signal(SIGINT) The test system VALIDATES THAT Status.shield==YES Process A ignores the signal(SIGINT) The test system VALIDATES THAT it is time to unblock the signal Process A handles the signal(SIGINT) Process A quits Postcondition (Test Oracle) Specific Alternative RFS 2 Flows 1 Process A ignores the signal(SIGINT) (Test Sequence) 2 ABORT Postcondition Process A quits (Test Oracle) Specific Alternative RFS 4 Flows 1 The signal keeps blocking (Test Sequence) 2 Process A keep waiting 2 ABORT 48

测试规格说明书

Postcondition The signal is blocked (Test Oracle) Oracle Verification RFS 3 Flows 1 Tester VERFIES THAT process A keeps running (Test Sequence) Postcondition Process A keeps running (Test Oracle) Oracle Verification RFS 5 Flows 1 Tester VERFIES THAT process A quits (Test Sequence) Postcondition Process A quits (Test Oracle) 信号屏蔽测试代码

49

测试规格说明书

信号屏蔽测试代码正常运行结果

信号屏蔽测试代码异常运行结果——信号未屏蔽

信号屏蔽测试代码异常运行结果——激活时间未到

运行结果分析

首先,我们能过sigaction函数改变了SIGINT信号的默认行为,使之执行指定的函数handler,所以输出了语句:Handle the signal 2。然后,通过sigprocmask设置进程的信号屏蔽字,把SIGINT信号屏蔽起来,所以过了10秒之后,用sigpending函数去获取被阻塞的信号集时,检测到了被阻塞的信号SIGINT,输出The SIGINT signal has ignored。最后,用函数sigdelset函数去除先前用sigaddset函数加在sigset上的信号SIGINT,再调用函数sigsuspend,把进程的屏蔽字再次修改为sigset(不包含SIGINT),并挂起进程。由于先前的SIGINT信号停留在待处理状态,而现在进程已经不再阻塞该信号,所以进程马上对该信号进行处理,从而在最后,你不用输入Ctrl+c也会出现后面的处理语句,最后过了5秒程序就成功退出了

3.3总结阶段

50

因篇幅问题不能全部显示,请点此查看更多更全内容