Commit b5cadaff authored by Mauricio Vasquez B's avatar Mauricio Vasquez B

fix get_table_offline for percpu hash table

Use get_value() instead of lookup() as the value as in the case of
percpu tables the ValueType is an std::vector that has to be resized
before performing the lookup function.

Add also some testing for it.

Solves https://github.com/iovisor/bcc/issues/1860Signed-off-by: default avatarMauricio Vasquez B <mauricio.vasquez@polito.it>
parent 1cf67ae2
......@@ -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