Add lifetime property for drives interface

This will set the lifetime property when the eStoraged object is
created. This change does not expect the lifetime to change.

Tested:
busctl introspect  xyz.openbmc_project.eStoraged.mmcblk0 /xyz/openbmc_project/inventory/storage/mmcblk0
NAME                                      TYPE      SIGNATURE RESULT/VALUE FLAGS
org.freedesktop.DBus.Introspectable       interface -         -            -
.Introspect                               method    -         s            -
org.freedesktop.DBus.Peer                 interface -         -            -
.GetMachineId                             method    -         s            -
.Ping                                     method    -         -            -
org.freedesktop.DBus.Properties           interface -         -            -
.Get                                      method    ss        v            -
.GetAll                                   method    s         a{sv}        -
.Set                                      method    ssv       -            -
.PropertiesChanged                        signal    sa{sv}as  -            -
xyz.openbmc_project.Inventory.Item.Drive  interface -         -            -
.Capacity                                 property  t         (top secret) emits-change
.PredictedMediaLifeLeftPercent            property  y         100          emits-change
xyz.openbmc_project.Inventory.Item.Volume interface -         -            -
.ChangePassword                           method    ayay      -            -
.Erase                                    method    s         -            -
.FormatLuks                               method    ays       -            -
.Lock                                     method    -         -            -
.Unlock                                   method    ay        -            -

Signed-off-by: John Edward Broadbent <jebr@google.com>
Change-Id: Ifbbed7d81c55e3edbe519c2b1048b5d1731fbb0e
diff --git a/src/test/estoraged_test.cpp b/src/test/estoraged_test.cpp
index 05f872f..b98144e 100644
--- a/src/test/estoraged_test.cpp
+++ b/src/test/estoraged_test.cpp
@@ -39,6 +39,7 @@
     const char* testFileName = "testfile";
     const char* testLuksDevName = "testfile_luksDev";
     const uint64_t testSize = 24;
+    const uint8_t testLifeTime = 25;
     std::ofstream testFile;
     const char* testPath = "/test/openbmc_project/storage/test_dev";
     const char* estoragedInterface =
@@ -83,7 +84,7 @@
 
         esObject = std::make_unique<estoraged::EStoraged>(
             *objectServer, testFileName, testLuksDevName, testSize,
-            std::move(cryptIface), std::move(fsIface));
+            testLifeTime, std::move(cryptIface), std::move(fsIface));
     }
 
     void TearDown() override
diff --git a/src/test/meson.build b/src/test/meson.build
index 29cdda4..180d9d5 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -8,6 +8,7 @@
   'erase/crypto_test',
   'erase/sanitize_test',
   'estoraged_test',
+  'util_test',
 ]
 
 test_eStoraged_headers = include_directories('include')
diff --git a/src/test/util_test.cpp b/src/test/util_test.cpp
new file mode 100644
index 0000000..8f53510
--- /dev/null
+++ b/src/test/util_test.cpp
@@ -0,0 +1,52 @@
+#include <util.hpp>
+
+#include <fstream>
+
+#include <gmock/gmock-matchers.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+namespace estoraged_test
+{
+using estoraged::util::findPredictedMediaLifeLeftPercent;
+
+TEST(utilTest, passFindPredictedMediaLife)
+{
+    std::string prefixName = ".";
+    std::string testFileName = prefixName + "/life_time";
+    std::ofstream testFile;
+    testFile.open(testFileName,
+                  std::ios::out | std::ios::binary | std::ios::trunc);
+    testFile << "0x07 0x04";
+    testFile.close();
+    EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 40);
+}
+
+TEST(utilTest, estimatesSame)
+{
+
+    std::string prefixName = ".";
+    std::string testFileName = prefixName + "/life_time";
+    std::ofstream testFile;
+    testFile.open(testFileName,
+                  std::ios::out | std::ios::binary | std::ios::trunc);
+    testFile << "0x04 0x04";
+    testFile.close();
+
+    EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 70);
+}
+
+TEST(utilTest, estimatesNotAvailable)
+{
+
+    std::string prefixName = ".";
+    std::string testFileName = prefixName + "/life_time";
+    std::ofstream testFile;
+    testFile.open(testFileName,
+                  std::ios::out | std::ios::binary | std::ios::trunc);
+    testFile.close();
+
+    EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 255);
+}
+
+} // namespace estoraged_test