diff --git a/CMakeLists.txt b/CMakeLists.txt index 2885111..3a9b5f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,6 @@ FetchContent_Declare( URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip ) -# Current not working, figure it out why! TODO: Fix pybind11 FetchContent_Declare( pybind11 GIT_REPOSITORY https://github.com/pybind/pybind11.git @@ -44,6 +43,12 @@ add_library( src/detectmateperformance/_core/_type/templates.cpp ) +add_library( + parsedelement + src/detectmateperformance/_core/_type/element.h + src/detectmateperformance/_core/_type/element.cpp +) + add_library( parsed src/detectmateperformance/_core/_type/parsed.h @@ -112,6 +117,8 @@ pybind11_add_module( src/detectmateperformance/_core/aux.cpp src/detectmateperformance/_core/_type/templates.h src/detectmateperformance/_core/_type/templates.cpp + src/detectmateperformance/_core/_type/element.h + src/detectmateperformance/_core/_type/element.cpp src/detectmateperformance/_core/_type/parsed.h src/detectmateperformance/_core/_type/parsed.cpp src/detectmateperformance/_core/template_matcher/tree.h @@ -128,6 +135,7 @@ target_link_libraries( test_c GTest::gtest_main templates + parsedelement parsed tree variable @@ -140,6 +148,7 @@ target_link_libraries( test_type GTest::gtest_main templates + parsedelement parsed aux ) @@ -154,6 +163,7 @@ target_link_libraries( test_matcher_vars GTest::gtest_main templates + parsedelement parsed tree variable diff --git a/compile.sh b/compile.sh index ad1f1f1..b57c4a6 100644 --- a/compile.sh +++ b/compile.sh @@ -16,6 +16,7 @@ cd .. mkdir lib cp build/bind_class* src/detectmateperformance/lib/ chmod 775 src/detectmateperformance/lib/* +chmod 775 -R build/* # Install package $HOME/.local/bin/uv pip uninstall detectmateperformance diff --git a/docker-compose.yml b/docker-compose.yml index 86cea2c..fc3352f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,11 +6,7 @@ services: volumes: - ./:/app working_dir: /app - command: > - sh -c " - apt-get update && apt-get install -y python3 curl cmake python3-dev && - curl -LsSf https://astral.sh/uv/install.sh | sh && - sh compile.sh" + command: ["sh", "install_compile.sh"] x86_64_builder: image: gcc:latest @@ -18,8 +14,4 @@ services: volumes: - ./:/app working_dir: /app - command: > - sh -c " - apt-get update && apt-get install -y python3 curl cmake python3-dev && - curl -LsSf https://astral.sh/uv/install.sh | sh && - sh compile.sh" + command: ["sh", "install_compile.sh"] diff --git a/install_compile.sh b/install_compile.sh new file mode 100644 index 0000000..2d07275 --- /dev/null +++ b/install_compile.sh @@ -0,0 +1,4 @@ + +apt-get update && apt-get install -y python3 curl cmake python3-dev +curl -LsSf https://astral.sh/uv/install.sh | sh +sh compile.sh diff --git a/src/detectmateperformance/_core/_type/element.cpp b/src/detectmateperformance/_core/_type/element.cpp new file mode 100644 index 0000000..6dc5a4a --- /dev/null +++ b/src/detectmateperformance/_core/_type/element.cpp @@ -0,0 +1,34 @@ + +#include "element.h" + + +std::string postProcessTemp(const std::string& input){ + std::string pattern = "\\bVAR\\b"; + std::regex re(pattern); + std::string result = std::regex_replace(input, re, "<*>"); + return result; +} + +std::deque postProcessVars(const std::string& input_vars) { + return preprocessing(input_vars); +} + +ParsedElement::ParsedElement( + int event_id, std::string log_template, std::string variables +) { + this->event_id = event_id; + this->log_template = postProcessTemp(log_template); + this->variables = postProcessVars(variables); +} + +ParsedElement::ParsedElement( + int event_id, std::string log_template +) { + this->event_id = event_id; + this->log_template = postProcessTemp(log_template); + this->variables = {}; +} + +ParsedElement::~ParsedElement() { + +} diff --git a/src/detectmateperformance/_core/_type/element.h b/src/detectmateperformance/_core/_type/element.h new file mode 100644 index 0000000..574cf4a --- /dev/null +++ b/src/detectmateperformance/_core/_type/element.h @@ -0,0 +1,32 @@ +#ifndef M_PARSEDELEM_H +#define M_PARSEDELEM_H + +#include +#include +#include "../aux.h" +#include + + + + +std::string postProcessTemp(const std::string& input); + +std::deque postProcessVars(const std::string& input_vars); + +class ParsedElement { + +public: + int event_id; + std::string log_template; + std::deque variables; + + ParsedElement( + int event_id, std::string log_template, std::string variables + ); + ParsedElement(int event_id, std::string log_template); + + ~ParsedElement(); + +}; + +#endif diff --git a/src/detectmateperformance/_core/_type/parsed.cpp b/src/detectmateperformance/_core/_type/parsed.cpp index a652247..55e1dba 100644 --- a/src/detectmateperformance/_core/_type/parsed.cpp +++ b/src/detectmateperformance/_core/_type/parsed.cpp @@ -29,21 +29,26 @@ int ParsedMessages::getElemID(int n) { return this->event_ids[n]; } -std::string ParsedMessages::getElem(int n) { +ParsedElement ParsedMessages::getElem(int n) { int event_idsf = this->getElemID(n); if (event_idsf == -1) { - return "template not found"; + return ParsedElement(-1, "template not found"); } - return id_to_template[event_idsf]; + return ParsedElement(event_idsf, id_to_template[event_idsf]); } -std::pair ParsedMessages::getElemWithVar(int n) { - std::string temp = ParsedMessages::getElem(n); - std::string vars = this->variables[n]; +ParsedElement ParsedMessages::getElemWithVar(int n) { + std::string variables = this->variables[n]; + int event_idsf = this->getElemID(n); + + if (event_idsf == -1) { + return ParsedElement(-1, "template not found", variables); + } + std::string template_ = id_to_template[event_idsf]; - return std::make_pair(temp, vars); + return ParsedElement(event_idsf, template_, variables); } void ParsedMessages::setElem(int n, std::string template_) { @@ -77,14 +82,20 @@ std::vector ParsedMessages::getAllElemts() { std::vector templates(this->size()); for (int i = 0; i < this->size(); i++) { - templates[i] = this->getElem(i); + templates[i] = this->getElem(i).log_template; } return templates; } -std::vector ParsedMessages::getAllVar() { - return this->variables; +std::vector> ParsedMessages::getAllVar() { + std::vector> vars(this->size()); + + for (int i = 0; i < this->size(); i++) { + vars[i] = this->getElemWithVar(i).variables; + } + + return vars; } int ParsedMessages::size() { diff --git a/src/detectmateperformance/_core/_type/parsed.h b/src/detectmateperformance/_core/_type/parsed.h index a4ad037..ceb6f9b 100644 --- a/src/detectmateperformance/_core/_type/parsed.h +++ b/src/detectmateperformance/_core/_type/parsed.h @@ -7,6 +7,7 @@ #include #include "templates.h" +#include "element.h" #include @@ -25,8 +26,8 @@ class ParsedMessages { ~ParsedMessages(); int getElemID(int n); - std::string getElem(int n); - std::pair getElemWithVar(int n); + ParsedElement getElem(int n); + ParsedElement getElemWithVar(int n); void setElem(int n, std::string template_); void setElemWithVar( int n, std::string template_, std::string vars @@ -34,7 +35,7 @@ class ParsedMessages { std::vector getAllIDs(); std::vector getAllElemts(); - std::vector getAllVar(); + std::vector> getAllVar(); int size(); std::pair shape(); diff --git a/src/detectmateperformance/_core/bind_class.cpp b/src/detectmateperformance/_core/bind_class.cpp index 49104de..35c5b3e 100644 --- a/src/detectmateperformance/_core/bind_class.cpp +++ b/src/detectmateperformance/_core/bind_class.cpp @@ -2,6 +2,7 @@ #include #include "template_matcher/match_tree.h" +#include "_type/element.h" #include "_type/templates.h" #include "_type/parsed.h" @@ -15,6 +16,10 @@ PYBIND11_MODULE(bind_class, m) { .def("get_next_template", &Templates::getNext) .def("size", &Templates::size) .def("shape", &Templates::shape); + py::class_(m, "ParsedElement") + .def_readonly("event_id", &ParsedElement::event_id) + .def_readonly("log_template", &ParsedElement::log_template) + .def_readonly("variables", &ParsedElement::variables); py::class_(m, "Parsed") .def(py::init()) .def("get_elem_id", &ParsedMessages::getElemID) diff --git a/src/detectmateperformance/lib/bind_class.cpython-312-x86_64-linux-gnu.so b/src/detectmateperformance/lib/bind_class.cpython-312-x86_64-linux-gnu.so index f8c845a..ff43b91 100755 Binary files a/src/detectmateperformance/lib/bind_class.cpython-312-x86_64-linux-gnu.so and b/src/detectmateperformance/lib/bind_class.cpython-312-x86_64-linux-gnu.so differ diff --git a/src/detectmateperformance/lib/bind_class.cpython-313-aarch64-linux-gnu.so b/src/detectmateperformance/lib/bind_class.cpython-313-aarch64-linux-gnu.so index c03366d..d637585 100755 Binary files a/src/detectmateperformance/lib/bind_class.cpython-313-aarch64-linux-gnu.so and b/src/detectmateperformance/lib/bind_class.cpython-313-aarch64-linux-gnu.so differ diff --git a/src/detectmateperformance/lib/bind_class.cpython-313-x86_64-linux-gnu.so b/src/detectmateperformance/lib/bind_class.cpython-313-x86_64-linux-gnu.so index 8bca450..cc093fe 100755 Binary files a/src/detectmateperformance/lib/bind_class.cpython-313-x86_64-linux-gnu.so and b/src/detectmateperformance/lib/bind_class.cpython-313-x86_64-linux-gnu.so differ diff --git a/src/detectmateperformance/pipeline_op.py b/src/detectmateperformance/pipeline_op.py index 1626358..e525dd0 100644 --- a/src/detectmateperformance/pipeline_op.py +++ b/src/detectmateperformance/pipeline_op.py @@ -41,13 +41,6 @@ def add_parsed(df: pl.DataFrame, results: ParsedLogs) -> pl.DataFrame: return df -def postprocessing(df: pl.DataFrame) -> pl.DataFrame: - df = df.with_columns(pl.col("Templates").str.replace_all("VAR", "<*>")) - if "ParamList" in df.columns: - df = df.with_columns(pl.col("ParamList").str.split(by=" ")) - return df - - def run_batches( func: Callable[[list[str], bool, int], ParsedLogs], table: pl.DataFrame, @@ -69,8 +62,7 @@ def run_batches( df = pl.concat([df, add_parsed(df=table[i-batch: i], results=results)]) del results - print(">>> Postprocessing results") - return postprocessing(df) + return df def run_full_pipeline( diff --git a/src/detectmateperformance/types_.py b/src/detectmateperformance/types_.py index 3f66329..569dfd8 100644 --- a/src/detectmateperformance/types_.py +++ b/src/detectmateperformance/types_.py @@ -1,4 +1,6 @@ -from detectmateperformance.lib.bind_class import Templates, Parsed +from detectmateperformance.lib.bind_class import Templates, Parsed, ParsedElement + +from typing import Any def _load_file(path: str) -> list[str]: @@ -42,6 +44,20 @@ def from_file(cls, path: str) -> "LogTemplates": return cls(_load_file(path)) +class ParsedLogElement: + def __init__(self, parsed_ele: ParsedElement) -> None: + self.event_id: int = parsed_ele.event_id + self.log_template: str = parsed_ele.log_template + self.variables: list[str] = parsed_ele.variables + + def to_dict(self) -> dict[str, Any]: + return { + "EventID": self.event_id, + "Template": self.log_template, + "ParamList": self.variables, + } + + class ParsedLogs: def __init__( self, templates: LogTemplates, n: int, with_vars: bool = False @@ -64,10 +80,12 @@ def shape(self) -> tuple[int, int]: def __str__(self) -> str: return f"ParsedLogs(shape={self.shape()}, vars={self.with_vars})" - def __getitem__(self, idx: int) -> str | tuple[str, str]: + def __getitem__(self, idx: int) -> dict[str, Any]: if self.with_vars: - return self.inst.get_elem_with_var(idx) # type: ignore - return self.inst.get_elem(idx) # type: ignore + result = ParsedLogElement(self.inst.get_elem_with_var(idx)) + else: + result = ParsedLogElement(self.inst.get_elem(idx)) + return result.to_dict() def __setitem__(self, idx: int, values: str | tuple[str, str]) -> str: if self.with_vars: @@ -80,7 +98,7 @@ def get_all_events_ids(self) -> list[int]: def get_all_templates(self) -> list[str]: return self.inst.get_all_elem() # type: ignore - def get_all_vars(self) -> list[str] | None: + def get_all_vars(self) -> list[list[str]] | None: if self.with_vars: return self.inst.get_all_var() # type: ignore return None diff --git a/tests/test_c/test_message.cpp b/tests/test_c/test_message.cpp index 96c09e0..b40479f 100644 --- a/tests/test_c/test_message.cpp +++ b/tests/test_c/test_message.cpp @@ -4,6 +4,7 @@ #include "../../src/detectmateperformance/_core/_type/templates.h" #include "../../src/detectmateperformance/_core/_type/parsed.h" +#include "../../src/detectmateperformance/_core/_type/element.h" #include "../../src/detectmateperformance/_core/template_matcher/tree.h" #include "../../src/detectmateperformance/_core/template_matcher/variables.h" @@ -228,15 +229,15 @@ TEST(TreeMatchTest, MatchString) { ParsedMessages* result1 = matcher->match_string("hi there"); EXPECT_EQ(result1->size(), 1); - EXPECT_EQ(result1->getElem(0), "hi there"); + EXPECT_EQ(result1->getElem(0).log_template, "hi there"); ParsedMessages* result2 = matcher->match_string("hi general mr. and mrs. kenobi"); EXPECT_EQ(result2->size(), 1); - EXPECT_EQ(result2->getElem(0), "hi general VAR kenobi"); + EXPECT_EQ(result2->getElem(0).log_template, "hi general <*> kenobi"); ParsedMessages* result3 = matcher->match_string("hi random guy"); EXPECT_EQ(result3->size(), 1); - EXPECT_EQ(result3->getElem(0), "template not found"); + EXPECT_EQ(result3->getElem(0).log_template, "template not found"); delete matcher; } @@ -248,27 +249,29 @@ TEST(TreeMatchTest, MatchStringWithVar) { Templates* temp = new Templates(sequences); MatchTree* matcher = new MatchTree(temp); - auto result1 = matcher->match_string_with_var("hi there")->getElemWithVar(0); - std::string expected1 = ""; - EXPECT_EQ(result1.first, "hi there"); - EXPECT_EQ(result1.second, expected1); + ParsedElement result1 = matcher->match_string_with_var("hi there")->getElemWithVar(0); + std::deque expected1 = {}; + EXPECT_EQ(result1.log_template, "hi there"); + EXPECT_EQ(result1.variables, expected1); - auto result2 = matcher->match_string_with_var( + ParsedElement result2 = matcher->match_string_with_var( "hi general mr. and mrs. kenobi" )->getElemWithVar(0); - std::string expected2 = "mr and mrs"; - EXPECT_EQ(result2.first, "hi general VAR kenobi"); - EXPECT_EQ(result2.second, expected2); + std::deque expected2 = {"mr", "and", "mrs"}; + EXPECT_EQ(result2.log_template, "hi general <*> kenobi"); + EXPECT_EQ(result2.variables, expected2); - auto result3 = matcher->match_string_with_var("hi random guy")->getElemWithVar(0); - EXPECT_EQ(result3.first, "template not found"); + ParsedElement result3 = matcher->match_string_with_var( + "hi random guy" + )->getElemWithVar(0); + EXPECT_EQ(result3.log_template, "template not found"); - auto result4 = matcher->match_string_with_var( + ParsedElement result4 = matcher->match_string_with_var( "load 1213 asd from 112 bye" )->getElemWithVar(0); - std::string expected4 = "1213 asd 112 bye"; - EXPECT_EQ(result4.first, "load VAR from VAR"); - EXPECT_EQ(result4.second, expected4); + std::deque expected4 = {"1213", "asd", "112", "bye"}; + EXPECT_EQ(result4.log_template, "load <*> from <*>"); + EXPECT_EQ(result4.variables, expected4); delete matcher; } @@ -298,8 +301,8 @@ TEST(TreeMatchTest, MatchStringBatch) { EXPECT_EQ(4, msg.size()); for (int i = 0; i < msg.size(); i++) { - EXPECT_EQ(expected->getElem(i), results->getElem(i)); - EXPECT_EQ(results_threats->getElem(i), results->getElem(i)); + EXPECT_EQ(expected->getElem(i).log_template, results->getElem(i).log_template); + EXPECT_EQ(results_threats->getElem(i).log_template, results->getElem(i).log_template); } delete matcher; @@ -315,9 +318,15 @@ TEST(TreeMatchTest, MatchStringBatchVar) { std::vector msg = { "hi there", "hi general VAR kenobi", "template not found", "load VAR from VAR" }; + std::vector msg_ex = { + "hi there", "hi general <*> kenobi", "template not found", "load <*> from <*>" + }; std::vector vector_vars = { "", "mr and mrs", "", "1213 asd 112 bye" }; + std::vector> ex_vector_vars = { + {}, {"mr", "and", "mrs"}, {}, {"1213", "asd", "112", "bye"} + }; Templates* temp2 = new Templates(sequences); ParsedMessages* expected = new ParsedMessages(temp2, 4); @@ -332,10 +341,14 @@ TEST(TreeMatchTest, MatchStringBatchVar) { EXPECT_EQ(4, msg.size()); for (int i = 0; i < msg.size(); i++) { - EXPECT_EQ(results_threats->getElemWithVar(i), results->getElemWithVar(i)); - auto aux = results->getElemWithVar(i); - EXPECT_EQ(aux.first, msg[i]); - EXPECT_EQ(aux.second, vector_vars[i]); + EXPECT_EQ(results_threats->getElemWithVar(i).variables, results->getElemWithVar(i).variables); + ParsedElement aux = results->getElemWithVar(i); + + if (msg_ex[i] == "template not found") + EXPECT_EQ(-1, aux.event_id); + + EXPECT_EQ(msg_ex[i], aux.log_template); + EXPECT_EQ(aux.variables, ex_vector_vars[i]); } delete matcher; @@ -354,7 +367,7 @@ TEST(ParsedMessagesTest, HardCases1) { ParsedMessages* result1 = matcher->match_string(log); EXPECT_EQ(result1->size(), 1); - EXPECT_EQ(result1->getElem(0), "VAR floating point alignment exceptions"); + EXPECT_EQ(result1->getElem(0).log_template, "<*> floating point alignment exceptions"); } @@ -370,7 +383,7 @@ TEST(ParsedMessagesTest, HardCases2) { ParsedMessages* result1 = matcher->match_string(log); EXPECT_EQ(result1->size(), 1); - EXPECT_EQ(result1->getElem(0), "VAR Exception writing block VAR to mirror VAR"); + EXPECT_EQ(result1->getElem(0).log_template, "<*> Exception writing block <*> to mirror <*>"); } @@ -386,7 +399,7 @@ TEST(ParsedMessagesTest, HardCases3) { ParsedMessages* result1 = matcher->match_string(log); EXPECT_EQ(result1->size(), 1); - EXPECT_EQ(result1->getElem(0), "rts kernel terminated for reason VAR"); + EXPECT_EQ(result1->getElem(0).log_template, "rts kernel terminated for reason <*>"); } @@ -402,6 +415,6 @@ TEST(ParsedMessagesTest, HardCases4) { ParsedMessages* result1 = matcher->match_string(log); EXPECT_EQ(result1->size(), 1); - EXPECT_EQ(result1->getElem(0), "data TLB error interrupt"); + EXPECT_EQ(result1->getElem(0).log_template, "data TLB error interrupt"); } diff --git a/tests/test_c/test_type.cpp b/tests/test_c/test_type.cpp index f1c9b5c..a9292e6 100644 --- a/tests/test_c/test_type.cpp +++ b/tests/test_c/test_type.cpp @@ -3,6 +3,7 @@ #include "../../src/detectmateperformance/_core/aux.h" #include "../../src/detectmateperformance/_core/_type/templates.h" +#include "../../src/detectmateperformance/_core/_type/element.h" #include "../../src/detectmateperformance/_core/_type/parsed.h" @@ -43,6 +44,44 @@ TEST(TemplatesTest, GetNextTemplate) { EXPECT_TRUE(message3.empty()); } +TEST(ParsedMessagesTest, ParsedElementtest) { + ParsedElement* parsed = new ParsedElement( + 0, "VAR template VAR VAR", "var1 var2 var3" + ); + std::deque expected = {"var1", "var2", "var3"}; + + EXPECT_EQ(parsed->event_id, 0); + EXPECT_EQ(parsed->log_template, "<*> template <*> <*>"); + EXPECT_EQ(parsed->variables, expected); + + ParsedElement* parsed2 = new ParsedElement( + 0, "VAR template VAR VAR" + ); + std::deque expected2 = {}; + + EXPECT_EQ(parsed2->event_id, 0); + EXPECT_EQ(parsed2->log_template, "<*> template <*> <*>"); + EXPECT_EQ(parsed2->variables, expected2); + + ParsedElement* parsed3 = new ParsedElement( + -1, "template not found", "5 1 2" + ); + std::deque expected3 = {"5", "1", "2"}; + + EXPECT_EQ(parsed3->event_id, -1); + EXPECT_EQ(parsed3->log_template, "template not found"); + EXPECT_EQ(parsed3->variables, expected3); + + ParsedElement* parsed4 = new ParsedElement( + -1, "template not found" + ); + std::deque expected4 = {}; + + EXPECT_EQ(parsed4->event_id, -1); + EXPECT_EQ(parsed4->log_template, "template not found"); + EXPECT_EQ(parsed4->variables, expected4); +} + TEST(ParsedMessagesTest, Initialization) { std::deque input = {"Hello VAR, world=VAR:VAR VAR", "Goodbye VAR"}; Templates* templates = new Templates(input); @@ -68,14 +107,14 @@ TEST(ParsedMessagesTest, GetNext) { parsed.setElem(2, "Goodbye VAR"); parsed.setElem(3, "random thing"); - std::string temp1 = "Hello VAR world VAR"; - std::string temp2 = "Goodbye VAR"; + std::string temp1 = "Hello <*> world <*>"; + std::string temp2 = "Goodbye <*>"; std::string temp3 = "template not found"; - EXPECT_EQ(parsed.getElem(0), temp1); - EXPECT_EQ(parsed.getElem(1), temp1); - EXPECT_EQ(parsed.getElem(2), temp2); - EXPECT_EQ(parsed.getElem(3), temp3); + EXPECT_EQ(parsed.getElem(0).log_template, temp1); + EXPECT_EQ(parsed.getElem(1).log_template, temp1); + EXPECT_EQ(parsed.getElem(2).log_template, temp2); + EXPECT_EQ(parsed.getElem(3).log_template, temp3); } TEST(ParsedMessagesTest, GetAllIDs) { @@ -98,7 +137,7 @@ TEST(ParsedMessagesTest, GetAllNext) { std::vector results = parsed.getAllElemts(); for (int i = 0; i < results.size(); i++) { - EXPECT_EQ(parsed.getElem(i), results[i]); + EXPECT_EQ(parsed.getElem(i).log_template, results[i]); } } @@ -116,20 +155,20 @@ TEST(ParsedMessagesTest, GetNextWithVar) { parsed.setElemWithVar(2, "Goodbye VAR", var2); parsed.setElemWithVar(3, "random thing", var1); - std::string temp1 = "Hello VAR world VAR"; - std::string temp2 = "Goodbye VAR"; + std::string temp1 = "Hello <*> world <*>"; + std::string temp2 = "Goodbye <*>"; std::string temp3 = "template not found"; - std::string evar1 = ""; - std::string evar2 = "a b"; - - EXPECT_EQ(parsed.getElemWithVar(0).first, temp1); - EXPECT_EQ(parsed.getElemWithVar(0).second, evar1); - EXPECT_EQ(parsed.getElemWithVar(1).first, temp1); - EXPECT_EQ(parsed.getElemWithVar(1).second, evar2); - EXPECT_EQ(parsed.getElemWithVar(2).first, temp2); - EXPECT_EQ(parsed.getElemWithVar(2).second, evar2); - EXPECT_EQ(parsed.getElemWithVar(3).first, temp3); - EXPECT_EQ(parsed.getElemWithVar(3).second, evar1); + std::deque evar1 = {}; + std::deque evar2 = {"a", "b"}; + + EXPECT_EQ(parsed.getElemWithVar(0).log_template, temp1); + EXPECT_EQ(parsed.getElemWithVar(0).variables, evar1); + EXPECT_EQ(parsed.getElemWithVar(1).log_template, temp1); + EXPECT_EQ(parsed.getElemWithVar(1).variables, evar2); + EXPECT_EQ(parsed.getElemWithVar(2).log_template, temp2); + EXPECT_EQ(parsed.getElemWithVar(2).variables, evar2); + EXPECT_EQ(parsed.getElemWithVar(3).log_template, temp3); + EXPECT_EQ(parsed.getElemWithVar(3).variables, evar1); } TEST(ParsedMessagesTest, GetAllVar) { @@ -145,9 +184,9 @@ TEST(ParsedMessagesTest, GetAllVar) { parsed.setElemWithVar(2, "Goodbye VAR", var2); parsed.setElemWithVar(3, "random thing", var1); - std::vector result = parsed.getAllVar(); + std::vector> result = parsed.getAllVar(); for (int i = 0; i < result.size(); i++) { - EXPECT_EQ(parsed.getElemWithVar(i).second, result[i]); + EXPECT_EQ(parsed.getElemWithVar(i).variables, result[i]); } } diff --git a/tests/test_python/test_match_tree.py b/tests/test_python/test_match_tree.py index 901ac69..012e470 100644 --- a/tests/test_python/test_match_tree.py +++ b/tests/test_python/test_match_tree.py @@ -26,30 +26,33 @@ def test_match_log(self): tree_matcher = TreeMatcher(LogTemplates(["Hello`=<*> kenobi"])) log = "Hello`=there general kenobi" - assert tree_matcher.match_log(log, False)[0] == "Hello VAR kenobi" + assert tree_matcher.match_log(log, False)[0]["Template"] == "Hello <*> kenobi" def test_match_log_with_var(self): tree_matcher = TreeMatcher(LogTemplates(["Hello`=<*> kenobi"])) log = "Hello`=there general kenobi" result = tree_matcher.match_log(log, True) - assert result[0] == ("Hello VAR kenobi", "there general") + assert result[0]["Template"] == "Hello <*> kenobi" + assert result[0]["ParamList"] == ["there", "general"] def test_match_batch(self): tree_matcher = TreeMatcher(LogTemplates(["Hello`=<*> kenobi"])) logs = ["Hello`=there general kenobi", "roger roger"] results = tree_matcher.match_batch(logs, False) - assert results[0] == "Hello VAR kenobi" - assert results[1] == "template not found" + assert results[0]["Template"] == "Hello <*> kenobi" + assert results[1]["Template"] == "template not found" def test_match_batch_with_var(self): tree_matcher = TreeMatcher(LogTemplates(["Hello`=<*> kenobi"])) logs = ["Hello`=there general kenobi", "roger roger"] results = tree_matcher.match_batch(logs, True) - assert results[0] == ("Hello VAR kenobi", "there general") - assert results[1] == ("template not found", "") + assert results[0]["Template"] == "Hello <*> kenobi" + assert results[1]["Template"] == "template not found" + assert results[0]["ParamList"] == ["there", "general"] + assert results[1]["ParamList"] == [] def test_big_batch(self): logs = load_logs() @@ -57,7 +60,7 @@ def test_big_batch(self): results = tree_matcher.match_batch(logs, False, n_workers=3) for i in range(len(results)): - assert "template not found" != results[i] + assert "template not found" != results[i]["Template"] def test_big_batch_with_var(self): logs = load_logs() @@ -65,7 +68,7 @@ def test_big_batch_with_var(self): results = tree_matcher.match_batch(logs, True, n_workers=3) for i in range(len(results)): - assert "template not found" != results[i][0] + assert "template not found" != results[i]["Template"] def test_call(self): logs = load_logs() diff --git a/tests/test_python/test_types.py b/tests/test_python/test_types.py index 296764e..9367eb6 100644 --- a/tests/test_python/test_types.py +++ b/tests/test_python/test_types.py @@ -47,8 +47,8 @@ def test_add_elements(self): parsed[0] = "Hello VAR world VAR" parsed[3] = "ciaoo bellaaa" - assert parsed[0] == "Hello VAR world VAR" - assert parsed[3] == "template not found" + assert parsed[0]["Template"] == "Hello <*> world <*>" + assert parsed[3]["Template"] == "template not found" def test_get_all_ids(self): parsed = ParsedLogs(LogTemplates(templates), 3) @@ -64,7 +64,7 @@ def test_get_all_templates(self): parsed[0] = "Hello VAR world VAR" parsed[1] = "ciaoo bellaaa" - expected = ["Hello VAR world VAR", "template not found"] + expected = ["Hello <*> world <*>", "template not found"] assert parsed.get_all_templates() == expected def test_add_elements_with_vars(self): @@ -73,15 +73,17 @@ def test_add_elements_with_vars(self): parsed[0] = ("Hello VAR world VAR", "") parsed[3] = ("ciaoo bellaaa", "a b c") - assert parsed[0] == ("Hello VAR world VAR", "") - assert parsed[3] == ("template not found", "a b c") + assert parsed[0]["Template"] == "Hello <*> world <*>" + assert parsed[0]["ParamList"] == [] + assert parsed[3]["Template"] == "template not found" + assert parsed[3]["ParamList"] == ["a", "b", "c"] def test_get_all_variables(self): parsed = ParsedLogs(LogTemplates(templates), 2, with_vars=True) parsed[0] = ("Hello VAR world VAR", "") parsed[1] = ("ciaoo bellaaa", "a b c") - expected = ["", "a b c"] + expected = [[], ["a", "b", "c"]] assert parsed.get_all_vars() == expected def test_add_elements_shape_(self): diff --git a/uv.lock b/uv.lock index 568166f..150f461 100644 --- a/uv.lock +++ b/uv.lock @@ -1,5 +1,5 @@ version = 1 -revision = 2 +revision = 3 requires-python = ">=3.13" [[package]]