build: Use global variables instead of macros for test features

We don't want the build to depend on recompiling objects for test
separately from other executables. We can tweak settings via global
variables instead.

Change-Id: Ifdd078c2e381848ca1789934a36731eb8ceaf8b1
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/extensions/openpower-pels/tools/peltool.cpp b/extensions/openpower-pels/tools/peltool.cpp
index fe3afac..9c034fc 100644
--- a/extensions/openpower-pels/tools/peltool.cpp
+++ b/extensions/openpower-pels/tools/peltool.cpp
@@ -33,6 +33,8 @@
 #include <string>
 #include <xyz/openbmc_project/Common/File/error.hpp>
 
+#include "config_main.h"
+
 namespace fs = std::filesystem;
 using namespace phosphor::logging;
 using namespace openpower::pels;
@@ -63,6 +65,11 @@
 constexpr auto logging = "/xyz/openbmc_project/logging";
 } // namespace object_path
 
+std::string pelLogDir()
+{
+    return std::string(EXTENSION_PERSIST_DIR) + "/pels/logs";
+}
+
 /**
  * @brief helper function to get PEL commit timestamp from file name
  * @retrun BCDTime - PEL commit timestamp
@@ -288,13 +295,12 @@
     std::string val;
     char tmpValStr[50];
     std::string listStr;
-    char name[50];
-    sprintf(name, "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X_%.8X", itr.second.yearMSB,
+    char name[51];
+    sprintf(name, "/%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X_%.8X", itr.second.yearMSB,
             itr.second.yearLSB, itr.second.month, itr.second.day,
             itr.second.hour, itr.second.minutes, itr.second.seconds,
             itr.second.hundredths, itr.first);
-    std::string fileName(name);
-    fileName = EXTENSION_PERSIST_DIR "/pels/logs/" + fileName;
+    auto fileName = pelLogDir() + name;
     try
     {
         std::vector<uint8_t> data = getFileData(fileName);
@@ -450,7 +456,7 @@
     std::map<uint32_t, BCDTime> PELs;
     std::vector<std::string> plugins;
     listStr = "{\n";
-    for (auto it = fs::directory_iterator(EXTENSION_PERSIST_DIR "/pels/logs");
+    for (auto it = fs::directory_iterator(pelLogDir());
          it != fs::directory_iterator(); ++it)
     {
         if (!fs::is_regular_file((*it).path()))
@@ -539,7 +545,7 @@
 
     bool found = false;
 
-    for (auto it = fs::directory_iterator(EXTENSION_PERSIST_DIR "/pels/logs");
+    for (auto it = fs::directory_iterator(pelLogDir());
          it != fs::directory_iterator(); ++it)
     {
         // The PEL ID is part of the filename, so use that to find the PEL if
@@ -604,7 +610,7 @@
         pelID.erase(0, 2);
     }
 
-    for (auto it = fs::directory_iterator(EXTENSION_PERSIST_DIR "/pels/logs");
+    for (auto it = fs::directory_iterator(pelLogDir());
          it != fs::directory_iterator(); ++it)
     {
         if (ends_with((*it).path(), pelID))
@@ -621,8 +627,7 @@
 {
     log<level::INFO>("peltool deleting all event logs");
 
-    for (const auto& entry :
-         fs::directory_iterator(EXTENSION_PERSIST_DIR "/pels/logs"))
+    for (const auto& entry : fs::directory_iterator(pelLogDir()))
     {
         fs::remove(entry.path());
     }
@@ -668,7 +673,8 @@
                    const std::optional<std::regex>& scrubRegex)
 {
     std::size_t count = 0;
-    for (auto it = fs::directory_iterator(EXTENSION_PERSIST_DIR "/pels/logs");
+
+    for (auto it = fs::directory_iterator(pelLogDir());
          it != fs::directory_iterator(); ++it)
     {
         if (!fs::is_regular_file((*it).path()))