test: common: software version
Test Software Version DBus API.
Change-Id: I287b7e7957199463ec80bda8f71bf881bc0e5cb8
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/test/common/exampledevice/example_device.cpp b/test/common/exampledevice/example_device.cpp
index 9200bb2..c46e842 100644
--- a/test/common/exampledevice/example_device.cpp
+++ b/test/common/exampledevice/example_device.cpp
@@ -41,10 +41,14 @@
SoftwareManager(ctx, "ExampleUpdater" + std::to_string(uniqueSuffix))
{}
-ExampleCodeUpdater::ExampleCodeUpdater(sdbusplus::async::context& ctx,
- const char* swVersion) :
+ExampleCodeUpdater::ExampleCodeUpdater(
+ sdbusplus::async::context& ctx, bool createDevice, const char* swVersion) :
ExampleCodeUpdater(ctx)
{
+ if (!createDevice)
+ {
+ return;
+ }
const std::string exampleInvObjPath =
"/xyz/openbmc_project/inventory/system/board/ExampleBoard/ExampleDevice";
auto exampleDevice = std::make_unique<ExampleDevice>(ctx, &(*this));
diff --git a/test/common/exampledevice/example_device.hpp b/test/common/exampledevice/example_device.hpp
index 52da92d..67269d5 100644
--- a/test/common/exampledevice/example_device.hpp
+++ b/test/common/exampledevice/example_device.hpp
@@ -20,9 +20,12 @@
ExampleCodeUpdater(sdbusplus::async::context& ctx,
long uniqueSuffix = getRandomId());
+ // @param createDevice create an ExampleDevice. Prerequisite for param
+ // 'swVersion'.
// @param swVersion if this is nullptr, do not create the software
// version.
- ExampleCodeUpdater(sdbusplus::async::context& ctx, const char* swVersion);
+ ExampleCodeUpdater(sdbusplus::async::context& ctx, bool createDevice,
+ const char* swVersion);
std::unique_ptr<ExampleDevice>& getDevice();
diff --git a/test/common/software/meson.build b/test/common/software/meson.build
index 62c97de..a5ed0bf 100644
--- a/test/common/software/meson.build
+++ b/test/common/software/meson.build
@@ -3,6 +3,7 @@
'software_get_random_softwareid',
'software_config',
'software_association',
+ 'software_version',
]
foreach t : testcases
diff --git a/test/common/software/software_association.cpp b/test/common/software/software_association.cpp
index c8da550..98fe3a9 100644
--- a/test/common/software/software_association.cpp
+++ b/test/common/software/software_association.cpp
@@ -22,7 +22,8 @@
{
protected:
SoftwareAssocTest() :
- exampleUpdater(ctx, "swVersion"), device(exampleUpdater.getDevice()),
+ exampleUpdater(ctx, true, "swVersion"),
+ device(exampleUpdater.getDevice()),
objPathCurrentSoftware(
reinterpret_cast<ExampleSoftware*>(device->softwareCurrent.get())
->objectPath),
diff --git a/test/common/software/software_version.cpp b/test/common/software/software_version.cpp
new file mode 100644
index 0000000..a81cc21
--- /dev/null
+++ b/test/common/software/software_version.cpp
@@ -0,0 +1,75 @@
+#include "../exampledevice/example_device.hpp"
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <unistd.h>
+
+#include <phosphor-logging/lg2.hpp>
+#include <sdbusplus/async/context.hpp>
+#include <xyz/openbmc_project/Software/Update/client.hpp>
+#include <xyz/openbmc_project/Software/Version/client.hpp>
+
+#include <gtest/gtest.h>
+
+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<ExampleSoftware>(ctx, *device);
+
+ std::string objPathCurrentSoftware =
+ reinterpret_cast<ExampleSoftware*>(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();
+}