regulators: Build IDMap for system

The IDMap class is used to map string IDs to the corresponding C++
Device, Rail, and Rule objects.

The IDMap class is complete and tested, but it was not previously being
populated except in testcases.

Add new methods to the System, Chassis, and Device classes to populate
the IDMap with all the ID -> object mappings in the system.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I80f39b663b011ca643c91f7281ff50c956631331
diff --git a/phosphor-regulators/test/chassis_tests.cpp b/phosphor-regulators/test/chassis_tests.cpp
index 707fff5..0f66d24 100644
--- a/phosphor-regulators/test/chassis_tests.cpp
+++ b/phosphor-regulators/test/chassis_tests.cpp
@@ -16,6 +16,7 @@
 #include "chassis.hpp"
 #include "device.hpp"
 #include "i2c_interface.hpp"
+#include "id_map.hpp"
 #include "test_utils.hpp"
 
 #include <memory>
@@ -41,12 +42,8 @@
     {
         // Create vector of Device objects
         std::vector<std::unique_ptr<Device>> devices{};
-        devices.push_back(std::make_unique<Device>(
-            "vdd_reg1", true, "/system/chassis/motherboard/reg1",
-            std::move(createI2CInterface())));
-        devices.push_back(std::make_unique<Device>(
-            "vdd_reg2", true, "/system/chassis/motherboard/reg2",
-            std::move(createI2CInterface())));
+        devices.emplace_back(createDevice("vdd_reg1"));
+        devices.emplace_back(createDevice("vdd_reg2"));
 
         // Create Chassis
         Chassis chassis{1, std::move(devices)};
@@ -70,6 +67,34 @@
     }
 }
 
+TEST(ChassisTests, AddToIDMap)
+{
+    // Create vector of Device objects
+    std::vector<std::unique_ptr<Device>> devices{};
+    devices.emplace_back(createDevice("reg1", {"rail1"}));
+    devices.emplace_back(createDevice("reg2", {"rail2a", "rail2b"}));
+    devices.emplace_back(createDevice("reg3"));
+
+    // Create Chassis
+    Chassis chassis{1, std::move(devices)};
+
+    // Add Device and Rail objects within the Chassis to an IDMap
+    IDMap idMap{};
+    chassis.addToIDMap(idMap);
+
+    // Verify all Devices are in the IDMap
+    EXPECT_NO_THROW(idMap.getDevice("reg1"));
+    EXPECT_NO_THROW(idMap.getDevice("reg2"));
+    EXPECT_NO_THROW(idMap.getDevice("reg3"));
+    EXPECT_THROW(idMap.getDevice("reg4"), std::invalid_argument);
+
+    // Verify all Rails are in the IDMap
+    EXPECT_NO_THROW(idMap.getRail("rail1"));
+    EXPECT_NO_THROW(idMap.getRail("rail2a"));
+    EXPECT_NO_THROW(idMap.getRail("rail2b"));
+    EXPECT_THROW(idMap.getRail("rail3"), std::invalid_argument);
+}
+
 TEST(ChassisTests, GetDevices)
 {
     // Test where no devices were specified in constructor
@@ -82,12 +107,8 @@
     {
         // Create vector of Device objects
         std::vector<std::unique_ptr<Device>> devices{};
-        devices.push_back(std::make_unique<Device>(
-            "vdd_reg1", true, "/system/chassis/motherboard/reg1",
-            std::move(createI2CInterface())));
-        devices.push_back(std::make_unique<Device>(
-            "vdd_reg2", true, "/system/chassis/motherboard/reg2",
-            std::move(createI2CInterface())));
+        devices.emplace_back(createDevice("vdd_reg1"));
+        devices.emplace_back(createDevice("vdd_reg2"));
 
         // Create Chassis
         Chassis chassis{1, std::move(devices)};