Alexander Hansen | 8d9e6da | 2025-01-14 14:17:19 +0100 | [diff] [blame^] | 1 | #include "../nopdevice/nopdevice.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 <cassert> |
| 13 | #include <cstdlib> |
| 14 | #include <cstring> |
| 15 | |
| 16 | #include <gtest/gtest.h> |
| 17 | |
| 18 | // NOLINTBEGIN |
| 19 | sdbusplus::async::task<> testSoftwareVersion(sdbusplus::async::context& ctx) |
| 20 | // NOLINTEND |
| 21 | { |
| 22 | NopCodeUpdater nopcu(ctx); |
| 23 | NopCodeUpdater* cu = &nopcu; |
| 24 | |
| 25 | const std::string service = nopcu.setupBusName(); |
| 26 | |
| 27 | auto device = std::make_unique<NopDevice>(ctx, cu); |
| 28 | |
| 29 | device->softwareCurrent = |
| 30 | std::make_unique<Software>(ctx, "swid_sw_version", *device); |
| 31 | |
| 32 | std::string objPathCurrentSoftware = |
| 33 | device->softwareCurrent->getObjectPath(); |
| 34 | |
| 35 | auto clientVersion = |
| 36 | sdbusplus::client::xyz::openbmc_project::software::Version<>(ctx) |
| 37 | .service(service) |
| 38 | .path(objPathCurrentSoftware); |
| 39 | |
| 40 | // the version is unavailable at this point |
| 41 | try |
| 42 | { |
| 43 | co_await clientVersion.version(); |
| 44 | assert(false); |
| 45 | } |
| 46 | catch (std::exception& e) |
| 47 | { |
| 48 | lg2::debug(e.what()); |
| 49 | } |
| 50 | |
| 51 | // now the version is available |
| 52 | { |
| 53 | device->softwareCurrent->setVersion("v12.6"); |
| 54 | |
| 55 | assert((co_await clientVersion.version()) == "v12.6"); |
| 56 | } |
| 57 | |
| 58 | // we cannot set the version twice |
| 59 | { |
| 60 | device->softwareCurrent->setVersion("v20"); |
| 61 | |
| 62 | assert((co_await clientVersion.version()) == "v12.6"); |
| 63 | } |
| 64 | |
| 65 | ctx.request_stop(); |
| 66 | |
| 67 | co_return; |
| 68 | } |
| 69 | |
| 70 | TEST(SoftwareUpdate, TestSoftwareUpdate) |
| 71 | { |
| 72 | sdbusplus::async::context ctx; |
| 73 | |
| 74 | ctx.spawn(testSoftwareVersion(ctx)); |
| 75 | |
| 76 | ctx.run(); |
| 77 | } |