#include "../exampledevice/example_device.hpp" #include #include #include #include #include #include #include #include PHOSPHOR_LOG2_USING; using namespace phosphor::software; using namespace phosphor::software::example_device; sdbusplus::async::task<> testSoftwareVersion(sdbusplus::async::context& ctx) { ExampleCodeUpdater exampleUpdater(ctx, true, nullptr); auto& device = exampleUpdater.getDevice(); device->softwareCurrent = std::make_unique(ctx, *device); std::string objPathCurrentSoftware = reinterpret_cast(device->softwareCurrent.get()) ->objectPath; auto busName = exampleUpdater.getBusName(); auto clientVersion = sdbusplus::client::xyz::openbmc_project::software::Version<>(ctx) .service(busName) .path(objPathCurrentSoftware); // the version is unavailable at this point try { co_await clientVersion.version(); EXPECT_TRUE(false); } catch (std::exception& e) { debug(e.what()); } // now the version is available { device->softwareCurrent->setVersion("v12.6"); EXPECT_EQ((co_await clientVersion.version()), "v12.6"); } // we can set the version twice { device->softwareCurrent->setVersion("v20"); EXPECT_EQ((co_await clientVersion.version()), "v20"); } ctx.request_stop(); co_return; } TEST(SoftwareUpdate, TestSoftwareUpdate) { sdbusplus::async::context ctx; ctx.spawn(testSoftwareVersion(ctx)); ctx.run(); }