Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion docs/statistics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ Details About Testcases
type == 'testcase' and derivation_technique == 'equivalence-classes'
type == 'testcase' and derivation_technique == 'fuzz-testing'
type == 'testcase' and derivation_technique == 'error-guessing'
type == 'testcase' and derivation_technique == 'explorative-testing'
type == 'testcase' and derivation_technique == 'explorative-testing'
7 changes: 7 additions & 0 deletions src/health_monitoring_lib/cpp/tests/health_monitor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ using ::testing::_;

class HealthMonitorTest : public ::testing::Test
{
protected:
void SetUp() override
{
RecordProperty("TestType", "requirements-based");
RecordProperty("DerivationTechnique", "requirements-analysis");
}
};

// For first review round, only single test case to show up API
TEST_F(HealthMonitorTest, TestName)
{
RecordProperty("Description", "This test demonstrates the usage of HealthMonitor and DeadlineMonitor APIs. It creates a HealthMonitor with a DeadlineMonitor, retrieves the DeadlineMonitor, and tests starting a deadline.");
auto builder_mon = deadline::DeadlineMonitorBuilder()
.add_deadline(IdentTag("deadline_1"),
TimeRange(std::chrono::milliseconds(100), std::chrono::milliseconds(200)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,47 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#include <memory>
#include <score/lcm/processstatereceiver.hpp>
#include <score/lcm/processstatenotifier.hpp>
#include <gtest/gtest.h>
#include <score/lcm/processstatenotifier.hpp>
#include <score/lcm/processstatereceiver.hpp>
#include <memory>

using namespace testing;
using namespace score::lcm;

using score::lcm::internal::ProcessStateNotifier;
using score::lcm::ProcessStateReceiver;
using score::lcm::internal::ProcessStateNotifier;

class ProcessStateClient_UT : public ::testing::Test {
protected:
void SetUp() override {
class ProcessStateClient_UT : public ::testing::Test
{
protected:
void SetUp() override
{
RecordProperty("TestType", "requirements-based");
RecordProperty("DerivationTechnique", "requirements-analysis");
notifier_ = std::make_unique<ProcessStateNotifier>();
receiver_ = notifier_->constructReceiver();
}
void TearDown() override {
void TearDown() override
{
receiver_.reset();
notifier_.reset();
}
std::unique_ptr<ProcessStateNotifier> notifier_;
std::unique_ptr<IProcessStateReceiver> receiver_;

};

TEST_F(ProcessStateClient_UT, ProcessStateClient_ConstructReceiver_Succeeds) {
TEST_F(ProcessStateClient_UT, ProcessStateClient_ConstructReceiver_Succeeds)
{
RecordProperty("Description", "This test verifies that the ProcessStateNotifier can successfully construct a ProcessStateReceiver instance.");
ASSERT_NE(notifier_, nullptr);
ASSERT_NE(receiver_, nullptr);
}

TEST_F(ProcessStateClient_UT, ProcessStateClient_QueueOneProcess_Succeeds) {
PosixProcess process1{
TEST_F(ProcessStateClient_UT, ProcessStateClient_QueueOneProcess_Succeeds)
{
RecordProperty("Description", "This test verifies that a single PosixProcess can be successfully queued using the ProcessStateNotifier and retrieved using the ProcessStateReceiver.");
PosixProcess process1{
.id = score::lcm::IdentifierHash("Process1"),
.processStateId = score::lcm::ProcessState::kRunning,
.processGroupStateId = score::lcm::IdentifierHash("PGState1"),
Expand All @@ -54,22 +62,25 @@ TEST_F(ProcessStateClient_UT, ProcessStateClient_QueueOneProcess_Succeeds) {

// Retrieve the queued process via the receiver
auto result = receiver_->getNextChangedPosixProcess();
ASSERT_TRUE(result.has_value()); // Result contains Optional value
ASSERT_TRUE(result->has_value()); // Optional contains PosixProcess
ASSERT_TRUE(result.has_value()); // Result contains Optional value
ASSERT_TRUE(result->has_value()); // Optional contains PosixProcess
EXPECT_EQ(result->value().id, process1.id);
EXPECT_EQ(result->value().processStateId, process1.processStateId);
EXPECT_EQ(result->value().processGroupStateId, process1.processGroupStateId);

// Ensure no more processes are queued
auto no_more = receiver_->getNextChangedPosixProcess();
ASSERT_TRUE(no_more.has_value()); // Result contains Optional value
ASSERT_FALSE(no_more->has_value()); // Optional is empty
ASSERT_TRUE(no_more.has_value()); // Result contains Optional value
ASSERT_FALSE(no_more->has_value()); // Optional is empty
}

TEST_F(ProcessStateClient_UT, ProcessStateClient_QueueMaxNumberOfProcesses_Succeeds) {
TEST_F(ProcessStateClient_UT, ProcessStateClient_QueueMaxNumberOfProcesses_Succeeds)
{
RecordProperty("Description", "This test verifies that the ProcessStateNotifier can successfully queue the maximum number of PosixProcess instances defined by the buffer size, and that they can be retrieved using the ProcessStateReceiver.");
// Queue maximum number of processes
for (size_t i = 0; i < static_cast<size_t>(BufferConstants::BUFFER_QUEUE_SIZE); ++i) {
PosixProcess process{
for (size_t i = 0; i < static_cast<size_t>(BufferConstants::BUFFER_QUEUE_SIZE); ++i)
{
PosixProcess process{
.id = score::lcm::IdentifierHash("Process" + std::to_string(i)),
.processStateId = score::lcm::ProcessState::kRunning,
.processGroupStateId = score::lcm::IdentifierHash("PGState" + std::to_string(i)),
Expand All @@ -79,7 +90,8 @@ TEST_F(ProcessStateClient_UT, ProcessStateClient_QueueMaxNumberOfProcesses_Succe
}

// Retrieve and verify all queued processes
for (size_t i = 0; i < static_cast<size_t>(BufferConstants::BUFFER_QUEUE_SIZE); ++i) {
for (size_t i = 0; i < static_cast<size_t>(BufferConstants::BUFFER_QUEUE_SIZE); ++i)
{
auto result = receiver_->getNextChangedPosixProcess();
ASSERT_TRUE(result.has_value());
ASSERT_TRUE(result->has_value());
Expand All @@ -92,16 +104,19 @@ TEST_F(ProcessStateClient_UT, ProcessStateClient_QueueMaxNumberOfProcesses_Succe
ASSERT_FALSE(no_more->has_value());
}

TEST_F(ProcessStateClient_UT, ProcessStateClient_QueueOneProcessTooMany_Fails) {
PosixProcess process1{
TEST_F(ProcessStateClient_UT, ProcessStateClient_QueueOneProcessTooMany_Fails)
{
RecordProperty("Description", "This test verifies that attempting to queue a PosixProcess when the buffer is already at maximum capacity results in a failure, and that no additional processes can be retrieved from the receiver.");
PosixProcess process1{
.id = score::lcm::IdentifierHash("Process1"),
.processStateId = score::lcm::ProcessState::kRunning,
.processGroupStateId = score::lcm::IdentifierHash("PGState1"),
};

// Fill the buffer to capacity
for (size_t i = 0; i < static_cast<size_t>(BufferConstants::BUFFER_QUEUE_SIZE); ++i) {
PosixProcess proc{
for (size_t i = 0; i < static_cast<size_t>(BufferConstants::BUFFER_QUEUE_SIZE); ++i)
{
PosixProcess proc{
.id = score::lcm::IdentifierHash("Process" + std::to_string(i)),
.processStateId = score::lcm::ProcessState::kRunning,
.processGroupStateId = score::lcm::IdentifierHash("PGState" + std::to_string(i)),
Expand Down
36 changes: 31 additions & 5 deletions tests/ut/identifier_hash_UT/identifier_hash_UT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,56 @@ using std::stringstream;

using score::lcm::IdentifierHash;

TEST(IdentifierHashTest, IdentifierHash_with_string_view_created)
class IdentifierHashTest : public ::testing::Test
{
protected:
void SetUp() override
{
RecordProperty("TestType", "requirements-based");
RecordProperty("DerivationTechnique", "requirements-analysis");
}
};

TEST_F(IdentifierHashTest, IdentifierHash_with_string_view_created)
{
RecordProperty("Description",
"This test verifies that an IdentifierHash can be successfully created using a std::string_view, "
"and that its string representation can be retrieved correctly.");
std::string_view idStrView = "ProcessGroup1/Startup";
IdentifierHash identifierHash(idStrView);
stringstream strStream;
strStream << identifierHash;
ASSERT_EQ(strStream.str(), idStrView);
}

TEST(IdentifierHashTest, IdentifierHash_with_string_created)
TEST_F(IdentifierHashTest, IdentifierHash_with_string_created)
{
RecordProperty("Description",
"This test verifies that an IdentifierHash can be successfully created using a std::string, and "
"that its string representation can be retrieved correctly.");
std::string idStr = "ProcessGroup1/Startup";
IdentifierHash identifierHash(idStr);
stringstream strStream;
strStream << identifierHash;
ASSERT_EQ(strStream.str(), idStr);
}

TEST(IdentifierHashTest, IdentifierHash_default_created)
TEST_F(IdentifierHashTest, IdentifierHash_default_created)
{
RecordProperty("Description",
"This test verifies that a default-constructed IdentifierHash can be created, and that its string "
"representation is empty.");
IdentifierHash identifierHash;
stringstream strStream;
strStream << identifierHash;
ASSERT_EQ(strStream.str(), "");
}

TEST(IdentifierHashTest, IdentifierHash_invalid_hash_no_string_representation)
TEST_F(IdentifierHashTest, IdentifierHash_invalid_hash_no_string_representation)
{
RecordProperty("Description",
"This test verifies that if an IdentifierHash is created with a string that is not registered in "
"the registry, its string representation indicates that it is unknown and includes the hash value.");
std::string idStr = "MainFG";
IdentifierHash identifierHash(idStr);

Expand All @@ -60,8 +82,12 @@ TEST(IdentifierHashTest, IdentifierHash_invalid_hash_no_string_representation)
ASSERT_TRUE(strStream.str().find(std::to_string(identifierHash.data())) != std::string::npos);
}

TEST(IdentifierHashTest, IdentifierHash_no_dangling_pointer_after_source_string_dies)
TEST_F(IdentifierHashTest, IdentifierHash_no_dangling_pointer_after_source_string_dies)
{
RecordProperty("Description",
"This test verifies that an IdentifierHash created from a std::string does not have a dangling "
"pointer to the original string after it goes out of scope, and that its string representation can "
"still be retrieved correctly.");
std::unique_ptr<IdentifierHash> hash_ptr;
std::string_view idStrView = "this string will be destroyed";

Expand Down
Loading