instance-id: Ensure database is appropriately sized

Fail initialisation if we know that we may fail to satisfy valid
allocations.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Iff38b27fd324da57a1d81b6ad3c5951e369ce3b3
diff --git a/tests/instance-id.cpp b/tests/instance-id.cpp
index 99366b1..57b6df2 100644
--- a/tests/instance-id.cpp
+++ b/tests/instance-id.cpp
@@ -63,6 +63,23 @@
     int fd;
 };
 
+TEST_F(PldmInstanceDbTest, dbLengthZero)
+{
+    struct pldm_instance_db* db = nullptr;
+
+    std::filesystem::resize_file(dbPath, 0);
+    EXPECT_EQ(pldm_instance_db_init(&db, dbPath.c_str()), -EINVAL);
+}
+
+TEST_F(PldmInstanceDbTest, dbLengthShort)
+{
+    struct pldm_instance_db* db = nullptr;
+
+    std::filesystem::resize_file(dbPath,
+                                 PLDM_MAX_TIDS * pldmMaxInstanceIds - 1);
+    EXPECT_EQ(pldm_instance_db_init(&db, dbPath.c_str()), -EINVAL);
+}
+
 TEST_F(PldmInstanceDbTest, dbInstance)
 {
     struct pldm_instance_db* db = nullptr;