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

stf_lib CTest regression #37

Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/ubuntu-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ jobs:
- name: Build
working-directory: ${{runner.workspace}}/build
run: cmake --build . --config $BUILD_TYPE

- name: Regress
working-directory: ${{runner.workspace}}/build
run: cmake --build . --config $BUILD_TYPE --target regress
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ add_subdirectory(lib)
if(BUILD_STF_PYTHON_LIB)
add_subdirectory(stfpy)
endif()

enable_testing()
add_subdirectory (tests)
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,16 @@ stf_writer << stf::InstOpcode32Record(0xfee59ce3);

```

## Unit Tests for STF_LIB

A regression target `regress` is available for unit testing STF_LIB. These tests are based on CTest and can be run using the following commands:

```sh
mkdir -p release/
cd release/
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j32 regress
cd ..
```

This setup provides a stub of CTest-based unit tests to ensure the functionality and reliability of the library. Please note that these tests do not yet cover the STF_LIB extensively and are currently just a stub.
24 changes: 24 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.17)
project(stf_tests)

include_directories(${PROJECT_SOURCE_DIR}/..)
include(CTest)

include(ProcessorCount)
ProcessorCount(NUM_CORES)

if (NOT NUM_CORES EQUAL 0)
set(CTEST_BUILD_FLAGS -j${NUM_CORES})
set(ctest_test_args "--parallel ${NUM_CORES}")
endif()

message(STATUS "Found " ${NUM_CORES} " cores in machine (for ctest)")

add_subdirectory(stf_writer_test)

add_custom_target(regress)
add_dependencies(regress stf stf_writer_test)

add_custom_command(TARGET regress POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Running tests..."
COMMAND ${CMAKE_CTEST_COMMAND} ${ctest_test_args})
54 changes: 54 additions & 0 deletions tests/stf_writer_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
cmake_minimum_required(VERSION 3.17)
project(stf_writer_test)

set(DISABLE_STF_DOXYGEN 1)
set(NO_STF_LTO 1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

include_directories(
${PROJECT_SOURCE_DIR}/../..
)

add_compile_options(
-g
-Wall
-Wno-parentheses
-MMD
-D_FILE_OFFSET_BITS=64
-D_LARGEFILE_SOURCE
-D_GNU_SOURCE
-D__STDC_FORMAT_MACROS
-Werror
-Wdeprecated
-Wextra
-Winline
-Winit-self
-Wno-unused-function
-Wuninitialized
-Wno-sequence-point
-Wno-inline
-Wno-unknown-pragmas
-Woverloaded-virtual
-Wno-unused-parameter
-Wno-missing-field-initializers
)
StanSofomoDev marked this conversation as resolved.
Show resolved Hide resolved

add_compile_options($<$<CONFIG:Release>:-Ofast>)
StanSofomoDev marked this conversation as resolved.
Show resolved Hide resolved
add_link_options($<$<CONFIG:Release>:-flto>)

set(SOURCES
main.cpp
)

add_executable(stf_writer_test ${SOURCES})
add_dependencies(stf_writer_test stf)

add_test(NAME stf_writer_basic_test
COMMAND bash -c "${PROJECT_BINARY_DIR}/stf_writer_test && \
diff ${PROJECT_BINARY_DIR}/stf_write_test.zstf \
${PROJECT_SOURCE_DIR}/golden/stf_write_test.zstf")

target_link_directories(stf_writer_test PRIVATE ${PROJECT_SOURCE_DIR}/../../stf_lib/release/lib)
target_link_libraries(stf_writer_test PRIVATE ${STF_LINK_LIBS})
Binary file added tests/stf_writer_test/golden/stf_write_test.zstf
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/stf_writer_test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "stf-inc/stf_writer.hpp"
#include "stf-inc/stf_record_types.hpp"

int main() {
uint64_t pc = 0x1000;

stf::STFWriter stf_writer;

stf_writer.open("stf_write_test.zstf");
stf_writer.addTraceInfo(stf::TraceInfoRecord(stf::STF_GEN::STF_GEN_DROMAJO,
1, 2, 0, "Trace from Dromajo"));
stf_writer.setISA(stf::ISA::RISCV);
stf_writer.setHeaderIEM(stf::INST_IEM::STF_INST_IEM_RV64);
stf_writer.setTraceFeature(stf::TRACE_FEATURES::STF_CONTAIN_RV64);
stf_writer.setTraceFeature(stf::TRACE_FEATURES::STF_CONTAIN_PHYSICAL_ADDRESS);
stf_writer.setHeaderPC(pc);
stf_writer.finalizeHeader();

stf_writer << stf::InstOpcode32Record(0x00b60733);

stf_writer.close();
return 0;
}
Loading