blob: 784d9a56d9f5eb4967c0789b3beb4c3a9547942c [file] [log] [blame]
/*
* Copyright (C) 2019 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 "perfetto/profiling/deobfuscator.h"
#include "test/gtest_and_gmock.h"
namespace perfetto {
namespace profiling {
bool operator==(const ObfuscatedClass& a, const ObfuscatedClass& b);
bool operator==(const ObfuscatedClass& a, const ObfuscatedClass& b) {
return a.deobfuscated_name == b.deobfuscated_name &&
a.deobfuscated_fields == b.deobfuscated_fields &&
a.deobfuscated_methods == b.deobfuscated_methods;
}
namespace {
using ::testing::ElementsAre;
TEST(ProguardParserTest, ReadClass) {
ProguardParser p;
ASSERT_TRUE(p.AddLine(
"android.arch.core.executor.ArchTaskExecutor -> android.arch.a.a.a:"));
ASSERT_THAT(p.ConsumeMapping(),
ElementsAre(std::pair<std::string, ObfuscatedClass>(
"android.arch.a.a.a",
"android.arch.core.executor.ArchTaskExecutor")));
}
TEST(ProguardParserTest, MissingColon) {
ProguardParser p;
ASSERT_FALSE(p.AddLine(
"android.arch.core.executor.ArchTaskExecutor -> android.arch.a.a.a"));
}
TEST(ProguardParserTest, UnexpectedMember) {
ProguardParser p;
ASSERT_FALSE(
p.AddLine(" android.arch.core.executor.TaskExecutor mDelegate -> b"));
}
TEST(ProguardParserTest, Member) {
ProguardParser p;
ASSERT_TRUE(p.AddLine(
"android.arch.core.executor.ArchTaskExecutor -> android.arch.a.a.a:"));
ASSERT_TRUE(
p.AddLine(" android.arch.core.executor.TaskExecutor mDelegate -> b"));
std::map<std::string, std::string> deobfuscated_fields{{"b", "mDelegate"}};
ASSERT_THAT(
p.ConsumeMapping(),
ElementsAre(std::pair<std::string, ObfuscatedClass>(
"android.arch.a.a.a", {"android.arch.core.executor.ArchTaskExecutor",
std::move(deobfuscated_fields),
{}})));
}
TEST(ProguardParserTest, Method) {
ProguardParser p;
ASSERT_TRUE(p.AddLine(
"android.arch.core.executor.ArchTaskExecutor -> android.arch.a.a.a:"));
ASSERT_TRUE(p.AddLine(" 15:15:boolean isMainThread():116:116 -> b"));
std::map<std::string, std::string> deobfuscated_methods{
{"b", "isMainThread"}};
ASSERT_THAT(
p.ConsumeMapping(),
ElementsAre(std::pair<std::string, ObfuscatedClass>(
"android.arch.a.a.a", {"android.arch.core.executor.ArchTaskExecutor",
{},
std::move(deobfuscated_methods)})));
}
TEST(ProguardParserTest, DuplicateClass) {
ProguardParser p;
ASSERT_TRUE(p.AddLine(
"android.arch.core.executor.ArchTaskExecutor -> android.arch.a.a.a:"));
ASSERT_FALSE(p.AddLine(
"android.arch.core.executor.ArchTaskExecutor2 -> android.arch.a.a.a:"));
}
TEST(ProguardParserTest, DuplicateField) {
ProguardParser p;
ASSERT_TRUE(p.AddLine(
"android.arch.core.executor.ArchTaskExecutor -> android.arch.a.a.a:"));
ASSERT_TRUE(
p.AddLine(" android.arch.core.executor.TaskExecutor mDelegate -> b"));
ASSERT_FALSE(
p.AddLine(" android.arch.core.executor.TaskExecutor mDelegate2 -> b"));
}
TEST(ProguardParserTest, DuplicateMethod) {
ProguardParser p;
ASSERT_TRUE(p.AddLine(
"android.arch.core.executor.ArchTaskExecutor -> android.arch.a.a.a:"));
ASSERT_TRUE(p.AddLine(" 15:15:boolean isMainThread():116:116 -> b"));
ASSERT_TRUE(p.AddLine(" 15:15:boolean doSomething(boolean):116:116 -> b"));
}
} // namespace
} // namespace profiling
} // namespace perfetto