| #include "trompeloeil_doctest.h" |
| #include "dbus-helpers/dbus_rauc_server.h" |
| #include "mock/system.h" |
| #include "pretty_printers.h" |
| #include "system/RAUC.h" |
| #include "test_log_setup.h" |
| |
| TEST_CASE("Fetch RAUC data over DBus") |
| { |
| using namespace std::literals::chrono_literals; |
| |
| TEST_INIT_LOGS; |
| trompeloeil::sequence seq1; |
| |
| // setup separate connections for both client and server. Can be done using one connection only but this way it is more generic |
| auto serverConnection = sdbus::createSessionBusConnection("de.pengutronix.rauc"); |
| auto clientConnectionSignals = sdbus::createSessionBusConnection(); |
| auto clientConnectionMethods = sdbus::createSessionBusConnection(); |
| |
| // enter client and servers event loops |
| clientConnectionSignals->enterEventLoopAsync(); |
| clientConnectionMethods->enterEventLoopAsync(); |
| serverConnection->enterEventLoopAsync(); |
| |
| std::string primarySlot = "rootfs.1"; |
| std::map<std::string, velia::system::RAUC::SlotProperties> status = { |
| {"rootfs.1", { |
| {"activated.count", uint32_t {39}}, |
| {"activated.timestamp", "2021-01-13T17:20:18Z"}, |
| {"bootname", "B"}, |
| {"boot-status", "good"}, |
| {"bundle.compatible", "czechlight-clearfog"}, |
| {"bundle.version", "v4-103-g34d2f48"}, |
| {"class", "rootfs"}, |
| {"device", "/dev/mmcblk0p3"}, |
| {"installed.count", uint32_t {39}}, |
| {"installed.timestamp", "2021-01-13T17:20:15Z"}, |
| {"mountpoint", "/"}, |
| {"sha256", "07b30d065c7aad64d2006ce99fd339c929d3ca97b666fca4584b9ef726469fc4"}, |
| {"size", uint64_t {45601892}}, |
| {"state", "booted"}, |
| {"status", "ok"}, |
| {"type", "ext4"}, |
| }}, |
| {"rootfs.0", { |
| {"activated.count", uint32_t {41}}, |
| {"activated.timestamp", "2021-01-13T17:15:54Z"}, |
| {"bootname", "A"}, |
| {"boot-status", "bad"}, |
| {"bundle.compatible", "czechlight-clearfog"}, |
| {"bundle.version", "v4-104-ge80fcd4"}, |
| {"class", "rootfs"}, |
| {"device", "/dev/mmcblk0p1"}, |
| {"installed.count", uint32_t {41}}, |
| {"installed.timestamp", "2021-01-13T17:15:50Z"}, |
| {"sha256", "6d81e8f341edd17c127811f7347c7e23d18c2fc25c0bdc29ac56999cc9c25629"}, |
| {"size", uint64_t {45647664}}, |
| {"state", "inactive"}, |
| {"status", "ok"}, |
| {"type", "ext4"}, |
| }}, |
| {"cfg.1", { |
| {"bundle.compatible", "czechlight-clearfog"}, |
| {"bundle.version", "v4-103-g34d2f48"}, |
| {"class", "cfg"}, |
| {"device", "/dev/mmcblk0p4"}, |
| {"installed.count", uint32_t {39}}, |
| {"installed.timestamp", "2021-01-13T17:20:18Z"}, |
| {"mountpoint", "/cfg"}, |
| {"parent", "rootfs.1"}, |
| {"sha256", "5ca1b6c461fc194055d52b181f57c63dc1d34c19d041f6395e6f6abc039692bb"}, |
| {"size", uint64_t {108}}, |
| {"state", "active"}, |
| {"status", "ok"}, |
| {"type", "ext4"}, |
| }}, |
| {"cfg.0", { |
| {"bundle.compatible", "czechlight-clearfog"}, |
| {"bundle.version", "v4-104-ge80fcd4"}, |
| {"class", "cfg"}, |
| {"device", "/dev/mmcblk0p2"}, |
| {"installed.count", uint32_t {41}}, |
| {"installed.timestamp", "2021-01-13T17:15:54Z"}, |
| {"parent", "rootfs.0"}, |
| {"sha256", "5ca1b6c461fc194055d52b181f57c63dc1d34c19d041f6395e6f6abc039692bb"}, |
| {"size", uint64_t {108}}, |
| {"state", "inactive"}, |
| {"status", "ok"}, |
| {"type", "ext4"}, |
| }}, |
| }; |
| |
| auto server = DBusRAUCServer(*serverConnection, primarySlot, status); |
| |
| auto fakeRaucInstallCb = FakeRAUCInstallCb(); |
| auto rauc = std::make_shared<velia::system::RAUC>( |
| *clientConnectionSignals, |
| *clientConnectionMethods, |
| [&fakeRaucInstallCb](const std::string& operation) { fakeRaucInstallCb.operationCallback(operation); }, |
| [&fakeRaucInstallCb](int32_t perc, const std::string& msg) { fakeRaucInstallCb.progressCallback(perc, msg); }, |
| [&fakeRaucInstallCb](int32_t retVal, const std::string& lastError) { fakeRaucInstallCb.completedCallback(retVal, lastError); }); |
| |
| REQUIRE(rauc->lastError() == ""); |
| REQUIRE(rauc->operation() == "idle"); |
| |
| SECTION("Test slot status") |
| { |
| REQUIRE(rauc->primarySlot() == primarySlot); |
| REQUIRE(rauc->slotStatus() == status); |
| } |
| |
| SECTION("Installation OK") |
| { |
| server.installBundleBehaviour(DBusRAUCServer::InstallBehaviour::OK); // Not cool but I don't feel like I should be creating some abstractions here in tests. |
| FAKE_RAUC_OPERATION("installing"); |
| FAKE_RAUC_PROGRESS(0, "Installing"); |
| FAKE_RAUC_PROGRESS(0, "Determining slot states"); |
| FAKE_RAUC_PROGRESS(20, "Determining slot states done."); |
| FAKE_RAUC_PROGRESS(20, "Checking bundle"); |
| FAKE_RAUC_PROGRESS(20, "Veryfing signature"); |
| FAKE_RAUC_PROGRESS(40, "Veryfing signature done."); |
| FAKE_RAUC_PROGRESS(40, "Checking bundle done."); |
| FAKE_RAUC_PROGRESS(40, "Loading manifest file"); |
| FAKE_RAUC_PROGRESS(60, "Loading manifest file done."); |
| FAKE_RAUC_PROGRESS(60, "Determining target install group"); |
| FAKE_RAUC_PROGRESS(80, "Determining target install group done."); |
| FAKE_RAUC_PROGRESS(80, "Updating slots"); |
| FAKE_RAUC_PROGRESS(80, "Checking slot rootfs.0"); |
| FAKE_RAUC_PROGRESS(85, "Checking slot rootfs.0 done."); |
| FAKE_RAUC_PROGRESS(85, "Copying image to rootfs.0"); |
| FAKE_RAUC_PROGRESS(90, "Copying image to rootfs.0 done."); |
| FAKE_RAUC_PROGRESS(90, "Checking slot cfg.0"); |
| FAKE_RAUC_PROGRESS(95, "Checking slot cfg.0 done."); |
| FAKE_RAUC_PROGRESS(95, "Copying image to cfg.0"); |
| FAKE_RAUC_PROGRESS(100, "Copying image to cfg.0 done."); |
| FAKE_RAUC_PROGRESS(100, "Updating slots done."); |
| FAKE_RAUC_PROGRESS(100, "Installing done."); |
| FAKE_RAUC_COMPLETED(0, ""); |
| FAKE_RAUC_OPERATION("idle"); |
| |
| rauc->install("/path/to/bundle"); |
| REQUIRE(rauc->operation() == "installing"); |
| |
| SECTION("Invoking another operation before the installation ends") |
| { |
| REQUIRE_THROWS_AS(rauc->install("/path/to/bundle"), sdbus::Error); |
| REQUIRE_THROWS_AS(rauc->slotStatus(), sdbus::Error); |
| REQUIRE_THROWS_AS(rauc->primarySlot(), sdbus::Error); |
| } |
| waitForCompletionAndBitMore(seq1); |
| } |
| |
| SECTION("Installation failure") |
| { |
| server.installBundleBehaviour(DBusRAUCServer::InstallBehaviour::FAILURE); |
| |
| FAKE_RAUC_OPERATION("installing"); |
| FAKE_RAUC_PROGRESS(0, "Installing"); |
| FAKE_RAUC_PROGRESS(0, "Determining slot states"); |
| FAKE_RAUC_PROGRESS(20, "Determining slot states done."); |
| FAKE_RAUC_PROGRESS(20, "Checking bundle"); |
| FAKE_RAUC_PROGRESS(40, "Checking bundle failed."); |
| FAKE_RAUC_PROGRESS(100, "Installing failed."); |
| 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"); |
| FAKE_RAUC_OPERATION("idle"); |
| |
| rauc->install("/path/to/bundle"); |
| REQUIRE(rauc->operation() == "installing"); |
| waitForCompletionAndBitMore(seq1); |
| 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"); |
| } |
| |
| REQUIRE(rauc->operation() == "idle"); |
| } |