summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-03-14 02:10:14 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-03-14 02:10:14 +0000
commitfb06409f4b3ceef5e30f9128f3c301bebee956cb (patch)
tree864a54e80927d7ad4c409c9d84616171f619c441
parent115d065bf166350ecf2a753c5a01a5b766634ad7 (diff)
parentf31988a3ec6ccdce08fb95eeb9045348ad968339 (diff)
downloadextras-fb06409f4b3ceef5e30f9128f3c301bebee956cb.tar.gz
Snap for 6294963 from f31988a3ec6ccdce08fb95eeb9045348ad968339 to rvc-release
Change-Id: I64901f057a821a3d36575f44a17de437965c3001
-rw-r--r--libperfmgr/HintManager.cc10
-rw-r--r--libperfmgr/NodeLooperThread.cc5
-rw-r--r--libperfmgr/include/perfmgr/HintManager.h5
-rw-r--r--libperfmgr/include/perfmgr/NodeLooperThread.h4
-rw-r--r--libperfmgr/tests/HintManagerTest.cc11
-rw-r--r--libperfmgr/tests/NodeLooperThreadTest.cc5
6 files changed, 34 insertions, 6 deletions
diff --git a/libperfmgr/HintManager.cc b/libperfmgr/HintManager.cc
index dd103533..13060b01 100644
--- a/libperfmgr/HintManager.cc
+++ b/libperfmgr/HintManager.cc
@@ -106,8 +106,12 @@ void HintManager::DumpToFd(int fd) {
fsync(fd);
}
+bool HintManager::Start() {
+ return nm_->Start();
+}
+
std::unique_ptr<HintManager> HintManager::GetFromJSON(
- const std::string& config_path) {
+ const std::string& config_path, bool start) {
std::string json_doc;
if (!android::base::ReadFileToString(config_path, &json_doc)) {
@@ -133,6 +137,10 @@ std::unique_ptr<HintManager> HintManager::GetFromJSON(
std::make_unique<HintManager>(std::move(nm), actions);
LOG(INFO) << "Initialized HintManager from JSON config: " << config_path;
+
+ if (start) {
+ hm->Start();
+ }
return hm;
}
diff --git a/libperfmgr/NodeLooperThread.cc b/libperfmgr/NodeLooperThread.cc
index eb5c9b43..9bb10c0b 100644
--- a/libperfmgr/NodeLooperThread.cc
+++ b/libperfmgr/NodeLooperThread.cc
@@ -120,13 +120,14 @@ bool NodeLooperThread::threadLoop() {
return true;
}
-void NodeLooperThread::onFirstRef() {
+bool NodeLooperThread::Start() {
auto ret = this->run("NodeLooperThread", PRIORITY_HIGHEST);
if (ret != NO_ERROR) {
- LOG(ERROR) << "NodeLooperThread start fail";
+ LOG(ERROR) << "NodeLooperThread start failed: " << ret;
} else {
LOG(INFO) << "NodeLooperThread started";
}
+ return ret == NO_ERROR;
}
void NodeLooperThread::Stop() {
diff --git a/libperfmgr/include/perfmgr/HintManager.h b/libperfmgr/include/perfmgr/HintManager.h
index 487e5bd9..bfb96fde 100644
--- a/libperfmgr/include/perfmgr/HintManager.h
+++ b/libperfmgr/include/perfmgr/HintManager.h
@@ -65,7 +65,7 @@ class HintManager {
// Static method to construct HintManager from the JSON config file.
static std::unique_ptr<HintManager> GetFromJSON(
- const std::string& config_path);
+ const std::string& config_path, bool start = true);
// Return available hints managed by HintManager
std::vector<std::string> GetHints() const;
@@ -73,6 +73,9 @@ class HintManager {
// Dump internal status to fd
void DumpToFd(int fd);
+ // Start thread loop
+ bool Start();
+
protected:
static std::vector<std::unique_ptr<Node>> ParseNodes(
const std::string& json_doc);
diff --git a/libperfmgr/include/perfmgr/NodeLooperThread.h b/libperfmgr/include/perfmgr/NodeLooperThread.h
index b04d2a40..981e64f2 100644
--- a/libperfmgr/include/perfmgr/NodeLooperThread.h
+++ b/libperfmgr/include/perfmgr/NodeLooperThread.h
@@ -76,11 +76,13 @@ class NodeLooperThread : public ::android::Thread {
// Dump all nodes to fd
void DumpToFd(int fd);
+ // Return true when successfully started the looper thread
+ bool Start();
+
private:
NodeLooperThread(NodeLooperThread const&) = delete;
void operator=(NodeLooperThread const&) = delete;
bool threadLoop() override;
- void onFirstRef() override;
static constexpr auto kMaxUpdatePeriod = std::chrono::milliseconds::max();
diff --git a/libperfmgr/tests/HintManagerTest.cc b/libperfmgr/tests/HintManagerTest.cc
index 4aa6469c..3323a27b 100644
--- a/libperfmgr/tests/HintManagerTest.cc
+++ b/libperfmgr/tests/HintManagerTest.cc
@@ -204,6 +204,7 @@ static inline void _VerifyPathValue(const std::string& path,
// Test GetHints
TEST_F(HintManagerTest, GetHintsTest) {
HintManager hm(nm_, actions_);
+ EXPECT_TRUE(hm.Start());
std::vector<std::string> hints = hm.GetHints();
EXPECT_TRUE(hm.IsRunning());
EXPECT_EQ(2u, hints.size());
@@ -214,6 +215,7 @@ TEST_F(HintManagerTest, GetHintsTest) {
// Test initialization of default values
TEST_F(HintManagerTest, HintInitDefaultTest) {
HintManager hm(nm_, actions_);
+ EXPECT_TRUE(hm.Start());
std::this_thread::sleep_for(kSLEEP_TOLERANCE_MS);
EXPECT_TRUE(hm.IsRunning());
_VerifyPathValue(files_[0]->path, "");
@@ -232,6 +234,7 @@ TEST_F(HintManagerTest, HintSupportedTest) {
// Test hint/cancel/expire with dummy actions
TEST_F(HintManagerTest, HintTest) {
HintManager hm(nm_, actions_);
+ EXPECT_TRUE(hm.Start());
EXPECT_TRUE(hm.IsRunning());
EXPECT_TRUE(hm.DoHint("INTERACTION"));
std::this_thread::sleep_for(kSLEEP_TOLERANCE_MS);
@@ -494,8 +497,14 @@ TEST_F(HintManagerTest, GetFromJSONTest) {
TemporaryFile json_file;
ASSERT_TRUE(android::base::WriteStringToFile(json_doc_, json_file.path))
<< strerror(errno);
- std::unique_ptr<HintManager> hm = HintManager::GetFromJSON(json_file.path);
+ std::unique_ptr<HintManager> hm = HintManager::GetFromJSON(json_file.path, false);
EXPECT_NE(nullptr, hm.get());
+ EXPECT_FALSE(hm->IsRunning());
+ EXPECT_TRUE(hm->Start());
+ EXPECT_TRUE(hm->IsRunning());
+ hm = HintManager::GetFromJSON(json_file.path);
+ EXPECT_NE(nullptr, hm.get());
+ EXPECT_TRUE(hm->IsRunning());
std::this_thread::sleep_for(kSLEEP_TOLERANCE_MS);
EXPECT_TRUE(hm->IsRunning());
// Initial default value on Node0
diff --git a/libperfmgr/tests/NodeLooperThreadTest.cc b/libperfmgr/tests/NodeLooperThreadTest.cc
index fd634d89..5683d117 100644
--- a/libperfmgr/tests/NodeLooperThreadTest.cc
+++ b/libperfmgr/tests/NodeLooperThreadTest.cc
@@ -64,6 +64,7 @@ static inline void _VerifyPathValue(const std::string& path,
// Test default value init
TEST_F(NodeLooperThreadTest, InitRunTest) {
sp<NodeLooperThread> th = new NodeLooperThread(std::move(nodes_));
+ EXPECT_TRUE(th->Start());
std::this_thread::sleep_for(kSLEEP_TOLERANCE_MS);
EXPECT_TRUE(th->isRunning());
_VerifyPathValue(files_[0]->path, "");
@@ -75,6 +76,7 @@ TEST_F(NodeLooperThreadTest, InitRunTest) {
// Test add request
TEST_F(NodeLooperThreadTest, AddRequest) {
sp<NodeLooperThread> th = new NodeLooperThread(std::move(nodes_));
+ EXPECT_TRUE(th->Start());
EXPECT_TRUE(th->isRunning());
// Dummy LAUNCH boost actions:
// Node0, value0, 200ms
@@ -97,6 +99,7 @@ TEST_F(NodeLooperThreadTest, AddRequest) {
// Test request to override expire time
TEST_F(NodeLooperThreadTest, AddRequestOverride) {
sp<NodeLooperThread> th = new NodeLooperThread(std::move(nodes_));
+ EXPECT_TRUE(th->Start());
EXPECT_TRUE(th->isRunning());
// Dummy LAUNCH boost actions:
// Node0, value0, 200ms
@@ -128,6 +131,7 @@ TEST_F(NodeLooperThreadTest, AddRequestOverride) {
// Test cancel request
TEST_F(NodeLooperThreadTest, CancelRequest) {
sp<NodeLooperThread> th = new NodeLooperThread(std::move(nodes_));
+ EXPECT_TRUE(th->Start());
EXPECT_TRUE(th->isRunning());
// Dummy LAUNCH boost actions:
// Node0, value0, forever
@@ -148,6 +152,7 @@ TEST_F(NodeLooperThreadTest, CancelRequest) {
// Test multiple request
TEST_F(NodeLooperThreadTest, MultipleRequest) {
sp<NodeLooperThread> th = new NodeLooperThread(std::move(nodes_));
+ EXPECT_TRUE(th->Start());
EXPECT_TRUE(th->isRunning());
// Dummy LAUNCH boost actions:
// Node0, value1, 800ms