diff options
author | Michael Tritz <mtritz@us.ibm.com> | 2017-02-19 20:57:46 -0600 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-03-15 13:42:18 +0000 |
commit | e0eb1dddb5d5975bb867767a4cbfa652b5792e79 (patch) | |
tree | da12f02eb7e5c6458bf24c3c6d9262e7f6e0c5d9 /logging_test.cpp | |
parent | 9cfe9f38d9ed2ddedea6d58040bed6bfc0831f08 (diff) | |
download | phosphor-logging-e0eb1dddb5d5975bb867767a4cbfa652b5792e79.tar.gz phosphor-logging-e0eb1dddb5d5975bb867767a4cbfa652b5792e79.zip |
Error log inject tool
This tool adds an option to the logging-test
to inject an error as specified by command
line.
Change-Id: I1028bd3964db23ed5ffa50414f7a6cc2f880c40c
Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
Diffstat (limited to 'logging_test.cpp')
-rw-r--r-- | logging_test.cpp | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/logging_test.cpp b/logging_test.cpp index cb7548a..2260861 100644 --- a/logging_test.cpp +++ b/logging_test.cpp @@ -1,5 +1,6 @@ // A basic unit test that runs on a BMC (qemu or hardware) +#include <getopt.h> #include <iostream> #include <systemd/sd-journal.h> #include <sstream> @@ -9,6 +10,14 @@ using namespace phosphor; using namespace logging; +const char *usage = "Usage: logging-test [OPTION] \n\n\ +Options: \n\ +[NONE] Default test case. \n\ +-h, --help Display this usage text. \n\ +-c, --commit <string> Commit desired error. \n\n\ +Valid errors to commit: \n\ +AutoTestSimple\n"; + // validate the journal metadata equals the input value int validate_journal(const char *i_entry, const char *i_value) { @@ -52,7 +61,7 @@ int validate_journal(const char *i_entry, const char *i_value) return rc; } -int main() +int elog_test() { // TEST 1 - Basic log log<level::DEBUG>("Basic phosphor logging test"); @@ -193,3 +202,60 @@ int main() return 0; } + +void commitError(const char *text) +{ + if (strcmp(text, "AutoTestSimple") == 0) + { + try + { + elog<example::xyz::openbmc_project::Example::Elog:: + Error::AutoTestSimple>( + example::xyz::openbmc_project::Example::Elog:: + Error::AutoTestSimple::STRING("FOO")); + } + catch (elogException<example::xyz::openbmc_project::Example::Elog:: + Error::AutoTestSimple>& e) + { + std::cout << "elog exception caught: " << e.what() << std::endl; + commit(e.name()); + } + } + + return; +} + +int main(int argc, char *argv[]) +{ + char arg; + + if (argc == 1) + return elog_test(); + + static struct option long_options[] = + { + {"help", no_argument, 0, 'h'}, + {"commit", required_argument, 0, 'c'}, + {0, 0, 0, 0} + }; + int option_index = 0; + + while((arg=getopt_long(argc,argv,"hc:",long_options,&option_index)) != -1) + { + switch (arg) + { + case 'c': + commitError(optarg); + return 0; + + case 'h': + case '?': + std::cerr << usage; + return 1; + + } + } + + return 0; + +} |