Commit 10f718f4 authored by Teng Qin's avatar Teng Qin Committed by GitHub

Merge pull request #1884 from netgroup-polito/fix-get-table-offline-percpu

fix get_table_offline for percpu hash table
parents 1cf67ae2 b5cadaff
......@@ -232,11 +232,14 @@ class BPFHashTable : public BPFTableBase<KeyType, ValueType> {
KeyType cur;
ValueType value;
StatusTuple r(0);
if (!this->first(&cur))
return res;
while (true) {
if (!this->lookup(&cur, &value))
r = get_value(cur, value);
if (r.code() != 0)
break;
res.emplace_back(cur, value);
if (!this->next(&cur, &cur))
......
......@@ -84,6 +84,10 @@ TEST_CASE("test hash table", "[hash_table]") {
REQUIRE(pair.first % 3 == 0);
REQUIRE(pair.first / 3 == pair.second);
}
// clear table
t.clear_table_non_atomic();
REQUIRE(t.get_table_offline().size() == 0);
}
}
......@@ -156,5 +160,34 @@ TEST_CASE("percpu hash table", "[percpu_hash_table]") {
res = t.get_value(k, v2);
REQUIRE(res.code() != 0);
}
SECTION("walk table") {
std::vector<uint64_t> v(ncpus);
for (int k = 3; k <= 30; k+=3) {
for (size_t cpu = 0; cpu < ncpus; cpu++) {
v[cpu] = k * cpu;
}
res = t.update_value(k, v);
REQUIRE(res.code() == 0);
}
// get whole table
auto offline = t.get_table_offline();
REQUIRE(offline.size() == 10);
for (int i = 0; i < 10; i++) {
// check the key
REQUIRE(offline.at(i).first % 3 == 0);
// check value
for (size_t cpu = 0; cpu < ncpus; cpu++) {
REQUIRE(offline.at(i).second.at(cpu) == cpu * offline.at(i).first);
}
}
// clear table
t.clear_table_non_atomic();
REQUIRE(t.get_table_offline().size() == 0);
}
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment