-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Lin Zhihao <[email protected]> Co-authored-by: Kirk Rodrigues <[email protected]>
- Loading branch information
1 parent
0b9e45c
commit d9a686e
Showing
7 changed files
with
204 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
set( | ||
SOURCES_LOG_SURGEON | ||
../src/log_surgeon/FileReader.cpp | ||
../src/log_surgeon/FileReader.hpp | ||
../src/log_surgeon/finite_automata/RegexAST.hpp | ||
../src/log_surgeon/finite_automata/RegexAST.tpp | ||
../src/log_surgeon/finite_automata/RegexNFA.hpp | ||
../src/log_surgeon/finite_automata/RegexNFA.tpp | ||
../src/log_surgeon/LALR1Parser.cpp | ||
../src/log_surgeon/LALR1Parser.hpp | ||
../src/log_surgeon/LALR1Parser.tpp | ||
../src/log_surgeon/ParserInputBuffer.hpp | ||
../src/log_surgeon/ParserInputBuffer.cpp | ||
../src/log_surgeon/Schema.hpp | ||
../src/log_surgeon/Schema.cpp | ||
../src/log_surgeon/SchemaParser.cpp | ||
../src/log_surgeon/SchemaParser.hpp | ||
../src/log_surgeon/Token.cpp | ||
../src/log_surgeon/Token.hpp | ||
) | ||
|
||
set(SOURCES_TESTS test-lexer.cpp) | ||
|
||
add_executable(unit-test ${SOURCES_LOG_SURGEON} ${SOURCES_TESTS}) | ||
target_link_libraries(unit-test PRIVATE Catch2::Catch2WithMain) | ||
target_include_directories(unit-test PRIVATE ${CMAKE_SOURCE_DIR}/src) | ||
target_compile_features(unit-test PRIVATE cxx_std_20) | ||
|
||
catch_discover_tests(unit-test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <catch2/catch_test_macros.hpp> | ||
|
||
#include <log_surgeon/Schema.hpp> | ||
#include <log_surgeon/SchemaParser.hpp> | ||
|
||
TEST_CASE("Test the Schema class", "[Schema]") { | ||
log_surgeon::Schema schema; | ||
schema.add_variable("myNumber", "123", -1); | ||
auto const schema_ast = schema.release_schema_ast_ptr(); | ||
REQUIRE(schema_ast->m_schema_vars.size() == 1); | ||
REQUIRE(schema.release_schema_ast_ptr()->m_schema_vars.empty()); | ||
|
||
auto& schema_var_ast_ptr = schema_ast->m_schema_vars[0]; | ||
REQUIRE(nullptr != schema_var_ast_ptr); | ||
auto& schema_var_ast = dynamic_cast<log_surgeon::SchemaVarAST&>(*schema_var_ast_ptr); | ||
REQUIRE("myNumber" == schema_var_ast.m_name); | ||
|
||
auto& regex_ast_cat = schema_var_ast.m_regex_ptr; | ||
REQUIRE(nullptr != regex_ast_cat); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Dependencies: | ||
# - cmake | ||
# - curl | ||
# - g++ | ||
# NOTE: Dependencies should be installed outside the script to allow the script to be largely | ||
# distro-agnostic | ||
|
||
# Exit on any error | ||
set -e | ||
|
||
# Error on undefined variable | ||
set -u | ||
|
||
cUsage="Usage: ${BASH_SOURCE[0]} <version>[ <.deb output directory>]" | ||
if [ "$#" -lt 1 ]; then | ||
echo "$cUsage" | ||
exit | ||
fi | ||
version=$1 | ||
|
||
package_name=catch2 | ||
temp_dir="/tmp/${package_name}-installation" | ||
deb_output_dir="$temp_dir" | ||
if [[ "$#" -gt 1 ]]; then | ||
deb_output_dir="$(readlink -f "$2")" | ||
if [ ! -d "$deb_output_dir" ]; then | ||
echo "$deb_output_dir does not exist or is not a directory" | ||
exit | ||
fi | ||
fi | ||
|
||
# Check if already installed | ||
set +e | ||
dpkg -l ${package_name} | grep "$version" | ||
installed=$? | ||
set -e | ||
if [ $installed -eq 0 ]; then | ||
# Nothing to do | ||
exit | ||
fi | ||
|
||
echo "Checking for elevated privileges..." | ||
install_cmd_args=() | ||
if [ ${EUID:-$(id -u)} -ne 0 ]; then | ||
sudo echo "Script can elevate privileges." | ||
install_cmd_args+=("sudo") | ||
fi | ||
|
||
# Get number of cpu cores | ||
num_cpus=$(grep -c ^processor /proc/cpuinfo) | ||
|
||
# Download | ||
mkdir -p "$temp_dir" | ||
cd "$temp_dir" | ||
extracted_dir="${temp_dir}/Catch2-${version}" | ||
if [ ! -e "${extracted_dir}" ]; then | ||
tar_filename="v${version}.tar.gz" | ||
if [ ! -e "${tar_filename}" ]; then | ||
curl \ | ||
-fsSL \ | ||
"https://github.com/catchorg/Catch2/archive/refs/tags/${tar_filename}" \ | ||
-o "${tar_filename}" | ||
fi | ||
|
||
tar -xf "${tar_filename}" | ||
fi | ||
|
||
# Build | ||
cd "$extracted_dir" | ||
cmake -B build -S . -DBUILD_TESTING=OFF | ||
cmake --build build --parallel "$num_cpus" | ||
|
||
# Check if checkinstall is installed | ||
set +e | ||
command -v checkinstall | ||
checkinstall_installed=$? | ||
set -e | ||
|
||
# Install | ||
if [ $checkinstall_installed -eq 0 ]; then | ||
install_cmd_args+=( | ||
checkinstall | ||
--pkgname "$package_name" | ||
--pkgversion "$version" | ||
--provides "$package_name" | ||
--nodoc | ||
-y | ||
--pakdir "$deb_output_dir" | ||
) | ||
fi | ||
install_cmd_args+=( | ||
cmake --install build | ||
) | ||
"${install_cmd_args[@]}" | ||
|
||
# Clean up | ||
rm -rf "$temp_dir" |