Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,33 @@

#include "score/mw/launch_manager/process_group_manager/details/os_handler.hpp"

namespace score {
namespace score
{

namespace lcm {
namespace lcm
{

namespace internal {
namespace internal
{

void OsHandler::run(void) {
while (is_running_) {
void OsHandler::run(void)
{
while (is_running_)
{
int32_t wait_status = 0;
auto result = sys_wait_.wait(&wait_status);

if (result.has_value() && result.value() > 0) {
if (-1 == safe_process_map_.findTerminated(result.value(), wait_status)) {
LM_LOG_ERROR() << "No more resources available to track process with PID " << result.value() << "(SafeProcessMap capacity exceeded).";
if (result.has_value() && result.value() > 0)
{
if (score::lcm::internal::SafeProcessMap::SafeProcessMapReturnType::kInsertionError ==
safe_process_map_.findTerminated(result.value(), wait_status))
{
LM_LOG_ERROR() << "No more resources available to track process with PID " << result.value()
<< "(SafeProcessMap capacity exceeded).";
}
} else {
}
else
{
// This process has no children to wait for at present,
// or the wait was interrupted by a signal.
// Wait a while to stop this thread from hogging cpu time
Expand All @@ -37,8 +48,8 @@ void OsHandler::run(void) {
}
}

} // namespace lcm

} // namespace internal

} // namespace lcm

} // namespace score
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

#include "score/mw/launch_manager/process_group_manager/details/os_handler.hpp"

#include "score/mw/launch_manager/process_group_manager/details/safe_process_map.hpp"
#include "score/mw/launch_manager/common/constants.hpp"
#include "score/mw/launch_manager/process_group_manager/details/safe_process_map.hpp"
#include "score/os/mocklib/sys_wait_mock.h"

using namespace testing;
Expand All @@ -32,13 +32,13 @@ namespace

class MockTerminationCallback : public ITerminationCallback
{
public:
public:
MOCK_METHOD(void, terminated, (int32_t process_status), (override));
};

class OsHandlerTest : public ::testing::Test
{
protected:
protected:
void SetUp() override
{
RecordProperty("TestType", "interface-test");
Expand Down Expand Up @@ -81,8 +81,7 @@ TEST_F(OsHandlerTest, WaitReturnsProcessId_FindTerminatedIsCalled)

TEST_F(OsHandlerTest, WaitReturnsError_OsHandlerSleepsAndDoesNotCallFindTerminated)
{
RecordProperty("Description",
"When sys_wait returns an error, OsHandler sleeps and does not call findTerminated.");
RecordProperty("Description", "When sys_wait returns an error, OsHandler sleeps and does not call findTerminated.");

// given — insert a callback that should NOT be invoked
StrictMock<MockTerminationCallback> callback;
Expand All @@ -101,8 +100,7 @@ TEST_F(OsHandlerTest, WaitReturnsError_OsHandlerSleepsAndDoesNotCallFindTerminat

TEST_F(OsHandlerTest, WaitReturnsZeroPid_OsHandlerSleepsAndDoesNotCallFindTerminated)
{
RecordProperty("Description",
"When sys_wait returns pid 0, OsHandler sleeps and does not call findTerminated.");
RecordProperty("Description", "When sys_wait returns pid 0, OsHandler sleeps and does not call findTerminated.");

// given
StrictMock<MockTerminationCallback> callback;
Expand Down Expand Up @@ -156,7 +154,8 @@ TEST_F(OsHandlerTest, WaitReturnsProcessIdBeforeRegistration_LaterRegistrationRe
// callback immediately with the saved exit status instead of creating a new live entry.
StrictMock<MockTerminationCallback> callback;
EXPECT_CALL(callback, terminated(99)).Times(1);
EXPECT_EQ(process_map_.insertIfNotTerminated(4000, &callback), 1);
EXPECT_EQ(process_map_.insertIfNotTerminated(4000, &callback),
score::lcm::internal::SafeProcessMap::SafeProcessMapReturnType::kYield);

sut_.reset();
}
Expand All @@ -171,7 +170,8 @@ TEST_F(OsHandlerTest, WaitReturnsUnknownPidWhenMapIsFull_OutOfResourcesPathDoesN
StrictMock<MockTerminationCallback> callbacks[kCapacity];
for (uint32_t i = 0; i < kCapacity; ++i)
{
ASSERT_EQ(process_map_.insertIfNotTerminated(static_cast<int32_t>(i + 1U), &callbacks[i]), 0);
ASSERT_EQ(process_map_.insertIfNotTerminated(static_cast<int32_t>(i + 1U), &callbacks[i]),
score::lcm::internal::SafeProcessMap::SafeProcessMapReturnType::kOk);
}

EXPECT_CALL(*sys_wait_mock_, wait(_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

#include "process_info_node.hpp"
#include "graph.hpp"
#include "score/mw/launch_manager/process_group_manager/process_group_manager.hpp"
#include "score/mw/launch_manager/common/log.hpp"
#include "score/mw/launch_manager/osal/ipc_comms.hpp"
#include "score/mw/launch_manager/process_group_manager/process_group_manager.hpp"

namespace score
{
Expand Down Expand Up @@ -407,10 +407,11 @@ void ProcessInfoNode::handleProcessStarted(uint32_t execution_error_code)
{
switch (graph_->getProcessGroupManager()->getProcessMap()->insertIfNotTerminated(pid_, this))
{
case 0: // Normal case, entry was put in the map, process still running
case score::lcm::internal::SafeProcessMap::SafeProcessMapReturnType::kOk: // Normal case, entry was put in
// the map, process still running
handleProcessStillStarting(execution_error_code);
break;
case 1: // Process has already exited
case score::lcm::internal::SafeProcessMap::SafeProcessMapReturnType::kYield: // Process has already exited
handleProcessAlreadyTerminated(execution_error_code);
break;
default: // Error case when pn == -1
Expand Down
Loading
Loading