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

Added leak sanitizer and refactored test for feature-checker #75

Merged
merged 2 commits into from
Apr 12, 2024
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
9 changes: 8 additions & 1 deletion cmake/sanitizers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand Down
44 changes: 27 additions & 17 deletions test/featurechecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,42 @@

#include "utap/utap.h"

#include <filesystem>
#include <fstream>
#include <iostream>
#include <system_error>

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<char>(ifs)), (std::istreambuf_iterator<char>()));
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<char>{ifs}, std::istreambuf_iterator<char>{}};

auto document = std::make_unique<UTAP::Document>();
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<UTAP::Document>();
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;
}
}
}
Loading