summaryrefslogtreecommitdiffstats
path: root/logging_test.cpp
diff options
context:
space:
mode:
authorAndrew Geissler <andrewg@us.ibm.com>2016-10-18 12:51:29 -0500
committerAndrew Geissler <andrewg@us.ibm.com>2016-11-08 08:52:00 -0600
commitc830e0f492c50e712c2bf1589e0282eebb4107ab (patch)
tree0b97a05d0bb56ff3ef081325954c7e8dd50ae4ca /logging_test.cpp
parent6d910ad9e2b3c83d7dccbcf25f9bdce9e4b13a58 (diff)
downloadphosphor-logging-c830e0f492c50e712c2bf1589e0282eebb4107ab.tar.gz
phosphor-logging-c830e0f492c50e712c2bf1589e0282eebb4107ab.zip
Build the required error log header file for elogs
Take the elog.yaml file and generate the required hpp file required for build time validation and error log processing. A future commit will delete elog-gen.hpp and will start dynamically generating it during build. Change-Id: I21a87d959096a2541de69fde47f57f02482a00cc Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
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