Get eraseMaxGeometry and eraseMinGeometry from dbus
Also, make findDevice return output parameters based on RVO.
With the change like in EntityManager JSON:
```
{
"Name": "example_emmc",
"Type": "EmmcDevice",
"LocationCode": "location"
"EraseMaxGeometry": 10000000000,
"EraseMinGeometry": 5000000000,
}
```
and geometry values will be set to estoraged.
Tested:
- unit test pass:
```
5/7 util_test OK 0.05s
```
Change-Id: Ia8499af2168c7e740558978273fc80456eb29282
Signed-off-by: Tom Tung <shes050117@gmail.com>
diff --git a/src/test/erase/verifyGeometry_test.cpp b/src/test/erase/verifyGeometry_test.cpp
index 8b362f3..57feebd 100644
--- a/src/test/erase/verifyGeometry_test.cpp
+++ b/src/test/erase/verifyGeometry_test.cpp
@@ -15,21 +15,24 @@
TEST(VerifyGeometry, TooBigFail)
{
VerifyDriveGeometry maxVerify("");
- EXPECT_THROW(maxVerify.geometryOkay(ERASE_MAX_GEOMETRY + 1),
+ EXPECT_THROW(maxVerify.geometryOkay(ERASE_MAX_GEOMETRY, ERASE_MIN_GEOMETRY,
+ ERASE_MAX_GEOMETRY + 1),
InternalFailure);
}
TEST(VerifyGeometry, TooSmallFail)
{
VerifyDriveGeometry minVerify("");
- EXPECT_THROW(minVerify.geometryOkay(ERASE_MIN_GEOMETRY - 1),
+ EXPECT_THROW(minVerify.geometryOkay(ERASE_MAX_GEOMETRY, ERASE_MIN_GEOMETRY,
+ ERASE_MIN_GEOMETRY - 1),
InternalFailure);
}
TEST(VerifyGeometry, pass)
{
VerifyDriveGeometry passVerify("");
- EXPECT_NO_THROW(passVerify.geometryOkay(ERASE_MIN_GEOMETRY + 1));
+ EXPECT_NO_THROW(passVerify.geometryOkay(
+ ERASE_MAX_GEOMETRY, ERASE_MIN_GEOMETRY, ERASE_MIN_GEOMETRY + 1));
}
} // namespace estoraged_test
diff --git a/src/test/estoraged_test.cpp b/src/test/estoraged_test.cpp
index bd6db0d..520c7ec 100644
--- a/src/test/estoraged_test.cpp
+++ b/src/test/estoraged_test.cpp
@@ -1,6 +1,7 @@
#include "estoraged_test.hpp"
#include "estoraged.hpp"
+#include "estoraged_conf.hpp"
#include <unistd.h>
@@ -89,7 +90,8 @@
esObject = std::make_unique<estoraged::EStoraged>(
*objectServer, testConfigPath, testFileName, testLuksDevName,
testSize, testLifeTime, testPartNumber, testSerialNumber,
- testLocationCode, std::move(cryptIface), std::move(fsIface));
+ testLocationCode, ERASE_MAX_GEOMETRY, ERASE_MIN_GEOMETRY,
+ std::move(cryptIface), std::move(fsIface));
}
void TearDown() override
diff --git a/src/test/util_test.cpp b/src/test/util_test.cpp
index 5f8dca5..708454d 100644
--- a/src/test/util_test.cpp
+++ b/src/test/util_test.cpp
@@ -1,3 +1,4 @@
+#include "estoraged_conf.hpp"
#include "getConfig.hpp"
#include <boost/container/flat_map.hpp>
@@ -131,15 +132,73 @@
/* Look for the device file. */
std::filesystem::path deviceFile, sysfsDir;
std::string luksName, locationCode;
- EXPECT_TRUE(estoraged::util::findDevice(data, std::filesystem::path("./"),
- deviceFile, sysfsDir, luksName,
- locationCode));
+ auto result = estoraged::util::findDevice(data,
+ std::filesystem::path("./"));
+ EXPECT_TRUE(result.has_value());
/* Validate the results. */
- EXPECT_EQ("/dev/mmcblk0", deviceFile.string());
- EXPECT_EQ("./mmcblk0/device", sysfsDir.string());
- EXPECT_EQ("luks-mmcblk0", luksName);
- EXPECT_EQ("U102020", locationCode);
+ EXPECT_EQ("/dev/mmcblk0", result->deviceFile.string());
+ EXPECT_EQ("./mmcblk0/device", result->sysfsDir.string());
+ EXPECT_EQ("luks-mmcblk0", result->luksName);
+ EXPECT_EQ("U102020", result->locationCode);
+ EXPECT_EQ(ERASE_MAX_GEOMETRY, result->eraseMaxGeometry);
+ EXPECT_EQ(ERASE_MIN_GEOMETRY, result->eraseMinGeometry);
+
+ /* Delete the dummy files. */
+ EXPECT_EQ(3U, std::filesystem::remove_all("mmcblk0"));
+ EXPECT_EQ(3U, std::filesystem::remove_all("abc"));
+ EXPECT_EQ(2U, std::filesystem::remove_all("def"));
+}
+
+/* Test case where we successfully find the device file with updating the
+ * min/max geometry. */
+TEST(utilTest, findDeviceWithMaxAndMinGeometryPass)
+{
+ estoraged::StorageData data;
+
+ /* Set up the map of properties. */
+ data.emplace(std::string("Type"),
+ estoraged::BasicVariantType("EmmcDevice"));
+ data.emplace(std::string("Name"), estoraged::BasicVariantType("emmc"));
+ data.emplace(std::string("LocationCode"),
+ estoraged::BasicVariantType("U102020"));
+ data.emplace(std::string("EraseMaxGeometry"),
+ estoraged::BasicVariantType((uint64_t)5566));
+ data.emplace(std::string("EraseMinGeometry"),
+ estoraged::BasicVariantType((uint64_t)1234));
+
+ /* Create a dummy device. */
+ std::filesystem::create_directories("abc/device");
+ const std::string dummyTypeFileName("abc/device/type");
+ std::ofstream dummyTypeFile(dummyTypeFileName,
+ std::ios::out | std::ios::trunc);
+ dummyTypeFile << "SSD";
+ dummyTypeFile.close();
+
+ /* Another device. */
+ std::filesystem::create_directories("def/device");
+
+ /* Create a dummy eMMC device. */
+ std::filesystem::create_directories("mmcblk0/device");
+ const std::string typeFileName("mmcblk0/device/type");
+ std::ofstream typeFile(typeFileName, std::ios::out | std::ios::trunc);
+ typeFile << "MMC";
+ typeFile.close();
+
+ /* Look for the device file. */
+ std::filesystem::path deviceFile, sysfsDir;
+ std::string luksName, locationCode;
+ auto result = estoraged::util::findDevice(data,
+ std::filesystem::path("./"));
+ EXPECT_TRUE(result.has_value());
+
+ /* Validate the results. */
+ EXPECT_EQ("/dev/mmcblk0", result->deviceFile.string());
+ EXPECT_EQ("./mmcblk0/device", result->sysfsDir.string());
+ EXPECT_EQ("luks-mmcblk0", result->luksName);
+ EXPECT_EQ("U102020", result->locationCode);
+ EXPECT_EQ(5566, result->eraseMaxGeometry);
+ EXPECT_EQ(1234, result->eraseMinGeometry);
/* Delete the dummy files. */
EXPECT_EQ(3U, std::filesystem::remove_all("mmcblk0"));
@@ -174,11 +233,9 @@
typeFile.close();
/* Look for the device file. */
- std::filesystem::path deviceFile, sysfsDir;
- std::string luksName, locationCode;
- EXPECT_FALSE(estoraged::util::findDevice(data, std::filesystem::path("./"),
- deviceFile, sysfsDir, luksName,
- locationCode));
+ auto result = estoraged::util::findDevice(data,
+ std::filesystem::path("./"));
+ EXPECT_FALSE(result.has_value());
/* Delete the dummy files. */
EXPECT_EQ(3U, std::filesystem::remove_all("mmcblk0"));
@@ -215,11 +272,9 @@
typeFile.close();
/* Look for the device file. */
- std::filesystem::path deviceFile, sysfsDir;
- std::string luksName, locationCode;
- EXPECT_FALSE(estoraged::util::findDevice(data, std::filesystem::path("./"),
- deviceFile, sysfsDir, luksName,
- locationCode));
+ auto result = estoraged::util::findDevice(data,
+ std::filesystem::path("./"));
+ EXPECT_FALSE(result.has_value());
/* Delete the dummy files. */
EXPECT_EQ(3U, std::filesystem::remove_all("mmcblk0"));
@@ -249,11 +304,9 @@
std::filesystem::create_directories("def/device");
/* Look for the device file. */
- std::filesystem::path deviceFile, sysfsDir;
- std::string luksName, locationCode;
- EXPECT_FALSE(estoraged::util::findDevice(data, std::filesystem::path("./"),
- deviceFile, sysfsDir, luksName,
- locationCode));
+ auto result = estoraged::util::findDevice(data,
+ std::filesystem::path("./"));
+ EXPECT_FALSE(result.has_value());
/* Delete the dummy files. */
EXPECT_EQ(3U, std::filesystem::remove_all("abc"));