mirror of
https://gitee.com/openharmony/xts_hats
synced 2025-02-17 00:50:07 +00:00
!1400 【xts_hats】【kernel】shmctl用例优化
Merge pull request !1400 from 马江峰/shmget
This commit is contained in:
commit
ea388077d9
@ -68,9 +68,9 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
HWTEST_F(ShmatApiTest, ShmdtAttachShmSuccess_0001, Function | MediumTest | Level1)
|
HWTEST_F(ShmatApiTest, ShmdtAttachShmSuccess_0001, Function | MediumTest | Level1)
|
||||||
{
|
{
|
||||||
key_t key = ftok("shmfile", 65);
|
key_t key = 1234;
|
||||||
int shmid = shmget(key, MEM_SIZE, 0644 | IPC_CREAT | IPC_EXCL);
|
int shmid = shmget(key, MEM_SIZE, 0644 | IPC_CREAT | IPC_EXCL);
|
||||||
EXPECT_TRUE(shmid >= 0);
|
EXPECT_TRUE(shmid != -1);
|
||||||
|
|
||||||
void* addr = nullptr;
|
void* addr = nullptr;
|
||||||
addr = shmat(shmid, nullptr, 0);
|
addr = shmat(shmid, nullptr, 0);
|
||||||
|
@ -62,10 +62,10 @@ const int MEM_SIZE = 1024;
|
|||||||
*/
|
*/
|
||||||
HWTEST_F(ShmctlApiTest, ShmctlCmdTestSuccess_0001, Function | MediumTest | Level1)
|
HWTEST_F(ShmctlApiTest, ShmctlCmdTestSuccess_0001, Function | MediumTest | Level1)
|
||||||
{
|
{
|
||||||
key_t key = ftok("shmfile", 66);
|
key_t key = 1234;
|
||||||
|
|
||||||
int shmid = shmget(key, MEM_SIZE, 0666 | IPC_CREAT);
|
int shmid = shmget(key, MEM_SIZE, 0666 | IPC_CREAT);
|
||||||
EXPECT_TRUE(shmid != 0);
|
EXPECT_TRUE(shmid != -1);
|
||||||
|
|
||||||
struct shmid_ds ds;
|
struct shmid_ds ds;
|
||||||
int ret = shmctl(shmid, IPC_STAT, &ds);
|
int ret = shmctl(shmid, IPC_STAT, &ds);
|
||||||
@ -88,10 +88,10 @@ HWTEST_F(ShmctlApiTest, ShmctlCmdTestSuccess_0001, Function | MediumTest | Level
|
|||||||
*/
|
*/
|
||||||
HWTEST_F(ShmctlApiTest, ShmctlInvalidCommandFailed_0002, Function | MediumTest | Level2)
|
HWTEST_F(ShmctlApiTest, ShmctlInvalidCommandFailed_0002, Function | MediumTest | Level2)
|
||||||
{
|
{
|
||||||
key_t key = ftok("shmfile", 66);
|
key_t key = 1234;
|
||||||
|
|
||||||
int shmid = shmget(key, MEM_SIZE, 0666 | IPC_CREAT);
|
int shmid = shmget(key, MEM_SIZE, 0666 | IPC_CREAT);
|
||||||
EXPECT_TRUE(shmid != 0);
|
EXPECT_TRUE(shmid != -1);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
int ret = shmctl(shmid, 999, nullptr);
|
int ret = shmctl(shmid, 999, nullptr);
|
||||||
@ -112,10 +112,10 @@ HWTEST_F(ShmctlApiTest, ShmctlInvalidCommandFailed_0002, Function | MediumTest |
|
|||||||
*/
|
*/
|
||||||
HWTEST_F(ShmctlApiTest, ShmctlInvalidIdFailed_0003, Function | MediumTest | Level2)
|
HWTEST_F(ShmctlApiTest, ShmctlInvalidIdFailed_0003, Function | MediumTest | Level2)
|
||||||
{
|
{
|
||||||
key_t key = ftok("shmfile", 66);
|
key_t key = 1234;
|
||||||
|
|
||||||
int shmid = shmget(key, MEM_SIZE, 0666 | IPC_CREAT);
|
int shmid = shmget(key, MEM_SIZE, 0666 | IPC_CREAT);
|
||||||
EXPECT_TRUE(shmid != 0);
|
EXPECT_TRUE(shmid != -1);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
int ret = shmctl(-1, IPC_STAT, nullptr);
|
int ret = shmctl(-1, IPC_STAT, nullptr);
|
||||||
|
@ -62,9 +62,9 @@ const int MEM_SIZE = 1024;
|
|||||||
*/
|
*/
|
||||||
HWTEST_F(ShmgetApiTest, ShmgetCreateSharedMemoryObjectAndReturnIdentifierSuccess_0001, Function | MediumTest | Level1)
|
HWTEST_F(ShmgetApiTest, ShmgetCreateSharedMemoryObjectAndReturnIdentifierSuccess_0001, Function | MediumTest | Level1)
|
||||||
{
|
{
|
||||||
key_t key = ftok("shmfile", 65);
|
key_t key = 1234;
|
||||||
int shmid = shmget(key, MEM_SIZE, 0666 | IPC_CREAT);
|
int shmid = shmget(key, MEM_SIZE, 0666 | IPC_CREAT);
|
||||||
EXPECT_TRUE(shmid != 0);
|
EXPECT_TRUE(shmid != -1);
|
||||||
|
|
||||||
int ret = shmctl(shmid, IPC_RMID, nullptr);
|
int ret = shmctl(shmid, IPC_RMID, nullptr);
|
||||||
EXPECT_TRUE(ret == 0);
|
EXPECT_TRUE(ret == 0);
|
||||||
@ -82,10 +82,10 @@ HWTEST_F(ShmgetApiTest, ShmgetCreateSharedMemoryObjectAndReturnIdentifierSuccess
|
|||||||
{
|
{
|
||||||
char* ptrSharedData = nullptr;
|
char* ptrSharedData = nullptr;
|
||||||
const char* data = "Hello, shared memory!";
|
const char* data = "Hello, shared memory!";
|
||||||
key_t key = ftok("shmfile", 66);
|
key_t key = 1234;
|
||||||
|
|
||||||
int shmid = shmget(key, MEM_SIZE, 0666 | IPC_CREAT);
|
int shmid = shmget(key, MEM_SIZE, 0666 | IPC_CREAT);
|
||||||
EXPECT_TRUE(shmid != 0);
|
EXPECT_TRUE(shmid != -1);
|
||||||
|
|
||||||
void* ptrData = shmat(shmid, nullptr, 0);
|
void* ptrData = shmat(shmid, nullptr, 0);
|
||||||
EXPECT_TRUE(ptrData != reinterpret_cast<void*>(-1));
|
EXPECT_TRUE(ptrData != reinterpret_cast<void*>(-1));
|
||||||
@ -100,33 +100,3 @@ HWTEST_F(ShmgetApiTest, ShmgetCreateSharedMemoryObjectAndReturnIdentifierSuccess
|
|||||||
ret = shmctl(shmid, IPC_RMID, nullptr);
|
ret = shmctl(shmid, IPC_RMID, nullptr);
|
||||||
EXPECT_TRUE(ret == 0);
|
EXPECT_TRUE(ret == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* @tc.number : SUB_KERNEL_SYSCALL_SHMGET_0300
|
|
||||||
* @tc.name : ShmgetCreateSharedMemoryObjectAndReturnIdentifierSuccess_0003
|
|
||||||
* @tc.desc : Create a shared memory object and return the shared memory identifier success.
|
|
||||||
* @tc.size : MediumTest
|
|
||||||
* @tc.type : Function
|
|
||||||
* @tc.level : Level 1
|
|
||||||
*/
|
|
||||||
HWTEST_F(ShmgetApiTest, ShmgetCreateSharedMemoryObjectAndReturnIdentifierSuccess_0003, Function | MediumTest | Level1)
|
|
||||||
{
|
|
||||||
key_t key1 = ftok("shmfile1", 65);
|
|
||||||
key_t key2 = ftok("shmfile2", 65);
|
|
||||||
|
|
||||||
int shmid1 = shmget(key1, MEM_SIZE, IPC_CREAT | 0666);
|
|
||||||
EXPECT_TRUE(shmid1 != -1);
|
|
||||||
|
|
||||||
int shmid2 = shmget(key2, MEM_SIZE, IPC_CREAT | 0666);
|
|
||||||
EXPECT_TRUE(shmid2 != -1);
|
|
||||||
|
|
||||||
EXPECT_TRUE(shmid1 == shmid2);
|
|
||||||
|
|
||||||
if (shmid1 != -1) {
|
|
||||||
shmctl(shmid1, IPC_RMID, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shmid2 != -1) {
|
|
||||||
shmctl(shmid2, IPC_RMID, nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user