2018-09-22 00:44:31 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* 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 <unordered_set>
|
|
|
|
|
|
|
|
#include <android/hardware/atrace/1.0/IAtraceDevice.h>
|
|
|
|
|
2019-10-29 07:56:03 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <hidl/GtestPrinter.h>
|
|
|
|
#include <hidl/ServiceManagement.h>
|
2018-09-22 00:44:31 +02:00
|
|
|
|
|
|
|
using ::android::sp;
|
|
|
|
using ::android::hardware::hidl_string;
|
|
|
|
using ::android::hardware::hidl_vec;
|
|
|
|
using ::android::hardware::Return;
|
|
|
|
using ::android::hardware::atrace::V1_0::IAtraceDevice;
|
|
|
|
using ::android::hardware::atrace::V1_0::Status;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* There is no expected behaviour that can be tested so these tests check the
|
|
|
|
* HAL doesn't crash with different execution orders.
|
|
|
|
*/
|
2019-10-29 07:56:03 +01:00
|
|
|
struct AtraceHidlTest : public ::testing::TestWithParam<std::string> {
|
2018-09-22 00:44:31 +02:00
|
|
|
virtual void SetUp() override {
|
2019-10-29 07:56:03 +01:00
|
|
|
atrace = IAtraceDevice::getService(GetParam());
|
2018-09-22 00:44:31 +02:00
|
|
|
ASSERT_NE(atrace, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<IAtraceDevice> atrace;
|
|
|
|
};
|
|
|
|
|
|
|
|
hidl_vec<hidl_string> getVendorCategoryName(sp<IAtraceDevice> atrace) {
|
|
|
|
std::unordered_set<std::string> categories_set;
|
|
|
|
Return<void> ret = atrace->listCategories([&](const auto& list) {
|
|
|
|
for (const auto& category : list) {
|
|
|
|
std::string name = category.name;
|
|
|
|
if (categories_set.count(name)) {
|
|
|
|
ADD_FAILURE() << "Duplicate category: " << name;
|
|
|
|
} else {
|
|
|
|
categories_set.emplace(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!ret.isOk()) {
|
|
|
|
ADD_FAILURE();
|
|
|
|
}
|
|
|
|
hidl_vec<hidl_string> categories;
|
|
|
|
categories.resize(categories_set.size());
|
|
|
|
std::size_t i = 0;
|
|
|
|
for (auto& c : categories_set) {
|
|
|
|
categories[i++] = c;
|
|
|
|
}
|
|
|
|
return categories;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* list categories from vendors. */
|
2019-10-29 07:56:03 +01:00
|
|
|
TEST_P(AtraceHidlTest, listCategories) {
|
2018-09-22 00:44:31 +02:00
|
|
|
hidl_vec<hidl_string> vnd_categories = getVendorCategoryName(atrace);
|
|
|
|
EXPECT_NE(0, vnd_categories.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* enable categories. */
|
2019-10-29 07:56:03 +01:00
|
|
|
TEST_P(AtraceHidlTest, enableCategories) {
|
2018-09-22 00:44:31 +02:00
|
|
|
hidl_vec<hidl_string> vnd_categories = getVendorCategoryName(atrace);
|
|
|
|
// empty Category with ERROR_INVALID_ARGUMENT
|
|
|
|
hidl_vec<hidl_string> empty_categories;
|
|
|
|
auto ret = atrace->enableCategories(empty_categories);
|
|
|
|
ASSERT_TRUE(ret.isOk());
|
|
|
|
EXPECT_EQ(Status::ERROR_INVALID_ARGUMENT, ret);
|
|
|
|
// non-empty categories SUCCESS
|
|
|
|
ret = atrace->enableCategories(vnd_categories);
|
|
|
|
ASSERT_TRUE(ret.isOk());
|
|
|
|
EXPECT_EQ(Status::SUCCESS, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* enable categories. */
|
2019-10-29 07:56:03 +01:00
|
|
|
TEST_P(AtraceHidlTest, disableAllCategories) {
|
2018-09-22 00:44:31 +02:00
|
|
|
auto ret = atrace->disableAllCategories();
|
|
|
|
ASSERT_TRUE(ret.isOk());
|
|
|
|
EXPECT_EQ(Status::SUCCESS, ret);
|
|
|
|
}
|
|
|
|
|
2019-10-29 07:56:03 +01:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
|
|
|
PerInstance, AtraceHidlTest,
|
|
|
|
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IAtraceDevice::descriptor)),
|
|
|
|
android::hardware::PrintInstanceNameToString);
|