Skip to content

Commit

Permalink
libguard: Adding function to erase guardrecords
Browse files Browse the repository at this point in the history
Changes:
-Adding new function to erase/wipout all guard records present
in GUARD file.
-Adding -e option in tool, which will call the new API to erase
the data from GUARD file.
-Adding UT for the newly introduced function.
-Updating the README.md with new option details.

Test Results:
Running main() from ../googletest/src/gtest_main.cc
[==========] 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
No resolved Guard record found
Size left 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.ClearResolvedGuardRecord
[       OK ] TestGuardRecord.ClearResolvedGuardRecord (0 ms)
[ RUN      ] TestGuardRecord.EraseAllRecordsTest
[       OK ] TestGuardRecord.EraseAllRecordsTest (0 ms)
[----------] 15 tests from TestGuardRecord (7 ms total)

[----------] Global test environment tear-down
[==========] 15 tests from 1 test suite ran. (7 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 Aug 29, 2021
1 parent 726387c commit 2083004
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Options:
-r,--clearall Clears GUARD states for all resources.
-s,-clearresolvedrecord Delete GUARD states for oldest resolved resource
-p,--listresolvedrecords Listing of resolved GUARDed resources
-e,--eraseall Erase all the GUARDed resources
-v,--version Version of GUARD tool.
```
**Note:** Physical path can be fetched from device tree, using ATTR_PHYS_DEV_PATH
Expand Down Expand Up @@ -83,3 +84,7 @@ guard -p
ID | ERROR | Type | Path
ffffffff | 00000000 | manual | /sys-0/node-0/dimm-0
```
* To erase all the guard records
```
guard -e
```
13 changes: 12 additions & 1 deletion guard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ void guardCreate(const std::string& physicalPath)
std::cout << "Success" << std::endl;
}

void guardErase()
{
eraseAllRecords();
}

static void exitWithError(const std::string& help, const char* err)
{
std::cerr << "ERROR: " << err << std::endl << help << std::endl;
Expand All @@ -123,8 +128,8 @@ int main(int argc, char** argv)
std::optional<std::string> deleteGuardStr;
bool listGuardRecords = false;
bool clearAll = false;
bool clearResolvedRecord = false;
bool listResolvedGuardRecords = false;
bool eraseall = false;
bool gversion = false;

app.set_help_flag("-h, --help",
Expand All @@ -141,6 +146,8 @@ int main(int argc, char** argv)
"Clears GUARD states for all resources");
app.add_flag("-p, --listresolvedrecords", listResolvedGuardRecords,
"Listing of resolved GUARDed resources");
app.add_flag("-e, --eraseall", eraseall,
"Erase all the GUARDed resources");
app.add_flag("-v, --version", gversion, "Version of GUARD tool");

CLI11_PARSE(app, argc, argv);
Expand All @@ -167,6 +174,10 @@ int main(int argc, char** argv)
{
guardList(true);
}
else if (eraseall)
{
guardErase();
}
else if (gversion)
{
std::cout << "GUARD Tool version is " << GUARD_VERSION << std::endl;
Expand Down
7 changes: 7 additions & 0 deletions libguard/guard_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ int clearResolvedRecord()
return delpos;
}

void eraseAllRecords()
{
GuardFile file(guardFilePath);

file.erase(0, file.size());
}

void libguard_init(bool enableDevtree)
{
initialize();
Expand Down
7 changes: 7 additions & 0 deletions libguard/guard_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ void libguard_init(bool enableDevtree = true);
*/
const fs::path& getGuardFilePath();

/**
* @brief Erase/wipeout all the guard records from GUARD file
*
* @return NULL
*/
void eraseAllRecords();

namespace utest
{
void setGuardFile(const fs::path& file);
Expand Down
14 changes: 14 additions & 0 deletions test/guard_intf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,17 @@ TEST_F(TestGuardRecord, ClearResolvedGuardRecord)
openpower::guard::GuardRecords records = openpower::guard::getAll();
EXPECT_EQ(records.size(), 2);
}

TEST_F(TestGuardRecord, EraseAllRecordsTest)
{
openpower::guard::libguard_init();
std::string phyPath = "/sys-0/node-0/proc-1/eq-0/fc-0/core-0";
std::optional<openpower::guard::EntityPath> entityPath =
openpower::guard::getEntityPath(phyPath);
openpower::guard::create(*entityPath);
openpower::guard::GuardRecords records = openpower::guard::getAll();
EXPECT_EQ(records.size(), 1);
openpower::guard::eraseAllRecords();
openpower::guard::GuardRecords records = openpower::guard::getAll();
EXPECT_EQ(records.size(), 0);
}

0 comments on commit 2083004

Please sign in to comment.