Skip to content

Commit

Permalink
tool: Changes in options of guard tool
Browse files Browse the repository at this point in the history
Changes:
-Making options of guardtool more meaningful as per the
backend functionality.
Like -d to -i, this will Invalidate a single Guard record
Changing --clear-all to --reset, which will erase all the
guard records.
-Adding -I, will Invalidates all the Guard records
-Adding -a option to list the resolved guard records
-Updating README with new options

Test:
-creating and invalidating guard records, checking if its getting
displayed with new option or not.
-with changed options able to invalidate the guard records.

[==========] Running 15 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 15 tests from TestGuardRecord
[ RUN      ] TestGuardRecord.CreateGuardRecord
[       OK ] TestGuardRecord.CreateGuardRecord (0 ms)
[ RUN      ] TestGuardRecord.ClearGuardGoodPathTest
[       OK ] TestGuardRecord.ClearGuardGoodPathTest (0 ms)
[ RUN      ] TestGuardRecord.DeleteGuardGoodPathTest
[       OK ] TestGuardRecord.DeleteGuardGoodPathTest (0 ms)
[ RUN      ] TestGuardRecord.NegTestCaseEP
[       OK ] TestGuardRecord.NegTestCaseEP (0 ms)
[ RUN      ] TestGuardRecord.NegTestCaseFullGuardFile
Guard file size is 656 and space remaining in GUARD file is 0

[       OK ] TestGuardRecord.NegTestCaseFullGuardFile (0 ms)
[ RUN      ] TestGuardRecord.AlreadyGuardedTC
Already guard record is available in the GUARD partition
[       OK ] TestGuardRecord.AlreadyGuardedTC (0 ms)
[ RUN      ] TestGuardRecord.GetCreatedGuardRecordTC
[       OK ] TestGuardRecord.GetCreatedGuardRecordTC (0 ms)
[ RUN      ] TestGuardRecord.DeleteByEntityPath
[       OK ] TestGuardRecord.DeleteByEntityPath (0 ms)
[ RUN      ] TestGuardRecord.DeleteWithNotExistentEntity
Guard record not found
[       OK ] TestGuardRecord.DeleteWithNotExistentEntity (0 ms)
[ RUN      ] TestGuardRecord.DeleteByRecordId
[       OK ] TestGuardRecord.DeleteByRecordId (0 ms)
[ RUN      ] TestGuardRecord.DeleteWithNotExistentRecordId
Guard record not found
[       OK ] TestGuardRecord.DeleteWithNotExistentRecordId (0 ms)
[ RUN      ] TestGuardRecord.GetGuardFilePathTC
[       OK ] TestGuardRecord.GetGuardFilePathTC (0 ms)
[ RUN      ] TestGuardRecord.GetGuardFilePathWhenLibguradDidNotInitTC
Guard file is not initialised.
[       OK ] TestGuardRecord.GetGuardFilePathWhenLibguradDidNotInitTC (0 ms)
[ RUN      ] TestGuardRecord.ClearGuardInvalidatePathTest
[       OK ] TestGuardRecord.ClearGuardInvalidatePathTest (0 ms)
[ RUN      ] TestGuardRecord.ClearResolvedGuardRecord
[       OK ] TestGuardRecord.ClearResolvedGuardRecord (0 ms)
[----------] 15 tests from TestGuardRecord (4 ms total)

[----------] Global test environment tear-down
[==========] 15 tests from 1 test suite ran. (5 ms total)
[  PASSED  ] 15 tests.
------------------------------------------------------------------------------
Ok:                 1
Expected Fail:      0
Fail:               0
Unexpected Pass:    0
Skipped:            0
Timeout:            0

Signed-off-by: Chirag Sharma <[email protected]>
  • Loading branch information
Chirag Sharma committed Sep 3, 2021
1 parent 79cba70 commit 60a3b31
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 52 deletions.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ GUARD Tool
Usage: guard [OPTIONS]
Options:
-h,--help Use the below listed functions.
Warning: Don't try guard on non guardable units
(sys, perv)
-c,--create TEXT Create GUARD record, expects physical path as input.
-d,--delete TEXT Delete GUARD record, expects physical path as input.
-l,--list Listing of GUARDed resources.
-r,--clearall Clears GUARD states for all resources.
-v,--version Version of GUARD tool.
-h,--help Guard CLI tool options
-c,--create TEXT Create Guard record, expects physical path as input
-i,--invalidate TEXT Invalidate a single Guard record, expects physical
path as input
-I,--invalidate-all Invalidates all the Guard records
-l,--list List all the GUARD'ed resources
-r,--reset Erase all the Guard records
-v,--version Version of GUARD tool
```
**Note:** Physical path can be fetched from device tree, using ATTR_PHYS_DEV_PATH
attribute of the corresponding target.
Expand All @@ -64,11 +65,15 @@ guard -l
ID | ERROR | Type | Path
00000001 | 00000000 | manual | physical:sys-0/node-0/proc-0/mc-0/mi-0/mcc-0
```
* To clear all the guard records
* To erase all the guard records
```
guard -r
```
* To clear a particular guard record
* To invalidate a single guard record
```
guard -i sys-0/node-0/proc-0/mc-0/mi-0/mcc-0
```
* To invalidate all the guard records
```
guard -d sys-0/node-0/proc-0/mc-0/mi-0/mcc-0
guard -I
```
130 changes: 91 additions & 39 deletions guard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,83 @@
#include "libguard/guard_interface.hpp"
#include "libguard/include/guard_record.hpp"

#include <config.h>

#include <CLI/CLI.hpp>

using namespace std;
using namespace openpower::guard;

void guardList()
void guardList(bool displayResolved)
{
auto records = getAll();
if (!records.size())
{
std::cout << "No Records to display" << std::endl;
return;
}
std::cout << "ID | ERROR | Type | Path " << std::endl;

bool isHeaderPrinted = false;
for (const auto& elem : records)
{
if ((elem.errType != GARD_Reconfig) &&
(elem.recordId != GUARD_RESOLVED))
// Not to print guard records with errorlog type set as GARD_Reconfig
// As guard below type records are for internal usage only.
if (elem.errType == GARD_Reconfig)
{
continue;
}
// To list resolved records as user wants to list resolved records
else if (displayResolved && (elem.recordId != GUARD_RESOLVED))
{
continue;
}
// To list unresolved records as user wants to list unresolved records
else if (!displayResolved && (elem.recordId == GUARD_RESOLVED))
{
continue;
}

// Don't print the header if already printed header since
// records mixed of resolved and unresolved records so if have
// only either one in retrieved records and user tried to see opposite
// one then we should not print header else user will get confused.
if (!isHeaderPrinted)
{
std::cout << "ID | ERROR | Type | Path " << std::endl;
isHeaderPrinted = true;
}

std::cout << std::hex << std::setw(8) << std::setfill('0')
<< elem.recordId;

std::cout << " | ";
std::cout << std::hex << std::setw(8) << std::setfill('0')
<< elem.elogId;

std::cout << " | ";
std::optional<std::string> gReasonToStr =
guardReasonToStr(elem.errType);
std::cout << *gReasonToStr;

std::cout << " | ";
std::optional<std::string> physicalPath =
getPhysicalPath(elem.targetId);
if (!physicalPath)
{
std::cout << "Unknown ";
}
else
{
std::cout << std::hex << std::setw(8) << std::setfill('0')
<< elem.recordId;
std::cout << " | ";
std::cout << std::hex << std::setw(8) << std::setfill('0')
<< elem.elogId;

std::cout << " | ";
std::optional<std::string> gReasonToStr =
guardReasonToStr(elem.errType);
std::cout << *gReasonToStr;
std::cout << " | ";
std::optional<std::string> physicalPath =
getPhysicalPath(elem.targetId);
if (!physicalPath)
{
std::cout << "Unknown ";
}
else
{
std::cout << *physicalPath;
}
std::cout << std::endl;
std::cout << *physicalPath;
}
std::cout << std::endl;
}

if (!isHeaderPrinted)
{
std::cout << "No "
<< (displayResolved == true ? "resolved" : "unresolved")
<< " records to display" << std::endl;
}
}

Expand All @@ -63,6 +98,11 @@ void guardClear()
clearAll();
}

void guardInvalidateAll()
{
invalidateAll();
}

void guardCreate(const std::string& physicalPath)
{
std::optional<EntityPath> entityPath = getEntityPath(physicalPath);
Expand All @@ -85,25 +125,29 @@ int main(int argc, char** argv)
{
try
{
CLI::App app{"GUARD Tool"};
CLI::App app{"Guard Tool"};
std::optional<std::string> createGuardStr;
std::optional<std::string> deleteGuardStr;
bool listGuardRecords = false;
bool clearAll = false;
bool listResolvedGuardRecords = false;
bool invalidateAll = false;
bool gversion = false;

app.set_help_flag("-h, --help",
"Use the below listed functions.\n"
"Warning: Don't try guard on non guardable units "
"(sys, perv)");
app.set_help_flag("-h, --help", "Guard CLI tool options");
app.add_option("-c, --create", createGuardStr,
"Create GUARD record, expects physical path as input");
app.add_option("-d, --delete", deleteGuardStr,
"Delete GUARD record, expects physical path as input");
"Create Guard record, expects physical path as input");
app.add_option(
"-i, --invalidate", deleteGuardStr,
"Invalidate a single Guard record, expects physical path as input");
app.add_flag("-I, --invalidate-all", invalidateAll,
"Invalidates all the Guard records");
app.add_flag("-l, --list", listGuardRecords,
"Listing of GUARDed resources.");
app.add_flag("-r, --clearall", clearAll,
"Clears GUARD states for all resources");
"List all the Guard'ed resources");
app.add_flag("-r, --reset", clearAll, "Erase all the Guard records");
app.add_flag("-a, --listresolvedrecords", listResolvedGuardRecords,
"List all the resolved Guard'ed resources")
->group("");
app.add_flag("-v, --version", gversion, "Version of GUARD tool");

CLI11_PARSE(app, argc, argv);
Expand All @@ -124,11 +168,19 @@ int main(int argc, char** argv)
}
else if (listGuardRecords)
{
guardList();
guardList(false);
}
else if (listResolvedGuardRecords)
{
guardList(true);
}
else if (invalidateAll)
{
guardInvalidateAll();
}
else if (gversion)
{
std::cout << "GUARD Tool version is " << GUARD_VERSION << std::endl;
std::cout << "Guard tool " << GUARD_VERSION << std::endl;
}
else
{
Expand Down
6 changes: 4 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ conf_data.set_quoted('GUARD_PRSV_PATH', get_option('GUARD_PRSV_PATH'),
description : 'GUARD file in pnor prsv partition'
)

conf_data.set_quoted('GUARD_VERSION', 'v1.0',
description : 'Setting guard tool version'
)

conf_data.set('DEV_TREE', get_option('devtree').enabled(),
description : 'Use device tree to get physical path value'
)
Expand All @@ -40,8 +44,6 @@ configure_file(output: 'config.h',
)

#add_project_arguments('-DPGUARD', language : 'cpp')
add_project_arguments('-DGUARD_VERSION', language : 'cpp')
set_variable('GUARD_VERSION', '1.0')

subdir('libguard')

Expand Down

0 comments on commit 60a3b31

Please sign in to comment.