summaryrefslogtreecommitdiffstats
path: root/logging_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'logging_test.cpp')
-rw-r--r--logging_test.cpp56
1 files changed, 32 insertions, 24 deletions
diff --git a/logging_test.cpp b/logging_test.cpp
index 9a638c3..c5f622c 100644
--- a/logging_test.cpp
+++ b/logging_test.cpp
@@ -1,9 +1,11 @@
// A basic unit test that runs on a BMC (qemu or hardware)
#include <iostream>
-#include <elog.hpp>
-#include <log.hpp>
#include <systemd/sd-journal.h>
+#include <sstream>
+#include "elog.hpp"
+#include "log.hpp"
+#include "elog-gen.hpp"
using namespace phosphor;
using namespace logging;
@@ -44,7 +46,8 @@ int validate_journal(const char *i_entry, const char *i_value)
rc = (validated) ? 0 : 1;
if(rc)
{
- std::cerr << "Failed to find " << i_entry << " in journal!" << "\n";
+ std::cerr << "Failed to find " << i_entry << " with value " << i_value
+ <<" in journal!" << "\n";
}
return rc;
@@ -72,56 +75,61 @@ int main()
const char *test_string = "/tmp/test_string/";
try
{
- elog<file_not_found>(file_not_found::errnum(number),
- file_not_found::file_path(test_string),
- file_not_found::file_name("elog_test_3.txt"));
+ elog<FILE_NOT_FOUND>(FILE_NOT_FOUND::ERRNUM(number),
+ FILE_NOT_FOUND::FILE_PATH(test_string),
+ FILE_NOT_FOUND::FILE_NAME("elog_test_3.txt"));
}
- catch (elogException<file_not_found>& e)
+ catch (elogException<FILE_NOT_FOUND>& e)
{
std::cout << "elog exception caught: " << e.what() << std::endl;
}
// Now read back and verify our data made it into the journal
- rc = validate_journal(file_not_found::errnum::str_short,
- std::to_string(number).c_str());
+ std::stringstream stream;
+ stream << std::hex << number;
+ rc = validate_journal(FILE_NOT_FOUND::ERRNUM::str_short,
+ std::string(stream.str()).c_str());
if(rc)
return(rc);
- rc = validate_journal(file_not_found::file_path::str_short,
+ rc = validate_journal(FILE_NOT_FOUND::FILE_PATH::str_short,
test_string);
if(rc)
return(rc);
- rc = validate_journal(file_not_found::file_name::str_short,
+ rc = validate_journal(FILE_NOT_FOUND::FILE_NAME::str_short,
"elog_test_3.txt");
if(rc)
return(rc);
// TEST 4 - Create error log with previous entry use
- number = 0xFEDC;
+ number = 0x9876;
try
{
- elog<file_not_found>(file_not_found::errnum(number),
- prev_entry<file_not_found::file_path>(),
- file_not_found::file_name("elog_test_4.txt"));
+ elog<FILE_NOT_FOUND>(FILE_NOT_FOUND::ERRNUM(number),
+ prev_entry<FILE_NOT_FOUND::FILE_PATH>(),
+ FILE_NOT_FOUND::FILE_NAME("elog_test_4.txt"));
}
catch (elogExceptionBase& e)
{
std::cout << "elog exception caught: " << e.what() << std::endl;
}
+
// Now read back and verify our data made it into the journal
- rc = validate_journal(file_not_found::errnum::str_short,
- std::to_string(number).c_str());
+ stream.str("");
+ stream << std::hex << number;
+ rc = validate_journal(FILE_NOT_FOUND::ERRNUM::str_short,
+ std::string(stream.str()).c_str());
if(rc)
return(rc);
// This should just be equal to what we put in test 3
- rc = validate_journal(file_not_found::file_path::str_short,
+ rc = validate_journal(FILE_NOT_FOUND::FILE_PATH::str_short,
test_string);
if(rc)
return(rc);
- rc = validate_journal(file_not_found::file_name::str_short,
+ rc = validate_journal(FILE_NOT_FOUND::FILE_NAME::str_short,
"elog_test_4.txt");
if(rc)
return(rc);
@@ -129,13 +137,13 @@ int main()
// Compile fail tests
// Simple test to prove we fail to compile due to missing param
- //elog<file_not_found>(file_not_found::errnum(1),
- // file_not_found::file_path("test"));
+ //elog<FILE_NOT_FOUND>(FILE_NOT_FOUND::ERRNUM(1),
+ // FILE_NOT_FOUND::FILE_PATH("test"));
// Simple test to prove we fail to compile due to invalid param
- //elog<file_not_found>(file_not_found::errnum(1),
- // file_not_found::file_path("test"),
- // file_not_found::file_name(1));
+ //elog<FILE_NOT_FOUND>(FILE_NOT_FOUND::ERRNUM(1),
+ // FILE_NOT_FOUND::FILE_PATH("test"),
+ // FILE_NOT_FOUND::FILE_NAME(1));
return 0;
}
OpenPOWER on IntegriCloud