Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Critical signature uts #5

Merged
merged 2 commits into from
Jun 13, 2021
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
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)
1 change: 1 addition & 0 deletions test/Common_Defs_gtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ TEST(OperRepresentation, TestConversion) {
ASSERT_EQ("ALLOCA", OperRepresentation(OPERATION::ALLOCA));
ASSERT_EQ("BITCAST", OperRepresentation(OPERATION::BITCAST));
ASSERT_EQ("GETELEMENTPTR", OperRepresentation(OPERATION::GETELEMENTPTR));
ASSERT_EQ("UNKNOWN", OperRepresentation(OPERATION(OPERATION::SHL + OPERATION::MUL)));
}

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());
}