blob: 5eae56dcb2f967967f8132b04a2ffc2250ca8bba [file] [log] [blame]
Alexander Hansen8d9e6da2025-01-14 14:17:19 +01001#include "../nopdevice/nopdevice.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// NOLINTBEGIN
15sdbusplus::async::task<> endContext(sdbusplus::async::context& ctx)
16// NOLINTEND
17{
18 ctx.request_stop();
19
20 co_return;
21}
22
23TEST(SoftwareTest, TestSoftwareConstructor)
24{
25 sdbusplus::async::context ctx;
26 NopCodeUpdater nopcu(ctx);
27 NopCodeUpdater* cu = &nopcu;
28
29 auto device = std::make_unique<NopDevice>(ctx, cu);
30
31 // the software version is currently unknown
32 assert(device->softwareCurrent == nullptr);
33
34 auto sw = std::make_unique<Software>(ctx, "swid_test_constructor", *device);
35
36 // since that software is not an update, there is no progress
37 assert(sw->optSoftwareActivationProgress == nullptr);
38
39 // test succeeds if we construct without any exception
40 // and can run the context
41
42 ctx.spawn(endContext(ctx));
43 ctx.run();
44}
45
46TEST(SoftwareTest, TestSoftwareId)
47{
48 sdbusplus::async::context ctx;
49 NopCodeUpdater nopcu(ctx);
50 NopCodeUpdater* cu = &nopcu;
51
52 auto device = std::make_unique<NopDevice>(ctx, cu);
53
54 // the software version is currently unknown
55 assert(device->softwareCurrent == nullptr);
56
57 auto sw = std::make_unique<Software>(ctx, "Nop_swid_test_swid", *device);
58
59 // design: Swid = <DeviceX>_<RandomId>
60 assert(sw->swid.starts_with("Nop"));
61}
62
63TEST(SoftwareTest, TestSoftwareObjectPath)
64{
65 sdbusplus::async::context ctx;
66 NopCodeUpdater nopcu(ctx);
67 NopCodeUpdater* cu = &nopcu;
68
69 auto device = std::make_unique<NopDevice>(ctx, cu);
70
71 auto sw = std::make_unique<Software>(ctx, "swid_test_obj_path", *device);
72
73 lg2::debug("{PATH}", "PATH", sw->getObjectPath());
74
75 // assert that the object path is as per the design
76 // design: /xyz/openbmc_project/Software/<SwId>
77 assert(std::string(sw->getObjectPath())
78 .starts_with("/xyz/openbmc_project/software/"));
79}