diff --git a/.envrc b/.envrc index 488f293..4460a8b 100644 --- a/.envrc +++ b/.envrc @@ -1,4 +1,8 @@ -module load ./Modulefile +module load tools/utilities +module load tools/cmake/3.28 +module load tools/clang/14.0 +module load tools/vscode + distro=`/bin/lsb_release -i -s` if [ $distro == "CentOS" ]; then . /opt/rh/devtoolset-8/enable diff --git a/.gitignore b/.gitignore index ffab976..6bdbe0f 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,6 @@ /.venv/ /.cache /CMakeUserPresets.json +/*.scview +/*.log +/config \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 1ddda03..a836f0d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "scc"] - path = scc - url = https://github.com/Minres/SystemC-Components.git [submodule "cmake-conan"] path = cmake-conan url = https://github.com/conan-io/cmake-conan.git diff --git a/.launch/.gitignore b/.launch/.gitignore new file mode 100644 index 0000000..a2be07b --- /dev/null +++ b/.launch/.gitignore @@ -0,0 +1 @@ +/cxs_tlm single-packet.launch diff --git a/.launch/ace_pin_level.launch b/.launch/ace_pin_level.launch new file mode 100644 index 0000000..979107a --- /dev/null +++ b/.launch/ace_pin_level.launch @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/ahb_pin_level ahb_delayed_read_write.launch b/.launch/ahb_pin_level ahb_delayed_read_write.launch new file mode 100644 index 0000000..a53fcee --- /dev/null +++ b/.launch/ahb_pin_level ahb_delayed_read_write.launch @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/ahb_pin_level ahb_narrow_read_write.launch b/.launch/ahb_pin_level ahb_narrow_read_write.launch new file mode 100644 index 0000000..89a8e15 --- /dev/null +++ b/.launch/ahb_pin_level ahb_narrow_read_write.launch @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/ahb_pin_level ahb_read_write.launch b/.launch/ahb_pin_level ahb_read_write.launch new file mode 100644 index 0000000..3d4c9d6 --- /dev/null +++ b/.launch/ahb_pin_level ahb_read_write.launch @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/apb_pin_level apb_narrow_read_write.launch b/.launch/apb_pin_level apb_narrow_read_write.launch new file mode 100644 index 0000000..d125e6e --- /dev/null +++ b/.launch/apb_pin_level apb_narrow_read_write.launch @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/apb_pin_level.launch b/.launch/apb_pin_level.launch new file mode 100644 index 0000000..af0bb0f --- /dev/null +++ b/.launch/apb_pin_level.launch @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/axi4_pin_level axi4_narrow_burst.launch b/.launch/axi4_pin_level axi4_narrow_burst.launch new file mode 100644 index 0000000..cccfb97 --- /dev/null +++ b/.launch/axi4_pin_level axi4_narrow_burst.launch @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/axi4_pin_level.launch b/.launch/axi4_pin_level.launch new file mode 100644 index 0000000..833d933 --- /dev/null +++ b/.launch/axi4_pin_level.launch @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/configurer.launch b/.launch/configurer.launch new file mode 100644 index 0000000..96b0a61 --- /dev/null +++ b/.launch/configurer.launch @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/cxs_tlm.launch b/.launch/cxs_tlm.launch new file mode 100644 index 0000000..73588d7 --- /dev/null +++ b/.launch/cxs_tlm.launch @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/memory_subsys.launch b/.launch/memory_subsys.launch new file mode 100644 index 0000000..ec418dc --- /dev/null +++ b/.launch/memory_subsys.launch @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/sc_fixed_tracing.launch b/.launch/sc_fixed_tracing.launch new file mode 100644 index 0000000..afe8bbc --- /dev/null +++ b/.launch/sc_fixed_tracing.launch @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/sim_performance.launch b/.launch/sim_performance.launch new file mode 100644 index 0000000..85d34c7 --- /dev/null +++ b/.launch/sim_performance.launch @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/transaction_recording.launch b/.launch/transaction_recording.launch new file mode 100644 index 0000000..92cc9d6 --- /dev/null +++ b/.launch/transaction_recording.launch @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project index 781e2b6..e7ad514 100644 --- a/.project +++ b/.project @@ -28,5 +28,6 @@ org.eclipse.cdt.core.ccnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.python.pydev.pythonNature diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..ff64ab2 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,16 @@ +{ + "recommendations": [ + "mkhl.direnv", + "sanaajani.taskrunnercode", + "ms-vscode.cpptools-themes", + "cnshenj.vscode-task-manager", + "twxs.cmake", + "kylinideteam.cmake-intellisence", + "kylinideteam.kylin-cmake-tools", + "llvm-vs-code-extensions.vscode-clangd", + "eclipse-cdt.cdt-gdb-vscode", + "eclipse-cdt.memory-inspector", + "eclipse-cdt.peripheral-inspector", + "ms-python.python" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index fc26538..57bd73b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,25 +1,80 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [{ - "name": "cci_param_restricted", - "type": "cppdbg", - "request": "launch", - "cwd": "${workspaceRoot}", - "program": "${workspaceRoot}/build/tests/cci_param_restricted/cci_param_restricted", - "linux": { - "MIMode": "gdb", - "miDebuggerPath": "/usr/bin/gdb" - }, - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ], - "preLaunchTask": "CMake: build" - }] + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "gdb", + "request": "launch", + "name": "quantum_keeper_mt", + "program": "${workspaceFolder}/build/Debug/tests/quantum_keeper_mt/quantum_keeper_mt", + "environment": { + "SCC_TEST_VERBOSE": "7" + } + }, + { + "type": "gdb", + "request": "launch", + "name": "cci-example", + "program": "${workspaceFolder}/build/Debug/tests/configuration/cci-example", + "environment": { + "SCC_TEST_VERBOSE": "7" + } + }, + { + "name": "cppdbg quantum_keeper_mt", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceRoot}/build/Debug/tests/quantum_keeper_mt/quantum_keeper_mt", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + }, + { + "name": "cci_param_restricted", + "type": "gdb", + "request": "launch", + "cwd": "${workspaceRoot}", + "program": "${workspaceRoot}/build/Debug/tests/cci_param_restricted/cci_param_restricted", + "preLaunchTask": "CMake: build" + }, + { + "name": "dmi_access", + "type": "gdb", + "request": "launch", + "cwd": "${workspaceRoot}", + "program": "${workspaceRoot}/build/Debug/tests/memory_subsys/memory_subsys", + "preLaunchTask": "CMake: build" + }, + { + "name": "cxs_tlm", + "type": "gdb", + "request": "launch", + "cwd": "${workspaceRoot}", + "program": "${workspaceRoot}/build/Debug/tests/cxs_tlm/cxs_tlm", + "arguments": "-n single-packet", + "preLaunchTask": "CMake: build", + "environment": { + "SCC_TEST_TRACE": "1", + "SCC_TEST_VERBOSE": "1" + }, + "openGdbConsole": true + } + ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d46a1f1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,36 @@ +{ + "editor.rulers": [ + { + "column": 140, + "comment": "clang-format" + } + ], + "editor.formatOnSave": true, + "editor.hover.delay": 1500, + "clangd.arguments": [ + "--pretty", + "--background-index", + "--compile-commands-dir=${workspaceFolder}/build" + ], + "cmake.buildDirectory": "${workspaceRoot}/build/${buildType}", + //"cmake.configureArgs": ["-B", "${workspaceRoot}/build/${buildType}"], + "cmake.configureOnOpen": false, + "cmake.configureOnEdit": true, + "cmake.autoSelectActiveFolder": true, + "cmake.exportCompileCommandsFile": true, + "cmake.skipConfigureIfCachePresent": false, + "cmake.copyCompileCommands": "${workspaceFolder}/build/compile_commands.json", + "cmake.options.statusBarVisibility": "hidden", + "cmake.options.advanced": { + "configure": { + "projectStatusVisibility": "visible" + }, + "build": { + "statusBarVisibility": "visible" + } + }, + "todo-tree.ripgrep.ripgrep": "/bin/rg", + "files.watcherExclude": { + "**/build": true + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 8714fea..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "type": "cmake", - "label": "CMake: build", - "command": "build", - "targets": [ - "all" - ], - "group": "build", - "problemMatcher": ["$gcc"], - "detail": "CMake template build task", - } - ] -} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 30fb7c7..a49bf95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.16) -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/scc/cmake) cmake_policy(SET CMP0110 NEW) project(SCC_Test) @@ -7,6 +6,25 @@ project(SCC_Test) option(FULL_TEST_SUITE "enable also long-running tests" OFF) option(ENABLE_SCV "Enable use of SCV" OFF) option(ENABLE_CLANG_TIDY "Enable clang-tidy checks" OFF) +option(ENABLE_CLANG_FORMAT "Enable clang-format targets" OFF) +option(THREAD_SANITIZER "Enable thread sanitizer TSan" OFF) +option(ADDR_SANITIZER "Enable address sanitizer ASan" OFF) + +if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/scc") + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/scc/cmake) +else() + include(FetchContent) + FetchContent_Declare( + scc_git + GIT_REPOSITORY https://github.com/Minres/SystemC-Components.git + GIT_TAG develop + ) + FetchContent_GetProperties(scc_git) + if(NOT scc_git_POPULATED) + FetchContent_Populate(scc_git) + endif() + list(APPEND CMAKE_MODULE_PATH ${scc_git_SOURCE_DIR}/cmake) +endif() include(GNUInstallDirs) include(BuildType) @@ -30,7 +48,15 @@ if(ENABLE_COVERAGE) include(CodeCoverage) append_coverage_compiler_flags() endif() - +if (THREAD_SANITIZER) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -O0 -g") +elseif(ADDR_SANITIZER) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -O0 -g") +else() + if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) + endif() +endif() if(ENABLE_CLANG_TIDY) find_program(CLANG_TIDY_EXE NAMES "clang-tidy") if(CLANG_TIDY_EXE) @@ -43,8 +69,10 @@ if(ENABLE_CLANG_TIDY) endif() endif() -set(CLANG_FORMAT_EXCLUDE_PATTERNS "/third_party/" "/build/") -find_package(ClangFormat) +set(CLANG_FORMAT_EXCLUDE_PATTERNS "/third_party/" "/build/" ".direnv") +if(ENABLE_CLANG_FORMAT) + find_package(ClangFormat) +endif() find_package(ZLIB) find_package(lz4) # This line finds the boost lib and headers. @@ -57,9 +85,13 @@ find_package(Catch2) include(SystemCPackage) include(CTest) include(Catch) - enable_testing() +set(WITH_SCP4SCC ON) -add_subdirectory(scc) +if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/scc") + add_subdirectory(scc) +else() + add_subdirectory(${scc_git_SOURCE_DIR}) +endif() add_subdirectory(src) add_subdirectory(tests) diff --git a/CMakePresets.json b/CMakePresets.json index 86840c3..6427ff7 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -10,31 +10,63 @@ }, "configurePresets": [ { - "name": "Debug", + "name": "Base", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", "cacheVariables": { "CMAKE_POLICY_DEFAULT_CMP0091": "NEW", + "CMAKE_CXX_STANDARD": "20", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", + "CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "cmake-conan/conan_provider.cmake", + "CONAN_HOST_PROFILE": "auto-cmake", + "CONAN_BUILD_PROFILE": "conan_host_profile" + } + }, + { + "name": "Debug", + "inherits": "Base", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "DebugWFormat", + "inherits": "Base", + "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_CXX_STANDARD": "17", - "CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "cmake-conan/conan_provider.cmake" + "ENABLE_CLANG_FORMAT": "ON" + } + }, + { + "name": "DebugCXX20", + "inherits": "Base", + "cacheVariables": { + "CMAKE_CXX_STANDARD": "20", + "CMAKE_BUILD_TYPE": "Debug" } }, { "name": "RelWithDebInfo", + "inherits": "Base", "cacheVariables": { - "CMAKE_POLICY_DEFAULT_CMP0091": "NEW", - "CMAKE_BUILD_TYPE": "RelWithDebInfo", - "CMAKE_CXX_STANDARD": "17", - "CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "cmake-conan/conan_provider.cmake" + "CMAKE_BUILD_TYPE": "RelWithDebInfo" } }, { "name": "Release", + "inherits": "Base", "cacheVariables": { - "CMAKE_POLICY_DEFAULT_CMP0091": "NEW", - "CMAKE_BUILD_TYPE": "Release", - "CMAKE_CXX_STANDARD": "17", - "CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "cmake-conan/conan_provider.cmake" + "CMAKE_BUILD_TYPE": "Release" } } + ], + "testPresets": [ + { + "name": "test-all", + "description": "run all test with Debug build", + "displayName": "", + "configurePreset": "Debug" + } ] } \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index d9dbfe3..b0bd918 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,10 +31,12 @@ void checkout_project() { void build_n_test_project() { sh''' - python3 -mvenv .venv - . .venv/bin/activate - pip3 install -r requirements.txt - cmake -S . -B build --preset Release + python3 -mvenv .venv + . .venv/bin/activate + pip3 install -r requirements.txt + conan remove -c "systemc/*" + cmake -S . -B build --preset Release -DCONAN_INSTALL_ARGS="--build=*" -DENABLE_CLANG_FORMAT=ON + cmake --build build --target format-check cmake --build build -j12 cmake --build build --target test ''' @@ -52,34 +54,25 @@ pipeline { stage('SCC test pipeline') { parallel { stage('ubuntu-22.04') { - agent {docker { image 'ubuntu-22.04' } } + agent {docker { + image 'ubuntu-22.04' + args ' -e CONAN_HOME=/var/jenkins_home/workspace/conan-jammy-cxx20' + } } stages { stage('Checkout') { steps { checkout_project() }} stage('Build & test') { steps { build_n_test_project() }} } } stage('rockylinux8') { - agent {docker { image 'rockylinux8' } } + agent {docker { + image 'rockylinux8' + args ' -e CONAN_HOME=/var/jenkins_home/workspace/conan-rocky8-cxx20' + } } stages { stage('Checkout') { steps { checkout_project() }} stage('Build & test') { steps { build_n_test_project() }} } } - stage('Format check') { - agent {docker { image 'ubuntu-22.04' } } - stages { - stage('Checkout') { steps { checkout_project() }} - stage('Build & check format') { steps { - sh''' - python3 -mvenv .venv - . .venv/bin/activate - pip3 install -r requirements.txt - cmake -S . -B build --preset Release - cmake --build build --target format-check - ''' - }} - } - } } } } diff --git a/Modulefile b/Modulefile deleted file mode 100644 index 4891e78..0000000 --- a/Modulefile +++ /dev/null @@ -1,17 +0,0 @@ -#%Module###################################################################### -## -## Project Module -## -proc ModulesHelp { } { - puts stderr "\tThe SCC Tests Project Module\n" - puts stderr "\tThis module loads PATHs and variables for SCC tests." -} - -set distro [exec /usr/bin/lsb_release -i -s] -if { $distro == "CentOS" && ![info exists ::env(PROJECT)] && ![info exists ::env(PCP_DIR)] } { - puts stderr "Don't forget to execute 'scl enable devtoolset-7 llvm-toolset-7 bash'" -} - -module load tools/utilities -module load tools/cmake/3.28 -module load tools/clang/14.0 diff --git a/README.md b/README.md index 98bb81b..a572179 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ In Console: python3 -mvenv .venv . .venv/bin/activate pip3 install -r requirements.txt - cmake -S . -B build --preset Release - cmake --build build -j30 - cmake --build build --target test + cmake --preset Release + cmake --build build/Release -j30 + cmake --build build/Release --target test \ No newline at end of file diff --git a/cmake-conan b/cmake-conan index c22bbf0..b0e4d1e 160000 --- a/cmake-conan +++ b/cmake-conan @@ -1 +1 @@ -Subproject commit c22bbf0af0b73d5f0def24a9cdf4ce503ae79e5d +Subproject commit b0e4d1ec08edb35ef31033938567d621f6643c17 diff --git a/cmake/GetGitRevisionDescription.cmake b/cmake/GetGitRevisionDescription.cmake deleted file mode 100644 index bcd1d72..0000000 --- a/cmake/GetGitRevisionDescription.cmake +++ /dev/null @@ -1,130 +0,0 @@ -# - Returns a version string from Git -# -# These functions force a re-configure on each git commit so that you can -# trust the values of the variables in your build system. -# -# get_git_head_revision( [ ...]) -# -# Returns the refspec and sha hash of the current head revision -# -# git_describe( [ ...]) -# -# Returns the results of git describe on the source tree, and adjusting -# the output so that it tests false if an error occurs. -# -# git_get_exact_tag( [ ...]) -# -# Returns the results of git describe --exact-match on the source tree, -# and adjusting the output so that it tests false if there was no exact -# matching tag. -# -# Requires CMake 2.6 or newer (uses the 'function' command) -# -# Original Author: -# 2009-2010 Ryan Pavlik -# http://academic.cleardefinition.com -# Iowa State University HCI Graduate Program/VRAC -# -# Copyright Iowa State University 2009-2010. -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -if(__get_git_revision_description) - return() -endif() -set(__get_git_revision_description YES) - -# We must run the following at "include" time, not at function call time, -# to find the path to this module rather than the path to a calling list file -get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) - -function(get_git_head_revision _refspecvar _hashvar) - set(GIT_PARENT_DIR "${CMAKE_CURRENT_LIST_DIR}") - set(GIT_DIR "${GIT_PARENT_DIR}/.git") - while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories - set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") - get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) - if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) - # We have reached the root directory, we are not in git - set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - return() - endif() - set(GIT_DIR "${GIT_PARENT_DIR}/.git") - endwhile() - # check if this is a submodule - if(NOT IS_DIRECTORY ${GIT_DIR}) - file(READ ${GIT_DIR} submodule) - string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule}) - get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) - get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) - endif() - set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") - if(NOT EXISTS "${GIT_DATA}") - file(MAKE_DIRECTORY "${GIT_DATA}") - endif() - - if(NOT EXISTS "${GIT_DIR}/HEAD") - return() - endif() - set(HEAD_FILE "${GIT_DATA}/HEAD") - configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) - - configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" - "${GIT_DATA}/grabRef.cmake" - @ONLY) - include("${GIT_DATA}/grabRef.cmake") - - set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) - set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) -endfunction() - -function(git_describe _var) - if(NOT GIT_FOUND) - find_package(Git QUIET) - endif() - get_git_head_revision(refspec hash) - if(NOT GIT_FOUND) - set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) - return() - endif() - if(NOT hash) - set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) - return() - endif() - - # TODO sanitize - #if((${ARGN}" MATCHES "&&") OR - # (ARGN MATCHES "||") OR - # (ARGN MATCHES "\\;")) - # message("Please report the following error to the project!") - # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") - #endif() - - #message(STATUS "Arguments to execute_process: ${ARGN}") - - execute_process(COMMAND - "${GIT_EXECUTABLE}" - describe - ${hash} - ${ARGN} - WORKING_DIRECTORY - "${CMAKE_SOURCE_DIR}" - RESULT_VARIABLE - res - OUTPUT_VARIABLE - out - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - if(NOT res EQUAL 0) - set(out "${out}-${res}-NOTFOUND") - endif() - - set(${_var} "${out}" PARENT_SCOPE) -endfunction() - -function(git_get_exact_tag _var) - git_describe(out --exact-match ${ARGN}) - set(${_var} "${out}" PARENT_SCOPE) -endfunction() diff --git a/cmake/GetGitRevisionDescription.cmake.in b/cmake/GetGitRevisionDescription.cmake.in deleted file mode 100644 index 6d8b708..0000000 --- a/cmake/GetGitRevisionDescription.cmake.in +++ /dev/null @@ -1,41 +0,0 @@ -# -# Internal file for GetGitRevisionDescription.cmake -# -# Requires CMake 2.6 or newer (uses the 'function' command) -# -# Original Author: -# 2009-2010 Ryan Pavlik -# http://academic.cleardefinition.com -# Iowa State University HCI Graduate Program/VRAC -# -# Copyright Iowa State University 2009-2010. -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -set(HEAD_HASH) - -file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) - -string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) -if(HEAD_CONTENTS MATCHES "ref") - # named branch - string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") - if(EXISTS "@GIT_DIR@/${HEAD_REF}") - configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) - else() - configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY) - file(READ "@GIT_DATA@/packed-refs" PACKED_REFS) - if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}") - set(HEAD_HASH "${CMAKE_MATCH_1}") - endif() - endif() -else() - # detached HEAD - configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) -endif() - -if(NOT HEAD_HASH) - file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) - string(STRIP "${HEAD_HASH}" HEAD_HASH) -endif() diff --git a/cmake/PackageConfigurator.cmake b/cmake/PackageConfigurator.cmake deleted file mode 100644 index b67615d..0000000 --- a/cmake/PackageConfigurator.cmake +++ /dev/null @@ -1,44 +0,0 @@ -# Create package-config files : -# - ConfigVersion.cmake -# - Config.cmake -# They are installed in lib/cmake/. -# -# Required variables : -# - VERSION -# - PROJECT_NAME -# - -# Include needed for 'write_basic_package_version_file' -include(CMakePackageConfigHelpers) - -write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake" - VERSION ${VERSION} - COMPATIBILITY AnyNewerVersion -) - -configure_file(cmake/${PROJECT_NAME}Config.cmake - "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake" - COPYONLY -) - -# Destination -set(config_install_dir lib/cmake/${PROJECT_NAME}) - -# Config installation -# * /lib/cmake//Targets.cmake -install( - EXPORT ${PROJECT_NAME}Targets - DESTINATION ${config_install_dir} -) - -# Config installation -# * /lib/cmake//Config.cmake -# * /lib/cmake//ConfigVersion.cmake -install( - FILES - cmake/${PROJECT_NAME}Config.cmake - "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake" - DESTINATION ${config_install_dir} - COMPONENT devel -) \ No newline at end of file diff --git a/cmake/Submodules.cmake b/cmake/Submodules.cmake deleted file mode 100644 index 0d1b89d..0000000 --- a/cmake/Submodules.cmake +++ /dev/null @@ -1,57 +0,0 @@ -if(EXISTS "${PROJECT_SOURCE_DIR}/.gitmodules") -message(STATUS "Updating submodules to their latest/fixed versions") -message(STATUS "(this can take a while, please be patient)") - -### First, get all submodules in -if(${GIT_SUBMODULES_CHECKOUT_QUIET}) - execute_process( - COMMAND git submodule update --init --recursive - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - OUTPUT_QUIET - ERROR_QUIET - ) -else() - execute_process( - COMMAND git submodule update --init --recursive - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - ) -endif() - -### Then, checkout each submodule to the specified commit -# Note: Execute separate processes here, to make sure each one is run, -# should one crash (because of branch not existing, this, that ... whatever) -foreach(GIT_SUBMODULE ${GIT_SUBMODULES}) - - if( "${GIT_SUBMODULE_VERSION_${GIT_SUBMODULE}}" STREQUAL "" ) - message(STATUS "no specific version given for submodule ${GIT_SUBMODULE}, checking out master") - if( "${GIT_SUBMODULE_BRANCH_${GIT_SUBMODULE}}" STREQUAL "" ) - set(GIT_SUBMODULE_VERSION_${GIT_SUBMODULE} "master") - else() - set(GIT_SUBMODULE_VERSION_${GIT_SUBMODULE} ${GIT_SUBMODULE_BRANCH_${GIT_SUBMODULE}}) - endif() - endif() - - if( "${GIT_SUBMODULE_DIR_${GIT_SUBMODULE}}" STREQUAL "" ) - set(GIT_SUBMODULES_DIRECTORY external) - else() - set(GIT_SUBMODULES_DIRECTORY ${GIT_SUBMODULE_DIR_${GIT_SUBMODULE}}) - endif() - - if(${GIT_SUBMODULES_CHECKOUT_QUIET}) - execute_process( - COMMAND git checkout ${GIT_SUBMODULE_VERSION_${GIT_SUBMODULE}} - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/${GIT_SUBMODULES_DIRECTORY}/${GIT_SUBMODULE} - OUTPUT_QUIET - ERROR_QUIET - ) - else() - message(STATUS "checking out ${GIT_SUBMODULE}'s commit/tag ${GIT_SUBMODULE_VERSION_${GIT_SUBMODULE}}") - execute_process( - COMMAND git checkout ${GIT_SUBMODULE_VERSION_${GIT_SUBMODULE}} - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/${GIT_SUBMODULES_DIRECTORY}/${GIT_SUBMODULE} - ) - endif() - -endforeach(${GIT_SUBMODULE}) - -endif() diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..27b49bb --- /dev/null +++ b/conanfile.py @@ -0,0 +1,61 @@ +from conan import ConanFile +from conan.tools.cmake import cmake_layout +from conan.tools.cmake.toolchain.toolchain import CMakeToolchain +import os + + +class Pkg(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeDeps" + default_options = { + "systemc/*:shared": "True", + "boost/*:fPIC": "True", + "boost/*:header_only": "False", + "boost/*:without_contract": "True", + "boost/*:without_fiber": "True", + "boost/*:without_graph": "True", + "boost/*:without_graph_parallel": "True", + "boost/*:without_iostreams": "True", + "boost/*:without_json": "True", + "boost/*:without_locale": "True", + "boost/*:without_log": "True", + "boost/*:without_math": "True", + "boost/*:without_mpi": "True", + "boost/*:without_nowide": "True", + "boost/*:without_python": "True", + "boost/*:without_random": "True", + "boost/*:without_regex": "True", + "boost/*:without_stacktrace": "False", + "boost/*:without_test": "True", + "boost/*:without_timer": "True", + "boost/*:without_type_erasure": "True", + "boost/*:without_wave": "True", + } + + def requirements(self): + if self.settings.compiler.cppstd: + cppstd = str(self.settings.compiler.cppstd).replace("gnu", "") + if cppstd == "11" or cppstd == "14": + self.requires("systemc/2.3.4") + else: + self.requires("systemc/3.0.1") + else: + self.requires("systemc/2.3.4") + self.requires("spdlog/1.16.0") + self.requires("boost/1.89.0") + self.requires("lz4/1.10.0") + self.requires("yaml-cpp/0.8.0") + self.requires("jsoncpp/1.9.6") + self.requires("zlib/1.3.1") + self.requires("catch2/3.1.0") + + def build_requirements(self): + pass + + def layout(self): + cmake_layout(self) + + def generate(self): + tc = CMakeToolchain(self) + tc.user_presets_path = False + tc.generate() diff --git a/conanfile.txt b/conanfile.txt deleted file mode 100644 index 80c687f..0000000 --- a/conanfile.txt +++ /dev/null @@ -1,44 +0,0 @@ -[requires] -jsoncpp/1.9.5 -yaml-cpp/0.6.3 -spdlog/1.9.2 -fmt/8.0.1 -boost/1.85.0 -gsl-lite/0.37.0 -systemc/2.3.4 -catch2/3.1.0 -zlib/1.2.11 -lz4/1.9.4 -rapidjson/cci.20230929 - -[options] -boost/*:fPIC=True -boost/*:header_only=False -boost/*:without_contract=True -boost/*:without_fiber=True -boost/*:without_graph=True -boost/*:without_graph_parallel=True -boost/*:without_iostreams=True -boost/*:without_json=True -boost/*:without_locale=True -boost/*:without_log=True -boost/*:without_math=True -boost/*:without_mpi=True -boost/*:without_nowide=True -boost/*:without_python=True -boost/*:without_random=True -boost/*:without_regex=True -boost/*:without_stacktrace=True -boost/*:without_test=True -boost/*:without_timer=True -boost/*:without_type_erasure=True -boost/*:without_wave=True -systemc/*:shared=False -systemc/*:disable_virtual_bind=False - -[generators] -CMakeDeps -CMakeToolchain - -[layout] -cmake_layout diff --git a/requirements.txt b/requirements.txt index b7d8b70..44a40ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ conan>=2.0 -cmake +cmake<4.0 clang-format==14.0 \ No newline at end of file diff --git a/scc b/scc deleted file mode 160000 index bccc926..0000000 --- a/scc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bccc9269ff84181d1287dd6021ab5eb52f8909d0 diff --git a/src/sc_main.cpp b/src/sc_main.cpp index b1fe425..a530f12 100644 --- a/src/sc_main.cpp +++ b/src/sc_main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -27,10 +28,12 @@ int sc_main(int argc, char* argv[]) { auto level = getenv("SCC_TEST_VERBOSE"); auto log_lvl = level ? static_cast(std::min(strtoul(level, nullptr, 10) + 4, 7UL)) : log::FATAL; scc::init_logging(LogConfig().logLevel(log_lvl).logAsync(false).msgTypeFieldWidth(35)); + scc::configurer cfg(""); // create tracer if environment variable SCC_TEST_TRACE is defined std::unique_ptr tracer; if(auto* test_trace = getenv("SCC_TEST_TRACE")) { tracer = std::make_unique(my_name, scc::tracer::ENABLE, scc::tracer::ENABLE); + cfg.set_value("scc_tracer.default_trace_enable", true); } int result = -1; if(setjmp(abrt) == 0) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7004527..90877e2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,6 +9,10 @@ add_subdirectory(configuration) add_subdirectory(configurer) add_subdirectory(sc_fixed_tracing) add_subdirectory(cxs_tlm) +add_subdirectory(tlm_memory) +add_subdirectory(memory_subsys) +add_subdirectory(quantum_keeper_mt) +add_subdirectory(sim_speed) if(FULL_TEST_SUITE) add_subdirectory(sim_performance) endif() diff --git a/tests/ace_pin_level/CMakeLists.txt b/tests/ace_pin_level/CMakeLists.txt index 78d5cf1..f16e4c4 100644 --- a/tests/ace_pin_level/CMakeLists.txt +++ b/tests/ace_pin_level/CMakeLists.txt @@ -5,5 +5,6 @@ add_executable(${PROJECT_NAME} ${test_util_SOURCE_DIR}/sc_main.cpp ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) - -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/ahb_pin_level/CMakeLists.txt b/tests/ahb_pin_level/CMakeLists.txt index 621893d..d13d684 100644 --- a/tests/ahb_pin_level/CMakeLists.txt +++ b/tests/ahb_pin_level/CMakeLists.txt @@ -6,4 +6,6 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/apb_pin_level/CMakeLists.txt b/tests/apb_pin_level/CMakeLists.txt index bd52313..085edec 100644 --- a/tests/apb_pin_level/CMakeLists.txt +++ b/tests/apb_pin_level/CMakeLists.txt @@ -6,4 +6,6 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/axi4_pin_level/CMakeLists.txt b/tests/axi4_pin_level/CMakeLists.txt index 53ff21a..a16c2db 100644 --- a/tests/axi4_pin_level/CMakeLists.txt +++ b/tests/axi4_pin_level/CMakeLists.txt @@ -5,5 +5,6 @@ add_executable(${PROJECT_NAME} ${test_util_SOURCE_DIR}/sc_main.cpp ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) - -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/cci_param_restricted/CMakeLists.txt b/tests/cci_param_restricted/CMakeLists.txt index 6ac195e..9d85664 100644 --- a/tests/cci_param_restricted/CMakeLists.txt +++ b/tests/cci_param_restricted/CMakeLists.txt @@ -6,4 +6,6 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/configuration/top_module.h b/tests/configuration/top_module.h index 2ce77ee..35a8efb 100644 --- a/tests/configuration/top_module.h +++ b/tests/configuration/top_module.h @@ -32,14 +32,17 @@ #define EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_TOP_MODULE_H_ #include +#include #include #include #include #include +#include "cci/core/cci_value.h" #include "initiator.h" #include "router.h" #include "target.h" +#include /** * @class top_module @@ -89,15 +92,13 @@ public: /// Creating instances of initiator(s) for(int i = 0; i < n_initiators; i++) { - snprintf(initiatorName, sizeof(initiatorName), "initiator_%d", i); + auto initiatorName = fmt::format("initiator_{}", i); SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] : Creating initiator : " << initiatorName; - snprintf(stringMisc, sizeof(stringMisc), "%s.%s.initiator_ID", name(), initiatorName); - - snprintf(initiatorName, sizeof(initiatorName), "\"initiator_%d\"", i); - m_broker.set_preset_cci_value(stringMisc, cci::cci_value::from_json(initiatorName)); - snprintf(initiatorName, sizeof(initiatorName), "initiator_%d", i); - initiatorList.push_back(new initiator(initiatorName)); + auto paramName = fmt::format("{}.{}.initiator_ID", name(), initiatorName); + auto quotedInitiatorName = fmt::format("\"initiator_{}\"", i); + m_broker.set_preset_cci_value(paramName, cci::cci_value::from_json(quotedInitiatorName)); + initiatorList.push_back(new initiator(initiatorName.c_str())); // Binding of initiator to Router SCCINFO(SCMOD) << "[TOP MODULE C_TOR] : Binding Router_Initiator to " << initiatorName; @@ -109,22 +110,23 @@ public: // Creating instances of target(s) for(int i = 0; i < n_targets; i++) { - snprintf(targetName, sizeof(targetName), "target_%d", i); + auto targetName = fmt::format("target_{}", i); SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] : Creating target : " << targetName; - snprintf(stringMisc, sizeof(stringMisc), "%s.%s.target_ID", name(), targetName); - snprintf(targetName, sizeof(targetName), "\"target_%d\"", i); - m_broker.set_preset_cci_value(stringMisc, cci::cci_value::from_json(targetName)); - snprintf(targetName, sizeof(targetName), "target_%d", i); + auto paramName0 = fmt::format("{}.{}.initiator_ID", name(), targetName); + auto quotedTargetName = fmt::format("\"target_{}\"", i); + cci::cci_value v; + v.set(targetName); + m_broker.set_preset_cci_value(paramName0, v); // Set preset value for maximum target size(memory) - snprintf(stringMisc, sizeof(stringMisc), "%s.%s.s_size", name(), targetName); + auto paramName1 = fmt::format("{}.{}.initiator_ID", name(), targetName); ss.clear(); ss.str(""); ss << targetSize; - m_broker.set_preset_cci_value(stringMisc, cci::cci_value::from_json(ss.str())); - targetList.push_back(new target(targetName)); + m_broker.set_preset_cci_value(paramName1, cci::cci_value::from_json(ss.str())); + targetList.push_back(new target(targetName.c_str())); // Binding Router to target SCCINFO(SCMOD) << "[TOP MODULE C_TOR] : Binding Router_Initiator to " << targetName; @@ -133,7 +135,7 @@ public: // Try re-setting locked values for Router Table contents for(int i = 0; i < n_targets; i++) { - snprintf(targetName, sizeof(targetName), "%s.RouterInstance.r_index_%d", name(), i); + auto targetName = fmt::format("{}.RouterInstance.r_index_{}", name(), i); ss.clear(); ss.str(""); ss << i; @@ -142,15 +144,15 @@ public: SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] : Re-setting fields of target_" << i; m_broker.set_preset_cci_value(targetName, cci::cci_value::from_json(ss.str())); } catch(sc_core::sc_report const& exception) { - SCCINFO(SCMOD) << "[ROUTER : Caught] : " << exception.what(); + SCCINFO(SCMOD) << "[ROUTER : Caught] : " << exception.what() << " (expected)"; } - snprintf(targetName, sizeof(targetName), "%s.RouterInstance.r_sa_%d", name(), i); + targetName = fmt::format("{}.RouterInstance.r_sa_{}", name(), i); ss.clear(); ss.str(""); ss << (i * targetSize); - snprintf(targetBaseAddr, sizeof(targetBaseAddr), "%s.target_%d.s_base_addr", name(), i); + auto targetBaseAddr = fmt::format("{}.target_{}.s_base_addr", name(), i); cci::cci_param_untyped_handle h = m_broker.get_param_handle(targetBaseAddr); h.set_cci_value(cci::cci_value::from_json(ss.str())); @@ -162,7 +164,7 @@ public: SCCINFO(SCMOD) << "[ROUTER : Caught] : " << exception.what(); } - snprintf(targetName, sizeof(targetName), "%s.RouterInstance.r_ea_%d", name(), i); + targetName = fmt::format("{}.RouterInstance.r_ea_{}", name(), i); ss.clear(); ss.str(""); ss << ((i + 1) * targetSize - 1); @@ -210,15 +212,9 @@ private: std::vector initiatorList; ///< STD::VECTOR for initiators std::vector targetList; ///< STD::VECTOR for targets - char initiatorName[50]; ///< initiator_ID - char targetName[50]; ///< target_ID - char stringMisc[50]; ///< String to be used for misc things - char targetBaseAddr[50]; ///< The base address of the target - int addrValue{0}; ///< Address Value int targetSize; ///< Maximum target Size (preset value) int r_addr_max; ///< Maximum Router Table's memory range }; - // top_module #endif // EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_TOP_MODULE_H_ diff --git a/tests/cxs_tlm/CMakeLists.txt b/tests/cxs_tlm/CMakeLists.txt index ede8eff..d5c1190 100644 --- a/tests/cxs_tlm/CMakeLists.txt +++ b/tests/cxs_tlm/CMakeLists.txt @@ -5,4 +5,6 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC scc::busses test_util) -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/cxs_tlm/csx_packet_test.cpp b/tests/cxs_tlm/csx_packet_test.cpp index 8bfdcf3..39ace08 100644 --- a/tests/cxs_tlm/csx_packet_test.cpp +++ b/tests/cxs_tlm/csx_packet_test.cpp @@ -5,7 +5,6 @@ #undef CHECK #include #include -#include using namespace sc_core; namespace cxs { @@ -13,10 +12,10 @@ factory::add> tb8; factory::add> tb9; factory::add> tb10; -template unsigned run_scenario(STATE& state, unsigned burst_factor = 0) { +template unsigned run_scenario(STATE& state) { auto& dut = factory::get>(); - if(burst_factor) - dut.tx.burst_len.set_value(burst_factor); + dut.tx.burst_len.set_value(state.burst_factor); + dut.rx.max_credit.set_value(state.credits); dut.rst.write(true); sc_start(state.reset_cycles * dut.clk.period()); dut.rst.write(false); @@ -67,7 +66,7 @@ template unsigned run_scenario(STATE& state, un return cycles; } -template unsigned run_scenario(int width, STATE& state, unsigned burst_factor = 0) { +template unsigned run_scenario(int width, STATE& state) { switch(width) { case 8: case 256: @@ -85,32 +84,40 @@ template unsigned run_scenario(int width, STATE& state, unsigne TEST_CASE("single-packet", "[CXS][tlm-level]") { struct { unsigned int reset_cycles{4}; - unsigned int max_cycles = 5000; + unsigned int max_cycles = 20000; std::vector packet_sizes; unsigned granularity{1}; unsigned resp_cnt{0}; + unsigned burst_factor{1}; + unsigned credits{1}; } state; state.packet_sizes.assign({4, 8, 16, 32, 64, 128, 256, 1024}); + std::array credits{1, 4, 15}; for(auto width = 8; width < 11; ++width) { - state.resp_cnt = 0; - auto cycles = run_scenario(width, state); + for(auto credit : credits) { + state.resp_cnt = 0; + state.credits = credit; + auto cycles = run_scenario(width, state); - REQUIRE(cycles < state.max_cycles); - REQUIRE(sc_report_handler::get_count(SC_ERROR) == 0); - REQUIRE(sc_report_handler::get_count(SC_WARNING) == 0); + REQUIRE(cycles < state.max_cycles); + REQUIRE(sc_report_handler::get_count(SC_ERROR) == 0); + REQUIRE(sc_report_handler::get_count(SC_WARNING) == 0); - REQUIRE(state.resp_cnt == state.packet_sizes.size()); + REQUIRE(state.resp_cnt == state.packet_sizes.size()); + } } } TEST_CASE("multi-packet", "[CXS][tlm-level]") { struct { unsigned int reset_cycles{4}; - unsigned int max_cycles = 5000; + unsigned int max_cycles = 20000; std::vector packet_sizes; unsigned granularity{2}; unsigned resp_cnt{0}; + unsigned burst_factor{1}; + unsigned credits{15}; } state; state.packet_sizes.assign({4, 8, 16, 32, 16, 64, 16, 128, 16, 256, 16, 1024}); @@ -128,16 +135,18 @@ TEST_CASE("multi-packet", "[CXS][tlm-level]") { TEST_CASE("single-packet-burst2", "[CXS][tlm-level]") { struct { unsigned int reset_cycles{4}; - unsigned int max_cycles = 5000; + unsigned int max_cycles = 20000; std::vector packet_sizes; unsigned granularity{1}; unsigned resp_cnt{0}; + unsigned burst_factor{2}; + unsigned credits{2}; } state; state.packet_sizes.assign({4, 8, 16, 32, 64, 128, 256, 1024}); for(auto width = 8; width < 11; ++width) { state.resp_cnt = 0; - auto cycles = run_scenario(width, state, 2); + auto cycles = run_scenario(width, state); REQUIRE(cycles < state.max_cycles); REQUIRE(sc_report_handler::get_count(SC_ERROR) == 0); @@ -150,16 +159,18 @@ TEST_CASE("single-packet-burst2", "[CXS][tlm-level]") { TEST_CASE("multi-packet-burst2", "[CXS][tlm-level]") { struct { unsigned int reset_cycles{4}; - unsigned int max_cycles = 5000; + unsigned int max_cycles = 20000; std::vector packet_sizes; unsigned granularity{2}; unsigned resp_cnt{0}; + unsigned burst_factor{2}; + unsigned credits{2}; } state; state.packet_sizes.assign({4, 8, 16, 32, 16, 64, 16, 128, 16, 256, 16, 1024}); for(auto width = 8; width < 11; ++width) { state.resp_cnt = 0; - auto cycles = run_scenario(width, state, 2); + auto cycles = run_scenario(width, state); REQUIRE(cycles < state.max_cycles); REQUIRE(sc_report_handler::get_count(SC_ERROR) == 0); diff --git a/tests/cxs_tlm/testbench.h b/tests/cxs_tlm/testbench.h index 00d99b9..77cead5 100644 --- a/tests/cxs_tlm/testbench.h +++ b/tests/cxs_tlm/testbench.h @@ -2,12 +2,13 @@ #define _TESTBENCH_H_ #include +#include #include #include +#include #include #include #include -#include #include #include #include @@ -27,9 +28,11 @@ template struct testbench : public sc_core::sc_module { sc_core::sc_signal rst{"rst"}; tlm::nw::initiator_mixin, cxs_packet_types> isck{"isck"}; cxs_transmitter tx{"tx"}; + tlm::nw::scv::tlm_recorder_module tx_rec{"tx_rec"}; cxs_channel cxs_chan{"cxs_chan"}; + tlm::nw::scv::tlm_recorder_module rx_rec{"rx_rec"}; cxs_receiver rx{"rx"}; - tlm::nw::target_mixin, cxs_packet_types> tsck{"tsck"}; + tlm::nw::target_mixin, false, cxs_packet_types> tsck{"tsck"}; testbench() : testbench(sc_core::sc_gen_unique_name("testbench", false)) {} @@ -43,18 +46,31 @@ template struct testbench : public sc_core::sc_module { isck(tx.tsck); tx.clk_i(clk); tx.rst_i(rst); + cxs_chan.tx_clk_i(clk); + cxs_chan.rx_clk_i(clk); +#if 0 tx.isck(cxs_chan.tsck); cxs_chan.isck(rx.tsck); +#else + tx.isck(tx_rec.ts); + tx_rec.is(cxs_chan.tsck); + cxs_chan.isck(rx_rec.ts); + rx_rec.is(rx.tsck); +#endif rx.clk_i(clk); rx.rst_i(rst); rx.isck(tsck); + tx.clock_period.set_value(1_ns); + cxs_chan.tx_clock_period.set_value(1_ns); cxs_chan.channel_delay.set_value(100_ns); + cxs_chan.rx_clock_period.set_value(1_ns); + rx.clock_period.set_value(1_ns); rx.max_credit.set_value(15); } tlm::tlm_sync_enum nb_transport_fw(transaction_type& trans, phase_type& phase, sc_core::sc_time& t) { if(phase == tlm::nw::REQUEST) { - SCCINFO(SCMOD) << "Received non-blocking transaction with phase " << phase.get_name(); + SCCDEBUG(SCMOD) << "Received non-blocking transaction with phase " << phase.get_name(); recv.push_back(&trans); phase = tlm::nw::CONFIRM; return tlm::TLM_UPDATED; diff --git a/tests/memory_subsys/CMakeLists.txt b/tests/memory_subsys/CMakeLists.txt new file mode 100644 index 0000000..92ebe28 --- /dev/null +++ b/tests/memory_subsys/CMakeLists.txt @@ -0,0 +1,10 @@ +project (memory_subsys) +add_executable(${PROJECT_NAME} + memory_test.cpp + ${test_util_SOURCE_DIR}/sc_main.cpp +) +target_link_libraries (${PROJECT_NAME} PUBLIC scc::components test_util) + +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/memory_subsys/memory_test.cpp b/tests/memory_subsys/memory_test.cpp new file mode 100644 index 0000000..92f8f0d --- /dev/null +++ b/tests/memory_subsys/memory_test.cpp @@ -0,0 +1,99 @@ + +#include "testbench.h" +#include +#include +#undef CHECK +#include +#include +#include + +using namespace sc_core; +namespace scc { +factory::add tb; + +template void prepare_trans(tlm::tlm_generic_payload& trans, tlm::tlm_command cmd, uint64_t addr, T val) { + unsigned len = cmd == tlm::TLM_IGNORE_COMMAND ? 0 : sizeof(val); + unsigned char* data = len ? new unsigned char[len] : nullptr; + if(cmd == tlm::TLM_WRITE_COMMAND) { + memcpy(data, &val, len); + trans.set_command(cmd); + } + if(cmd == tlm::TLM_READ_COMMAND) { + memset(data, 0, len); + trans.set_command(tlm::TLM_READ_COMMAND); + } + trans.set_address(addr); + trans.set_data_ptr(data); + trans.set_data_length(len); + trans.set_streaming_width(len); + trans.set_response_status(tlm::TLM_INCOMPLETE_RESPONSE); +} + +template void do_dmi_access(T& isck, uint64_t address, uint64_t expected_size) { + tlm::tlm_generic_payload gp; + tlm::tlm_dmi dmi; + gp.set_address(address); + auto res = isck->get_direct_mem_ptr(gp, dmi); + REQUIRE(res == true); + REQUIRE(dmi.get_start_address() == address); + REQUIRE(dmi.get_end_address() == (address + expected_size - 1)); + REQUIRE(dmi.is_read_write_allowed()); +} + +TEST_CASE("dmi_access", "[memory][tlm-level]") { + auto& dut = factory::get(); + std::array ref_data; + auto val = 256; + for(auto& e : ref_data) + e = --val; + dut.rst.write(true); + sc_start(10 * dut.clk.read()); + dut.rst.write(false); + sc_start(dut.clk.read()); + + do_dmi_access(dut.isck0, 0, 1_kB); + do_dmi_access(dut.isck0, 1_kB, 1_kB); + do_dmi_access(dut.isck0, 16_MB, 16_MB); + do_dmi_access(dut.isck0, 32_MB, 16_MB); + do_dmi_access(dut.isck0, 48_MB, 4_MB); + do_dmi_access(dut.isck0, 64_MB, 16_MB); + do_dmi_access(dut.isck0, 80_MB, 4_MB); + do_dmi_access(dut.isck1, 0 - 1_MB, 1_kB); + do_dmi_access(dut.isck1, 1_kB - 1_MB, 1_kB); + do_dmi_access(dut.isck1, 16_MB - 1_MB, 16_MB); + do_dmi_access(dut.isck1, 32_MB - 1_MB, 16_MB); + do_dmi_access(dut.isck1, 48_MB - 1_MB, 4_MB); + do_dmi_access(dut.isck0, 128_MB, 16_MB); + sc_start(dut.clk.read()); +} + +TEST_CASE("page_boundary_check", "[memory][tlm-level]") { + auto& dut = factory::get(); + constexpr uint64_t kPageSize = decltype(dut.mem3)::page_size; + + std::array write_data{{0xAAu, 0xBBu}}; + tlm::tlm_generic_payload write; + sc_core::sc_time delay = sc_core::SC_ZERO_TIME; + write.set_command(tlm::TLM_WRITE_COMMAND); + write.set_address(kPageSize - 1); // straddles page boundary + write.set_data_length(write_data.size()); + write.set_streaming_width(write_data.size()); + write.set_data_ptr(write_data.data()); + dut.mem3.handle_operation(write, delay); + + std::array read_buf{{0xEEu, 0x00u, 0x00u, 0xEEu}}; + tlm::tlm_generic_payload read; + read.set_command(tlm::TLM_READ_COMMAND); + read.set_address(kPageSize - 1); + read.set_data_length(write_data.size()); + read.set_streaming_width(write_data.size()); + read.set_data_ptr(read_buf.data() + 1); // leave guard bytes at both ends + dut.mem3.handle_operation(read, delay); + + REQUIRE(read_buf[0] == 0xEEu); // leading guard untouched + REQUIRE(read_buf[1] == 0xAAu); // first byte read correctly + REQUIRE(read_buf[2] == 0xBBu); // second byte read correctly + REQUIRE(read_buf[3] == 0xEEu); // trailing guard must remain +} + +} // namespace scc diff --git a/tests/memory_subsys/testbench.h b/tests/memory_subsys/testbench.h new file mode 100644 index 0000000..d0e6fc8 --- /dev/null +++ b/tests/memory_subsys/testbench.h @@ -0,0 +1,63 @@ +#ifndef _TESTBENCH_H_ +#define _TESTBENCH_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace sc_core; +using namespace sc_dt; +using namespace std; +namespace scc { + +const char* sc_gen_unique_name(const char*, bool preserve_first); +struct testbench : public sc_core::sc_module { + + using transaction_type = tlm::tlm_base_protocol_types::tlm_payload_type; + using phase_type = tlm::tlm_base_protocol_types::tlm_phase_type; + + sc_core::sc_signal clk{"clk"}; + sc_core::sc_signal rst{"rst"}; + tlm::scc::initiator_mixin> isck0{"isck0"}; + tlm::scc::initiator_mixin> isck1{"isck1"}; + scc::router router{"router", 6, 2}; + scc::memory_tl<1_kB, scc::LT> mem0{"mem0"}; + scc::memory_tl<1_kB, scc::LT> mem1{"mem1"}; + scc::memory_tl<18_MB, scc::LT> mem2{"mem2"}; + scc::memory_tl<24_MB, scc::LT> mem3{"mem3"}; + scc::memory_tl<88_MB, scc::LT> mem4{"mem4"}; + scc::memory<4_GB> mem5{"mem5"}; + + testbench() + : testbench(sc_core::sc_gen_unique_name("testbench", false)) {} + + testbench(sc_core::sc_module_name const& nm) + : sc_module(nm) { + isck0(router.target[0]); + isck1(router.target[1]); + router.set_initiator_base(1, 1_MB); + router.bind_target(mem0.target, 0, 0, 1_kB); + router.bind_target(mem1.target, 1, 1_kB, 1_kB); + router.bind_target(mem2.target, 2, 16_MB, 16_MB); + router.bind_target(mem3.target, 3, 32_MB, 20_MB); + router.bind_target(mem4.target, 4, 64_MB, 20_MB, false); + router.initiator[5].bind(mem5.target); + router.set_default_target(5); + mem0.clk_i(clk); + mem1.clk_i(clk); + mem2.clk_i(clk); + mem3.clk_i(clk); + mem4.clk_i(clk); + } + void start_of_simulation() { clk = 10_ns; } +}; +} // namespace scc +#endif // _TESTBENCH_H_ diff --git a/tests/ordered_semaphore/CMakeLists.txt b/tests/ordered_semaphore/CMakeLists.txt index cf2d27d..334a28f 100644 --- a/tests/ordered_semaphore/CMakeLists.txt +++ b/tests/ordered_semaphore/CMakeLists.txt @@ -6,4 +6,6 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/quantum_keeper_mt/CMakeLists.txt b/tests/quantum_keeper_mt/CMakeLists.txt new file mode 100644 index 0000000..980c0ca --- /dev/null +++ b/tests/quantum_keeper_mt/CMakeLists.txt @@ -0,0 +1,5 @@ +if(SC_VERSION_MAJOR GREATER 2) + add_executable (quantum_keeper_mt sc_main.cpp) + target_link_libraries (quantum_keeper_mt LINK_PUBLIC scc::components) + add_test(NAME quantum_keeper_mt COMMAND quantum_keeper_mt) +endif() \ No newline at end of file diff --git a/tests/quantum_keeper_mt/sc_main.cpp b/tests/quantum_keeper_mt/sc_main.cpp new file mode 100644 index 0000000..34a1961 --- /dev/null +++ b/tests/quantum_keeper_mt/sc_main.cpp @@ -0,0 +1,49 @@ +#include "top_module.h" +#include "util/logging.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace scc; +using namespace sc_core; + +jmp_buf abrt; +void ABRThandler(int sig) { longjmp(abrt, 1); } + +int sc_main(int argc, char* argv[]) { + signal(SIGABRT, ABRThandler); + auto my_name = util::split(argv[0], '/').back(); + auto level = getenv("SCC_TEST_VERBOSE"); + auto log_lvl = level ? static_cast(std::min(strtoul(level, nullptr, 10), 7UL)) : log::FATAL; + scc::init_logging(LogConfig().logLevel(log_lvl).logAsync(false).msgTypeFieldWidth(35).printSysTime()); + scc::configurer cfg(""); + // create tracer if environment variable SCC_TEST_TRACE is defined + std::unique_ptr tracer; + if(auto* test_trace = getenv("SCC_TEST_TRACE")) { + tracer = std::make_unique(my_name, scc::tracer::ENABLE, scc::tracer::ENABLE); + tracer->set_default_trace_enable(true); + } + int result = -1; + tlm_utils::tlm_quantumkeeper::set_global_quantum(3_us); + if(setjmp(abrt) == 0) { + // instantiate design(s) + top_module top_mod("top_module_inst"); + // Start the simulation + sc_core::sc_start(20_us); + if(sc_core::sc_is_running()) + sc_core::sc_stop(); + SCCINFO() << "Simulation finished"; + } else { + SCCERR() << "Some error occured"; + } + return sc_core::sc_report_handler::get_count(sc_core::SC_ERROR) + sc_core::sc_report_handler::get_count(sc_core::SC_WARNING); +} diff --git a/tests/quantum_keeper_mt/top_module.h b/tests/quantum_keeper_mt/top_module.h new file mode 100644 index 0000000..a08e34e --- /dev/null +++ b/tests/quantum_keeper_mt/top_module.h @@ -0,0 +1,111 @@ +#ifndef _TOP_MODULE_H_ +#define _TOP_MODULE_H_ + +#include "scc/mt19937_rng.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { CLIENT_DELAY = 100, SC_DELAY = 10 }; + +struct initiator : ::sc_core ::sc_module { + tlm_utils::simple_initiator_socket isckt{"isckt"}; + + initiator(sc_core::sc_module_name nm, sc_core::sc_time period = 1_us) + : sc_core::sc_module(nm) + , period(period) { + SC_THREAD(run); + } + + ~initiator() = default; + +private: + void run() { + wait(sc_core::SC_ZERO_TIME); // guard elaboration phase + quantum_keeper.reset(); + core_executor.start([this]() { return thread_exec(); }); + wait(core_executor.thread_finish_event()); + sc_core::sc_stop(); + } + + sc_core::sc_time thread_exec() { + SCCDEBUG(SCMOD) << "starting thread_exec"; + for(auto i = 0u; i < 16; ++i) { + std::this_thread::sleep_for(std::chrono::milliseconds(CLIENT_DELAY)); + if(i && (i % 3) == 0) { + tlm::tlm_generic_payload gp; + sc_core::sc_time t; + SCCDEBUG(SCMOD) << "initiating b_transport at local time " << quantum_keeper.get_local_absolute_time(); + quantum_keeper.execute_on_sysc([this, &gp, &t]() { + SCCDEBUG(SCMOD) << "executing b_transport"; + this->isckt->b_transport(gp, t); + }); + if(t.value()) { + SCCDEBUG(SCMOD) << "incrementing local time by b_transport delay of " << t; + quantum_keeper.inc(t); + } + } else { + quantum_keeper.check_and_sync(period); + } + SCCDEBUG(SCMOD) << "local time now " << quantum_keeper.get_local_absolute_time(); + } + SCCDEBUG(SCMOD) << "finished thread_exec at local time " << quantum_keeper.get_local_absolute_time(); + return quantum_keeper.get_local_absolute_time(); + } + tlm::scc::quantumkeeper_mt quantum_keeper; + scc::async_thread core_executor; + const sc_core::sc_time period{1_us}; +}; + +// top_module +struct top_module : ::sc_core ::sc_module { + initiator core0{"core0"}; + initiator core1{"core1", 1500_ns}; + scc::router router{"router", 1, 2}; + + tlm_utils::simple_target_socket tsckt{"tsckt"}; + + top_module(sc_core::sc_module_name nm) + : sc_core::sc_module(nm) { + core0.isckt(router.target[0]); + core1.isckt(router.target[1]); + router.initiator[0](tsckt); + router.set_default_target(0); + tsckt.register_b_transport(this, &top_module::b_transport); + SC_THREAD(run); + } + + ~top_module() = default; + + void b_transport(tlm::tlm_generic_payload& gp, sc_core::sc_time& t) { + SCCDEBUG(SCMOD) << "Received b_transport call at local time " << t; + auto cycles = rng.uniform(0, 5); + t += sc_core::sc_time(cycles, sc_core::SC_US); + gp.set_response_status(tlm::TLM_OK_RESPONSE); + } + + void run() { + wait(sc_core::SC_ZERO_TIME); + while(true) { + std::this_thread::sleep_for(std::chrono::milliseconds(SC_DELAY)); + wait(500_ns); + } + } + + scc::MT19937 rng; +}; +#endif // _TOP_MODULE_H_ diff --git a/tests/sim_speed/CMakeLists.txt b/tests/sim_speed/CMakeLists.txt new file mode 100644 index 0000000..8516c5c --- /dev/null +++ b/tests/sim_speed/CMakeLists.txt @@ -0,0 +1,3 @@ +project (sim_speed) +add_executable(${PROJECT_NAME} sc_main.cpp) +target_link_libraries (${PROJECT_NAME} LINK_PUBLIC scc-sysc) diff --git a/tests/sim_speed/sc_main.cpp b/tests/sim_speed/sc_main.cpp new file mode 100644 index 0000000..a9936b7 --- /dev/null +++ b/tests/sim_speed/sc_main.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +using namespace sc_core; + +int sc_main(int argc, char* argv[]) { + const uint64_t NS_VAL = 100000000; + + sc_clock clk("clk", 1, SC_NS); + sc_time run_time(NS_VAL, SC_NS); + + auto start = std::chrono::high_resolution_clock::now(); + sc_start(run_time); + auto end = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast(end - start); + + double simulated_cycles = (double)NS_VAL; + double real_us = duration.count(); + double speed_Mhz = simulated_cycles / real_us; + std::cout << "Simulation speed: " << speed_Mhz << " MHz\n"; + + return 0; +} diff --git a/tests/tlm_memory/CMakeLists.txt b/tests/tlm_memory/CMakeLists.txt new file mode 100644 index 0000000..31e2864 --- /dev/null +++ b/tests/tlm_memory/CMakeLists.txt @@ -0,0 +1,10 @@ +project (tlm_memory) +add_executable(${PROJECT_NAME} + memory_test.cpp + ${test_util_SOURCE_DIR}/sc_main.cpp +) +target_link_libraries (${PROJECT_NAME} PUBLIC scc::components test_util) + +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/tlm_memory/memory_test.cpp b/tests/tlm_memory/memory_test.cpp new file mode 100644 index 0000000..f07c0cc --- /dev/null +++ b/tests/tlm_memory/memory_test.cpp @@ -0,0 +1,137 @@ + +#include "testbench.h" +#include +#include +#undef CHECK +#include +#include +#include +#include +#include + +using namespace sc_core; +namespace scc { +factory::add tb; + +template void prepare_trans(tlm::tlm_generic_payload& trans, tlm::tlm_command cmd, uint64_t addr, T val) { + unsigned len = cmd == tlm::TLM_IGNORE_COMMAND ? 0 : sizeof(val); + unsigned char* data = len ? new unsigned char[len] : nullptr; + if(cmd == tlm::TLM_WRITE_COMMAND) { + memcpy(data, &val, len); + trans.set_command(cmd); + } + if(cmd == tlm::TLM_READ_COMMAND) { + memset(data, 0, len); + trans.set_command(tlm::TLM_READ_COMMAND); + } + trans.set_address(addr); + trans.set_data_ptr(data); + trans.set_data_length(len); + trans.set_streaming_width(len); + trans.set_response_status(tlm::TLM_INCOMPLETE_RESPONSE); +} + +TEST_CASE("simple_read_write_with host memory map", "[memory][tlm-level]") { + auto& dut = factory::get(); + std::array ref_data; + auto val = 256; + for(auto& e : ref_data) + e = --val; + dut.rst.write(true); + sc_start(10 * dut.clk.read()); + dut.rst.write(false); + sc_start(dut.clk.read()); + { + tlm::tlm_generic_payload gp; + sc_core::sc_time t; + for(uint64_t addr = 0; addr < 1024; addr += sizeof(uint64_t)) { + prepare_trans(gp, tlm::TLM_WRITE_COMMAND, addr, 123456789ULL); + dut.isck->b_transport(gp, t); + delete gp.get_data_ptr(); + sc_start(dut.clk.read()); + } + } + { + tlm::tlm_generic_payload gp; + prepare_trans(gp, tlm::TLM_READ_COMMAND, 256, 0ULL); + sc_core::sc_time t; + dut.isck->b_transport(gp, t); + uint64_t res; + memcpy(&res, gp.get_data_ptr(), sizeof(uint64_t)); + REQUIRE(res == 123456789ULL); + delete gp.get_data_ptr(); + } + sc_start(dut.clk.read()); + { + tlm::tlm_generic_payload gp; + gp.set_command(tlm::TLM_IGNORE_COMMAND); + gp.set_address(256); + gp.set_data_ptr(nullptr); + gp.set_data_length(256); + gp.set_streaming_width(256); + gp.set_response_status(tlm::TLM_INCOMPLETE_RESPONSE); + auto ext = new scc::host_mem_map_extension(ref_data.data()); + gp.set_extension(ext); + dut.isck->transport_dbg(gp); + } + sc_start(dut.clk.read()); + { + tlm::tlm_generic_payload gp; + prepare_trans(gp, tlm::TLM_READ_COMMAND, 256, 0ULL); + sc_core::sc_time t; + dut.isck->b_transport(gp, t); + uint64_t res; + memcpy(&res, gp.get_data_ptr(), sizeof(uint64_t)); + REQUIRE(res == 0xf8f9fafbfcfdfeffULL); + delete gp.get_data_ptr(); + } + sc_start(dut.clk.read()); + { + tlm::tlm_generic_payload gp; + prepare_trans(gp, tlm::TLM_READ_COMMAND, 384, 0ULL); + sc_core::sc_time t; + dut.isck->b_transport(gp, t); + uint64_t res; + memcpy(&res, gp.get_data_ptr(), sizeof(uint64_t)); + REQUIRE(res == 0x78797a7b7c7d7e7fULL); + delete gp.get_data_ptr(); + } + sc_start(dut.clk.read()); + { + tlm::tlm_generic_payload gp; + gp.set_command(tlm::TLM_IGNORE_COMMAND); + gp.set_address(256); + gp.set_data_ptr(nullptr); + gp.set_data_length(256); + gp.set_streaming_width(256); + gp.set_response_status(tlm::TLM_INCOMPLETE_RESPONSE); + auto ext = new scc::host_mem_map_extension(nullptr); + gp.set_extension(ext); + dut.isck->transport_dbg(gp); + } + sc_start(dut.clk.read()); + { + tlm::tlm_generic_payload gp; + prepare_trans(gp, tlm::TLM_READ_COMMAND, 256, 0ULL); + sc_core::sc_time t; + dut.isck->b_transport(gp, t); + uint64_t res; + memcpy(&res, gp.get_data_ptr(), sizeof(uint64_t)); + REQUIRE(res == 123456789ULL); + delete gp.get_data_ptr(); + } + sc_start(dut.clk.read()); + { + tlm::tlm_generic_payload gp; + prepare_trans(gp, tlm::TLM_READ_COMMAND, 256, 0ULL); + sc_core::sc_time t; + dut.isck->b_transport(gp, t); + uint64_t res; + memcpy(&res, gp.get_data_ptr(), sizeof(uint64_t)); + REQUIRE(res == 123456789ULL); + delete gp.get_data_ptr(); + } + sc_start(dut.clk.read()); +} + +} // namespace scc diff --git a/tests/tlm_memory/testbench.h b/tests/tlm_memory/testbench.h new file mode 100644 index 0000000..4f0b721 --- /dev/null +++ b/tests/tlm_memory/testbench.h @@ -0,0 +1,42 @@ +#ifndef _TESTBENCH_H_ +#define _TESTBENCH_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace sc_core; +using namespace sc_dt; +using namespace std; +namespace scc { + +const char* sc_gen_unique_name(const char*, bool preserve_first); +struct testbench : public sc_core::sc_module { + + using transaction_type = tlm::tlm_base_protocol_types::tlm_payload_type; + using phase_type = tlm::tlm_base_protocol_types::tlm_phase_type; + + sc_core::sc_signal clk{"clk"}; + sc_core::sc_signal rst{"rst"}; + tlm::scc::initiator_mixin> isck{"isck"}; + scc::memory_tl<1_kB, scc::LT> mem{"mem"}; + + testbench() + : testbench(sc_core::sc_gen_unique_name("testbench", false)) {} + + testbench(sc_core::sc_module_name const& nm) + : sc_module(nm) { + isck(mem.target); + mem.clk_i(clk); + } + void start_of_simulation() { clk = 10_ns; } +}; +} // namespace scc +#endif // _TESTBENCH_H_