Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shillaker committed Sep 8, 2021
1 parent 6c37486 commit b7e17d9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/faabric/snapshot/SnapshotRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SnapshotRegistry

faabric::util::SnapshotData& getSnapshot(const std::string& key);

bool snapshotExists(const std::string &key);
bool snapshotExists(const std::string& key);

void mapSnapshot(const std::string& key, uint8_t* target);

Expand Down
32 changes: 29 additions & 3 deletions tests/test/snapshot/test_snapshot_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,24 @@ TEST_CASE_METHOD(SnapshotTestFixture,
std::string keyB = "snapB";
std::string keyC = "snapC";

REQUIRE(!reg.snapshotExists(keyA));
REQUIRE(!reg.snapshotExists(keyB));
REQUIRE(!reg.snapshotExists(keyC));

SnapshotData snapA = takeSnapshot(keyA, 1, true);
SnapshotData snapB = takeSnapshot(keyB, 2, false);
SnapshotData snapC = takeSnapshot(keyA, 3, true);

REQUIRE(reg.snapshotExists(keyA));
REQUIRE(reg.snapshotExists(keyB));
REQUIRE(!reg.snapshotExists(keyC));
REQUIRE(reg.getSnapshotCount() == 2);

SnapshotData snapC = takeSnapshot(keyC, 3, true);

REQUIRE(reg.snapshotExists(keyA));
REQUIRE(reg.snapshotExists(keyB));
REQUIRE(reg.snapshotExists(keyC));
REQUIRE(reg.getSnapshotCount() == 3);

// Add some random bits of data to the vectors
for (int i = 0; i < HOST_PAGE_SIZE - 10; i += 50) {
Expand All @@ -32,12 +47,11 @@ TEST_CASE_METHOD(SnapshotTestFixture,
snapC.data[i + 2] = i;
}

// Take snapshots again with updated data
reg.takeSnapshot(keyA, snapA);
reg.takeSnapshot(keyB, snapB, false);
reg.takeSnapshot(keyC, snapC);

REQUIRE(reg.getSnapshotCount() == 3);

SnapshotData actualA = reg.getSnapshot(keyA);
SnapshotData actualB = reg.getSnapshot(keyB);
SnapshotData actualC = reg.getSnapshot(keyC);
Expand Down Expand Up @@ -81,7 +95,19 @@ TEST_CASE_METHOD(SnapshotTestFixture,

removeSnapshot(keyA, 1);
removeSnapshot(keyB, 2);

REQUIRE(!reg.snapshotExists(keyA));
REQUIRE(!reg.snapshotExists(keyB));
REQUIRE(reg.snapshotExists(keyC));
REQUIRE(reg.getSnapshotCount() == 1);

removeSnapshot(keyC, 3);

REQUIRE(!reg.snapshotExists(keyA));
REQUIRE(!reg.snapshotExists(keyB));
REQUIRE(!reg.snapshotExists(keyC));
REQUIRE(reg.getSnapshotCount() == 0);

deallocatePages(actualDataA, 1);
deallocatePages(actualDataB, 2);
deallocatePages(actualDataC, 3);
Expand Down

0 comments on commit b7e17d9

Please sign in to comment.