forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit aims to introduce a new abstraction for these new map types: BPFQueueStackTableBase. As all the allowed operation on these map types are different from the "traditional" ones, I thought to introduce a new abstraction, following the already used programming style (template classes and utility func). Moreover, I had to update libbpf.h/c to insert the new bpf_map_lookup_and_delete_elem(), used when calling "pop()" Signed-off-by: Simone Magnani <[email protected]>
- Loading branch information
1 parent
fbde62b
commit 30a420d
Showing
6 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) 2020 Politecnico di Torino | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "BPF.h" | ||
#include "catch.hpp" | ||
#include <iostream> | ||
#include <linux/version.h> | ||
|
||
//Queue/Stack types are available only from 5.0.0 | ||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) | ||
TEST_CASE("queue table", "[queue_table]") { | ||
const std::string BPF_PROGRAM = R"( | ||
BPF_QUEUE(myqueue, int, 30); | ||
)"; | ||
|
||
ebpf::BPF bpf; | ||
ebpf::StatusTuple res(0); | ||
res = bpf.init(BPF_PROGRAM); | ||
REQUIRE(res.code() == 0); | ||
|
||
ebpf::BPFQueueStackTable<int> t = bpf.get_queuestack_table<int>("myqueue"); | ||
|
||
SECTION("standard methods") { | ||
int i, val; | ||
std::string value; | ||
|
||
// insert elements | ||
for (i=0; i<30; i++) { | ||
res = t.push_value(i); | ||
REQUIRE(res.code() == 0); | ||
} | ||
|
||
// checking head (peek) | ||
res = t.get_head(val); | ||
REQUIRE(res.code() == 0); | ||
REQUIRE(val == 0); | ||
|
||
// retrieve elements | ||
for (i=0; i<30; i++) { | ||
res = t.pop_value(val); | ||
REQUIRE(res.code() == 0); | ||
REQUIRE(val == i); | ||
} | ||
// get non existing element | ||
res = t.pop_value(val); | ||
REQUIRE(res.code() != 0); | ||
} | ||
} | ||
|
||
TEST_CASE("stack table", "[stack_table]") { | ||
const std::string BPF_PROGRAM = R"( | ||
BPF_STACK(mystack, int, 30); | ||
)"; | ||
|
||
ebpf::BPF bpf; | ||
ebpf::StatusTuple res(0); | ||
res = bpf.init(BPF_PROGRAM); | ||
REQUIRE(res.code() == 0); | ||
|
||
ebpf::BPFQueueStackTable<int> t = bpf.get_queuestack_table<int>("mystack"); | ||
|
||
SECTION("standard methods") { | ||
int i, val; | ||
std::string value; | ||
|
||
// insert elements | ||
for (i=0; i<30; i++) { | ||
res = t.push_value(i); | ||
REQUIRE(res.code() == 0); | ||
} | ||
|
||
// checking head (peek) | ||
res = t.get_head(val); | ||
REQUIRE(res.code() == 0); | ||
REQUIRE(val == 29); | ||
|
||
// retrieve elements | ||
for (i=0; i<30; i++) { | ||
res = t.pop_value(val); | ||
REQUIRE(res.code() == 0); | ||
REQUIRE( val == (30 - 1 - i)); | ||
} | ||
// get non existing element | ||
res = t.pop_value(val); | ||
REQUIRE(res.code() != 0); | ||
} | ||
} | ||
#endif |