1 #include "../exampledevice/example_device.hpp" 2 3 #include <phosphor-logging/lg2.hpp> 4 #include <sdbusplus/asio/connection.hpp> 5 #include <sdbusplus/asio/object_server.hpp> 6 #include <sdbusplus/async.hpp> 7 #include <sdbusplus/server.hpp> 8 9 #include <memory> 10 #include <regex> 11 12 #include <gtest/gtest.h> 13 14 PHOSPHOR_LOG2_USING; 15 16 using namespace phosphor::software; 17 using namespace phosphor::software::example_device; 18 19 class TestSoftware : public Software 20 { 21 public: 22 static std::string wrapGetRandomSoftwareId(Device& parent) 23 { 24 return Software::getRandomSoftwareId(parent); 25 }; 26 }; 27 28 constexpr const char* mb1ExampleComponent = "MB1ExampleComponent"; 29 30 TEST(SoftwareTest, testGetRandomSoftwareId) 31 { 32 sdbusplus::async::context ctx; 33 ExampleCodeUpdater exampleUpdater(ctx); 34 35 std::string objPath = 36 "/xyz/openbmc_project/inventory/system/board/ExampleBoard/ExampleDevice"; 37 38 SoftwareConfig config(objPath, 0x1234, "my.example.compatible", "Example", 39 mb1ExampleComponent); 40 41 auto device = std::make_unique<ExampleDevice>(ctx, &exampleUpdater, config); 42 43 std::string swid = TestSoftware::wrapGetRandomSoftwareId(*device); 44 debug("{SWID}", "SWID", swid); 45 46 std::regex re("[a-zA-Z0-9]+_[0-9]+"); 47 std::cmatch m; 48 49 EXPECT_TRUE(std::regex_match(swid.c_str(), m, re)); 50 51 EXPECT_TRUE(swid.starts_with(std::string(mb1ExampleComponent) + "_")); 52 } 53