Skip to content

Commit

Permalink
Add coverage for test-subr. At 62.9%
Browse files Browse the repository at this point in the history
  • Loading branch information
TricksterGuy committed Feb 4, 2018
1 parent 39c8590 commit 6d63f75
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
19 changes: 8 additions & 11 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,30 @@ file(GLOB SRC_TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
add_executable(
lc3_test_suite
${SRC_TESTS}
../lc3test/XmlTestParser.cpp
)
../lc3test/XmlTestParser.cpp)

target_link_libraries(
lc3_test_suite
lc3
${wxWidgets_LIBRARIES}
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
)
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})

add_dependencies(
lc3_test_suite
lc3_multiply
lc3_udiv
)
lc3_udiv)

add_custom_command(
TARGET lc3_test_suite POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/plugins/instructions/liblc3_multiply.so ${CMAKE_BINARY_DIR}/liblc3_multiply.so
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/plugins/traps/liblc3_udiv.so ${CMAKE_BINARY_DIR}/liblc3_udiv.so
COMMENT "Copying needed plugins for testing"
)
COMMENT "Copying needed plugins for testing")

set_target_properties(lc3_test_suite PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

add_test(NAME lc3_test_suite WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lc3_test_suite)
add_test(NAME lc3_test_suite
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lc3_test_suite --log_level=message)

if(ENABLE_COVERAGE)
set(CMAKE_SKIP_RPATH FALSE)
Expand All @@ -54,6 +52,5 @@ if(ENABLE_COVERAGE)
setup_target_for_coverage(
NAME "lc3_test_coverage"
EXECUTABLE lc3_test_suite -j ${PROCESSOR_COUNT}
DEPENDENCIES lc3_test_suite
)
DEPENDENCIES lc3_test_suite)
endif(ENABLE_COVERAGE)
1 change: 1 addition & 0 deletions tests/lc3_basic_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const unsigned char simplesubr[] = {
};
const unsigned int simplesubr_len = 22;


BOOST_FIXTURE_TEST_CASE(InstructionDecodeTest, LC3BasicTest)
{
std::stringstream file(std::string(reinterpret_cast<char*>(allinstrs), allinstrs_len));
Expand Down
50 changes: 50 additions & 0 deletions tests/lc3_test_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,56 @@ BOOST_FIXTURE_TEST_CASE(OutputTest, LC3TestTest)
BOOST_CHECK_EQUAL(test.executions, 3);
}

BOOST_FIXTURE_TEST_CASE(SubroutineTest, LC3TestTest)
{
const std::string xml = R"(<?xml version="1.0" encoding="UTF-8"?>
<test-suite>
<test-case>
<name>Hello world test</name>
<has-max-executions>1</has-max-executions>
<max-executions>1000000</max-executions>
<input>
<test-subr><name>RETURN7</name><stack>xF000</stack><r5>xCAFE</r5><r7>x8000</r7></test-subr>
</input>
<output>
<test-subr><answer>7</answer></test-subr>
</output>
</test-case>
</test-suite>)";

BOOST_REQUIRE(XmlTestParser().LoadTestSuiteData(suite, xml));

std::stringstream assembly(R"(
.orig x3000
RETURN7
ADD R6, R6, -3
STR R5, R6, 0
STR R7, R6, 1
AND R5, R5, 0
ADD R5, R5, 7
STR R5, R6, 2
LDR R5, R6, 0
LDR R7, R6, 1
ADD R6, R6, 2
RET
.end
)");

lc3_run_test_suite(suite, assembly, 0, 0);

std::stringstream oss;
lc3_write_test_report(oss, suite, "");

BOOST_REQUIRE(suite.passed);
BOOST_REQUIRE_EQUAL(suite.tests.size(), 1);

const lc3_test& test = suite.tests[0];
BOOST_CHECK(test.passed);
BOOST_CHECK(test.has_halted);
BOOST_CHECK(test.has_halted_normally);
BOOST_CHECK_EQUAL(test.executions, 11); // Plus implicit halt at x8000.
}

BOOST_FIXTURE_TEST_CASE(StrictExecutionTest, LC3TestTest)
{
const std::string xml = R"(<?xml version="1.0" encoding="UTF-8"?>
Expand Down

0 comments on commit 6d63f75

Please sign in to comment.