From: Dave Marchevsky Date: Tue, 11 Jan 2022 23:42:20 +0000 (-0500) Subject: Disable tests that will fail when rwengine=off X-Git-Tag: v0.24.0~4^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=074502f351c67c30998881db547afd4712435ce6;p=platform%2Fupstream%2Fbcc.git Disable tests that will fail when rwengine=off When ENABLE_LLVM_NATIVECODEGEN is OFF, the bpf module rw_engine code will not be used. This is the code that generates custom sscanf and printf functions for BPF map defs. These generated functions are used to serialize arguments to update_value (and similar calls which take string as input) to the correct key / value types. It's still possible to use update_value and its ilk without rw_engine enabled, just need to use the variants that take raw bytes and do serialization manually. In the future we can add some simple sscanf/printfs for common types that can be used without LLVM generation. For now, when rw_engine is disabled, it's fine to skip tests that require these autogenerated functions. --- diff --git a/src/cc/bcc_common.cc b/src/cc/bcc_common.cc index 5c349d70..c33e37af 100644 --- a/src/cc/bcc_common.cc +++ b/src/cc/bcc_common.cc @@ -37,6 +37,10 @@ void * bpf_module_create_c_from_string(const char *text, unsigned flags, const c return mod; } +bool bpf_module_rw_engine_enabled() { + return ebpf::bpf_module_rw_engine_enabled(); +} + void bpf_module_destroy(void *program) { auto mod = static_cast(program); if (!mod) return; diff --git a/src/cc/bcc_common.h b/src/cc/bcc_common.h index b5f77db9..ed68f543 100644 --- a/src/cc/bcc_common.h +++ b/src/cc/bcc_common.h @@ -30,6 +30,7 @@ void * bpf_module_create_c(const char *filename, unsigned flags, const char *cfl void * bpf_module_create_c_from_string(const char *text, unsigned flags, const char *cflags[], int ncflags, bool allow_rlimit, const char *dev_name); +bool bpf_module_rw_engine_enabled(); void bpf_module_destroy(void *program); char * bpf_module_license(void *program); unsigned bpf_module_kern_version(void *program); diff --git a/src/python/bcc/libbcc.py b/src/python/bcc/libbcc.py index f9b83b3c..076d84c3 100644 --- a/src/python/bcc/libbcc.py +++ b/src/python/bcc/libbcc.py @@ -26,6 +26,8 @@ lib.bpf_module_create_c.argtypes = [ct.c_char_p, ct.c_uint, lib.bpf_module_create_c_from_string.restype = ct.c_void_p lib.bpf_module_create_c_from_string.argtypes = [ct.c_char_p, ct.c_uint, ct.POINTER(ct.c_char_p), ct.c_int, ct.c_bool, ct.c_char_p] +lib.bpf_module_rw_engine_enabled.restype = ct.c_bool +lib.bpf_module_rw_engine_enabled.argtypes = None lib.bpf_module_destroy.restype = None lib.bpf_module_destroy.argtypes = [ct.c_void_p] lib.bpf_module_license.restype = ct.c_char_p diff --git a/tests/cc/test_bpf_table.cc b/tests/cc/test_bpf_table.cc index 2d5a5644..43bf28b0 100644 --- a/tests/cc/test_bpf_table.cc +++ b/tests/cc/test_bpf_table.cc @@ -21,7 +21,7 @@ #include "BPF.h" #include "catch.hpp" -TEST_CASE("test bpf table", "[bpf_table]") { +TEST_CASE("test bpf table", ebpf::bpf_module_rw_engine_enabled() ? "[bpf_table]" : "[bpf_table][!mayfail]") { const std::string BPF_PROGRAM = R"( BPF_TABLE("hash", int, int, myhash, 128); )"; @@ -92,7 +92,7 @@ TEST_CASE("test bpf table", "[bpf_table]") { } #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) -TEST_CASE("test bpf percpu tables", "[bpf_percpu_table]") { +TEST_CASE("test bpf percpu tables", ebpf::bpf_module_rw_engine_enabled() ? "[bpf_percpu_table]" : "[bpf_percpu_table][!mayfail]") { const std::string BPF_PROGRAM = R"( BPF_PERCPU_HASH(myhash, int, u64, 128); )"; diff --git a/tests/python/test_clang.py b/tests/python/test_clang.py index 7bf12cc3..519e5021 100755 --- a/tests/python/test_clang.py +++ b/tests/python/test_clang.py @@ -3,6 +3,7 @@ # Licensed under the Apache License, Version 2.0 (the "License") from bcc import BPF +from bcc.libbcc import lib import ctypes as ct from unittest import main, skipUnless, TestCase from utils import kernel_version_ge @@ -143,6 +144,7 @@ int do_completion(struct pt_regs *ctx, struct request *req) { b = BPF(text=text, debug=0) fns = b.load_funcs(BPF.KPROBE) + @skipUnless(lib.bpf_module_rw_engine_enabled(), "requires enabled rwengine") def test_sscanf(self): text = """ BPF_HASH(stats, int, struct { u64 a; u64 b; u64 c:36; u64 d:28; struct { u32 a; u32 b; } s; }, 10); @@ -164,6 +166,7 @@ int foo(void *ctx) { self.assertEqual(l.s.a, 5) self.assertEqual(l.s.b, 6) + @skipUnless(lib.bpf_module_rw_engine_enabled(), "requires enabled rwengine") def test_sscanf_array(self): text = """ BPF_HASH(stats, int, struct { u32 a[3]; u32 b; }, 10); @@ -180,6 +183,7 @@ BPF_HASH(stats, int, struct { u32 a[3]; u32 b; }, 10); self.assertEqual(l.a[2], 3) self.assertEqual(l.b, 4) + @skipUnless(lib.bpf_module_rw_engine_enabled(), "requires enabled rwengine") def test_sscanf_string(self): text = """ struct Symbol {