Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 1 | #include "trompeloeil_doctest.h" |
| 2 | #include "dbus-helpers/dbus_rauc_server.h" |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 3 | #include "mock/system.h" |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 4 | #include "pretty_printers.h" |
| 5 | #include "system/RAUC.h" |
| 6 | #include "test_log_setup.h" |
| 7 | |
Tomáš Pecka | 91836f3 | 2021-11-15 17:12:32 +0100 | [diff] [blame^] | 8 | using namespace std::literals::chrono_literals; |
| 9 | |
| 10 | /** @brief waits until expectation is saturated, but 150ms at most */ |
| 11 | void waitForSaturation(const std::unique_ptr<trompeloeil::expectation>& exp) |
| 12 | { |
| 13 | static const auto WAIT_FOR_INSTALLATION_START_STEP = 5ms; |
| 14 | static const auto WAIT_FOR_INSTALLATION_START_MAX_STEPS = 30; |
| 15 | |
| 16 | for (auto i = 0; i < WAIT_FOR_INSTALLATION_START_MAX_STEPS && !exp->is_saturated(); i++) { |
| 17 | std::this_thread::sleep_for(WAIT_FOR_INSTALLATION_START_STEP); |
| 18 | } |
| 19 | REQUIRE(exp->is_saturated()); |
| 20 | } |
| 21 | |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 22 | TEST_CASE("Fetch RAUC data over DBus") |
| 23 | { |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 24 | TEST_INIT_LOGS; |
| 25 | trompeloeil::sequence seq1; |
| 26 | |
| 27 | // setup separate connections for both client and server. Can be done using one connection only but this way it is more generic |
| 28 | auto serverConnection = sdbus::createSessionBusConnection("de.pengutronix.rauc"); |
Tomáš Pecka | d51d4cb | 2021-02-03 14:15:49 +0100 | [diff] [blame] | 29 | auto clientConnectionSignals = sdbus::createSessionBusConnection(); |
| 30 | auto clientConnectionMethods = sdbus::createSessionBusConnection(); |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 31 | |
| 32 | // enter client and servers event loops |
Tomáš Pecka | d51d4cb | 2021-02-03 14:15:49 +0100 | [diff] [blame] | 33 | clientConnectionSignals->enterEventLoopAsync(); |
| 34 | clientConnectionMethods->enterEventLoopAsync(); |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 35 | serverConnection->enterEventLoopAsync(); |
| 36 | |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 37 | std::string primarySlot = "rootfs.1"; |
| 38 | std::map<std::string, velia::system::RAUC::SlotProperties> status = { |
| 39 | {"rootfs.1", { |
| 40 | {"activated.count", uint32_t {39}}, |
| 41 | {"activated.timestamp", "2021-01-13T17:20:18Z"}, |
| 42 | {"bootname", "B"}, |
| 43 | {"boot-status", "good"}, |
| 44 | {"bundle.compatible", "czechlight-clearfog"}, |
| 45 | {"bundle.version", "v4-103-g34d2f48"}, |
| 46 | {"class", "rootfs"}, |
| 47 | {"device", "/dev/mmcblk0p3"}, |
| 48 | {"installed.count", uint32_t {39}}, |
| 49 | {"installed.timestamp", "2021-01-13T17:20:15Z"}, |
| 50 | {"mountpoint", "/"}, |
| 51 | {"sha256", "07b30d065c7aad64d2006ce99fd339c929d3ca97b666fca4584b9ef726469fc4"}, |
| 52 | {"size", uint64_t {45601892}}, |
| 53 | {"state", "booted"}, |
| 54 | {"status", "ok"}, |
| 55 | {"type", "ext4"}, |
| 56 | }}, |
| 57 | {"rootfs.0", { |
| 58 | {"activated.count", uint32_t {41}}, |
| 59 | {"activated.timestamp", "2021-01-13T17:15:54Z"}, |
| 60 | {"bootname", "A"}, |
| 61 | {"boot-status", "bad"}, |
| 62 | {"bundle.compatible", "czechlight-clearfog"}, |
| 63 | {"bundle.version", "v4-104-ge80fcd4"}, |
| 64 | {"class", "rootfs"}, |
| 65 | {"device", "/dev/mmcblk0p1"}, |
| 66 | {"installed.count", uint32_t {41}}, |
| 67 | {"installed.timestamp", "2021-01-13T17:15:50Z"}, |
| 68 | {"sha256", "6d81e8f341edd17c127811f7347c7e23d18c2fc25c0bdc29ac56999cc9c25629"}, |
| 69 | {"size", uint64_t {45647664}}, |
| 70 | {"state", "inactive"}, |
| 71 | {"status", "ok"}, |
| 72 | {"type", "ext4"}, |
| 73 | }}, |
| 74 | {"cfg.1", { |
| 75 | {"bundle.compatible", "czechlight-clearfog"}, |
| 76 | {"bundle.version", "v4-103-g34d2f48"}, |
| 77 | {"class", "cfg"}, |
| 78 | {"device", "/dev/mmcblk0p4"}, |
| 79 | {"installed.count", uint32_t {39}}, |
| 80 | {"installed.timestamp", "2021-01-13T17:20:18Z"}, |
| 81 | {"mountpoint", "/cfg"}, |
| 82 | {"parent", "rootfs.1"}, |
| 83 | {"sha256", "5ca1b6c461fc194055d52b181f57c63dc1d34c19d041f6395e6f6abc039692bb"}, |
| 84 | {"size", uint64_t {108}}, |
| 85 | {"state", "active"}, |
| 86 | {"status", "ok"}, |
| 87 | {"type", "ext4"}, |
| 88 | }}, |
| 89 | {"cfg.0", { |
| 90 | {"bundle.compatible", "czechlight-clearfog"}, |
| 91 | {"bundle.version", "v4-104-ge80fcd4"}, |
| 92 | {"class", "cfg"}, |
| 93 | {"device", "/dev/mmcblk0p2"}, |
| 94 | {"installed.count", uint32_t {41}}, |
| 95 | {"installed.timestamp", "2021-01-13T17:15:54Z"}, |
| 96 | {"parent", "rootfs.0"}, |
| 97 | {"sha256", "5ca1b6c461fc194055d52b181f57c63dc1d34c19d041f6395e6f6abc039692bb"}, |
| 98 | {"size", uint64_t {108}}, |
| 99 | {"state", "inactive"}, |
| 100 | {"status", "ok"}, |
| 101 | {"type", "ext4"}, |
| 102 | }}, |
| 103 | }; |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 104 | |
| 105 | auto server = DBusRAUCServer(*serverConnection, primarySlot, status); |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 106 | |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 107 | auto fakeRaucInstallCb = FakeRAUCInstallCb(); |
| 108 | auto rauc = std::make_shared<velia::system::RAUC>( |
Tomáš Pecka | d51d4cb | 2021-02-03 14:15:49 +0100 | [diff] [blame] | 109 | *clientConnectionSignals, |
| 110 | *clientConnectionMethods, |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 111 | [&fakeRaucInstallCb](const std::string& operation) { fakeRaucInstallCb.operationCallback(operation); }, |
| 112 | [&fakeRaucInstallCb](int32_t perc, const std::string& msg) { fakeRaucInstallCb.progressCallback(perc, msg); }, |
Tomáš Pecka | cb7a5f8 | 2021-01-20 15:12:00 +0100 | [diff] [blame] | 113 | [&fakeRaucInstallCb](int32_t retVal, const std::string& lastError) { fakeRaucInstallCb.completedCallback(retVal, lastError); }); |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 114 | |
Tomáš Pecka | c764b76 | 2021-01-23 21:46:21 +0100 | [diff] [blame] | 115 | REQUIRE(rauc->lastError() == ""); |
| 116 | REQUIRE(rauc->operation() == "idle"); |
| 117 | |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 118 | SECTION("Test slot status") |
| 119 | { |
| 120 | REQUIRE(rauc->primarySlot() == primarySlot); |
| 121 | REQUIRE(rauc->slotStatus() == status); |
| 122 | } |
| 123 | |
| 124 | SECTION("Installation OK") |
| 125 | { |
| 126 | server.installBundleBehaviour(DBusRAUCServer::InstallBehaviour::OK); // Not cool but I don't feel like I should be creating some abstractions here in tests. |
Tomáš Pecka | 91836f3 | 2021-11-15 17:12:32 +0100 | [diff] [blame^] | 127 | auto exp = NAMED_REQUIRE_CALL(fakeRaucInstallCb, operationCallback("installing")).IN_SEQUENCE(seq1); |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 128 | FAKE_RAUC_PROGRESS(0, "Installing"); |
| 129 | FAKE_RAUC_PROGRESS(0, "Determining slot states"); |
| 130 | FAKE_RAUC_PROGRESS(20, "Determining slot states done."); |
| 131 | FAKE_RAUC_PROGRESS(20, "Checking bundle"); |
| 132 | FAKE_RAUC_PROGRESS(20, "Veryfing signature"); |
| 133 | FAKE_RAUC_PROGRESS(40, "Veryfing signature done."); |
| 134 | FAKE_RAUC_PROGRESS(40, "Checking bundle done."); |
| 135 | FAKE_RAUC_PROGRESS(40, "Loading manifest file"); |
| 136 | FAKE_RAUC_PROGRESS(60, "Loading manifest file done."); |
| 137 | FAKE_RAUC_PROGRESS(60, "Determining target install group"); |
| 138 | FAKE_RAUC_PROGRESS(80, "Determining target install group done."); |
| 139 | FAKE_RAUC_PROGRESS(80, "Updating slots"); |
| 140 | FAKE_RAUC_PROGRESS(80, "Checking slot rootfs.0"); |
| 141 | FAKE_RAUC_PROGRESS(85, "Checking slot rootfs.0 done."); |
| 142 | FAKE_RAUC_PROGRESS(85, "Copying image to rootfs.0"); |
| 143 | FAKE_RAUC_PROGRESS(90, "Copying image to rootfs.0 done."); |
| 144 | FAKE_RAUC_PROGRESS(90, "Checking slot cfg.0"); |
| 145 | FAKE_RAUC_PROGRESS(95, "Checking slot cfg.0 done."); |
| 146 | FAKE_RAUC_PROGRESS(95, "Copying image to cfg.0"); |
| 147 | FAKE_RAUC_PROGRESS(100, "Copying image to cfg.0 done."); |
| 148 | FAKE_RAUC_PROGRESS(100, "Updating slots done."); |
| 149 | FAKE_RAUC_PROGRESS(100, "Installing done."); |
| 150 | FAKE_RAUC_COMPLETED(0, ""); |
| 151 | FAKE_RAUC_OPERATION("idle"); |
| 152 | |
| 153 | rauc->install("/path/to/bundle"); |
Tomáš Pecka | 91836f3 | 2021-11-15 17:12:32 +0100 | [diff] [blame^] | 154 | waitForSaturation(exp); // wait until installation starts |
Tomáš Pecka | c764b76 | 2021-01-23 21:46:21 +0100 | [diff] [blame] | 155 | REQUIRE(rauc->operation() == "installing"); |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 156 | |
| 157 | SECTION("Invoking another operation before the installation ends") |
| 158 | { |
| 159 | REQUIRE_THROWS_AS(rauc->install("/path/to/bundle"), sdbus::Error); |
| 160 | REQUIRE_THROWS_AS(rauc->slotStatus(), sdbus::Error); |
| 161 | REQUIRE_THROWS_AS(rauc->primarySlot(), sdbus::Error); |
| 162 | } |
| 163 | waitForCompletionAndBitMore(seq1); |
| 164 | } |
| 165 | |
| 166 | SECTION("Installation failure") |
| 167 | { |
| 168 | server.installBundleBehaviour(DBusRAUCServer::InstallBehaviour::FAILURE); |
| 169 | |
Tomáš Pecka | 91836f3 | 2021-11-15 17:12:32 +0100 | [diff] [blame^] | 170 | auto exp = NAMED_REQUIRE_CALL(fakeRaucInstallCb, operationCallback("installing")).IN_SEQUENCE(seq1); |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 171 | FAKE_RAUC_PROGRESS(0, "Installing"); |
| 172 | FAKE_RAUC_PROGRESS(0, "Determining slot states"); |
| 173 | FAKE_RAUC_PROGRESS(20, "Determining slot states done."); |
| 174 | FAKE_RAUC_PROGRESS(20, "Checking bundle"); |
| 175 | FAKE_RAUC_PROGRESS(40, "Checking bundle failed."); |
| 176 | FAKE_RAUC_PROGRESS(100, "Installing failed."); |
| 177 | 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"); |
| 178 | FAKE_RAUC_OPERATION("idle"); |
| 179 | |
| 180 | rauc->install("/path/to/bundle"); |
Tomáš Pecka | 91836f3 | 2021-11-15 17:12:32 +0100 | [diff] [blame^] | 181 | waitForSaturation(exp); // wait until installation starts |
Tomáš Pecka | c764b76 | 2021-01-23 21:46:21 +0100 | [diff] [blame] | 182 | REQUIRE(rauc->operation() == "installing"); |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 183 | waitForCompletionAndBitMore(seq1); |
Tomáš Pecka | c764b76 | 2021-01-23 21:46:21 +0100 | [diff] [blame] | 184 | 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áš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 185 | } |
Tomáš Pecka | c764b76 | 2021-01-23 21:46:21 +0100 | [diff] [blame] | 186 | |
| 187 | REQUIRE(rauc->operation() == "idle"); |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 188 | } |