mirror of
https://github.com/hyprwm/hyprlang.git
synced 2024-11-16 18:25:57 +01:00
CI: fuzz and sanitize
This commit is contained in:
parent
55e6ca0e67
commit
eb9cdea176
5 changed files with 150 additions and 21 deletions
115
.github/workflows/arch.yml
vendored
115
.github/workflows/arch.yml
vendored
|
@ -19,22 +19,102 @@ jobs:
|
||||||
pacman --noconfirm --noprogressbar -Syyu
|
pacman --noconfirm --noprogressbar -Syyu
|
||||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
||||||
|
|
||||||
- name: Build with gcc
|
- name: Build hyprlang with gcc
|
||||||
run: |
|
run: |
|
||||||
CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build
|
CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
||||||
CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --build ./build --config Release --target hyprlang -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||||
cp ./build/libhyprlang.so /usr/lib
|
cmake --install ./build
|
||||||
|
|
||||||
- name: Build with clang
|
- name: Build tests with clang
|
||||||
run: |
|
run: |
|
||||||
rm -rf ./build
|
rm -rf ./build
|
||||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build
|
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
||||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --build ./build --config Release --target tests -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||||
rm ./build/libhyprlang.so
|
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
cd ./tests && ../build/hyprlang_test
|
cd ./build && ctest --output-on-failure
|
||||||
|
|
||||||
|
asan:
|
||||||
|
name: "gcc build / ASan tests"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: archlinux
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository actions
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
sparse-checkout: .github/actions
|
||||||
|
|
||||||
|
- name: Get required pkgs
|
||||||
|
run: |
|
||||||
|
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
||||||
|
pacman --noconfirm --noprogressbar -Syyu
|
||||||
|
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
||||||
|
|
||||||
|
- name: Build with gcc
|
||||||
|
run: |
|
||||||
|
CXXFLAGS="-fsanitize=address" CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
||||||
|
CXXFLAGS="-fsanitize=address" CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||||
|
cmake --install ./build
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: |
|
||||||
|
cd ./build && ctest --output-on-failure
|
||||||
|
|
||||||
|
ubsan:
|
||||||
|
name: "gcc build / UBSan tests"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: archlinux
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository actions
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
sparse-checkout: .github/actions
|
||||||
|
|
||||||
|
- name: Get required pkgs
|
||||||
|
run: |
|
||||||
|
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
||||||
|
pacman --noconfirm --noprogressbar -Syyu
|
||||||
|
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
||||||
|
|
||||||
|
- name: Build with gcc
|
||||||
|
run: |
|
||||||
|
CXXFLAGS="-fsanitize=undefined" CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
||||||
|
CXXFLAGS="-fsanitize=undefined" CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||||
|
cmake --install ./build
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: |
|
||||||
|
cd ./build && ctest --output-on-failure
|
||||||
|
|
||||||
|
msan:
|
||||||
|
name: "gcc build / MSan tests"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: archlinux
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository actions
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
sparse-checkout: .github/actions
|
||||||
|
|
||||||
|
- name: Get required pkgs
|
||||||
|
run: |
|
||||||
|
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
||||||
|
pacman --noconfirm --noprogressbar -Syyu
|
||||||
|
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
||||||
|
|
||||||
|
- name: Build with gcc
|
||||||
|
run: |
|
||||||
|
CXXFLAGS="-fsanitize=leak" CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
||||||
|
CXXFLAGS="-fsanitize=leak" CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||||
|
cmake --install ./build
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: |
|
||||||
|
cd ./build && ctest --output-on-failure
|
||||||
|
|
||||||
clang:
|
clang:
|
||||||
name: "clang build / gcc test"
|
name: "clang build / gcc test"
|
||||||
|
@ -53,22 +133,21 @@ jobs:
|
||||||
pacman --noconfirm --noprogressbar -Syyu
|
pacman --noconfirm --noprogressbar -Syyu
|
||||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
||||||
|
|
||||||
- name: Build with clang
|
- name: Build hyprlang with clang
|
||||||
run: |
|
run: |
|
||||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build
|
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
||||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --build ./build --config Release --target hyprlang -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||||
cp ./build/libhyprlang.so /usr/lib
|
cmake --install ./build
|
||||||
|
|
||||||
- name: Build with gcc
|
- name: Build tests with gcc
|
||||||
run: |
|
run: |
|
||||||
rm -rf ./build
|
rm -rf ./build
|
||||||
CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build
|
CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
||||||
CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --build ./build --config Release --target tests -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||||
rm ./build/libhyprlang.so
|
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
cd ./tests && ../build/hyprlang_test
|
cd ./build && ctest --output-on-failure
|
||||||
|
|
||||||
doxygen:
|
doxygen:
|
||||||
name: "Deploy docs"
|
name: "Deploy docs"
|
||||||
|
|
|
@ -25,9 +25,18 @@ set_target_properties(hyprlang PROPERTIES PUBLIC_HEADER include/hyprlang.hpp)
|
||||||
|
|
||||||
install(TARGETS hyprlang)
|
install(TARGETS hyprlang)
|
||||||
|
|
||||||
add_executable(hyprlang_test "tests/main.cpp")
|
# tests
|
||||||
|
add_custom_target(tests)
|
||||||
|
|
||||||
|
add_executable(hyprlang_test "tests/parse/main.cpp")
|
||||||
target_link_libraries(hyprlang_test PRIVATE hyprlang)
|
target_link_libraries(hyprlang_test PRIVATE hyprlang)
|
||||||
add_test(NAME "Parsing" WORKING_DIRECTORY "../tests/" COMMAND hyprlang_test "parse")
|
add_test(NAME "Parsing" WORKING_DIRECTORY "../tests/" COMMAND hyprlang_test "parse")
|
||||||
|
add_dependencies(tests hyprlang_test)
|
||||||
|
|
||||||
|
add_executable(hyprlang_fuzz "tests/fuzz/main.cpp")
|
||||||
|
target_link_libraries(hyprlang_fuzz PRIVATE hyprlang)
|
||||||
|
add_test(NAME "Fuzz" WORKING_DIRECTORY "../tests/" COMMAND hyprlang_fuzz "fuzz")
|
||||||
|
add_dependencies(tests hyprlang_fuzz)
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
install(TARGETS hyprlang
|
install(TARGETS hyprlang
|
||||||
|
|
|
@ -351,11 +351,10 @@ CParseResult CConfig::parseVariable(const std::string& lhs, const std::string& r
|
||||||
else {
|
else {
|
||||||
impl->variables.push_back({lhs.substr(1), rhs});
|
impl->variables.push_back({lhs.substr(1), rhs});
|
||||||
std::sort(impl->variables.begin(), impl->variables.end(), [](const auto& lhs, const auto& rhs) { return lhs.name.length() > rhs.name.length(); });
|
std::sort(impl->variables.begin(), impl->variables.end(), [](const auto& lhs, const auto& rhs) { return lhs.name.length() > rhs.name.length(); });
|
||||||
|
IT = std::find_if(impl->variables.begin(), impl->variables.end(), [&](const auto& v) { return v.name == lhs.substr(1); });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dynamic) {
|
if (dynamic) {
|
||||||
if (IT == impl->variables.end())
|
|
||||||
IT = std::find_if(impl->variables.begin(), impl->variables.end(), [&](const auto& v) { return v.name == lhs.substr(1); });
|
|
||||||
for (auto& l : IT->linesContainingVar) {
|
for (auto& l : IT->linesContainingVar) {
|
||||||
parseLine(l, true);
|
parseLine(l, true);
|
||||||
}
|
}
|
||||||
|
|
42
tests/fuzz/main.cpp
Normal file
42
tests/fuzz/main.cpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <hyprlang.hpp>
|
||||||
|
|
||||||
|
#define FUZZ_ITERS 1337
|
||||||
|
|
||||||
|
std::string garbage() {
|
||||||
|
srand(time(nullptr));
|
||||||
|
|
||||||
|
int len = rand() % 10000;
|
||||||
|
|
||||||
|
std::string chars;
|
||||||
|
for (int i = 0; i < len; ++i) {
|
||||||
|
chars += rand() % 254 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return chars;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv, char** envp) {
|
||||||
|
|
||||||
|
Hyprlang::CConfig config("./eeeeeeeUnused", {.allowMissingConfig = true});
|
||||||
|
config.addConfigValue("test", {0L});
|
||||||
|
|
||||||
|
config.parseDynamic("");
|
||||||
|
config.parseDynamic("", "");
|
||||||
|
config.parseDynamic("}");
|
||||||
|
for (size_t i = 0; i < FUZZ_ITERS; ++i) {
|
||||||
|
config.parseDynamic(garbage().c_str(), garbage().c_str());
|
||||||
|
config.parseDynamic((garbage() + "=" + garbage()).c_str());
|
||||||
|
config.parseDynamic(garbage().c_str());
|
||||||
|
config.parseDynamic((garbage() + " {").c_str());
|
||||||
|
config.parseDynamic((std::string{"test = "} + garbage()).c_str());
|
||||||
|
config.parseDynamic((std::string{"$"} + garbage()).c_str());
|
||||||
|
config.parseDynamic((std::string{"$VAR = "} + garbage()).c_str());
|
||||||
|
}
|
||||||
|
config.parseDynamic("}");
|
||||||
|
|
||||||
|
std::cout << "Success, no fuzzing errors\n";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue