Skip to content

Commit

Permalink
[CMK-2379] - openhardware monitor starts only once
Browse files Browse the repository at this point in the history
- of found as running app, then reused
- simplified unit testing
- added disabled simulation of memory overflow

Change-Id: I84c26abb0b873412d3651dbbcd38e1434ebcb828
  • Loading branch information
s-kipnis committed Aug 5, 2019
1 parent c7effb3 commit 55b1d27
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
31 changes: 30 additions & 1 deletion agents/wnx/src/engine/service_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,16 @@ bool ServiceProcessor::conditionallyStartOhm() noexcept {

ohm_engine.resetError();
if (running) ohm_process_.start(ohm_exe.wstring());
} else
} else {
if (!ohm_process_.running()) {
XLOG::l.i("OHM is not running by Agent");
if (wtools::FindProcess(cma::provider::ohm::kExeModuleWide)) {
XLOG::l.i("OHM is found: REUSE running OHM");
return true;
}
}
ohm_process_.start(ohm_exe.wstring());
}
return true;
}

Expand Down Expand Up @@ -411,6 +419,27 @@ void ServiceProcessor::mainThread(world::ExternalPort* ex_port) noexcept {
auto mailslot_name = cma::IsService() ? cma::cfg::kServiceMailSlot
: cma::cfg::kTestingMailSlot;

#if 0
// ARtificial memory allocator in thread
std::vector<std::string> z;

auto alloca = std::thread([&z]() {
for (;;) {
std::string s =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
s = s + s + s + s + s + s + s + s + s + s + s + s + s + s + s + s +
s + s + s + s + s + s + s + s + s + s + s + s;
s = s + s + s + s + s + s + s + s + s + s + s + s + s + s + s + s +
s + s + s + s + s + s + s + s + s + s + s + s;
s = s + s + s + s + s + s + s + s + s + s + s + s + s + s + s + s +
s + s + s + s + s + s + s + s + s + s + s + s;
s = s + s + s + s + s + s + s + s + s + s + s + s + s + s + s + s +
s + s + s + s + s + s + s + s + s + s + s + s;
z.push_back(s);
::Sleep(100);
}
});
#endif
cma::MailSlot mailbox(mailslot_name, 0);
using namespace cma::carrier;
internal_port_ = BuildPortName(kCarrierMailslotName, mailbox.GetName());
Expand Down
3 changes: 3 additions & 0 deletions agents/wnx/src/engine/service_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,9 @@ class ServiceProcessor : public wtools::BaseServiceProcessor {
#if defined(GTEST_INCLUDE_GTEST_GTEST_H_)
friend class ServiceControllerTest;
FRIEND_TEST(ServiceControllerTest, StartStopExe);

friend class SectionProviderOhm;
FRIEND_TEST(SectionProviderOhm, ConditionallyStartOhm);
#endif
};

Expand Down
13 changes: 13 additions & 0 deletions agents/wnx/watest/test-ohm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,17 @@ TEST(SectionProviderOhm, StartStop) {
EXPECT_EQ(oprocess.thread_handle_, INVALID_HANDLE_VALUE);
EXPECT_TRUE(ret);
}

TEST(SectionProviderOhm, ConditionallyStartOhm) {
ServiceProcessor sp;
wtools::KillProcess(cma::provider::ohm::kExeModuleWide, 1);
auto found = wtools::FindProcess(cma::provider::ohm::kExeModuleWide);
ASSERT_EQ(found, 0);
auto ret = sp.conditionallyStartOhm();
found = wtools::FindProcess(cma::provider::ohm::kExeModuleWide);
ASSERT_EQ(found, 1);
ret = sp.conditionallyStartOhm();
found = wtools::FindProcess(cma::provider::ohm::kExeModuleWide);
ASSERT_EQ(found, 1);
}
} // namespace cma::srv

0 comments on commit 55b1d27

Please sign in to comment.