From 3a046a84677b59a096563d5616818ecb87848746 Mon Sep 17 00:00:00 2001 From: Rui Costa Date: Sat, 3 May 2025 17:25:34 +0100 Subject: [PATCH 1/3] add cmake presets and update gitignore --- .gitignore | 3 +- CMakePresets.json | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 CMakePresets.json diff --git a/.gitignore b/.gitignore index e2f2ac01..ad746b37 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ release/ *.orig *~ .idea - +.cache +compile_commands.json diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000..96498875 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,79 @@ +{ + "version": 7, + "cmakeMinimumRequired": { + "major": 3, + "minor": 23, + "patch": 0 + }, + "configurePresets": [ + { + "name": "common", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "installDir": "${sourceDir}/build/${presetName}/install", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "DLT_APP_DIR_NAME": "DLTViewer", + "DLT_EXECUTABLE_INSTALLATION_PATH": "DLTViewer/usr/bin", + "DLT_LIBRARY_INSTALLATION_PATH": "DLTViewer/usr/lib", + "DLT_PARSER": "OFF", + "DLT_PLUGIN_INSTALLATION_PATH": "DLTViewer/usr/bin/plugins", + "DLT_RESOURCE_INSTALLATION_PATH": "DLTViewer/usr/share", + "DLT_USE_QT_RPATH": "ON" + } + }, + { + "name": "debug-gcc", + "inherits": "common", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + } + }, + { + "name": "release-gcc", + "inherits": "common", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + } + }, + { + "name": "relwithdebinfo-gcc", + "inherits": "common", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + } + }, + { + "name": "relwithdebinfo-clang", + "inherits": "common", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + } + } + ], + "buildPresets": [ + { + "name": "build-debug-gcc", + "description": "", + "displayName": "", + "configurePreset": "debug-gcc" + } + ], + "testPresets": [ + { + "name": "test-debug-gcc", + "description": "", + "displayName": "", + "configurePreset": "debug-gcc" + } + ] +} From 83c219bfcb92561ab88ab8036e18eba8bba76ad4 Mon Sep 17 00:00:00 2001 From: Rui Costa Date: Sat, 10 May 2025 12:50:59 +0100 Subject: [PATCH 2/3] add benchmark for DltFileIndexer::run --- qdlt/qdltfile.cpp | 2 +- src/CMakeLists.txt | 25 +++++++++++++++++++++--- src/benchmark/CMakeLists.txt | 6 ++++++ src/benchmark/bench_dltfileindexer.cpp | 26 +++++++++++++++++++++++++ src/benchmark/testfile.dlt | Bin 0 -> 4474 bytes src/mainwindow.cpp | 2 +- 6 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 src/benchmark/CMakeLists.txt create mode 100644 src/benchmark/bench_dltfileindexer.cpp create mode 100644 src/benchmark/testfile.dlt diff --git a/qdlt/qdltfile.cpp b/qdlt/qdltfile.cpp index a61e4f65..f7007619 100644 --- a/qdlt/qdltfile.cpp +++ b/qdlt/qdltfile.cpp @@ -132,7 +132,7 @@ int QDltFile::sizeFilter() const bool QDltFile::open(QString _filename, bool append) { - qDebug() << "Open file" << _filename << "started"; + // qDebug() << "Open file" << _filename << "started"; /* check if file is already opened */ if(!append) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 73678316..c08ba341 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,8 +18,7 @@ else() QT5_ADD_RESOURCES(UI_RESOURCES_RCC resources/resource.qrc) endif() -add_executable(dlt-viewer - main.cpp +add_library(dlt_common mainwindow.cpp project.cpp ecudialog.cpp @@ -55,13 +54,23 @@ add_executable(dlt-viewer ecutree.cpp ) -target_link_libraries(dlt-viewer +target_link_libraries(dlt_common qdlt ${QT_PREFIX}::Core ${QT_PREFIX}::Network ${QT_PREFIX}::Widgets ${QT_PREFIX}::SerialPort) +target_include_directories(dlt_common + PUBLIC + . + $ + $ +) + +add_executable(dlt-viewer main.cpp) +target_link_libraries(dlt-viewer PRIVATE dlt_common) + if(CMAKE_COMPILER_IS_GNUCXX) # https://stackoverflow.com/questions/45329372/ubuntu-recognizes-executable-as-shared-library-and-wont-run-it-by-clicking # https://forum.juce.com/t/cmake-executable-build-shows-up-as-shared-library-on-linux-mint/45503/6 @@ -108,3 +117,13 @@ install(DIRECTORY COMPONENT dlt_viewer) include(cmake/${CMAKE_SYSTEM_NAME}.cmake OPTIONAL) + +find_package(GTest) +# configure unit tests only if gtest found on the system +if (GTest_FOUND) + message(STATUS "Tests enabled") + enable_testing() + add_subdirectory(tests) +endif() + +add_subdirectory(benchmark) \ No newline at end of file diff --git a/src/benchmark/CMakeLists.txt b/src/benchmark/CMakeLists.txt new file mode 100644 index 00000000..c16b23d5 --- /dev/null +++ b/src/benchmark/CMakeLists.txt @@ -0,0 +1,6 @@ +find_package(benchmark REQUIRED) + +add_executable(bench_dltfileindexer bench_dltfileindexer.cpp) +target_link_libraries(bench_dltfileindexer PRIVATE benchmark::benchmark dlt_common qdlt) + +file(COPY testfile.dlt DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ ) diff --git a/src/benchmark/bench_dltfileindexer.cpp b/src/benchmark/bench_dltfileindexer.cpp new file mode 100644 index 00000000..59da1f3f --- /dev/null +++ b/src/benchmark/bench_dltfileindexer.cpp @@ -0,0 +1,26 @@ +#include "dltfileindexer.h" +#include "qdltfile.h" + +#include + +#include + +static void DoSetup(const benchmark::State& /*state*/) { std::filesystem::remove_all("index/"); } + + +static void BN_dltfileindexer_run(benchmark::State& state) { + QString filename = "testfile.dlt"; + for (auto _ : state) { + QDltFile dltFile{}; + dltFile.open(filename); + QDltPluginManager pluginManager; + pluginManager.loadPlugins(QString{}); + + DltFileIndexer fileIndexer{&dltFile, &pluginManager, nullptr, nullptr}; + fileIndexer.setFilterCacheEnabled(true); + fileIndexer.run(); + } +} +BENCHMARK(BN_dltfileindexer_run)->Setup(DoSetup); + +BENCHMARK_MAIN(); diff --git a/src/benchmark/testfile.dlt b/src/benchmark/testfile.dlt new file mode 100644 index 0000000000000000000000000000000000000000..f77621c6b9cc00f605e47472a8daf7b05ccc3db6 GIT binary patch literal 4474 zcma)<$!^p@5QfVhk28yB2^oeEwqa3N!j?=}B}hzyl0aAlL7Z8JH6aolkhsDDAub%? z0eA{tfqh>d0deKRk-yw_(u+rJORbh%-(THs*SP+foSkz9cfLOL>t#U4Coa%Fq76Kc zJ-&Rn>4ay`(!`n5)JsI(-Oj?|WF~wCaO#4uF|!vzJ1Ln{&@yLcbO?KX@Y{*@ypgCH z((IWjnmc}e*oZpR2%RK)4En!0gK=s7GD9v=iKaXA^NX!xr!J~qVcbchO7bJtK|~d)6hoP|E}s{_%04UZN`NJMP_#dIr;&e33)lj-d- zy(6B7(o`Pp4n0}bj_J{O#+N5rbAOsTPy55XtUeOcN8@=cp2y>vf0f2_`gAn(o zx}2`dWz%`O4#k*dy}Yi=XVdw*&d;Xn(RDr9bOl{k$fhgmI__T?-d{=Am9pu|x-M#h z_Ilwjno?&$w)HByu98hx)pgZux|*)5Wz*Gl9ruF_@1a-MvAapvjpFw{UiDOG^ki|c zi!-w0iZjx1VRw}5OU}rSMn%Ejr~}yZzhU8wT115o9?rP$Q0W@(3n!!~Txzfl(fyCY z5EWm8iCm8oK-xD52(P0=TngSIk~kbCmZSPR#AIKi#62p$M?7*fN+3_A4+sbkqeOfP zJ|c1(!+7={s(-?L*{>+t0tKHDPh5%;D^ll qHU!zQlPd+uUlq&hO+hy8Z` literal 0 HcmV?d00001 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 176802d8..e40b9bd1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2350,7 +2350,7 @@ void MainWindow::applySettings() if(dltIndexer) dltIndexer->setFilterCacheEnabled(settings->filterCache); - // set DLT message chache size + // set DLT message cache size qfile.setCacheSize(settings->msgCacheSize); // set DLTv2 Support From 67e1c0f56c07dc3d58eae72fdca2d4dabfae9a99 Mon Sep 17 00:00:00 2001 From: Rui Costa Date: Sat, 5 Jul 2025 11:36:12 +0100 Subject: [PATCH 3/3] update branch --- .vscode/launch.json | 74 +++++++++++++++++++++ .vscode/settings.json | 5 ++ .vscode/tasks.json | 44 +++++++++++++ CMakePresets.json | 3 +- qdlt/tests/CMakeLists.txt | 17 +++++ qdlt/tests/test_parse_dlt_file.cpp | 85 +++++++++++++++++++++++++ qdlt/tests/testfile_10.dlt | Bin 0 -> 1800 bytes scripts/linux/version.cmake | 4 +- src/benchmark/CMakeLists.txt | 1 + src/benchmark/bench_dltfileindexer.cpp | 2 +- src/tests/CMakeLists.txt | 12 ++++ src/tests/test_dltfileindexer.cpp | 42 ++++++++++++ 12 files changed, 284 insertions(+), 5 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 qdlt/tests/test_parse_dlt_file.cpp create mode 100644 qdlt/tests/testfile_10.dlt create mode 100644 src/tests/CMakeLists.txt create mode 100644 src/tests/test_dltfileindexer.cpp diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..63e733db --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,74 @@ +{ + "configurations": [ + { + "name": "CPPDBG: Debug cmake launch target", + "type": "cppdbg", + "request": "launch", + "program": "${command:cmake.getLaunchTargetPath}", + "stopAtEntry": false, + "cwd": "${command:cmake.getLaunchTargetDirectory}", + "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 + } + ], + "miDebuggerPath": "/usr/bin/gdb", + "preLaunchTask": "CMake: build" + }, + { + "name": "CPPDBG: Debug dtl-viewer", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/${command:cmake.activeConfigurePresetName}/bin/dlt-viewer", + "args": [ + "${input:dltFile}" + ], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "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 + } + ], + "miDebuggerPath": "/usr/bin/gdb", + "preLaunchTask": "Delete dlt index folder" + }, + ], + "inputs": [ + { + "type": "pickString", + "id": "dltFile", + "description": "Choose dlt file", + "options": [ + "${env:HOME}/dlt/medium.dlt", + "${env:HOME}/dlt/big.dlt", + "${env:HOME}/dlt/test.dlt", + "${command:cmake.buildDirectory}/qdlt/tests/testfile_10.dlt", + "${command:cmake.buildDirectory}/src/benchmark/testfile.dlt", + "${command:cmake.buildDirectory}/src/benchmark/big.dlt", + ], + "default": "component" + }, + ], + "version": "2.0.0" +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..70a58793 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "streambuf": "cpp" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..bbda0044 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,44 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Delete dlt index folder", + "type": "shell", + "command": "rm", + "args": [ + "-f", + "~/dlt/index/*", + ], + "problemMatcher": [] + }, + { + "label": "Delete index folder", + "type": "shell", + "command": "rm", + "args": [ + "-rf", + "${command:cmake.buildDirectory}/index", + ], + "problemMatcher": [] + }, + { + "label": "CMake: build", + "type": "shell", + "command": "cmake", + "args": [ + "--build", + "${command:cmake.buildDirectory}", + ], + "problemMatcher": [] + }, + { + "label": "Delete Index and Build", + "dependsOn": [ + "Delete index folder", + "CMake: build" + ], + "problemMatcher": [], + "dependsOrder": "sequence" + } + ] +} \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index 96498875..37a8410e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,5 +1,5 @@ { - "version": 7, + "version": 6, "cmakeMinimumRequired": { "major": 3, "minor": 23, @@ -13,7 +13,6 @@ "binaryDir": "${sourceDir}/build/${presetName}", "installDir": "${sourceDir}/build/${presetName}/install", "cacheVariables": { - "CMAKE_BUILD_TYPE": "RelWithDebInfo", "DLT_APP_DIR_NAME": "DLTViewer", "DLT_EXECUTABLE_INSTALLATION_PATH": "DLTViewer/usr/bin", "DLT_LIBRARY_INSTALLATION_PATH": "DLTViewer/usr/lib", diff --git a/qdlt/tests/CMakeLists.txt b/qdlt/tests/CMakeLists.txt index 63408235..9d22f628 100644 --- a/qdlt/tests/CMakeLists.txt +++ b/qdlt/tests/CMakeLists.txt @@ -47,3 +47,20 @@ add_test( NAME test_qdltargument COMMAND $ ) + + +add_executable(test_parse_dlt_file + test_parse_dlt_file.cpp +) +target_link_libraries( + test_parse_dlt_file + PRIVATE + GTest::gtest_main + qdlt +) +add_test( + NAME test_parse_dlt_file + COMMAND $ +) +file(COPY testfile_10.dlt DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) + diff --git a/qdlt/tests/test_parse_dlt_file.cpp b/qdlt/tests/test_parse_dlt_file.cpp new file mode 100644 index 00000000..86a471c9 --- /dev/null +++ b/qdlt/tests/test_parse_dlt_file.cpp @@ -0,0 +1,85 @@ +#include "dlt_common.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define DLT_DAEMON_TEXTSIZE 10024 + +// TEST(ParseDltFile, initialize_open_free) { +// DltFile file; +// static char text[DLT_DAEMON_TEXTSIZE]; +// /* Get PWD so file can be used*/ +// std::filesystem::path openfile{std::filesystem::current_path() / "testfile_10.dlt"}; +// std::filesystem::path output{"/tmp/output_testfile_10.txt"}; +// +// /* Normal Use-Case, expected 0 */ +// EXPECT_LE(0, dlt_file_init(&file, 0)); +// EXPECT_LE(0, dlt_file_open(&file, openfile.c_str(), 0)); +// +// while (dlt_file_read(&file, 0) >= 0) { +// // throw std::exception{}; +// } +// +// for (int i = 0; i < file.counter; i++) { +// EXPECT_LE(0, dlt_file_message(&file, i, 0)); +// EXPECT_LE(0, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); +// } +// +// // for (int i = 0; i < file.counter; i++) { +// // EXPECT_LE(0, dlt_file_message(&file, i, 0)); +// // EXPECT_LE(0, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); +// // } +// +// EXPECT_LE(0, dlt_file_free(&file, 0)); +// } + +TEST(ParseDltFile, memory_mapped_file) { + using namespace boost::interprocess; + + // Define file names + const char* FileName = "testfile_10.dlt"; + + // Open the file mapping and map it as read-only + boost::interprocess::file_mapping m_file(FileName, read_only); + + mapped_region region(m_file, read_only); + + // Get the address of the mapped region + void* addr = region.get_address(); + std::size_t size = region.get_size(); + + // Check that memory was initialized to 1 + const char* mem = static_cast(addr); + for (std::size_t i = 0; i < size; ++i) + if (*mem++ != 1) + std::cout << *mem; +} + +// TEST(ParseDltFile, filebuffer) { +// // Define file names +// const char* FileName = "testfile_10.dlt"; +// const std::size_t FileSize = 10000; +// +// // Now test it reading the file +// std::filebuf fbuf; +// fbuf.open(FileName, std::ios_base::in | std::ios_base::binary); +// +// // Read it to memory +// std::vector vect(FileSize, 0); +// fbuf.sgetn(&vect[0], std::streamsize(vect.size())); +// +// // Check that memory was initialized to 1 +// const char* mem = static_cast(&vect[0]); +// for (std::size_t i = 0; i < FileSize; ++i) +// if (*mem++ != 1) +// std::cout << *mem; +// } diff --git a/qdlt/tests/testfile_10.dlt b/qdlt/tests/testfile_10.dlt new file mode 100644 index 0000000000000000000000000000000000000000..fed795494a5aed65f0de2912ba0ce430dc99848a GIT binary patch literal 1800 zcmd7Mu}T9$5C-7A%O#gQfR%**&?qcH;XeWro%EB&S zYiVl1O0cjNY(&r}@Pbn~Z?Mz+#qj@pgCq^UX5-`ciC<|OmyAD}d7@1jVT@75QN|{U*6Og%To<@qM z08%-lO958uswt}?Q$h(>Sa23{e$>o^w13kQG@le4c&<(y-(UkY?_Z)hAm&qQ4i;>0 z%qur&4vG1knj5Z1=G|K~w}^R4%`LCYANOdEh +#include + +#include + +class TestDltFileIndexer : public QObject { + Q_OBJECT + private slots: + void initTestCase() { std::filesystem::remove_all("index/"); } + + void constructor() { QVERIFY_THROWS_NO_EXCEPTION(DltFileIndexer{}); } + + void constructor_withargs() { + QDltFile qfile{}; + QDltPluginManager pluginManager{}; + QDltDefaultFilter defaultFilter{}; + DltFileIndexer fileIndexert{&qfile, &pluginManager, &defaultFilter, nullptr}; + } + + void run() { + QString filename = "testfile.dlt"; + QDltFile dltFile{}; + dltFile.open(filename); + QDltPluginManager pluginManager; + pluginManager.loadPlugins(QString{}); + + DltFileIndexer fileIndexer{&dltFile, &pluginManager, nullptr, nullptr}; + fileIndexer.setFilterCacheEnabled(true); + fileIndexer.run(); + + // QVERIFY(result); + } +}; + +QTEST_MAIN(TestDltFileIndexer) +#include "test_dltfileindexer.moc"