introduce isBpfSupported() helper

Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9e2a7e049746ad193eea01e7c9d6786d27728c72
This commit is contained in:
Maciej Żenczykowski 2020-02-11 15:01:21 -08:00
parent 8bd5f39348
commit c3a640db94
2 changed files with 10 additions and 6 deletions

View file

@ -72,7 +72,7 @@ void loadAllElfObjects(void) {
}
int main() {
if (android::bpf::getBpfSupportLevel() != android::bpf::BpfLevel::NONE) {
if (android::bpf::isBpfSupported()) {
// Load all ELF objects, create programs and maps, and pin them
loadAllElfObjects();
}

View file

@ -144,22 +144,26 @@ static inline int detachProgram(bpf_attach_type type, const base::unique_fd& cg_
}
uint64_t getSocketCookie(int sockFd);
int synchronizeKernelRCU();
int setrlimitForTest();
std::string BpfLevelToString(BpfLevel BpfLevel);
BpfLevel getBpfSupportLevel();
int synchronizeKernelRCU();
static inline bool isBpfSupported() {
return getBpfSupportLevel() != BpfLevel::NONE;
}
#define SKIP_IF_BPF_NOT_SUPPORTED \
do { \
if (android::bpf::getBpfSupportLevel() == android::bpf::BpfLevel::NONE) { \
if (!android::bpf::isBpfSupported()) { \
GTEST_LOG_(INFO) << "This test is skipped since bpf is not available\n"; \
return; \
} \
} while (0)
#define SKIP_IF_BPF_SUPPORTED \
do { \
if (android::bpf::getBpfSupportLevel() != android::bpf::BpfLevel::NONE) return; \
#define SKIP_IF_BPF_SUPPORTED \
do { \
if (android::bpf::isBpfSupported()) return; \
} while (0)
} // namespace bpf