add testsuites
Change-Id: Ice1193d1ae7f2e0d12a2a38a306a6399407f5037
This commit is contained in:
46
testsuites/unittest/security/vid/BUILD.gn
Normal file
46
testsuites/unittest/security/vid/BUILD.gn
Normal file
@@ -0,0 +1,46 @@
|
||||
# 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.
|
||||
|
||||
import("//build/lite/config/test.gni")
|
||||
|
||||
unittest("liteos_a_security_vid_unittest") {
|
||||
output_extension = "bin"
|
||||
output_dir = "$root_out_dir/test/unittest/kernel"
|
||||
include_dirs = [
|
||||
"../../common/include",
|
||||
"../../security/vid",
|
||||
]
|
||||
sources = [
|
||||
"../../common/osTest.cpp",
|
||||
"security_vid_test.cpp",
|
||||
"smoke/vid_test_001.cpp",
|
||||
]
|
||||
configs = [ "../..:public_config" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
}
|
||||
47
testsuites/unittest/security/vid/it_test_vid.h
Normal file
47
testsuites/unittest/security/vid/it_test_vid.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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_SECURITY_VID_H
|
||||
#define _IT_TEST_SECURITY_VID_H
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include "osTest.h"
|
||||
#include <time.h>
|
||||
#include "stdio.h"
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
#include "los_typedef.h"
|
||||
#include "sched.h"
|
||||
#include "signal.h"
|
||||
|
||||
extern VOID ItSuite_Security_Vid(VOID);
|
||||
extern VOID ItSecVid001(VOID);
|
||||
|
||||
#endif
|
||||
55
testsuites/unittest/security/vid/security_vid_test.cpp
Normal file
55
testsuites/unittest/security/vid/security_vid_test.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 "stdio.h"
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "it_test_vid.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
class SecurityVidTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: It_Sec_Vid_001
|
||||
* @tc.desc: function for SecurityVidTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(SecurityVidTest, ItSecVid001, TestSize.Level0)
|
||||
{
|
||||
ItSecVid001();
|
||||
}
|
||||
} // namespace OHOS
|
||||
137
testsuites/unittest/security/vid/smoke/vid_test_001.cpp
Normal file
137
testsuites/unittest/security/vid/smoke/vid_test_001.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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_vid.h"
|
||||
#include "stdio.h"
|
||||
#include "unistd.h"
|
||||
#include "sys/stat.h"
|
||||
#include "time.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
static VOID TimerFunc(int sig)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static void ChildFunc()
|
||||
{
|
||||
timer_t tid;
|
||||
struct sigevent ent;
|
||||
INT32 *ret1 = NULL;
|
||||
int ret;
|
||||
struct itimerspec its;
|
||||
struct itimerspec its2;
|
||||
timer_t *tid2 = nullptr;
|
||||
int i = 0;
|
||||
signal(SIGUSR1, TimerFunc);
|
||||
ent.sigev_notify = SIGEV_SIGNAL;
|
||||
ent.sigev_signo = SIGUSR1;
|
||||
|
||||
tid2 = (timer_t *)malloc(sizeof(UINTPTR) * 1024);
|
||||
ret1 = (int *)malloc(sizeof(int) * 1024);
|
||||
(void)memset_s(tid2, sizeof(char *) * 1024, 0, sizeof(char *) * 1024);
|
||||
(void)memset_s(ret1, sizeof(int) * 1024, 0xff, sizeof(int) * 1024);
|
||||
while (i < 1024) {
|
||||
*(ret1 + i) = timer_create(CLOCK_REALTIME, &ent, tid2 + i);
|
||||
if (*(ret1 + i) == 0) {
|
||||
ICUNIT_ASSERT_EQUAL_VOID(*(ret1 + i), 0, *(ret1 + i));
|
||||
ICUNIT_ASSERT_EQUAL_VOID(i, (int)(*(tid2 + i)), i);
|
||||
} else {
|
||||
ICUNIT_ASSERT_EQUAL_VOID(*(ret1 + i), -1, *(ret1 + i));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (*(ret1 + i) == 0) {
|
||||
ret = timer_delete(*(tid2 + i));
|
||||
ICUNIT_ASSERT_EQUAL_VOID(ret, 0, ret);
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < 1024) {
|
||||
*(ret1 + i) = timer_create(CLOCK_REALTIME, &ent, tid2 + i);
|
||||
if (*(ret1 + i) == 0) {
|
||||
ICUNIT_ASSERT_EQUAL_VOID(*(ret1 + i), 0, *(ret1 + i));
|
||||
ICUNIT_ASSERT_EQUAL_VOID(i, (int)(*(tid2 + i)), i);
|
||||
} else {
|
||||
ICUNIT_ASSERT_EQUAL_VOID(*(ret1 + i), -1, *(ret1 + i));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (*(ret1 + i) == 0) {
|
||||
ret = timer_delete(*(tid2 + i));
|
||||
ICUNIT_ASSERT_EQUAL_VOID(ret, 0, ret);
|
||||
i++;
|
||||
}
|
||||
|
||||
free(tid2);
|
||||
ret1 = (INT32 *)timer_create(CLOCK_REALTIME, &ent, &tid);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(ret1, 0, ret1);
|
||||
|
||||
its.it_interval.tv_sec = 1;
|
||||
its.it_interval.tv_nsec = 0;
|
||||
its.it_value.tv_sec = 1;
|
||||
its.it_value.tv_nsec = 0;
|
||||
ret1 = (INT32 *)timer_settime(tid, 0, &its, NULL);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(ret1, 0, ret1);
|
||||
sleep(1);
|
||||
ret1 = (INT32 *)timer_gettime(tid, &its2);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(ret1, 0, ret1);
|
||||
ret1 = (INT32 *)timer_getoverrun(tid);
|
||||
ret1 = (INT32 *)(((int)(intptr_t)ret1 >= 0) ? 0 : -1);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(ret1, 0, ret1);
|
||||
|
||||
ret1 = (INT32 *)timer_delete(tid);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(ret1, 0, ret1);
|
||||
|
||||
exit((int)(intptr_t)tid);
|
||||
}
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
int pid;
|
||||
int status = 0;
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ChildFunc();
|
||||
}
|
||||
|
||||
waitpid(pid, &status, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
VOID ItSecVid001(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("IT_SEC_VID_001", TestCase, TEST_POSIX, TEST_SEC, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
Reference in New Issue
Block a user