refactor: 内核测试套整改,简化分类
close: #I4OX3O Signed-off-by: arvinzzz <zhaotianyu9@huawei.com> Change-Id: I3ba65509135cee2ae3af82fec923a01e00ffdbe8
This commit is contained in:
53
testsuites/unittest/basic/mem/vm/config.gni
Normal file
53
testsuites/unittest/basic/mem/vm/config.gni
Normal file
@@ -0,0 +1,53 @@
|
||||
# Copyright (c) 2022-2022 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.
|
||||
|
||||
import("//kernel/liteos_a/testsuites/unittest/config.gni")
|
||||
|
||||
mem_vm_include_dirs = [ "$TEST_UNITTEST_DIR/basic/mem/vm" ]
|
||||
|
||||
mem_vm_sources_entry = [ "$TEST_UNITTEST_DIR/basic/mem/vm/mem_vm_test.cpp" ]
|
||||
|
||||
mem_vm_sources_smoke = [
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/mmap_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/mmap_test_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/mmap_test_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/mmap_test_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/mmap_test_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/mmap_test_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/mmap_test_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/mmap_test_008.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/mmap_test_009.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/mmap_test_010.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/mprotect_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/mremap_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/oom_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/open_wmemstream_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/mem/vm/smoke/user_copy_test_001.cpp",
|
||||
]
|
||||
|
||||
mem_vm_sources_full = []
|
||||
61
testsuites/unittest/basic/mem/vm/it_test_vm.h
Normal file
61
testsuites/unittest/basic/mem/vm/it_test_vm.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef _IT_TEST_MEM_VM_H
|
||||
#define _IT_TEST_MEM_VM_H
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/wait.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "osTest.h"
|
||||
|
||||
extern void ItTestMmap001(void);
|
||||
extern void ItTestMmap002(void);
|
||||
extern void ItTestMmap003(void);
|
||||
extern void ItTestMmap004(void);
|
||||
extern void ItTestMmap005(void);
|
||||
extern void ItTestMmap006(void);
|
||||
extern void ItTestMmap007(void);
|
||||
extern void ItTestMmap008(void);
|
||||
extern void ItTestMmap009(void);
|
||||
extern void ItTestMmap010(void);
|
||||
extern void ItTestMprotect001(void);
|
||||
extern void ItTestMremap001(void);
|
||||
extern void ItTestOom001(void);
|
||||
extern void ItTestUserCopy001(void);
|
||||
extern void open_wmemstream_test_001(void);
|
||||
#endif
|
||||
213
testsuites/unittest/basic/mem/vm/mem_vm_test.cpp
Normal file
213
testsuites/unittest/basic/mem/vm/mem_vm_test.cpp
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* 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 <climits>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "it_test_vm.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
class MemVmTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
};
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_SMOKE)
|
||||
/* *
|
||||
* @tc.name: it_test_mmap_001
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestMmap001, TestSize.Level0)
|
||||
{
|
||||
ItTestMmap001();
|
||||
}
|
||||
#if 0 // need tmpfs
|
||||
/* *
|
||||
* @tc.name: it_test_mmap_002
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestMmap002, TestSize.Level0)
|
||||
{
|
||||
ItTestMmap002();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_mmap_003
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestMmap003, TestSize.Level0)
|
||||
{
|
||||
ItTestMmap003();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_mmap_004
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestMmap004, TestSize.Level0)
|
||||
{
|
||||
ItTestMmap004();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_mmap_005
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestMmap005, TestSize.Level0)
|
||||
{
|
||||
ItTestMmap005();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_mmap_006
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestMmap006, TestSize.Level0)
|
||||
{
|
||||
ItTestMmap006();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_mmap_007
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestMmap007, TestSize.Level0)
|
||||
{
|
||||
ItTestMmap007();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_mmap_008
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestMmap008, TestSize.Level0)
|
||||
{
|
||||
ItTestMmap008();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_mmap_009
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestMmap009, TestSize.Level0)
|
||||
{
|
||||
ItTestMmap009();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_mmap_010
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: DTS202101220LSHEDP1100
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestMmap010, TestSize.Level0)
|
||||
{
|
||||
ItTestMmap010();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_mprotect_001
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestMprotect001, TestSize.Level0)
|
||||
{
|
||||
ItTestMprotect001();
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_USER_TEST_SMP
|
||||
/* *
|
||||
* @tc.name: it_test_oom_001
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestOom001, TestSize.Level0)
|
||||
{
|
||||
ItTestOom001();
|
||||
}
|
||||
|
||||
#endif
|
||||
/* *
|
||||
* @tc.name: it_test_mremap_001
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestMremap001, TestSize.Level0)
|
||||
{
|
||||
ItTestMremap001();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_user_copy_001
|
||||
* @tc.desc: function for MemVmTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, ItTestUserCopy001, TestSize.Level0)
|
||||
{
|
||||
ItTestUserCopy001();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: open_wmemstream_test_001
|
||||
* @tc.desc: function for open_wmemstream
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MemVmTest, open_wmemstream_test_001, TestSize.Level0)
|
||||
{
|
||||
open_wmemstream_test_001();
|
||||
}
|
||||
#endif
|
||||
} // namespace OHOS
|
||||
82
testsuites/unittest/basic/mem/vm/smoke/mmap_test_001.cpp
Normal file
82
testsuites/unittest/basic/mem/vm/smoke/mmap_test_001.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
|
||||
#define MAP_ARRAY_SIZE 9
|
||||
#define MAP_FLAGS (MAP_ANONYMOUS | MAP_PRIVATE)
|
||||
|
||||
static const struct {
|
||||
void *addr;
|
||||
int ret;
|
||||
unsigned int flags;
|
||||
} g_gMmapTests[MAP_ARRAY_SIZE] = {
|
||||
{(void *)0, 0, MAP_FLAGS},
|
||||
{(void *)1, -1, MAP_FLAGS | MAP_FIXED},
|
||||
{(void *)(PAGE_SIZE - 1), -1, MAP_FLAGS | MAP_FIXED},
|
||||
{(void *)PAGE_SIZE, -1, MAP_FLAGS | MAP_FIXED},
|
||||
{(void *)-1, 0, MAP_FLAGS},
|
||||
{(void *)(-PAGE_SIZE), -1, MAP_FLAGS | MAP_FIXED},
|
||||
{(void *)(-1 - PAGE_SIZE), -1, MAP_FLAGS | MAP_FIXED},
|
||||
{(void *)(-1 - PAGE_SIZE - 1), -1, MAP_FLAGS | MAP_FIXED},
|
||||
{(void *)(0x1000 * PAGE_SIZE), 0, MAP_FLAGS | MAP_FIXED},
|
||||
};
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
void *p = NULL;
|
||||
int i;
|
||||
int ret;
|
||||
int count = sizeof(g_gMmapTests) / sizeof(g_gMmapTests[0]);
|
||||
void *array[MAP_ARRAY_SIZE] = {NULL};
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
p = mmap((void *)g_gMmapTests[i].addr, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, g_gMmapTests[i].flags, -1,
|
||||
0);
|
||||
ret = (p == MAP_FAILED) ? -1 : 0;
|
||||
ICUNIT_ASSERT_EQUAL(g_gMmapTests[i].ret, ret, p);
|
||||
array[i] = p;
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
if (array[i] == MAP_FAILED) {
|
||||
continue;
|
||||
}
|
||||
ret = munmap(array[i], PAGE_SIZE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestMmap001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_MMAP_001", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
138
testsuites/unittest/basic/mem/vm/smoke/mmap_test_002.cpp
Normal file
138
testsuites/unittest/basic/mem/vm/smoke/mmap_test_002.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
|
||||
#define MAP_RESERVED0080 0x0080
|
||||
|
||||
static int CheckedMmap(int prot, int flags, int fd)
|
||||
{
|
||||
void *p = NULL;
|
||||
int pageSize = getpagesize();
|
||||
int ret;
|
||||
|
||||
if (pageSize < 0) {
|
||||
printf("err: mmap size invalid\n");
|
||||
return -1;
|
||||
}
|
||||
p = mmap(NULL, pageSize, prot, flags, fd, 0);
|
||||
if (p == MAP_FAILED) {
|
||||
return errno;
|
||||
} else {
|
||||
ret = munmap(p, pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int shmfd;
|
||||
int ret;
|
||||
int count;
|
||||
int pageSize = getpagesize();
|
||||
char *buf = NULL;
|
||||
|
||||
shmfd = shm_open("/test", O_RDWR | O_CREAT, 0644);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(shmfd, -1, shmfd);
|
||||
|
||||
if (pageSize <= 0) {
|
||||
printf("err: malloc size invalid\n");
|
||||
return -1;
|
||||
}
|
||||
if (pageSize <= 0) {
|
||||
printf("err: malloc size invalid\n");
|
||||
return -1;
|
||||
}
|
||||
buf = (char *)malloc(pageSize);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
|
||||
(void)memset_s(buf, pageSize, 0xf, pageSize);
|
||||
|
||||
count = write(shmfd, buf, pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(count, pageSize, count);
|
||||
|
||||
free(buf);
|
||||
|
||||
/* Simple MAP_ANONYMOUS */
|
||||
ret = CheckedMmap(PROT_READ | PROT_WRITE, MAP_ANONYMOUS, -1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
/* Simple shm fd shared */
|
||||
ret = CheckedMmap(PROT_READ | PROT_WRITE, MAP_SHARED, shmfd);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
/* Simple shm fd private */
|
||||
ret = CheckedMmap(PROT_READ | PROT_WRITE, MAP_PRIVATE, shmfd);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
/* MAP_ANONYMOUS with extra PROT flags */
|
||||
ret = CheckedMmap(PROT_READ | PROT_WRITE | 0x100000, MAP_ANONYMOUS, -1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
/* Shm fd with garbage PROT */
|
||||
ret = CheckedMmap(0xffff, MAP_SHARED, shmfd);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
/* Undefined flag. */
|
||||
ret = CheckedMmap(PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_RESERVED0080, -1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
/* Both MAP_SHARED and MAP_PRIVATE */
|
||||
ret = CheckedMmap(PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_SHARED, -1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
/* Shm fd with both SHARED and PRIVATE */
|
||||
ret = CheckedMmap(PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_SHARED, shmfd);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
/* At least one of MAP_SHARED or MAP_PRIVATE without ANON */
|
||||
ret = CheckedMmap(PROT_READ | PROT_WRITE, 0, shmfd);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
/* MAP_ANONYMOUS with either sharing flag (impacts fork). */
|
||||
ret = CheckedMmap(PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = CheckedMmap(PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
/* MAP_ANONYMOUS should require an fd of -1. */
|
||||
ret = CheckedMmap(PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = close(shmfd);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestMmap002(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_MMAP_002", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
83
testsuites/unittest/basic/mem/vm/smoke/mmap_test_003.cpp
Normal file
83
testsuites/unittest/basic/mem/vm/smoke/mmap_test_003.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
|
||||
#define MAP_TEST_FILE "/dev/shm/test"
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
char *p1 = NULL;
|
||||
char *p2 = NULL;
|
||||
char *p3 = NULL;
|
||||
int fd, pageSize;
|
||||
int ret;
|
||||
|
||||
pageSize = getpagesize();
|
||||
fd = open(MAP_TEST_FILE, O_RDONLY);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, -1, fd);
|
||||
|
||||
p1 = (char *)mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p1, MAP_FAILED, p1);
|
||||
(void)memset_s(p1, pageSize, 0, pageSize);
|
||||
|
||||
p2 = (char *)mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p2, MAP_FAILED, p2);
|
||||
(void)memset_s(p2, pageSize, 0, pageSize);
|
||||
|
||||
ret = memcmp(p1, p2, pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
p1[0] = 1;
|
||||
ICUNIT_ASSERT_EQUAL(p2[0], 0, p2[0]);
|
||||
|
||||
p2[0] = 2;
|
||||
ICUNIT_ASSERT_EQUAL(p1[0], 1, p1[0]);
|
||||
|
||||
p3 = (char *)mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p3, MAP_FAILED, p3);
|
||||
ICUNIT_ASSERT_EQUAL(p3[0], 0xf, p3[0]);
|
||||
|
||||
ret = munmap(p1, pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = munmap(p2, pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = munmap(p3, pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestMmap003(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_MMAP_003", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
83
testsuites/unittest/basic/mem/vm/smoke/mmap_test_004.cpp
Normal file
83
testsuites/unittest/basic/mem/vm/smoke/mmap_test_004.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
|
||||
#define MAP_TEST_FILE "/dev/shm/test"
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
char *p1 = NULL;
|
||||
char *p2 = NULL;
|
||||
char *p3 = NULL;
|
||||
int fd, pageSize;
|
||||
int ret;
|
||||
|
||||
pageSize = getpagesize();
|
||||
fd = open(MAP_TEST_FILE, O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, -1, fd);
|
||||
|
||||
p1 = (char *)mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p1, MAP_FAILED, p1);
|
||||
(void)memset_s(p1, pageSize, 0, pageSize);
|
||||
|
||||
p2 = (char *)mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p2, MAP_FAILED, p2);
|
||||
(void)memset_s(p2, pageSize, 0, pageSize);
|
||||
|
||||
ret = memcmp(p1, p2, pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
p1[0] = 1;
|
||||
ICUNIT_ASSERT_EQUAL(p2[0], 1, p2[0]);
|
||||
|
||||
p2[0] = 2;
|
||||
ICUNIT_ASSERT_EQUAL(p1[0], 2, p1[0]);
|
||||
|
||||
p3 = (char *)mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p3, MAP_FAILED, p3);
|
||||
ICUNIT_ASSERT_EQUAL(p3[0], 2, p3[0]);
|
||||
|
||||
ret = munmap(p1, pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = munmap(p2, pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = munmap(p3, pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestMmap004(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_MMAP_004", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
53
testsuites/unittest/basic/mem/vm/smoke/mmap_test_005.cpp
Normal file
53
testsuites/unittest/basic/mem/vm/smoke/mmap_test_005.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
|
||||
#define MAP_TEST_FILE "/lib/libc.so"
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
void *map = NULL;
|
||||
int fd;
|
||||
|
||||
fd = open(MAP_TEST_FILE, O_RDONLY);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, -1, fd);
|
||||
|
||||
map = mmap(NULL, 0, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
ICUNIT_ASSERT_EQUAL(map, MAP_FAILED, map);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestMmap005(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_MMAP_005", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
100
testsuites/unittest/basic/mem/vm/smoke/mmap_test_006.cpp
Normal file
100
testsuites/unittest/basic/mem/vm/smoke/mmap_test_006.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
#define INVALID_FD 0xFFFFFFFF
|
||||
#define INVALID_VADDR 0xAFFFFFFF
|
||||
#define VALIDE_ADDR 0x12000000
|
||||
#define ADDR_OFFSET 0X123
|
||||
#define OVER_LEN 0x40000000
|
||||
#define MAP_LEN 0x1000
|
||||
#define FLAG_NUM 3
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
void *mem = NULL;
|
||||
void *invalueAddr = NULL;
|
||||
size_t len = MAP_LEN;
|
||||
char file[] = "/storage/testMmapEINVAL.txt";
|
||||
int flags[FLAG_NUM] = {0, MAP_ANON, MAP_PRIVATE | MAP_SHARED};
|
||||
int ret, fd;
|
||||
|
||||
fd = open(file, O_CREAT | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, -1, fd);
|
||||
|
||||
invalueAddr = (void *)(VALIDE_ADDR | ADDR_OFFSET);
|
||||
mem = mmap(invalueAddr, len, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0);
|
||||
ICUNIT_GOTO_EQUAL(mem, MAP_FAILED, mem, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
|
||||
|
||||
mem = mmap((void *)INVALID_VADDR, len, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0);
|
||||
ICUNIT_GOTO_EQUAL(mem, MAP_FAILED, mem, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
|
||||
|
||||
mem = mmap((void *)INVALID_VADDR, len, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
|
||||
ICUNIT_GOTO_NOT_EQUAL(mem, MAP_FAILED, mem, EXIT);
|
||||
ret = munmap(mem, len);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
len = OVER_LEN;
|
||||
mem = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
ICUNIT_GOTO_EQUAL(mem, MAP_FAILED, mem, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
|
||||
|
||||
len = MAP_LEN;
|
||||
mem = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, INVALID_FD);
|
||||
ICUNIT_GOTO_EQUAL(mem, MAP_FAILED, mem, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
|
||||
|
||||
len = 0;
|
||||
mem = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
ICUNIT_GOTO_EQUAL(mem, MAP_FAILED, mem, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
|
||||
|
||||
len = MAP_LEN;
|
||||
for (int i = 0; i < FLAG_NUM; i++) {
|
||||
mem = mmap(NULL, len, PROT_READ | PROT_WRITE, flags[i], fd, 0);
|
||||
ICUNIT_GOTO_EQUAL(mem, MAP_FAILED, mem, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
|
||||
}
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = remove(file);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestMmap006(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_MMAP_006", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
93
testsuites/unittest/basic/mem/vm/smoke/mmap_test_007.cpp
Normal file
93
testsuites/unittest/basic/mem/vm/smoke/mmap_test_007.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
|
||||
#define MAP_LEN 0x200000
|
||||
#define MAP_ADDR 0x1200000
|
||||
#define MAP_OFFSET 0x100000
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
size_t len = MAP_LEN;
|
||||
unsigned long fixAddr = MAP_ADDR;
|
||||
unsigned long before, after;
|
||||
size_t shinkLen;
|
||||
unsigned int flags = MAP_ANON | MAP_SHARED | MAP_FIXED;
|
||||
void *mem = NULL;
|
||||
void *prev = NULL;
|
||||
void *next = NULL;
|
||||
void *belong = NULL;
|
||||
int ret;
|
||||
|
||||
mem = mmap((void *)fixAddr, len, PROT_READ | PROT_WRITE, flags, -1, 0);
|
||||
ICUNIT_GOTO_NOT_EQUAL(mem, MAP_FAILED, mem, EXIT);
|
||||
|
||||
before = fixAddr - MAP_OFFSET;
|
||||
prev = mmap((void *)before, len, PROT_READ | PROT_WRITE, flags, -1, 0);
|
||||
ICUNIT_GOTO_NOT_EQUAL(prev, MAP_FAILED, prev, EXIT1);
|
||||
|
||||
after = fixAddr + MAP_OFFSET;
|
||||
next = mmap((void *)after, len, PROT_READ | PROT_WRITE, flags, -1, 0);
|
||||
ICUNIT_GOTO_NOT_EQUAL(next, MAP_FAILED, next, EXIT2);
|
||||
|
||||
shinkLen = len - MAP_OFFSET;
|
||||
belong = mmap((void *)after, shinkLen, PROT_READ | PROT_WRITE, flags, -1, 0);
|
||||
ICUNIT_GOTO_NOT_EQUAL(belong, MAP_FAILED, belong, EXIT3);
|
||||
|
||||
ret = munmap(prev, len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = munmap(next, len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return LOS_OK;
|
||||
|
||||
EXIT1:
|
||||
ret = munmap(mem, len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return LOS_NOK;
|
||||
EXIT2:
|
||||
ret = munmap(mem, len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = munmap(prev, len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return LOS_NOK;
|
||||
EXIT3:
|
||||
ret = munmap(prev, len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = munmap(next, len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
EXIT:
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
void ItTestMmap007(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_MMAP_007", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
84
testsuites/unittest/basic/mem/vm/smoke/mmap_test_008.cpp
Normal file
84
testsuites/unittest/basic/mem/vm/smoke/mmap_test_008.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
|
||||
#define MAP_OFFSET 0x1000
|
||||
#define MAP_ADDR 0x1200000
|
||||
#define MAP_LEN 0x2000
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
unsigned long fixAddr = MAP_ADDR;
|
||||
unsigned int len = MAP_LEN;
|
||||
unsigned int flags = MAP_ANON | MAP_SHARED;
|
||||
void *mem = NULL;
|
||||
void *memFix = NULL;
|
||||
void *memNoFix = NULL;
|
||||
void *pre = NULL;
|
||||
void *next = NULL;
|
||||
void *overlay = NULL;
|
||||
int ret;
|
||||
|
||||
mem = mmap((void *)fixAddr, len, PROT_READ | PROT_WRITE, flags | MAP_FIXED, -1, 0);
|
||||
ICUNIT_GOTO_NOT_EQUAL(mem, MAP_FAILED, mem, EXIT);
|
||||
|
||||
memFix = mmap((void *)fixAddr, len, PROT_READ | PROT_WRITE, flags | MAP_FIXED, -1, 0);
|
||||
ICUNIT_GOTO_NOT_EQUAL(memFix, MAP_FAILED, memFix, EXIT1);
|
||||
ICUNIT_ASSERT_EQUAL(mem, memFix, mem);
|
||||
|
||||
memNoFix = mmap((void *)fixAddr, len, PROT_READ | PROT_WRITE, flags | MAP_FIXED_NOREPLACE, -1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(memNoFix, MAP_FAILED, memNoFix);
|
||||
|
||||
memNoFix = mmap((void *)(fixAddr - MAP_OFFSET), len, PROT_READ | PROT_WRITE, flags | MAP_FIXED_NOREPLACE, -1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(memNoFix, MAP_FAILED, memNoFix);
|
||||
|
||||
memNoFix = mmap((void *)(fixAddr + MAP_OFFSET), len, PROT_READ | PROT_WRITE, flags | MAP_FIXED_NOREPLACE, -1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(memNoFix, MAP_FAILED, memNoFix);
|
||||
|
||||
memNoFix = mmap((void *)(fixAddr - MAP_OFFSET), len + MAP_OFFSET, PROT_READ | PROT_WRITE,
|
||||
flags | MAP_FIXED_NOREPLACE, -1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(memNoFix, MAP_FAILED, memNoFix);
|
||||
|
||||
ret = munmap(mem, len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return LOS_OK;
|
||||
EXIT1:
|
||||
ret = munmap(mem, len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return LOS_NOK;
|
||||
EXIT:
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
void ItTestMmap008(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_MMAP_008", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
93
testsuites/unittest/basic/mem/vm/smoke/mmap_test_009.cpp
Normal file
93
testsuites/unittest/basic/mem/vm/smoke/mmap_test_009.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
|
||||
#define INVALID_PROCESS_ID 100000
|
||||
#define MMAP_SIZE 0x1000
|
||||
#define PARAM_INIT 0x123
|
||||
|
||||
/* Test PROT_NONE flag */
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret, param;
|
||||
int *ptr = NULL;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, INVALID_PROCESS_ID, pid);
|
||||
if (pid == 0) {
|
||||
ptr = (int *)mmap(0, MMAP_SIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ptr, MAP_FAILED, ptr);
|
||||
printf("%d\n", *ptr);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ret = WIFEXITED(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = WIFSIGNALED(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
|
||||
ret = WTERMSIG(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, SIGUSR2, ret);
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, INVALID_PROCESS_ID, pid);
|
||||
if (pid == 0) {
|
||||
ptr = (int *)mmap(0, MMAP_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ptr, MAP_FAILED, ptr);
|
||||
*ptr = PARAM_INIT;
|
||||
ret = mprotect(ptr, MMAP_SIZE, PROT_READ);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(*ptr, PARAM_INIT, *ptr);
|
||||
ret = mprotect(ptr, MMAP_SIZE, PROT_NONE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
printf("%d\n", *ptr);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ret = WIFEXITED(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = WIFSIGNALED(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
|
||||
ret = WTERMSIG(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, SIGUSR2, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestMmap009(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_MMAP_009", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
63
testsuites/unittest/basic/mem/vm/smoke/mmap_test_010.cpp
Normal file
63
testsuites/unittest/basic/mem/vm/smoke/mmap_test_010.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
|
||||
#define MMAP_SIZE 0x1000
|
||||
#define PARAM_INIT 0x123
|
||||
|
||||
/* Test PROT_WRITE and PROT_EXEC flag only */
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int *ptr = NULL;
|
||||
|
||||
ptr = (int *)mmap(0, MMAP_SIZE, PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ptr, MAP_FAILED, ptr);
|
||||
*ptr = PARAM_INIT;
|
||||
ICUNIT_ASSERT_EQUAL(*ptr, PARAM_INIT, *ptr);
|
||||
ret = munmap(ptr, MMAP_SIZE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ptr = (int *)mmap(0, MMAP_SIZE, PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ptr, MAP_FAILED, ptr);
|
||||
ICUNIT_ASSERT_EQUAL(*ptr, 0, *ptr);
|
||||
ret = munmap(ptr, MMAP_SIZE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestMmap010(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_MMAP_010", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
81
testsuites/unittest/basic/mem/vm/smoke/mprotect_test_001.cpp
Normal file
81
testsuites/unittest/basic/mem/vm/smoke/mprotect_test_001.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
char *p = NULL;
|
||||
int pageSize;
|
||||
int ret;
|
||||
|
||||
pageSize = getpagesize();
|
||||
|
||||
ret = mprotect(0, pageSize, PROT_NONE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = mprotect(0, pageSize, 0xffff);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = mprotect((void *)0x1000, pageSize, PROT_READ | PROT_WRITE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = mprotect((void *)0xffffff, pageSize, PROT_READ | PROT_WRITE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
p = (char *)mmap(NULL, pageSize * 3, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p, MAP_FAILED, p);
|
||||
|
||||
ret = mprotect(p, pageSize * 4, PROT_READ | PROT_WRITE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = mprotect(p, pageSize, PROT_READ | PROT_WRITE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
(void)memset_s(p, pageSize, 0xf, pageSize);
|
||||
|
||||
ret = mprotect(p + pageSize * 2, pageSize, PROT_READ | PROT_WRITE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
(void)memset_s(p + pageSize * 2, pageSize, 0xf, pageSize);
|
||||
|
||||
ret = munmap(p, pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestMprotect001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_MPROTECT_001", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
97
testsuites/unittest/basic/mem/vm/smoke/mremap_test_001.cpp
Normal file
97
testsuites/unittest/basic/mem/vm/smoke/mremap_test_001.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
char *p = NULL;
|
||||
void *newAddr = NULL;
|
||||
int pageSize;
|
||||
int size;
|
||||
int ret;
|
||||
|
||||
pageSize = getpagesize();
|
||||
size = pageSize << 1;
|
||||
|
||||
p = (char *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p, MAP_FAILED, p);
|
||||
|
||||
/* Parameter check */
|
||||
newAddr = mremap(0, 0, 0, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(newAddr, MAP_FAILED, newAddr);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
newAddr = mremap(p, size, size, MREMAP_FIXED, 0);
|
||||
ICUNIT_ASSERT_EQUAL(newAddr, MAP_FAILED, newAddr);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
/* Shrink a region */
|
||||
newAddr = mremap(p, size, pageSize, MREMAP_MAYMOVE, 0);
|
||||
ICUNIT_ASSERT_EQUAL(newAddr, p, newAddr);
|
||||
|
||||
/* Remap a region by same size */
|
||||
newAddr = mremap(p, pageSize, pageSize, MREMAP_MAYMOVE, 0);
|
||||
ICUNIT_ASSERT_EQUAL(newAddr, p, newAddr);
|
||||
|
||||
/* Expand a region */
|
||||
newAddr = mremap(p, pageSize, size, MREMAP_MAYMOVE, 0);
|
||||
ICUNIT_ASSERT_EQUAL(newAddr, p, newAddr);
|
||||
|
||||
/* New region overlaping with the old one */
|
||||
newAddr = mremap(p, size, pageSize, MREMAP_MAYMOVE | MREMAP_FIXED, p + pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(newAddr, MAP_FAILED, newAddr);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
newAddr = mremap(p, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, p - pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(newAddr, MAP_FAILED, newAddr);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
newAddr = mremap(p, size, size + pageSize, MREMAP_MAYMOVE | MREMAP_FIXED, p - pageSize);
|
||||
ICUNIT_ASSERT_EQUAL(newAddr, MAP_FAILED, newAddr);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
/* Remap to new addr */
|
||||
newAddr = mremap(p, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, p + size);
|
||||
ICUNIT_ASSERT_EQUAL(newAddr, p + size, newAddr);
|
||||
|
||||
newAddr = mremap(newAddr, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, (char *)newAddr - size);
|
||||
ICUNIT_ASSERT_EQUAL(newAddr, p, newAddr);
|
||||
|
||||
ret = munmap(p, size);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestMremap001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_MREMAP_001", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
67
testsuites/unittest/basic/mem/vm/smoke/oom_test_001.cpp
Normal file
67
testsuites/unittest/basic/mem/vm/smoke/oom_test_001.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
|
||||
#define MAX_MEM_SIZE 0x6000000
|
||||
/* test page fault oom */
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
unsigned int *ptr = NULL;
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
ptr = (unsigned int *)mmap(0, MAX_MEM_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ptr, MAP_FAILED, ptr);
|
||||
/* expect oom */
|
||||
for (int i = 0; i < MAX_MEM_SIZE / PAGE_SIZE; i++) {
|
||||
*(ptr + i * PAGE_SIZE / sizeof(unsigned int)) = 0;
|
||||
}
|
||||
|
||||
/* if we go here, phy mem is enough, should increase the MAX_MEM_SIZE and rerun */
|
||||
ICUNIT_ASSERT_EQUAL(1, 0, 1);
|
||||
} else {
|
||||
pid = ret;
|
||||
ret = waitpid(pid, &status, 0);
|
||||
status = WIFSIGNALED(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 1, status);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestOom001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_OOM_001", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +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_vm.h"
|
||||
#include "wchar.h"
|
||||
|
||||
static int testcase(void)
|
||||
{
|
||||
FILE *stream = nullptr;
|
||||
wchar_t *buf = nullptr;
|
||||
size_t len = 0;
|
||||
|
||||
stream = open_wmemstream(&buf, &len);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(stream, nullptr, stream);
|
||||
|
||||
fwprintf(stream, L"hello my world");
|
||||
int ret = fflush(stream);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(len, 14, len);
|
||||
off_t eob = ftello(stream);
|
||||
ret = fseeko(stream, 0, SEEK_SET);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
fwprintf(stream, L"good-bye");
|
||||
ret = fseeko(stream, eob, SEEK_SET);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = fclose(stream);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(len, 8, len);
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void open_wmemstream_test_001(void)
|
||||
{
|
||||
TEST_ADD_CASE("OPEN_WMEMSTEAM_TEST_001", testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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_vm.h"
|
||||
#include "signal.h"
|
||||
|
||||
#define INVALID_USER_VADDR 0x1200000
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
sigset_t oldset;
|
||||
const char *str = "Hi, OHOS.";
|
||||
|
||||
/* sigprocmask 内核系统调用接口通过arch_copy_from_user拷贝用户参数 */
|
||||
ret = sigprocmask(SIG_BLOCK, (sigset_t *)1, &oldset);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EFAULT, errno);
|
||||
|
||||
ret = sigprocmask(SIG_BLOCK, (sigset_t *)INVALID_USER_VADDR, &oldset);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EFAULT, errno);
|
||||
|
||||
/* sigprocmask 内核系统调用接口通过arch_copy_to_user将内核参数拷贝至用户 */
|
||||
ret = sigprocmask(SIG_BLOCK, (sigset_t *)INVALID_USER_VADDR, (sigset_t *)1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EFAULT, errno);
|
||||
|
||||
ret = sigprocmask(SIG_BLOCK, (sigset_t *)INVALID_USER_VADDR, (sigset_t *)INVALID_USER_VADDR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EFAULT, errno);
|
||||
|
||||
ret = sigprocmask(SIG_BLOCK, (sigset_t *)INVALID_USER_VADDR, (sigset_t *)str);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EFAULT, errno);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestUserCopy001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_MEM_USER_COPY_001", Testcase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
Reference in New Issue
Block a user