Skip to content

Commit

Permalink
Add tests for memory actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hassansalehe committed Jun 13, 2021
1 parent 7b4506c commit 58ea672
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/common/MemoryActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ class MemoryActions {
action.value = val;
action.lineNo = linNo;
action.isWrite = isWrite_;
isEmpty = false;

isEmpty = false;
taskId = action.taskId;
addr = action.addr;
}
}

Expand Down
4 changes: 3 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ link_libraries(${GTEST_LIBRARIES} pthread gtest_main gcov --coverage)
# the GTest and pthread library
add_executable(commonTests Common_Defs_gtest.cc)
add_executable(critalSigTests CriticalSignatures_gtest.cc)
add_executable(memoryActionsTests MemoryActions_gtest.cc)

# Add tests for Ctest
add_test(common_tests, commonTests)
add_test(critica_signatures_tests, critalSigTests)
add_test(critical_signatures_tests, critalSigTests)
add_test(memory_actions_tests, memoryActionsTests)
98 changes: 98 additions & 0 deletions test/MemoryActions_gtest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <gtest/gtest.h>

#include <ostream>
#include <string>

#include "common/MemoryActions.h"

class TestMemoryActionsFixture : public ::testing::Test {
protected:
INTEGER taskId = 123;
ADDRESS addr = 0x033;
VALUE value = 42;
VALUE lineNo = 100;
INTEGER funcId = 6;
std::string funcName = "some_function";
bool isWrite = true;

Action m_act;

virtual void SetUp() {
m_act = Action(taskId, addr, value, lineNo, funcId);
}
};

TEST_F(TestMemoryActionsFixture, CheckConstructorIsEmptyTrue) {
MemoryActions m_actions;
EXPECT_TRUE(m_actions.isEmpty);
}

TEST_F(TestMemoryActionsFixture, CheckConstructorWithActionArgument) {
MemoryActions m_actions(m_act);
EXPECT_FALSE(m_actions.isEmpty);
EXPECT_EQ(taskId, m_actions.taskId);
EXPECT_EQ(addr, m_actions.addr);
}

TEST_F(TestMemoryActionsFixture, CheckStoreActionFunction) {
MemoryActions m_actions(m_act);
EXPECT_FALSE(m_actions.isEmpty);
EXPECT_EQ(taskId, m_actions.taskId);
EXPECT_EQ(addr, m_actions.addr);
}

TEST_F(TestMemoryActionsFixture, CheckStoreActionFunctionWithParamsRead) {
MemoryActions m_actions;
EXPECT_TRUE(m_actions.isEmpty);

// store
uint ut = taskId;
m_actions.storeAction(ut, addr, value, lineNo, funcId, false);

EXPECT_EQ(taskId, m_actions.taskId);
EXPECT_EQ(addr, m_actions.addr);
EXPECT_FALSE(m_actions.isEmpty);

EXPECT_EQ(taskId, m_actions.action.taskId);
EXPECT_EQ(addr, m_actions.action.addr);
EXPECT_EQ(funcId, m_actions.action.funcId);
EXPECT_EQ(value, m_actions.action.value);
EXPECT_EQ(lineNo, m_actions.action.lineNo);
}

TEST_F(TestMemoryActionsFixture, CheckHasWrite) {
// Empty action has no write
MemoryActions m_actions;
EXPECT_FALSE(m_actions.hasWrite());

// Adding read action does not set acction to write
m_actions.storeAction(m_act);
EXPECT_FALSE(m_actions.hasWrite());

// Setting action to write
m_actions.action.isWrite = true;
EXPECT_TRUE(m_actions.hasWrite());

// adding a write action
m_actions.action.isWrite = false;
m_act.isWrite = true;
m_actions.storeAction(m_act);
EXPECT_TRUE(m_actions.hasWrite());
}

TEST_F(TestMemoryActionsFixture, ChecPrintEmptyAction) {
MemoryActions m_actions;
std::ostringstream os;
m_actions.printActions(os);
EXPECT_EQ(0UL, os.str().size());
}

TEST_F(TestMemoryActionsFixture, ChecPrintExistingAction) {
m_act.isWrite = true;
MemoryActions m_actions(m_act);
std::ostringstream os;
m_actions.printActions(os);

std::string expected_message = "123 W 0x33 42 100 6\n";
EXPECT_EQ(expected_message, os.str());
}

0 comments on commit 58ea672

Please sign in to comment.