[clang-tidy] Fix clang-tidy errors from g3/gsys config

Fix the clang-tidy errors found here: https://paste.googleplex.com/6044161211105280
Also add dummy .clang-tidy to prevent errors being thrown from xyz/
directory and auto-generated .pb.h files

Google-Bug-Id: 380138738
Change-Id: Iebc449b4d633c603739a4d752a24d77527ebd346
Signed-off-by: David Tang <davtang@google.com>
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..68454d8
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: ''
+
+WarningsAsErrors: '*'
+HeaderFilterRegex: '(?!\.pb\.h$)|(?!^xyz/)'
\ No newline at end of file
diff --git a/boot-time-blob/blob_handler.cpp b/boot-time-blob/blob_handler.cpp
index 2f8a057..069c318 100644
--- a/boot-time-blob/blob_handler.cpp
+++ b/boot-time-blob/blob_handler.cpp
@@ -109,7 +109,7 @@
         bus.call(method).read(checkpoints);
         for (auto checkpoint : checkpoints)
         {
-            auto cpProto = btProto.add_checkpoints();
+            auto* cpProto = btProto.add_checkpoints();
             cpProto->set_name(std::get<0>(checkpoint));
             cpProto->set_wall_time_ms(std::get<1>(checkpoint));
             cpProto->set_mono_time_ms(std::get<2>(checkpoint));
@@ -135,7 +135,7 @@
         bus.call(method).read(durations);
         for (auto duration : durations)
         {
-            auto durProto = btProto.add_durations();
+            auto* durProto = btProto.add_durations();
             durProto->set_name(std::get<0>(duration));
             durProto->set_duration_ms(std::get<1>(duration));
         }
@@ -174,7 +174,7 @@
     }
 
     std::vector<char> vec(btProto.ByteSizeLong());
-    if (!btProto.SerializeToArray(vec.data(), vec.size()))
+    if (!btProto.SerializeToArray(vec.data(), static_cast<int>(vec.size())))
     {
         fmt::print(stderr, "[{}]: Could not serialize protobuf to array\n",
                    __FUNCTION__);
@@ -260,12 +260,8 @@
 // Checks for a read-only flag.
 bool BlobHandler::isReadOnlyOpenFlags(const uint16_t flags)
 {
-    if (((flags & blobs::OpenFlags::read) == blobs::OpenFlags::read) &&
-        ((flags & blobs::OpenFlags::write) == 0))
-    {
-        return true;
-    }
-    return false;
+    return ((flags & blobs::OpenFlags::read) == blobs::OpenFlags::read) &&
+           ((flags & blobs::OpenFlags::write) == 0);
 }
 
 } // namespace blobs
diff --git a/boot-time-blob/blob_handler.hpp b/boot-time-blob/blob_handler.hpp
index 3f032da..3294b6c 100644
--- a/boot-time-blob/blob_handler.hpp
+++ b/boot-time-blob/blob_handler.hpp
@@ -34,7 +34,7 @@
     bool expire(uint16_t session) override;
 
   private:
-    bool isReadOnlyOpenFlags(uint16_t flag);
+    static bool isReadOnlyOpenFlags(uint16_t flag);
     std::unordered_map<uint16_t, std::vector<char>> sessions;
 };
 
diff --git a/include/bmc_monitor_app.hpp b/include/bmc_monitor_app.hpp
index 3a0dc09..2ff50fc 100644
--- a/include/bmc_monitor_app.hpp
+++ b/include/bmc_monitor_app.hpp
@@ -21,7 +21,7 @@
         "/xyz/openbmc_project/time/boot/bmc";
 
     BMCMonitorApp(sdbusplus::bus::bus& bus,
-                  std::shared_ptr<sdbusplus::asio::connection> conn);
+                  const std::shared_ptr<sdbusplus::asio::connection>& conn);
 
   private:
     sdbusplus::server::manager::manager objManager;
diff --git a/src/bmc_monitor_app.cpp b/src/bmc_monitor_app.cpp
index 25f2c9b..85371e3 100644
--- a/src/bmc_monitor_app.cpp
+++ b/src/bmc_monitor_app.cpp
@@ -55,7 +55,7 @@
 
 BMCMonitorApp::BMCMonitorApp(
     sdbusplus::bus::bus& bus,
-    std::shared_ptr<sdbusplus::asio::connection> conn) :
+    const std::shared_ptr<sdbusplus::asio::connection>& conn) :
     objManager(bus, kObjPath.data()), util(std::make_shared<Util>()),
     cpCSV(std::make_shared<FileUtil>(util->getCPPath(kNodeName, false))),
     durCSV(std::make_shared<FileUtil>(util->getDurPath(kNodeName, false))),
@@ -75,7 +75,7 @@
             // we're being canceled
             return;
         }
-        else if (ec)
+        if (ec)
         {
             fmt::print(stderr, "[checkBmcFinish] Timer Error: {}\n",
                        ec.message().c_str());
@@ -91,18 +91,12 @@
         // `free(): double free detected` or `free(): invalid pointer` error.
         SystemdTimestamp times;
         std::array<std::pair<std::string_view, uint64_t*>, 6> bootTimestamp = {
-            std::make_pair<std::string_view, uint64_t*>(
-                kSystemdFirmwareTime.data(), &times.firmware),
-            std::make_pair<std::string_view, uint64_t*>(
-                kSystemdLoaderTime.data(), &times.loader),
-            std::make_pair<std::string_view, uint64_t*>(
-                kSystemdKernelTime.data(), &times.kernel),
-            std::make_pair<std::string_view, uint64_t*>(
-                kSystemdInitRDTime.data(), &times.initRD),
-            std::make_pair<std::string_view, uint64_t*>(
-                kSystemdUserspaceTime.data(), &times.userspace),
-            std::make_pair<std::string_view, uint64_t*>(
-                kSystemdFinishTime.data(), &times.finish)};
+            std::make_pair(kSystemdFirmwareTime.data(), &times.firmware),
+            std::make_pair(kSystemdLoaderTime.data(), &times.loader),
+            std::make_pair(kSystemdKernelTime.data(), &times.kernel),
+            std::make_pair(kSystemdInitRDTime.data(), &times.initRD),
+            std::make_pair(kSystemdUserspaceTime.data(), &times.userspace),
+            std::make_pair(kSystemdFinishTime.data(), &times.finish)};
 
         for (const auto& timestamp : bootTimestamp)
         {
@@ -146,28 +140,34 @@
         // https://github.com/systemd/systemd/blob/82b7bf8c1c8c6ded6f56b43998c803843a3b944b/src/analyze/analyze-time-data.c#L176-L186
         // Special calculation for kernel duration:
         // https://github.com/systemd/systemd/blob/82b7bf8c1c8c6ded6f56b43998c803843a3b944b/src/analyze/analyze-time-data.c#L84-L87
-        bootManager->setDuration(convertName(kSystemdFirmwareTime),
-                                 times.firmware != 0
-                                     ? (times.firmware - times.loader) /
-                                           kMillisecondPerSecond
-                                     : 0);
+        bootManager->setDuration(
+            convertName(kSystemdFirmwareTime),
+            times.firmware != 0
+                ? static_cast<int64_t>((times.firmware - times.loader) /
+                                       kMillisecondPerSecond)
+                : 0);
         bootManager->setDuration(
             convertName(kSystemdLoaderTime),
-            times.loader != 0 ? times.loader / kMillisecondPerSecond : 0);
+            times.loader != 0
+                ? static_cast<int64_t>(times.loader / kMillisecondPerSecond)
+                : 0);
         bootManager->setDuration(
             convertName(kSystemdKernelTime),
-            (times.initRD > 0 ? times.initRD : times.userspace) /
-                kMillisecondPerSecond);
-        bootManager->setDuration(convertName(kSystemdInitRDTime),
-                                 times.initRD != 0
-                                     ? (times.userspace - times.initRD) /
-                                           kMillisecondPerSecond
-                                     : 0);
-        bootManager->setDuration(convertName(kSystemdUserspaceTime),
-                                 times.userspace != 0
-                                     ? (times.finish - times.userspace) /
-                                           kMillisecondPerSecond
-                                     : 0);
+            static_cast<int64_t>(
+                (times.initRD > 0 ? times.initRD : times.userspace) /
+                kMillisecondPerSecond));
+        bootManager->setDuration(
+            convertName(kSystemdInitRDTime),
+            times.initRD != 0
+                ? static_cast<int64_t>((times.userspace - times.initRD) /
+                                       kMillisecondPerSecond)
+                : 0);
+        bootManager->setDuration(
+            convertName(kSystemdUserspaceTime),
+            times.userspace != 0
+                ? static_cast<int64_t>((times.finish - times.userspace) /
+                                       kMillisecondPerSecond)
+                : 0);
 
 #ifdef NPCM7XX_OR_NEWER
         // NPCM7XX or newer Nuvoton BMC has a register that starts counting from
diff --git a/src/dbus_handler.cpp b/src/dbus_handler.cpp
index 79048a4..fda63e3 100644
--- a/src/dbus_handler.cpp
+++ b/src/dbus_handler.cpp
@@ -24,7 +24,7 @@
     sdbusplus::server::object::object<Duration>(dbus, objPath.c_str()),
     sdbusplus::server::object::object<Checkpoint>(dbus, objPath.c_str()),
     sdbusplus::server::object::object<Statistic>(dbus, objPath.c_str()),
-    bootManager(bootManager), util(util)
+    bootManager(std::move(bootManager)), util(std::move(util))
 {}
 
 void DbusHandler::setCheckpoint(std::string checkpointName, int64_t wallTime,
diff --git a/src/host_monitor_app.cpp b/src/host_monitor_app.cpp
index 05db6b0..3c0dced 100644
--- a/src/host_monitor_app.cpp
+++ b/src/host_monitor_app.cpp
@@ -29,9 +29,9 @@
 constexpr std::string_view kHostIface = "xyz.openbmc_project.State.Host";
 constexpr std::string_view kHostProperty = "CurrentHostState";
 
-constexpr std::string_view kHostStateRunning =
+[[maybe_unused]] constexpr std::string_view kHostStateRunning =
     "xyz.openbmc_project.State.Host.HostState.Running";
-constexpr std::string_view kHostStateOff =
+[[maybe_unused]] constexpr std::string_view kHostStateOff =
     "xyz.openbmc_project.State.Host.HostState.Off";
 
 constexpr std::string_view kOSStatusService =
diff --git a/src/main.cpp b/src/main.cpp
index 63021d9..7a9fc47 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,7 +7,8 @@
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server.hpp>
 
-using namespace boot_time_monitor;
+using boot_time_monitor::BMCMonitorApp;
+using boot_time_monitor::HostMonitorApp;
 
 int main()
 {
diff --git a/src/utils.cpp b/src/utils.cpp
index 2509ae3..b1afbef 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -119,13 +119,13 @@
 void FileUtil::addCheckpoint(std::string_view name, int64_t wallTimeInMs,
                              int64_t monoTimeInMs)
 {
-    (*ofs) << name << "," << wallTimeInMs << "," << monoTimeInMs << std::endl;
+    (*ofs) << name << "," << wallTimeInMs << "," << monoTimeInMs << '\n';
     ofs->flush();
 }
 
 void FileUtil::addDuration(std::string_view name, int64_t durationInMs)
 {
-    (*ofs) << name << "," << durationInMs << std::endl;
+    (*ofs) << name << "," << durationInMs << '\n';
     ofs->flush();
 }