Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20d170fc authored by Akilesh Kailash's avatar Akilesh Kailash Committed by Gerrit Code Review
Browse files

Merge "snapuserd_test: skip test if dm-user kernel driver is absent" into main

parents 3e464e6e a880e567
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -267,6 +267,10 @@ cc_test {
    test_suites: [
        "vts",
    ],
    test_options: {
        // VABC mandatory in Android T per VSR.
        min_shipping_api_level: 32,
    },
}

cc_binary_host {
+8 −0
Original line number Diff line number Diff line
@@ -1530,6 +1530,14 @@ INSTANTIATE_TEST_SUITE_P(Io, HandlerTest, ::testing::ValuesIn(GetTestConfigs()))
int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);

#ifdef __ANDROID__
    if (!android::snapshot::CanUseUserspaceSnapshots() ||
        android::snapshot::IsVendorFromAndroid12()) {
        std::cerr << "snapuserd_test not supported on this device\n";
        return 0;
    }
#endif

    gflags::ParseCommandLineFlags(&argc, &argv, false);

    return RUN_ALL_TESTS();
+37 −0
Original line number Diff line number Diff line
@@ -14,11 +14,14 @@

#include "utility.h"

#include <android-base/properties.h>
#include <sys/resource.h>
#include <sys/utsname.h>
#include <unistd.h>

#include <android-base/file.h>
#include <android-base/logging.h>
#include <libdm/dm.h>
#include <processgroup/processgroup.h>

#include <private/android_filesystem_config.h>
@@ -27,6 +30,7 @@ namespace android {
namespace snapshot {

using android::base::unique_fd;
using android::dm::DeviceMapper;

bool SetThreadPriority([[maybe_unused]] int priority) {
#ifdef __ANDROID__
@@ -61,5 +65,38 @@ bool KernelSupportsIoUring() {
    return major > 5 || (major == 5 && minor >= 6);
}

bool GetUserspaceSnapshotsEnabledProperty() {
    return android::base::GetBoolProperty("ro.virtual_ab.userspace.snapshots.enabled", false);
}

bool KernelSupportsCompressedSnapshots() {
    auto& dm = DeviceMapper::Instance();
    return dm.GetTargetByName("user", nullptr);
}

bool IsVendorFromAndroid12() {
    const std::string UNKNOWN = "unknown";
    const std::string vendor_release =
            android::base::GetProperty("ro.vendor.build.version.release_or_codename", UNKNOWN);

    if (vendor_release.find("12") != std::string::npos) {
        return true;
    }
    return false;
}

bool CanUseUserspaceSnapshots() {
    if (!GetUserspaceSnapshotsEnabledProperty()) {
        LOG(INFO) << "Virtual A/B - Userspace snapshots disabled";
        return false;
    }

    if (!KernelSupportsCompressedSnapshots()) {
        LOG(ERROR) << "Userspace snapshots requested, but no kernel support is available.";
        return false;
    }
    return true;
}

}  // namespace snapshot
}  // namespace android
+5 −0
Original line number Diff line number Diff line
@@ -24,5 +24,10 @@ bool SetThreadPriority(int priority);
bool SetProfiles(std::initializer_list<std::string_view> profiles);
bool KernelSupportsIoUring();

bool GetUserspaceSnapshotsEnabledProperty();
bool KernelSupportsCompressedSnapshots();
bool CanUseUserspaceSnapshots();
bool IsVendorFromAndroid12();

}  // namespace snapshot
}  // namespace android