diff --git a/README.md b/README.md index 5c83b4f..26710a1 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,8 @@ Options: -i,--delete TEXT Invalidate a single Guard record, expects physical path as input -I,--invalidate-all Invalidates all the Guard records - -l,--list Listing of GUARDed resources. + -l,--list List all the Guard'ed resources + -r,--reset Erase all the Guard records -v,--version Version of GUARD tool. ``` @@ -51,6 +52,10 @@ Physical path formats supported by guard tool:- * /sys-0/node-0/proc-0/mc-0/mi-0/mcc-0 * sys-0/node-0/proc-0/mc-0/mi-0/mcc-0 +**Note:** +-r option will mark recordId of existing records in GUARD file as 0xffffffff +-e option will delete all records present in the GUARD file. + ### Examples * To create a guard record. @@ -72,3 +77,7 @@ guard -I ``` guard -i sys-0/node-0/proc-0/mc-0/mi-0/mcc-0 ``` +* To erase all the guard records +``` +guard -r +``` diff --git a/guard.cpp b/guard.cpp index b2aae48..2514f17 100644 --- a/guard.cpp +++ b/guard.cpp @@ -2,6 +2,8 @@ #include "libguard/guard_interface.hpp" #include "libguard/include/guard_record.hpp" +#include + #include using namespace std; @@ -108,6 +110,11 @@ void guardCreate(const std::string& physicalPath) std::cout << "Success" << std::endl; } +void guardReset() +{ + eraseAllRecords(); +} + static void exitWithError(const std::string& help, const char* err) { std::cerr << "ERROR: " << err << std::endl << help << std::endl; @@ -118,12 +125,13 @@ int main(int argc, char** argv) { try { - CLI::App app{"GUARD Tool"}; + CLI::App app{"Guard Tool"}; std::optional createGuardStr; std::optional deleteGuardStr; bool listGuardRecords = false; bool clearAll = false; bool listResolvedGuardRecords = false; + bool reset = false; bool gversion = false; app.set_help_flag("-h, --help", "Guard CLI tool options"); @@ -139,6 +147,7 @@ int main(int argc, char** argv) app.add_flag("-a, --listresolvedrecords", listResolvedGuardRecords, "List all the resolved Guard'ed resources") ->group(""); + app.add_flag("-r, --reset", reset, "Erase all the Guard records"); app.add_flag("-v, --version", gversion, "Version of GUARD tool"); CLI11_PARSE(app, argc, argv); @@ -165,9 +174,13 @@ int main(int argc, char** argv) { guardList(true); } + else if (reset) + { + guardReset(); + } else if (gversion) { - std::cout << "Guard tool version is " << GUARD_VERSION << std::endl; + std::cout << "Guard tool " << GUARD_VERSION << std::endl; } else { diff --git a/libguard/guard_interface.cpp b/libguard/guard_interface.cpp index 851f345..b0fd7c6 100644 --- a/libguard/guard_interface.cpp +++ b/libguard/guard_interface.cpp @@ -320,6 +320,13 @@ void clearAll() } } +void eraseAllRecords() +{ + GuardFile file(guardFilePath); + + file.erase(0, file.size()); +} + void libguard_init(bool enableDevtree) { initialize(); diff --git a/libguard/guard_interface.hpp b/libguard/guard_interface.hpp index efb4172..7cb5b0d 100644 --- a/libguard/guard_interface.hpp +++ b/libguard/guard_interface.hpp @@ -88,6 +88,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); diff --git a/meson.build b/meson.build index 63d71b7..55bed5c 100644 --- a/meson.build +++ b/meson.build @@ -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' ) @@ -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') diff --git a/test/guard_intf_test.cpp b/test/guard_intf_test.cpp index 4b5a2a0..687b29c 100644 --- a/test/guard_intf_test.cpp +++ b/test/guard_intf_test.cpp @@ -264,7 +264,7 @@ TEST_F(TestGuardRecord, GetGuardFilePathWhenLibguradDidNotInitTC) // Checking without libguard_init() call. EXPECT_THROW({ openpower::guard::getGuardFilePath(); }, - openpower::guard::exception::InvalidEntry); + openpower::guard::exception::GuardFileOpenFailed); // Set the guard file since UT reached the end openpower::guard::utest::setGuardFile(guardFile); @@ -299,3 +299,17 @@ TEST_F(TestGuardRecord, ClearResolvedGuardRecord) openpower::guard::GuardRecords records = openpower::guard::getAll(); EXPECT_EQ(records.size(), 4); } + +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 entityPath = + openpower::guard::getEntityPath(phyPath); + openpower::guard::create(*entityPath); + openpower::guard::GuardRecords records = openpower::guard::getAll(); + EXPECT_EQ(records.size(), 1); + openpower::guard::eraseAllRecords(); + records = openpower::guard::getAll(); + EXPECT_EQ(records.size(), 0); +}