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

Commit 5b9efa30 authored by Yifan Hong's avatar Yifan Hong Committed by Automerger Merge Worker
Browse files

Merge "storaged: test do not crash on cuttlefish." am: ecbf9e4f am: 94fd5ca7 am: 4b83bd21

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1912709

Change-Id: I62838d448818b5c8d237962436a081f966852a5b
parents 5ff26282 4b83bd21
Loading
Loading
Loading
Loading
+16 −11
Original line number Original line Diff line number Diff line
@@ -64,20 +64,23 @@ void write_and_pause(uint32_t sec) {
} // namespace
} // namespace


// the return values of the tested functions should be the expected ones
// the return values of the tested functions should be the expected ones
const char* DISK_STATS_PATH;
const char* get_disk_stats_path() {
TEST(storaged_test, retvals) {
    struct disk_stats stats;
    memset(&stats, 0, sizeof(struct disk_stats));

    if (access(MMC_DISK_STATS_PATH, R_OK) >= 0) {
    if (access(MMC_DISK_STATS_PATH, R_OK) >= 0) {
        DISK_STATS_PATH = MMC_DISK_STATS_PATH;
        return MMC_DISK_STATS_PATH;
    } else if (access(SDA_DISK_STATS_PATH, R_OK) >= 0) {
    } else if (access(SDA_DISK_STATS_PATH, R_OK) >= 0) {
        DISK_STATS_PATH = SDA_DISK_STATS_PATH;
        return SDA_DISK_STATS_PATH;
    } else {
    } else {
        return;
        return nullptr;
    }
}
}
TEST(storaged_test, retvals) {
    struct disk_stats stats;
    memset(&stats, 0, sizeof(struct disk_stats));

    auto disk_stats_path = get_disk_stats_path();
    if (disk_stats_path == nullptr) GTEST_SKIP();


    EXPECT_TRUE(parse_disk_stats(DISK_STATS_PATH, &stats));
    EXPECT_TRUE(parse_disk_stats(disk_stats_path, &stats));


    struct disk_stats old_stats;
    struct disk_stats old_stats;
    memset(&old_stats, 0, sizeof(struct disk_stats));
    memset(&old_stats, 0, sizeof(struct disk_stats));
@@ -92,7 +95,9 @@ TEST(storaged_test, retvals) {


TEST(storaged_test, disk_stats) {
TEST(storaged_test, disk_stats) {
    struct disk_stats stats = {};
    struct disk_stats stats = {};
    ASSERT_TRUE(parse_disk_stats(DISK_STATS_PATH, &stats));
    auto disk_stats_path = get_disk_stats_path();
    if (disk_stats_path == nullptr) GTEST_SKIP();
    ASSERT_TRUE(parse_disk_stats(disk_stats_path, &stats));


    // every entry of stats (except io_in_flight) should all be greater than 0
    // every entry of stats (except io_in_flight) should all be greater than 0
    for (uint i = 0; i < DISK_STATS_SIZE; ++i) {
    for (uint i = 0; i < DISK_STATS_SIZE; ++i) {
@@ -103,7 +108,7 @@ TEST(storaged_test, disk_stats) {
    // accumulation of the increments should be the same with the overall increment
    // accumulation of the increments should be the same with the overall increment
    struct disk_stats base = {}, tmp = {}, curr, acc = {}, inc[5];
    struct disk_stats base = {}, tmp = {}, curr, acc = {}, inc[5];
    for (uint i = 0; i < 5; ++i) {
    for (uint i = 0; i < 5; ++i) {
        ASSERT_TRUE(parse_disk_stats(DISK_STATS_PATH, &curr));
        ASSERT_TRUE(parse_disk_stats(disk_stats_path, &curr));
        if (i == 0) {
        if (i == 0) {
            base = curr;
            base = curr;
            tmp = curr;
            tmp = curr;