-
Notifications
You must be signed in to change notification settings - Fork 12.2k
test-backend-ops: add support for specifying output format #14368
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
base: master
Are you sure you want to change the base?
Conversation
bfa7a43
to
359d792
Compare
359d792
to
34500f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for specifying the output format (console or SQL) for the test-backend-ops tool and unifies logging via a new printer interface.
- Introduces a printer interface with concrete implementations for console and SQL output.
- Updates test evaluation functions and the CLI to use the printer for logging.
- Adds new command-line option "--output" along with helper functions to parse the output format.
34500f9
to
679a141
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my end I think these changes to test-backend-ops
would be fine but keep in mind that it's an important piece of the project with many stakeholders.
passed = false; | ||
|
||
// Set test time | ||
time_t t = time(NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added to record the timestamp (the same as llama-bench
), but I haven’t decided how to use it.
Thanks for pointing that out! I’ll add the recent contributors as reviewers. |
tests/test-backend-ops.cpp
Outdated
// General purpose output methods | ||
virtual void print_info(const char * format, ...) = 0; | ||
virtual void print_error(const char * format, ...) = 0; | ||
virtual void print_device_info(const char * format, ...) = 0; | ||
virtual void print_test_summary(const char * format, ...) = 0; | ||
virtual void print_status_ok() = 0; | ||
virtual void print_status_fail() = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this a good design, all of these functions do the same and could be replaced with a single print_message
. If you want transfer the responsibility of formatting the output to a class, then the class needs to have the information to decide what to print, not an unstructured message. Ideally all of the functions would receive an object to print, and the class would determine how to format that object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I’ll update the code accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the latest commit. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really change anything. The ideal solution would be to remove all the messages entirely, and pass enough information to the printers so that they format the output in any way they want. That would require a significant refactor, and not simply replacing calls to printf
with printer->print_message
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check if I understand this correctly: f4f5512
Thanks.
76ca4f6
to
f4f5512
Compare
Signed-off-by: Xiaodong Ye <[email protected]>
Signed-off-by: Xiaodong Ye <[email protected]>
Signed-off-by: Xiaodong Ye <[email protected]>
Signed-off-by: Xiaodong Ye <[email protected]>
Signed-off-by: Xiaodong Ye <[email protected]>
Signed-off-by: Xiaodong Ye <[email protected]>
f4f5512
to
a4b376f
Compare
std::string type_str(type_name); | ||
|
||
if (type_str.find("test_operation_info") != std::string::npos) { | ||
handle_message(*static_cast<const test_operation_info*>(data)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a typical use-case for the visitor pattern, but idk if we should use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any suggestions for improvement here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes instead of the typeid->string dispatch, you can do a classic double dispatch, I mean indirectly you are following the same pattern
something like
struct msg { virtual void accept(message_visitor & v); = 0
struct message_visitor {
virtual void visit(const test_operation_info&) = 0;
virtual void visit(const device_info&) = 0;
....
};
struct test_operation_info : public msg{
void accept(message_visitor& v) const override { v.visit(*this); }
};
struct printer : message_visitor {
void print_message(const printable_message& m) { m.accept(*this); }
void visit(const test_operation_info&) override {}
};
struct console_printer : public printer {
/* override whatever you care about */
void visit(const test_operation_info& info) override { ...
};
struct sql_printer: public printer {
//same
};
Then at the call site
std::unique_ptr<printer> p = create_printer();
test_operation_info msg;
p->print_message(msg);
Signed-off-by: Xiaodong Ye <[email protected]>
Make sure to read the contributing guidelines before submitting a PR
Testing Done
Edit (added
build_commit
andbuild_number
for future use):