Last active
August 15, 2019 16:34
-
-
Save sotaoverride/4b19b92896f48c17f2c481b3d8a63457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//user_header_test.cpp | |
#include "extensions/openpower-pels/private_header.hpp" | |
#include "extensions/openpower-pels/user_header.hpp" | |
#include "extensions/openpower-pels/tools/peltool.hpp" | |
#include "pel_utils.hpp" | |
#include <string> // std::string | |
#include <iostream> // std::cout | |
#include <sstream> // std::stringstream | |
#include <gtest/gtest.h> | |
using namespace std; | |
using namespace openpower::pels; | |
TEST(UserHeaderTest, UserHeaderIdParseTest) | |
{ | |
auto data = pelDataFactory(TestPelType::userHeaderSimple); | |
std::cout << "AAtir testing: " << '\n'; | |
Stream stream(*data); | |
UserHeader uh(stream); | |
std::stringstream ss; | |
ss << std::hex << uh.header().id; | |
//ss.flags(std::ios::hex); | |
std::string foo; | |
ss >> foo; | |
std::cout << "foo: " << foo << '\n'; | |
foo = hexToString(foo); | |
ss << foo; | |
std::cout << "foo: " << foo << '\n'; | |
EXPECT_EQ(uh.valid(), true); | |
EXPECT_EQ(foo, "UH"); | |
} | |
TEST(UserHeaderTest, PrivateHeaderCreateTimeStampParseTest) | |
{ | |
auto data = pelDataFactory(TestPelType::privateHeaderSimple); | |
string n; | |
n ="1"; | |
PelTool pt(n); | |
std::cout << "AAtir testing private header timestamp: " << '\n'; | |
Stream stream(*data); | |
PrivateHeader ph(stream); | |
std::stringstream ss; | |
BCDTime foo; | |
std::string pts; | |
foo= ph.createTimestamp(); | |
//pts =pt.parseTimeStamp(foo); | |
//std::cout << "pts: " << pts << '\n'; | |
std::string _str,year,month,day,hour,minutes,seconds,hundredths; | |
//std::stringstream ss; | |
// year | |
//int _intForDate; | |
int yrindec = bcdToDec(foo.yearMSB); | |
int yrlsbindec = bcdToDec(foo.yearLSB); | |
//ss << std::hex << yrindec; | |
//ss >> _str; | |
//_str = hexToString(_str); | |
//std::cout << "year: in hex " << _str << '\n'; | |
//_str = hexToString(_str); | |
//ss << std::hex << foo.yearMSB; | |
//ss >> _intForDate; | |
//ss << year; | |
//ss >> _intForDate; | |
std::cout << "year: converted to decimal " << yrindec << '\n'; | |
std::cout << "year: converted to decimal " << yrlsbindec << '\n'; | |
} | |
//peltool_utility.hpp | |
#include <string> // std::string | |
#include <iostream> // std::cout | |
#include <sstream> // std::stringstream | |
#pragma once | |
using namespace std; | |
namespace openpower | |
{ | |
namespace pels | |
{ | |
int bcdToDec(uint8_t val) | |
{ | |
return ( (val/16*10) + (val%16) ); | |
} | |
int decToBcd(uint8_t val) | |
{ | |
return ( (val/10*16) + (val%10) ); | |
} | |
int hexCharToInt(char a){ | |
if(a>='0' && a<='9') | |
return(a-48); | |
else if(a>='A' && a<='Z') | |
return(a-55); | |
else | |
return(a-87); | |
} | |
string hexToString(string str){ | |
std::stringstream HexString; | |
for(long unsigned int i=0;i<str.length();i++){ | |
char a = str.at(i++); | |
char b = str.at(i); | |
int x = hexCharToInt(a); | |
int y = hexCharToInt(b); | |
HexString << (char)((16*x)+y); | |
} | |
return HexString.str(); | |
} | |
} | |
} | |
//peltool.hpp | |
#pragma once | |
#include "../section.hpp" | |
#include "../stream.hpp" | |
#include "../bcd_time.hpp" | |
#include "../private_header.hpp" | |
#include "../user_header.hpp" | |
#include "../pel.hpp" | |
#include "../repository.hpp" | |
#include "../bcd_time.hpp" | |
#include "../paths.hpp" | |
#include "peltool_utility.hpp" | |
#include <bitset> | |
#include <iostream> | |
#include <sstream> | |
#include <string> | |
using namespace std; | |
namespace openpower | |
{ | |
namespace pels | |
{ | |
/** | |
* @class pelTool | |
* | |
* pelTool class handels operations like parsing PELs. | |
*/ | |
class PelTool | |
{ | |
public: | |
PelTool() = delete; | |
~PelTool() = default; | |
PelTool(const PelTool&) = default; | |
PelTool& operator=(const PelTool&) = default; | |
PelTool(PelTool &&) = default; | |
PelTool& operator=(PelTool&&) = default; | |
/** | |
* @brief Constructor | |
* | |
* Fills in this class's data fields from the stream. | |
* | |
* @param[in] pel - the PEL data stream | |
*/ | |
explicit PelTool(string _cmd) | |
{ | |
} | |
/** | |
* @brief parse | |
* | |
* parse pel to human readable form | |
* | |
*/ | |
//char* PelTool::parse(const Repository&); | |
friend Stream& operator>>(Stream& s, PrivateHeader& ph); | |
friend Stream& operator<<(Stream& s, PrivateHeader& ph); | |
friend Stream& operator>>(Stream& s, UserHeader& uh); | |
friend Stream& operator<<(Stream& s, UserHeader& uh); | |
string parseTimeStamp(const BCDTime& timeStamp); | |
private: | |
//std::optional<std::vector<uint8_t>> Repository::getPELData(const LogID& id) | |
/** | |
* @brief parse a raw PEL into human readable strings | |
* | |
* @param[in] rawPelPath - The path to the file that contains the | |
* raw PEL. | |
* @param[in] obmcLogID - the corresponding OpenBMC event log id | |
*/ | |
// void parseRawPEL(const std::string& rawPelPath, uint32_t obmcLogID); | |
std::vector<uint8_t> data; | |
//Repository _repo; | |
std::stringstream ss; | |
}; | |
} // namespace pelTool | |
} // namespace openpower | |
//peltool.cpp | |
#include "peltool.hpp" | |
#include <iostream> | |
#include <iterator> | |
#include <map> | |
#include <phosphor-logging/log.hpp> | |
#include <fstream> | |
#include <filesystem> | |
#include <string> // std::string | |
#include <iostream> // std::cout | |
#include <sstream> // std::stringstream | |
#include "../pel.hpp" | |
namespace openpower | |
{ | |
namespace pels | |
{ | |
using namespace phosphor::logging; | |
namespace fs = std::filesystem; | |
#define SECTION_VERSION "Section Version" | |
//--------------UH------------------------ | |
#define SCOPE "Scope" // | |
#define SEVERITY "Severity" // | |
#define EVENT_TYPE "Event Type" // | |
#define PROBLEM_DOMAIN "Problem Domain" // | |
#define PROBLEM_VECTOR "Problem Vector" // | |
#define ACTION_FLAGS "Action Flags" // | |
//---------------------------------------- | |
//-------------PH---------------------------// | |
#define CREATE_TIME_STAMP "Created at" // | |
#define COMMIT_TIME_STAMP "Commited at" // | |
#define CREATOR_ID "Creator id" // | |
#define LOG_TYPE "Log type" // | |
#define SECTION_COUNT "Section count" // | |
#define OBMC_LOG_ID "Log id" // | |
#define CREATOR_VERSION "Creator version"// | |
#define ID "id" // | |
#define PLID "plid" // | |
//--------------------------------------- | |
#define SUBSECTION_TYPE "Subsection Type"// | |
#define CREATED_BY "Created by" // | |
#define CREATED_AT "Created at" // | |
#define COMMITED_AT "Commited at" | |
#define CREATOR_SUBSYSTEM "Creator Subsytemm" | |
#define CSSVER "CSSVER" | |
#define PLATFORM_LOG_ID "Platform Log Id" | |
#define ENTRY_ID "Entry ID" | |
#define LOG_SIZE "Total Log Size" | |
string PelTool::parseTimeStamp(const BCDTime& timeStamp) | |
{ | |
std::string _str,year,month,day,hour,minutes,seconds,hundredths; | |
std::stringstream ss; | |
// year | |
// ss << to_string(bcdToDec(timeStamp.yearMSB)) << "/" ; | |
//<< to_string(bcdToDec(timeStamp.yearLSB)); | |
/*<< "/" << to_string(bcdToDec(timeStamp.month)) << "/" to_string(bcdToDec(timeStamp.day)) << " " << to_string(bcdToDec(timeStamp.hour)) << ":" << to_string(bcdToDec(timeStamp.minutes)) << ":" << to_string(bcdToDec(timeStamp.seconds)) << ":" to_string(bcdToDec(timeStamp.hundredths)); | |
*/ | |
/*_str = hexToString(_str); | |
ss << year; | |
//month | |
ss << std::hex << timeStamp.month; | |
ss >> _str; | |
_str = hexToString(_str); | |
ss << month; | |
//day | |
ss << std::hex << timeStamp.day; | |
ss >> _str; | |
_str = hexToString(_str); | |
ss << day; | |
//hour | |
ss << std::hex << timeStamp.hour; | |
ss >> _str; | |
_str = hexToString(_str); | |
ss << hour; | |
//minutes | |
ss << std::hex << timeStamp.minutes; | |
ss >> _str; | |
_str = hexToString(_str); | |
ss << minutes; | |
//seconds | |
ss << std::hex << timeStamp.seconds; | |
ss >> _str; | |
_str = hexToString(_str); | |
ss << seconds; | |
//hundredths | |
ss << std::hex << timeStamp.hundredths; | |
ss >> _str; | |
_str = hexToString(_str); | |
ss << hundredths; | |
//complete date | |
_str = month + "/" + day + "/" + year + " " + hour + "::" + minutes + "::" + seconds + ":: " + hundredths; | |
*/ | |
return _str; | |
} | |
/*void PelTool::parseRawPEL(const std::string& rawPelPath, uint32_t obmcLogID) | |
{ | |
if (fs::exists(rawPelPath)) | |
{ | |
std::ifstream file(rawPelPath, std::ios::in | std::ios::binary); | |
auto data = std::vector<uint8_t>(std::istreambuf_iterator<char>(file), | |
std::istreambuf_iterator<char>()); | |
if (file.fail()) | |
{ | |
log<level::ERR>("Filesystem error reading a raw PEL", | |
entry("PELFILE=%s", rawPelPath.c_str()), | |
entry("OBMCLOGID=%d", obmcLogID)); | |
// TODO, Decide what to do here. Maybe nothing. | |
return; | |
} | |
file.close(); | |
auto pel = std::make_unique<PEL>(data, obmcLogID); | |
if (pel->valid()) | |
{ | |
// PELs created by others still need these fields set by us. | |
pel->assignID(); | |
pel->setCommitTime(); | |
try | |
{ | |
_repo.add(pel); | |
} | |
catch (std::exception& e) | |
{ | |
// Probably a full or r/o filesystem, not much we can do. | |
log<level::ERR>("Unable to add PEL to Repository", | |
entry("PEL_ID=0x%X", pel->id())); | |
} | |
//start parsing here. | |
//std::stringstream ss; | |
//user header | |
PelTool::ss << CREATOR_SUBSYSTEM << pel->userHeader()->subsystem() << SCOPE << pel->userHeader()->scope() | |
<< SEVERITY << pel->userHeader()->severity() << EVENT_TYPE << pel->userHeader()->eventType() | |
<< PROBLEM_DOMAIN << pel->userHeader()->problemDomain() << PROBLEM_VECTOR << pel->userHeader()->problemVector() | |
<< ACTION_FLAGS << pel->userHeader()->actionFlags() | |
//private header | |
<< CREATE_TIME_STAMP | |
<< pel->privateHeader()->createTimestamp().yearMSB | |
<< pel->privateHeader()->createTimestamp().yearLSB | |
<< pel->privateHeader()->createTimestamp().month | |
<< pel->privateHeader()->createTimestamp().day | |
<< pel->privateHeader()->createTimestamp().hour | |
<< pel->privateHeader()->createTimestamp().minutes | |
<< pel->privateHeader()->createTimestamp().seconds | |
<< pel->privateHeader()->createTimestamp().hundredths | |
<< COMMIT_TIME_STAMP | |
<< pel->privateHeader()->commitTimestamp().yearMSB | |
<< pel->privateHeader()->commitTimestamp().yearLSB | |
<< pel->privateHeader()->commitTimestamp().month | |
<< pel->privateHeader()->commitTimestamp().day | |
<< pel->privateHeader()->commitTimestamp().hour | |
<< pel->privateHeader()->commitTimestamp().minutes | |
<< pel->privateHeader()->commitTimestamp().seconds | |
<< pel->privateHeader()->commitTimestamp().hundredths | |
<< CREATOR_ID << pel->privateHeader()->creatorID() | |
<< LOG_TYPE << pel->privateHeader()->logType() << SECTION_COUNT << pel->privateHeader()->sectionCount() | |
<< OBMC_LOG_ID << pel->privateHeader()->obmcLogID() | |
// << CREATOR_VERSION << pel->privateHeader()->creatorVersion() | |
<< ID << pel->privateHeader()->id() << PLID << pel->privateHeader()->plid(); | |
} | |
else | |
{ | |
log<level::ERR>("Invalid PEL found", | |
entry("PELFILE=%s", rawPelPath.c_str()), | |
entry("OBMCLOGID=%d", obmcLogID)); | |
// TODO, make a whole new OpenBMC event log + PEL | |
} | |
} | |
else | |
{ | |
log<level::ERR>("Raw PEL file from BMC event log does not exist", | |
entry("PELFILE=%s", (rawPelPath).c_str()), | |
entry("OBMCLOGID=%d", obmcLogID)); | |
} | |
}*/ | |
} // namespace peltool | |
} // namespace openpower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment