blob: 3a20869c6dcc7f277540d33b18d20e3ac047c348 [file] [log] [blame]
Tomáš Pecka991e4d52021-01-11 10:03:14 +01001#include "trompeloeil_doctest.h"
2#include "dbus-helpers/dbus_rauc_server.h"
Tomáš Pecka9cc00942021-01-14 22:45:10 +01003#include "mock/system.h"
Tomáš Pecka991e4d52021-01-11 10:03:14 +01004#include "pretty_printers.h"
5#include "system/RAUC.h"
6#include "test_log_setup.h"
7
Tomáš Pecka991e4d52021-01-11 10:03:14 +01008TEST_CASE("Fetch RAUC data over DBus")
9{
10 using namespace std::literals::chrono_literals;
11
12 TEST_INIT_LOGS;
13 trompeloeil::sequence seq1;
14
15 // setup separate connections for both client and server. Can be done using one connection only but this way it is more generic
16 auto serverConnection = sdbus::createSessionBusConnection("de.pengutronix.rauc");
Tomáš Peckad51d4cb2021-02-03 14:15:49 +010017 auto clientConnectionSignals = sdbus::createSessionBusConnection();
18 auto clientConnectionMethods = sdbus::createSessionBusConnection();
Tomáš Pecka991e4d52021-01-11 10:03:14 +010019
20 // enter client and servers event loops
Tomáš Peckad51d4cb2021-02-03 14:15:49 +010021 clientConnectionSignals->enterEventLoopAsync();
22 clientConnectionMethods->enterEventLoopAsync();
Tomáš Pecka991e4d52021-01-11 10:03:14 +010023 serverConnection->enterEventLoopAsync();
24
Tomáš Pecka9cc00942021-01-14 22:45:10 +010025 std::string primarySlot = "rootfs.1";
26 std::map<std::string, velia::system::RAUC::SlotProperties> status = {
27 {"rootfs.1", {
28 {"activated.count", uint32_t {39}},
29 {"activated.timestamp", "2021-01-13T17:20:18Z"},
30 {"bootname", "B"},
31 {"boot-status", "good"},
32 {"bundle.compatible", "czechlight-clearfog"},
33 {"bundle.version", "v4-103-g34d2f48"},
34 {"class", "rootfs"},
35 {"device", "/dev/mmcblk0p3"},
36 {"installed.count", uint32_t {39}},
37 {"installed.timestamp", "2021-01-13T17:20:15Z"},
38 {"mountpoint", "/"},
39 {"sha256", "07b30d065c7aad64d2006ce99fd339c929d3ca97b666fca4584b9ef726469fc4"},
40 {"size", uint64_t {45601892}},
41 {"state", "booted"},
42 {"status", "ok"},
43 {"type", "ext4"},
44 }},
45 {"rootfs.0", {
46 {"activated.count", uint32_t {41}},
47 {"activated.timestamp", "2021-01-13T17:15:54Z"},
48 {"bootname", "A"},
49 {"boot-status", "bad"},
50 {"bundle.compatible", "czechlight-clearfog"},
51 {"bundle.version", "v4-104-ge80fcd4"},
52 {"class", "rootfs"},
53 {"device", "/dev/mmcblk0p1"},
54 {"installed.count", uint32_t {41}},
55 {"installed.timestamp", "2021-01-13T17:15:50Z"},
56 {"sha256", "6d81e8f341edd17c127811f7347c7e23d18c2fc25c0bdc29ac56999cc9c25629"},
57 {"size", uint64_t {45647664}},
58 {"state", "inactive"},
59 {"status", "ok"},
60 {"type", "ext4"},
61 }},
62 {"cfg.1", {
63 {"bundle.compatible", "czechlight-clearfog"},
64 {"bundle.version", "v4-103-g34d2f48"},
65 {"class", "cfg"},
66 {"device", "/dev/mmcblk0p4"},
67 {"installed.count", uint32_t {39}},
68 {"installed.timestamp", "2021-01-13T17:20:18Z"},
69 {"mountpoint", "/cfg"},
70 {"parent", "rootfs.1"},
71 {"sha256", "5ca1b6c461fc194055d52b181f57c63dc1d34c19d041f6395e6f6abc039692bb"},
72 {"size", uint64_t {108}},
73 {"state", "active"},
74 {"status", "ok"},
75 {"type", "ext4"},
76 }},
77 {"cfg.0", {
78 {"bundle.compatible", "czechlight-clearfog"},
79 {"bundle.version", "v4-104-ge80fcd4"},
80 {"class", "cfg"},
81 {"device", "/dev/mmcblk0p2"},
82 {"installed.count", uint32_t {41}},
83 {"installed.timestamp", "2021-01-13T17:15:54Z"},
84 {"parent", "rootfs.0"},
85 {"sha256", "5ca1b6c461fc194055d52b181f57c63dc1d34c19d041f6395e6f6abc039692bb"},
86 {"size", uint64_t {108}},
87 {"state", "inactive"},
88 {"status", "ok"},
89 {"type", "ext4"},
90 }},
91 };
Tomáš Pecka991e4d52021-01-11 10:03:14 +010092
93 auto server = DBusRAUCServer(*serverConnection, primarySlot, status);
Tomáš Pecka991e4d52021-01-11 10:03:14 +010094
Tomáš Pecka9cc00942021-01-14 22:45:10 +010095 auto fakeRaucInstallCb = FakeRAUCInstallCb();
96 auto rauc = std::make_shared<velia::system::RAUC>(
Tomáš Peckad51d4cb2021-02-03 14:15:49 +010097 *clientConnectionSignals,
98 *clientConnectionMethods,
Tomáš Pecka9cc00942021-01-14 22:45:10 +010099 [&fakeRaucInstallCb](const std::string& operation) { fakeRaucInstallCb.operationCallback(operation); },
100 [&fakeRaucInstallCb](int32_t perc, const std::string& msg) { fakeRaucInstallCb.progressCallback(perc, msg); },
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100101 [&fakeRaucInstallCb](int32_t retVal, const std::string& lastError) { fakeRaucInstallCb.completedCallback(retVal, lastError); });
Tomáš Pecka9cc00942021-01-14 22:45:10 +0100102
Tomáš Peckac764b762021-01-23 21:46:21 +0100103 REQUIRE(rauc->lastError() == "");
104 REQUIRE(rauc->operation() == "idle");
105
Tomáš Pecka9cc00942021-01-14 22:45:10 +0100106 SECTION("Test slot status")
107 {
108 REQUIRE(rauc->primarySlot() == primarySlot);
109 REQUIRE(rauc->slotStatus() == status);
110 }
111
112 SECTION("Installation OK")
113 {
114 server.installBundleBehaviour(DBusRAUCServer::InstallBehaviour::OK); // Not cool but I don't feel like I should be creating some abstractions here in tests.
115 FAKE_RAUC_OPERATION("installing");
116 FAKE_RAUC_PROGRESS(0, "Installing");
117 FAKE_RAUC_PROGRESS(0, "Determining slot states");
118 FAKE_RAUC_PROGRESS(20, "Determining slot states done.");
119 FAKE_RAUC_PROGRESS(20, "Checking bundle");
120 FAKE_RAUC_PROGRESS(20, "Veryfing signature");
121 FAKE_RAUC_PROGRESS(40, "Veryfing signature done.");
122 FAKE_RAUC_PROGRESS(40, "Checking bundle done.");
123 FAKE_RAUC_PROGRESS(40, "Loading manifest file");
124 FAKE_RAUC_PROGRESS(60, "Loading manifest file done.");
125 FAKE_RAUC_PROGRESS(60, "Determining target install group");
126 FAKE_RAUC_PROGRESS(80, "Determining target install group done.");
127 FAKE_RAUC_PROGRESS(80, "Updating slots");
128 FAKE_RAUC_PROGRESS(80, "Checking slot rootfs.0");
129 FAKE_RAUC_PROGRESS(85, "Checking slot rootfs.0 done.");
130 FAKE_RAUC_PROGRESS(85, "Copying image to rootfs.0");
131 FAKE_RAUC_PROGRESS(90, "Copying image to rootfs.0 done.");
132 FAKE_RAUC_PROGRESS(90, "Checking slot cfg.0");
133 FAKE_RAUC_PROGRESS(95, "Checking slot cfg.0 done.");
134 FAKE_RAUC_PROGRESS(95, "Copying image to cfg.0");
135 FAKE_RAUC_PROGRESS(100, "Copying image to cfg.0 done.");
136 FAKE_RAUC_PROGRESS(100, "Updating slots done.");
137 FAKE_RAUC_PROGRESS(100, "Installing done.");
138 FAKE_RAUC_COMPLETED(0, "");
139 FAKE_RAUC_OPERATION("idle");
140
141 rauc->install("/path/to/bundle");
Tomáš Peckac764b762021-01-23 21:46:21 +0100142 REQUIRE(rauc->operation() == "installing");
Tomáš Pecka9cc00942021-01-14 22:45:10 +0100143
144 SECTION("Invoking another operation before the installation ends")
145 {
146 REQUIRE_THROWS_AS(rauc->install("/path/to/bundle"), sdbus::Error);
147 REQUIRE_THROWS_AS(rauc->slotStatus(), sdbus::Error);
148 REQUIRE_THROWS_AS(rauc->primarySlot(), sdbus::Error);
149 }
150 waitForCompletionAndBitMore(seq1);
151 }
152
153 SECTION("Installation failure")
154 {
155 server.installBundleBehaviour(DBusRAUCServer::InstallBehaviour::FAILURE);
156
157 FAKE_RAUC_OPERATION("installing");
158 FAKE_RAUC_PROGRESS(0, "Installing");
159 FAKE_RAUC_PROGRESS(0, "Determining slot states");
160 FAKE_RAUC_PROGRESS(20, "Determining slot states done.");
161 FAKE_RAUC_PROGRESS(20, "Checking bundle");
162 FAKE_RAUC_PROGRESS(40, "Checking bundle failed.");
163 FAKE_RAUC_PROGRESS(100, "Installing failed.");
164 FAKE_RAUC_COMPLETED(1, "Failed to download bundle https://10.88.3.11:8000/update.raucb: Transfer failed: error:1408F10B:SSL routines:ssl3_get_record:wrong version number");
165 FAKE_RAUC_OPERATION("idle");
166
167 rauc->install("/path/to/bundle");
Tomáš Peckac764b762021-01-23 21:46:21 +0100168 REQUIRE(rauc->operation() == "installing");
Tomáš Pecka9cc00942021-01-14 22:45:10 +0100169 waitForCompletionAndBitMore(seq1);
Tomáš Peckac764b762021-01-23 21:46:21 +0100170 REQUIRE(rauc->lastError() == "Failed to download bundle https://10.88.3.11:8000/update.raucb: Transfer failed: error:1408F10B:SSL routines:ssl3_get_record:wrong version number");
Tomáš Pecka9cc00942021-01-14 22:45:10 +0100171 }
Tomáš Peckac764b762021-01-23 21:46:21 +0100172
173 REQUIRE(rauc->operation() == "idle");
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100174}