From 12bc5f573cd5495dd3755ff216fa87ad3ebac4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20Miku=C4=8Dionis?= Date: Thu, 11 Apr 2024 13:32:05 +0200 Subject: [PATCH] Added leak sanitizer and refactored test for feature-checker --- cmake/sanitizers.cmake | 9 ++++++++- test/featurechecker.cpp | 44 +++++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/cmake/sanitizers.cmake b/cmake/sanitizers.cmake index 2c0e2277..8a4d41f1 100644 --- a/cmake/sanitizers.cmake +++ b/cmake/sanitizers.cmake @@ -4,6 +4,7 @@ option(SSP "Stack Smashing Protector" OFF) # Available on Windows too option(UBSAN "Undefined Behavior Sanitizer" OFF) option(ASAN "Address Sanitizer" OFF) +option(LSAN "Leak Sanitizer" OFF) option(TSAN "Thread Sanitizer" OFF) if (SSP) @@ -12,7 +13,7 @@ if (SSP) message(STATUS "Enable Stack Smashing Protector") endif(SSP) -if (ASAN OR UBSAN OR TSAN) +if (ASAN OR UBSAN OR LSAN OR TSAN) add_compile_options(-fno-omit-frame-pointer) add_link_options(-fno-omit-frame-pointer) endif() @@ -29,6 +30,12 @@ if (ASAN) message(STATUS "Enabled Address Sanitizer") endif(ASAN) +if (LSAN) + add_compile_options(-fsanitize=leak) + add_link_options(-fsanitize=leak) + message(STATUS "Enabled Leak Sanitizer") +endif(LSAN) + if (TSAN) add_compile_options(-fsanitize=thread) add_link_options(-fsanitize=thread) diff --git a/test/featurechecker.cpp b/test/featurechecker.cpp index f74a9b64..172d0d21 100644 --- a/test/featurechecker.cpp +++ b/test/featurechecker.cpp @@ -24,32 +24,42 @@ #include "utap/utap.h" +#include #include #include +#include int main(int argc, char** argv) { - const auto& command = argv[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) Pretty hard to avoid + const auto command = std::filesystem::path{argv[0]}.filename().string(); if (argc != 2) { - std::cout - << "UPPAAL feature checker - Check which features are supported by the UPPAAL Model Checker for a given TA" - << std::endl; - std::cout << "Usage: " << command << " [filename]" << std::endl; + std::cerr << command << " checks which features are supported by UPPAAL for a given model\n" + << "Usage: " << command << " [model-file-path]" << std::endl; return 1; } - const auto& filename = argv[1]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) Pretty hard to avoid - std::ifstream ifs(filename); - std::string content((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + for (auto i = 1u; i < argc; ++i) { + auto path = std::filesystem::path{argv[i]}; + try { + if (!exists(path)) + throw std::system_error{ENOENT, std::system_category(), path.string()}; + auto ifs = std::ifstream{}; + ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit); + ifs.open(path); + auto content = std::string{std::istreambuf_iterator{ifs}, std::istreambuf_iterator{}}; - auto document = std::make_unique(); - parse_XML_buffer(content.c_str(), document.get(), true); - UTAP::FeatureChecker checker(*document); - const auto& type = checker.get_supported_methods(); + auto document = std::make_unique(); + parse_XML_buffer(content.c_str(), document.get(), true); + auto checker = UTAP::FeatureChecker{*document}; + const auto& type = checker.get_supported_methods(); - std::cout << "UTAP feature checker" << std::endl; - std::cout << "Checking file: " << filename << std::endl; + std::cout << "UTAP feature checker" << std::endl; + std::cout << "Checking file: " << path << std::endl; - std::cout << "Supports symbolic: " << type.symbolic << std::endl; - std::cout << "Supports concrete: " << type.concrete << std::endl; - std::cout << "Supports stochastic: " << type.stochastic << std::endl; + std::cout << "Supports symbolic: " << type.symbolic << std::endl; + std::cout << "Supports concrete: " << type.concrete << std::endl; + std::cout << "Supports stochastic: " << type.stochastic << std::endl; + } catch (std::exception& ex) { + std::cerr << "Failed to process " << path << ":\n" << ex.what() << std::endl; + } + } }