Skip to content

Commit 33d9ecb

Browse files
authored
Merge pull request #80 from cphurley82/fix-reading-across-page-boundary
Fix reading across page boundary
2 parents 4c72952 + 0f73336 commit 33d9ecb

File tree

11 files changed

+221
-3
lines changed

11 files changed

+221
-3
lines changed

.github/workflows/ci-compliance.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ jobs:
3131
- name: Install dependencies
3232
run: |
3333
sudo apt-get update
34-
sudo apt-get install -y g++ python3-pip cmake
35-
pip3 install conan
34+
sudo apt-get install -y g++ python3-pip cmake ninja-build
35+
pip3 install conan --break-system-packages
3636
cmake --version
3737
3838
- name: Configure
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI Unit Tests
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.cpp'
7+
- '**.h'
8+
- '**CMakeLists.txt'
9+
- '.github/workflows/**'
10+
- 'conanfile.py'
11+
pull_request:
12+
paths:
13+
- '**.cpp'
14+
- '**.h'
15+
- '**CMakeLists.txt'
16+
- '.github/workflows/**'
17+
- 'conanfile.py'
18+
19+
jobs:
20+
unit-tests:
21+
name: unit-tests (C++20)
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Cache Conan
27+
uses: actions/cache@v4
28+
with:
29+
path: ~/.conan
30+
key: conan-${{ runner.os }}-unit-cpp20-${{ hashFiles('conanfile.txt') }}
31+
32+
- name: Update submodules
33+
run: git submodule update --init --recursive
34+
35+
- name: Install dependencies
36+
run: |
37+
sudo apt-get update
38+
sudo apt-get install -y g++ python3-pip cmake ninja-build
39+
pip3 install conan --break-system-packages
40+
cmake --version
41+
42+
- name: Configure
43+
run: >
44+
cmake --preset Debug -B build
45+
-DBUILD_TESTING=ON
46+
-DCMAKE_CXX_STANDARD=20
47+
48+
- name: Build
49+
run: cmake --build build -j
50+
51+
- name: Run unit tests
52+
run: ctest --output-on-failure
53+
working-directory: build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/build/
77
/.cproject
88
/.venv
9+
/conan/

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ project(scc VERSION 2025.09 LANGUAGES CXX C)
66

77
option(USE_CWR_SYSTEMC "Use Synopsys Virtualizer SystemC" OFF)
88
option(USE_NCSC_SYSTEMC "Cadence Xcelium SystemC" OFF)
9+
option(BUILD_TESTING "Enable building tests" OFF)
910
option(BUILD_SCC_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" OFF)
1011
option(FULL_TRACE_TYPE_LIST "Test for extended set of templated datatypes" OFF)
1112
#Note: this needs to match the SystemC kernel build options
@@ -114,6 +115,10 @@ include(CheckSymbolExists)
114115
# Check for function getenv()
115116
check_symbol_exists(getenv "stdlib.h" HAVE_GETENV)
116117

118+
if(BUILD_TESTING)
119+
include(CTest)
120+
endif()
121+
117122
if(NOT TARGET lz4::lz4)
118123
message(STATUS "${PROJECT_NAME}: using built-in version of lz4")
119124
add_subdirectory(third_party/lz4-1.9.4)
@@ -134,6 +139,10 @@ if(SystemC_FOUND)
134139
endif()
135140
endif()
136141

142+
if(BUILD_TESTING)
143+
add_subdirectory(tests)
144+
endif()
145+
137146
# Define the scc library
138147
add_library(scc INTERFACE)
139148
add_library(scc::scc ALIAS scc)

Dockerfile.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM ubuntu:24.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update && \
6+
apt-get install -y --no-install-recommends \
7+
build-essential \
8+
cmake \
9+
ninja-build \
10+
git \
11+
python3 \
12+
python3-pip \
13+
ca-certificates && \
14+
pip3 install "conan" && \
15+
rm -rf /var/lib/apt/lists/*
16+
17+
WORKDIR /work

TESTING.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Running Tests
2+
3+
This repository has a GoogleTest-based suite (see `tests/`). The tests target the CMake option `BUILD_TESTING=ON` and require the same dependencies as the main build plus GoogleTest (fetched automatically via `FetchContent`).
4+
5+
## Prerequisites
6+
7+
- CMake ≥ 3.20
8+
- A C++ compiler (GCC/Clang) with C++17 or later
9+
- Ninja build system
10+
- Python 3 with `conan` installed. A virtual environment is recommended:
11+
12+
```bash
13+
python3 -m venv .venv
14+
source .venv/bin/activate
15+
pip install conan
16+
```
17+
18+
If Conan cannot supply SystemC/CCI on your host, use the Docker flow below or point CMake at a local SystemC install via `SYSTEMC_HOME`.
19+
20+
## Configure and Build
21+
22+
```bash
23+
cmake --preset Debug -B build -DBUILD_TESTING=ON -DCMAKE_CXX_STANDARD=20
24+
cmake --build build -j
25+
```
26+
27+
## Run Tests
28+
29+
```bash
30+
cd build
31+
32+
# unit tests
33+
ctest --output-on-failure
34+
35+
# transaction recording example binary
36+
./examples/transaction_recording/transaction_recording
37+
```
38+
39+
## Run Tests in Docker (Linux toolchain)
40+
41+
If your host setup cannot fetch SystemC via Conan, use the provided Dockerfile:
42+
43+
```bash
44+
# from repo root
45+
docker build -f Dockerfile.test -t scc-tests .
46+
docker run --rm -v "$PWD":/work -w /work scc-tests /bin/bash -lc "\
47+
cmake --preset Debug -B build -DBUILD_TESTING=ON -DCMAKE_CXX_STANDARD=20 && \
48+
cmake --build build -j && \
49+
cd build && ctest --output-on-failure && \
50+
./examples/transaction_recording/transaction_recording"
51+
```
52+
53+
## CI
54+
55+
### Unit Tests
56+
Tests run in `.github/workflows/ci-unit-tests.yml`, which configures with `-DBUILD_TESTING=ON`, builds, and runs `ctest` with C++20.
57+
58+
### C++ Standards Compliance
59+
The repository is tested for compliance with multiple C++ standards in `.github/workflows/ci-compliance.yml`. This workflow:
60+
- Tests against C++11, C++14, C++17, and C++20
61+
- Builds the project with each standard
62+
- Runs the `transaction_recording` example to verify basic functionality
63+
64+
To test a specific C++ standard locally:
65+
66+
```bash
67+
cmake --preset Debug -B build -DCMAKE_CXX_STANDARD=<11|14|17|20>
68+
cmake --build build -j
69+
./build/examples/transaction_recording/transaction_recording
70+
```

conanfile.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ def requirements(self):
3939
self.requires("systemc/2.3.4")
4040
else:
4141
self.requires("systemc/3.0.1")
42+
if cppstd == "11":
43+
self.requires("gtest/1.10.0")
44+
else:
45+
self.requires("gtest/1.14.0")
4246
else:
4347
self.requires("systemc/2.3.4")
48+
self.requires("gtest/1.14.0")
4449
self.requires("spdlog/1.16.0")
4550
self.requires("boost/1.89.0")
4651
self.requires("lz4/1.10.0")

src/components/scc/memory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ int memory<SIZE, BUSWIDTH>::handle_operation(tlm::tlm_generic_payload& trans, sc
251251
auto first_part = mem.page_size - offs;
252252
std::copy(p.data() + offs, p.data() + offs + first_part, ptr);
253253
const auto& p2 = mem((adr / mem.page_size) + 1);
254-
std::copy(p2.data(), p2.data() + len, ptr + first_part);
254+
auto second_part = len - first_part;
255+
std::copy(p2.data(), p2.data() + second_part, ptr + first_part);
255256
} else {
256257
std::copy(p.data() + offs, p.data() + offs + len, ptr);
257258
}

tests/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
find_package(GTest REQUIRED)
2+
3+
add_executable(memory_boundary_test
4+
memory_boundary_test.cpp
5+
gtest_sc_main.cpp
6+
)
7+
8+
target_link_libraries(memory_boundary_test
9+
PRIVATE
10+
GTest::gtest
11+
scc::scc
12+
SystemC::systemc
13+
)
14+
target_compile_definitions(memory_boundary_test PRIVATE SC_DISABLE_API_VERSION_CHECK)
15+
16+
add_test(NAME memory_boundary_test COMMAND memory_boundary_test)

tests/gtest_sc_main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <gtest/gtest.h>
2+
#include <systemc>
3+
4+
int sc_main(int argc, char* argv[]) {
5+
::testing::InitGoogleTest(&argc, argv);
6+
return RUN_ALL_TESTS();
7+
}

0 commit comments

Comments
 (0)