diff options
author | Patrick Venture <venture@google.com> | 2018-10-26 18:14:00 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2018-10-26 18:16:27 -0700 |
commit | f18bf836d206b1bc5b4fd849127a2e706eddf0aa (patch) | |
tree | 5c61f65861a2350f84080f21c6b996d33d0c2ab3 /logging_test.cpp | |
parent | aabb92ef56c4faa8f05487e9fcdf83f1053f1a22 (diff) | |
download | phosphor-logging-f18bf836d206b1bc5b4fd849127a2e706eddf0aa.tar.gz phosphor-logging-f18bf836d206b1bc5b4fd849127a2e706eddf0aa.zip |
add .clang-format
Change-Id: I2c36b7886a25d0b235693b0776019d29608e1d52
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'logging_test.cpp')
-rw-r--r-- | logging_test.cpp | 224 |
1 files changed, 107 insertions, 117 deletions
diff --git a/logging_test.cpp b/logging_test.cpp index 0ad10b7..3a144f8 100644 --- a/logging_test.cpp +++ b/logging_test.cpp @@ -1,18 +1,19 @@ // A basic unit test that runs on a BMC (qemu or hardware) #include <getopt.h> -#include <iostream> #include <systemd/sd-journal.h> -#include <sstream> -#include <sdbusplus/exception.hpp> + +#include <iostream> +#include <phosphor-logging/elog-errors.hpp> #include <phosphor-logging/elog.hpp> #include <phosphor-logging/log.hpp> -#include <phosphor-logging/elog-errors.hpp> +#include <sdbusplus/exception.hpp> +#include <sstream> using namespace phosphor; using namespace logging; -const char *usage = "Usage: logging-test [OPTION] \n\n\ +const char* usage = "Usage: logging-test [OPTION] \n\n\ Options: \n\ [NONE] Default test case. \n\ -h, --help Display this usage text. \n\ @@ -21,29 +22,31 @@ Valid errors to commit: \n\ AutoTestSimple, AutoTestCreateAndCommit\n"; // validate the journal metadata equals the input value -int validate_journal(const char *i_entry, const char *i_value) +int validate_journal(const char* i_entry, const char* i_value) { - sd_journal *journal; - const void *data; + sd_journal* journal; + const void* data; size_t l; int rc; bool validated = false; rc = sd_journal_open(&journal, SD_JOURNAL_LOCAL_ONLY); - if (rc < 0) { - std::cerr << "Failed to open journal: " << strerror(-rc) << "\n"; - return 1; + if (rc < 0) + { + std::cerr << "Failed to open journal: " << strerror(-rc) << "\n"; + return 1; } rc = sd_journal_query_unique(journal, i_entry); - if (rc < 0) { - std::cerr << "Failed to query journal: " << strerror(-rc) << "\n"; - return 1; + if (rc < 0) + { + std::cerr << "Failed to query journal: " << strerror(-rc) << "\n"; + return 1; } SD_JOURNAL_FOREACH_UNIQUE(journal, data, l) { std::string journ_entry((const char*)data); std::cout << journ_entry << "\n"; - if(journ_entry.find(i_value) != std::string::npos) + if (journ_entry.find(i_value) != std::string::npos) { std::cout << "We found it!\n"; validated = true; @@ -54,10 +57,11 @@ int validate_journal(const char *i_entry, const char *i_value) sd_journal_close(journal); rc = (validated) ? 0 : 1; - if(rc) + if (rc) { std::cerr << "Failed to find " << i_entry << " with value " << i_value - <<" in journal!" << "\n"; + << " in journal!" + << "\n"; } return rc; @@ -69,35 +73,36 @@ int elog_test() log<level::DEBUG>("Basic phosphor logging test"); // TEST 2 - Log with metadata field - const char *file_name = "phosphor_logging_test.txt"; + const char* file_name = "phosphor_logging_test.txt"; int number = 0xFEFE; - log<level::DEBUG>("phosphor logging test with attribute", - entry("FILE_NAME_WITH_NUM_TEST=%s_%x", file_name, number)); + log<level::DEBUG>( + "phosphor logging test with attribute", + entry("FILE_NAME_WITH_NUM_TEST=%s_%x", file_name, number)); // Now read back and verify our data made it into the journal int rc = validate_journal("FILE_NAME_WITH_NUM_TEST", "phosphor_logging_test.txt_fefe"); - if(rc) - return(rc); + if (rc) + return (rc); // TEST 3 - Create error log with 2 meta data fields (rvalue and lvalue) number = 0x1234; - const char *test_string = "/tmp/test_string/"; + const char* test_string = "/tmp/test_string/"; try { elog<example::xyz::openbmc_project::Example::Elog::TestErrorOne>( - example::xyz::openbmc_project::Example::Elog:: - TestErrorOne::ERRNUM(number), - example::xyz::openbmc_project::Example::Elog:: - TestErrorOne::FILE_PATH(test_string), - example::xyz::openbmc_project::Example::Elog:: - TestErrorOne::FILE_NAME("elog_test_3.txt"), - example::xyz::openbmc_project::Example::Elog:: - TestErrorTwo::DEV_ADDR(0xDEADDEAD), - example::xyz::openbmc_project::Example::Elog:: - TestErrorTwo::DEV_ID(100), - example::xyz::openbmc_project::Example::Elog:: - TestErrorTwo::DEV_NAME("test case 3")); + example::xyz::openbmc_project::Example::Elog::TestErrorOne::ERRNUM( + number), + example::xyz::openbmc_project::Example::Elog::TestErrorOne:: + FILE_PATH(test_string), + example::xyz::openbmc_project::Example::Elog::TestErrorOne:: + FILE_NAME("elog_test_3.txt"), + example::xyz::openbmc_project::Example::Elog::TestErrorTwo:: + DEV_ADDR(0xDEADDEAD), + example::xyz::openbmc_project::Example::Elog::TestErrorTwo::DEV_ID( + 100), + example::xyz::openbmc_project::Example::Elog::TestErrorTwo:: + DEV_NAME("test case 3")); } catch (example::xyz::openbmc_project::Example::Elog::TestErrorOne& e) { @@ -112,44 +117,39 @@ int elog_test() stream << std::hex << number; rc = validate_journal(TestErrorOne::ERRNUM::str_short, std::string(stream.str()).c_str()); - if(rc) - return(rc); - - rc = validate_journal(TestErrorOne::FILE_PATH::str_short, - test_string); - if(rc) - return(rc); - - rc = validate_journal(TestErrorOne::FILE_NAME::str_short, - "elog_test_3.txt"); - if(rc) - return(rc); - - rc = validate_journal(TestErrorTwo::DEV_ADDR::str_short, - "0xDEADDEAD"); - if(rc) - return(rc); - - rc = validate_journal(TestErrorTwo::DEV_ID::str_short, - "100"); - if(rc) - return(rc); - - rc = validate_journal(TestErrorTwo::DEV_NAME::str_short, - "test case 3"); - if(rc) - return(rc); + if (rc) + return (rc); + + rc = validate_journal(TestErrorOne::FILE_PATH::str_short, test_string); + if (rc) + return (rc); + + rc = + validate_journal(TestErrorOne::FILE_NAME::str_short, "elog_test_3.txt"); + if (rc) + return (rc); + + rc = validate_journal(TestErrorTwo::DEV_ADDR::str_short, "0xDEADDEAD"); + if (rc) + return (rc); + + rc = validate_journal(TestErrorTwo::DEV_ID::str_short, "100"); + if (rc) + return (rc); + + rc = validate_journal(TestErrorTwo::DEV_NAME::str_short, "test case 3"); + if (rc) + return (rc); // TEST 4 - Create error log with previous entry use number = 0x9876; try { - elog<TestErrorOne>(TestErrorOne::ERRNUM(number), - prev_entry<TestErrorOne::FILE_PATH>(), - TestErrorOne::FILE_NAME("elog_test_4.txt"), - TestErrorTwo::DEV_ADDR(0xDEADDEAD), - TestErrorTwo::DEV_ID(100), - TestErrorTwo::DEV_NAME("test case 4")); + elog<TestErrorOne>( + TestErrorOne::ERRNUM(number), prev_entry<TestErrorOne::FILE_PATH>(), + TestErrorOne::FILE_NAME("elog_test_4.txt"), + TestErrorTwo::DEV_ADDR(0xDEADDEAD), TestErrorTwo::DEV_ID(100), + TestErrorTwo::DEV_NAME("test case 4")); } catch (sdbusplus::exception_t& e) { @@ -161,62 +161,56 @@ int elog_test() stream << std::hex << number; rc = validate_journal(TestErrorOne::ERRNUM::str_short, std::string(stream.str()).c_str()); - if(rc) - return(rc); + if (rc) + return (rc); // This should just be equal to what we put in test 3 - rc = validate_journal(TestErrorOne::FILE_PATH::str_short, - test_string); - if(rc) - return(rc); - - rc = validate_journal(TestErrorOne::FILE_NAME::str_short, - "elog_test_4.txt"); - if(rc) - return(rc); - - rc = validate_journal(TestErrorTwo::DEV_ADDR::str_short, - "0xDEADDEAD"); - if(rc) - return(rc); - - rc = validate_journal(TestErrorTwo::DEV_ID::str_short, - "100"); - if(rc) - return(rc); - - rc = validate_journal(TestErrorTwo::DEV_NAME::str_short, - "test case 4"); - if(rc) - return(rc); + rc = validate_journal(TestErrorOne::FILE_PATH::str_short, test_string); + if (rc) + return (rc); + + rc = + validate_journal(TestErrorOne::FILE_NAME::str_short, "elog_test_4.txt"); + if (rc) + return (rc); + + rc = validate_journal(TestErrorTwo::DEV_ADDR::str_short, "0xDEADDEAD"); + if (rc) + return (rc); + + rc = validate_journal(TestErrorTwo::DEV_ID::str_short, "100"); + if (rc) + return (rc); + + rc = validate_journal(TestErrorTwo::DEV_NAME::str_short, "test case 4"); + if (rc) + return (rc); // Compile fail tests // Simple test to prove we fail to compile due to missing param - //elog<TestErrorOne>(TestErrorOne::ERRNUM(1), + // elog<TestErrorOne>(TestErrorOne::ERRNUM(1), // TestErrorOne::FILE_PATH("test")); // Simple test to prove we fail to compile due to invalid param - //elog<TestErrorOne>(TestErrorOne::ERRNUM(1), + // elog<TestErrorOne>(TestErrorOne::ERRNUM(1), // TestErrorOne::FILE_PATH("test"), // TestErrorOne::FILE_NAME(1)); return 0; } -void commitError(const char *text) +void commitError(const char* text) { if (strcmp(text, "AutoTestSimple") == 0) { try { - elog<example::xyz::openbmc_project::Example::Elog:: - AutoTestSimple>( - example::xyz::openbmc_project::Example::Elog:: - AutoTestSimple::STRING("FOO")); + elog<example::xyz::openbmc_project::Example::Elog::AutoTestSimple>( + example::xyz::openbmc_project::Example::Elog::AutoTestSimple:: + STRING("FOO")); } - catch (example::xyz::openbmc_project::Example::Elog:: - AutoTestSimple& e) + catch (example::xyz::openbmc_project::Example::Elog::AutoTestSimple& e) { std::cout << "elog exception caught: " << e.what() << std::endl; commit(e.name()); @@ -224,31 +218,29 @@ void commitError(const char *text) } else if (strcmp(text, "AutoTestCreateAndCommit") == 0) { - report<example::xyz::openbmc_project::Example::Elog:: - AutoTestSimple>( - example::xyz::openbmc_project::Example::Elog:: - AutoTestSimple::STRING("FOO")); + report<example::xyz::openbmc_project::Example::Elog::AutoTestSimple>( + example::xyz::openbmc_project::Example::Elog::AutoTestSimple:: + STRING("FOO")); } return; } -int main(int argc, char *argv[]) +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} - }; + 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) + while ((arg = getopt_long(argc, argv, "hc:", long_options, + &option_index)) != -1) { switch (arg) { @@ -259,10 +251,8 @@ int main(int argc, char *argv[]) case '?': std::cerr << usage; return 1; - } } return 0; - } |