| Alexander Hansen | d880e4d | 2025-08-08 11:24:28 +0200 | [diff] [blame] | 1 | #include "../exampledevice/example_device.hpp" |
| 2 | |
| 3 | #include <fcntl.h> |
| 4 | #include <inttypes.h> |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | #include <phosphor-logging/lg2.hpp> |
| 8 | #include <sdbusplus/async/context.hpp> |
| 9 | #include <xyz/openbmc_project/Software/Update/client.hpp> |
| 10 | #include <xyz/openbmc_project/Software/Version/client.hpp> |
| 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 | sdbusplus::async::task<> testSoftwareVersion(sdbusplus::async::context& ctx) |
| 20 | { |
| 21 | ExampleCodeUpdater exampleUpdater(ctx, true, nullptr); |
| 22 | |
| 23 | auto& device = exampleUpdater.getDevice(); |
| 24 | |
| 25 | device->softwareCurrent = std::make_unique<ExampleSoftware>(ctx, *device); |
| 26 | |
| 27 | std::string objPathCurrentSoftware = |
| 28 | reinterpret_cast<ExampleSoftware*>(device->softwareCurrent.get()) |
| 29 | ->objectPath; |
| 30 | |
| 31 | auto busName = exampleUpdater.getBusName(); |
| 32 | |
| 33 | auto clientVersion = |
| 34 | sdbusplus::client::xyz::openbmc_project::software::Version<>(ctx) |
| 35 | .service(busName) |
| 36 | .path(objPathCurrentSoftware); |
| 37 | |
| 38 | // the version is unavailable at this point |
| 39 | try |
| 40 | { |
| 41 | co_await clientVersion.version(); |
| 42 | EXPECT_TRUE(false); |
| 43 | } |
| 44 | catch (std::exception& e) |
| 45 | { |
| 46 | debug(e.what()); |
| 47 | } |
| 48 | |
| 49 | // now the version is available |
| 50 | { |
| 51 | device->softwareCurrent->setVersion("v12.6"); |
| 52 | |
| 53 | EXPECT_EQ((co_await clientVersion.version()), "v12.6"); |
| 54 | } |
| 55 | |
| 56 | // we can set the version twice |
| 57 | { |
| 58 | device->softwareCurrent->setVersion("v20"); |
| 59 | |
| 60 | EXPECT_EQ((co_await clientVersion.version()), "v20"); |
| 61 | } |
| 62 | |
| 63 | ctx.request_stop(); |
| 64 | |
| 65 | co_return; |
| 66 | } |
| 67 | |
| 68 | TEST(SoftwareUpdate, TestSoftwareUpdate) |
| 69 | { |
| 70 | sdbusplus::async::context ctx; |
| 71 | |
| 72 | ctx.spawn(testSoftwareVersion(ctx)); |
| 73 | |
| 74 | ctx.run(); |
| 75 | } |