增加memorytracker接口用例

Signed-off-by: limeng151 <limeng151@huawei.com>
Change-Id: Idbee1bd83d12eeb2cfafa74dc65234e6fc86b10c
This commit is contained in:
limeng151 2022-06-16 19:20:37 +08:00
parent fc24301a99
commit d9015be01e
4 changed files with 225 additions and 0 deletions

View File

@ -21,6 +21,7 @@ group("kernel") {
deps = [
"accesstokenid:HatsAccesstokenidTest",
"cam:HatsCamTest",
"memtracker:HatsMemoryTrackerTest",
"open_posix_testsuite/conformance/interfaces_gn:${posix_interface_module}",
"prctl:HatsPrctlTest",
]

View File

@ -0,0 +1,40 @@
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "hats/memtracker"
memorytracker_external_deps = [
"device_driver_framework:libhdf_utils",
"ipc:ipc_core",
"memorytracker_device_driver_interface:libmemorytracker_proxy_1.0",
]
ohos_moduletest_suite("HatsMemoryTrackerTest") {
module_out_path = module_output_path
sources = [ "./MemTrackerTest.cpp" ]
if (is_standard_system) {
external_deps = memorytracker_external_deps
}
deps = [
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
include_dirs = [
"//test/xts/tools/hctest/include",
"//utils/",
]
cflags = [ "-Wno-error" ]
}

View File

@ -0,0 +1,166 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#define private public
#define protected public
#include <v1_0/imemory_tracker_interface.h>
#include "hdf_base.h"
#undef private
#undef protected
namespace OHOS {
namespace Memory {
using namespace testing;
using namespace testing::ext;
using namespace OHOS::HDI::MemoryTracker::V1_0;
class MemTrackerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void MemTrackerTest::SetUpTestCase()
{
}
void MemTrackerTest::TearDownTestCase()
{
}
void MemTrackerTest::SetUp()
{
}
void MemTrackerTest::TearDown()
{
}
/**
* @tc.number SUB_KERNEL_Get_MemoryTest_0101
* @tc.name Unable to obtain related services
* @tc.desc [C- SOFTWARE -0200]
*/
HWTEST_F(MemTrackerTest, GetMemoryTest_01, TestSize.Level1)
{
printf("begin call memtrack by service \n");
sptr<IMemoryTrackerInterface> memtrack = IMemoryTrackerInterface::Get();
if (memtrack == nullptr) {
printf("memtrack service is null \n");
return;
}
std::vector<MemoryRecord> records;
int errCode = memtrack->GetDevMem(0, MEMORY_TRACKER_TYPE_GL, records);
ASSERT_EQ(errCode, HDF_SUCCESS);
}
/**
* @tc.number SUB_KERNEL_Get_MemoryTest_0102
* @tc.name Obtain relevant services and input legal parameters
* @tc.desc [C- SOFTWARE -0200]
*/
HWTEST_F(MemTrackerTest, GetMemoryTest_02, TestSize.Level1)
{
printf("begin call memtrack passthrough \n");
sptr<IMemoryTrackerInterface> memtrack = IMemoryTrackerInterface::Get(true);
if (memtrack == nullptr) {
printf("memtrack service is null \n");
return;
}
std::vector<MemoryRecord> records;
int errCode = memtrack->GetDevMem(0, MEMORY_TRACKER_TYPE_GL, records);
ASSERT_EQ(errCode, HDF_SUCCESS);
}
/**
* @tc.number SUB_KERNEL_Get_MemoryTest_0103
* @tc.name replace MemoryTrackerType is MEMORY_TRACKER_TYPE_CAM
* @tc.desc [C- SOFTWARE -0200]
*/
HWTEST_F(MemTrackerTest, GetMemoryTest_03, TestSize.Level1)
{
printf("begin call memtrack passthrough \n");
sptr<IMemoryTrackerInterface> memtrack = IMemoryTrackerInterface::Get(true);
if (memtrack == nullptr) {
printf("memtrack service is null \n");
return;
}
std::vector<MemoryRecord> records;
int errCode = memtrack->GetDevMem(0, MEMORY_TRACKER_TYPE_CAM, records);
ASSERT_EQ(errCode, HDF_SUCCESS);
}
/**
* @tc.number SUB_KERNEL_Get_MemoryTest_0104
* @tc.name replace MemoryTrackerType is MEMORY_TRACKER_TYPE_MM
* @tc.desc [C- SOFTWARE -0200]
*/
HWTEST_F(MemTrackerTest, GetMemoryTest_04, TestSize.Level1)
{
printf("begin call memtrack passthrough \n");
sptr<IMemoryTrackerInterface> memtrack = IMemoryTrackerInterface::Get(true);
if (memtrack == nullptr) {
printf("memtrack service is null \n");
return;
}
std::vector<MemoryRecord> records;
int errCode = memtrack->GetDevMem(0, MEMORY_TRACKER_TYPE_MM, records);
ASSERT_EQ(errCode, HDF_SUCCESS);
}
/**
* @tc.number SUB_KERNEL_Get_MemoryTest_0105
* @tc.name replace MemoryTrackerType is MEMORY_TRACKER_TYPE_GRAPH
* @tc.desc [C- SOFTWARE -0200]
*/
HWTEST_F(MemTrackerTest, GetMemoryTest_05, TestSize.Level1)
{
printf("begin call memtrack passthrough \n");
sptr<IMemoryTrackerInterface> memtrack = IMemoryTrackerInterface::Get(true);
if (memtrack == nullptr) {
printf("memtrack service is null \n");
return;
}
std::vector<MemoryRecord> records;
int errCode = memtrack->GetDevMem(0, MEMORY_TRACKER_TYPE_GRAPH, records);
ASSERT_EQ(errCode, HDF_SUCCESS);
}
/**
* @tc.number SUB_KERNEL_Get_MemoryTest_0106
* @tc.name replace MemoryTrackerType is MEMORY_TRACKER_TYPE_OTHER
* @tc.desc [C- SOFTWARE -0200]
*/
HWTEST_F(MemTrackerTest, GetMemoryTest_06, TestSize.Level1)
{
printf("begin call memtrack passthrough \n");
sptr<IMemoryTrackerInterface> memtrack = IMemoryTrackerInterface::Get(true);
if (memtrack == nullptr) {
printf("memtrack service is null \n");
return;
}
std::vector<MemoryRecord> records;
int errCode = memtrack->GetDevMem(0, MEMORY_TRACKER_TYPE_OTHER, records);
ASSERT_EQ(errCode, HDF_SUCCESS);
}
}
}

View File

@ -0,0 +1,18 @@
{
"description": "Configuration for MemTrackerTest Tests",
"kits": [
{
"push": [
"HatsMemoryTrackerTest->/data/local/tmp/HatsMemoryTrackerTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "HatsMemoryTrackerTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
}
}