From 32bd071ecbd37f2186c0d2ba249d4f35cc7c178d Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 13 Jan 2022 15:44:29 +0900 Subject: [PATCH 1/2] Minor simplifications in bpf_existence_test. 1. Use set instead of vector. This simplifies the code a bit. 2. Use proper NDK constants and functions to check the device OS version. Test: test-only change Test: passes on flame running qt-dev build (no-op) Test: passes on flame running RQ3A build Test: passes on raven running SP2A build Test: passes on barbet running aosp/master Change-Id: Ie13e1df674e50fcfb70811bc0dccae515cbb6e1c --- tests/mts/bpf_existence_test.cpp | 43 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/tests/mts/bpf_existence_test.cpp b/tests/mts/bpf_existence_test.cpp index 5e3df5711b..081bf216e8 100644 --- a/tests/mts/bpf_existence_test.cpp +++ b/tests/mts/bpf_existence_test.cpp @@ -17,32 +17,37 @@ */ #include +#include #include -#include -#include +#include #include #include #include using std::find; +using std::set; using std::string; -using std::vector; using android::modules::sdklevel::IsAtLeastR; using android::modules::sdklevel::IsAtLeastS; using android::modules::sdklevel::IsAtLeastT; +// Mainline development branches lack the constant for the current development OS. +#ifndef __ANDROID_API_T__ +#define __ANDROID_API_T__ 33 +#endif + class BpfExistenceTest : public ::testing::Test { }; -static const vector INTRODUCED_R = { +static const set INTRODUCED_R = { "/sys/fs/bpf/prog_offload_schedcls_ingress_tether_ether", "/sys/fs/bpf/prog_offload_schedcls_ingress_tether_rawip", }; -static const vector INTRODUCED_S = { +static const set INTRODUCED_S = { "/sys/fs/bpf/tethering/prog_offload_schedcls_tether_downstream4_ether", "/sys/fs/bpf/tethering/prog_offload_schedcls_tether_downstream4_rawip", "/sys/fs/bpf/tethering/prog_offload_schedcls_tether_downstream6_ether", @@ -53,32 +58,28 @@ static const vector INTRODUCED_S = { "/sys/fs/bpf/tethering/prog_offload_schedcls_tether_upstream6_rawip", }; -static const vector REMOVED_S = { +static const set REMOVED_S = { "/sys/fs/bpf/prog_offload_schedcls_ingress_tether_ether", "/sys/fs/bpf/prog_offload_schedcls_ingress_tether_rawip", }; -static const vector INTRODUCED_T = { +static const set INTRODUCED_T = { }; -static const vector REMOVED_T = { +static const set REMOVED_T = { }; -void addAll(vector* a, const vector& b) { - a->insert(a->end(), b.begin(), b.end()); +void addAll(set* a, const set& b) { + a->insert(b.begin(), b.end()); } -void removeAll(vector* a, const vector b) { +void removeAll(set* a, const set b) { for (const auto& toRemove : b) { - auto iter = find(a->begin(), a->end(), toRemove); - while (iter != a->end()) { - a->erase(iter); - iter = find(a->begin(), a->end(), toRemove); - } + a->erase(toRemove); } } -void getFileLists(vector* expected, vector* unexpected) { +void getFileLists(set* expected, set* unexpected) { unexpected->clear(); expected->clear(); @@ -112,8 +113,8 @@ void getFileLists(vector* expected, vector* unexpected) { } void checkFiles() { - vector mustExist; - vector mustNotExist; + set mustExist; + set mustNotExist; getFileLists(&mustExist, &mustNotExist); @@ -132,9 +133,9 @@ void checkFiles() { TEST_F(BpfExistenceTest, TestPrograms) { // Pre-flight check to ensure test has been updated. - uint64_t buildVersionSdk = android::base::GetUintProperty("ro.build.version.sdk", 0); + uint64_t buildVersionSdk = android_get_device_api_level(); ASSERT_NE(0, buildVersionSdk) << "Unable to determine device SDK version"; - if (buildVersionSdk > 33 && buildVersionSdk != 10000) { + if (buildVersionSdk > __ANDROID_API_T__ && buildVersionSdk != __ANDROID_API_FUTURE__) { FAIL() << "Unknown OS version " << buildVersionSdk << ", please update this test"; } From 8db39c457292de8a2982183fd7a718580d660e50 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 13 Jan 2022 16:11:31 +0900 Subject: [PATCH 2/2] Test for the existence of maps as well as programs. Test: passes on barbet running aosp/master Change-Id: I41dcf8aa99a38a00227d608f421672c398cd2065 --- tests/mts/bpf_existence_test.cpp | 45 +++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/tests/mts/bpf_existence_test.cpp b/tests/mts/bpf_existence_test.cpp index 081bf216e8..ac8096c558 100644 --- a/tests/mts/bpf_existence_test.cpp +++ b/tests/mts/bpf_existence_test.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * bpf_existence_test.cpp - checks that the device runs expected BPF programs + * bpf_existence_test.cpp - checks that the device has expected BPF programs and maps */ #include @@ -39,28 +39,47 @@ using android::modules::sdklevel::IsAtLeastT; #define __ANDROID_API_T__ 33 #endif +#define PLATFORM "/sys/fs/bpf/" +#define TETHERING "/sys/fs/bpf/tethering/" + class BpfExistenceTest : public ::testing::Test { }; static const set INTRODUCED_R = { - "/sys/fs/bpf/prog_offload_schedcls_ingress_tether_ether", - "/sys/fs/bpf/prog_offload_schedcls_ingress_tether_rawip", + PLATFORM "map_offload_tether_ingress_map", + PLATFORM "map_offload_tether_limit_map", + PLATFORM "map_offload_tether_stats_map", + PLATFORM "prog_offload_schedcls_ingress_tether_ether", + PLATFORM "prog_offload_schedcls_ingress_tether_rawip", }; static const set INTRODUCED_S = { - "/sys/fs/bpf/tethering/prog_offload_schedcls_tether_downstream4_ether", - "/sys/fs/bpf/tethering/prog_offload_schedcls_tether_downstream4_rawip", - "/sys/fs/bpf/tethering/prog_offload_schedcls_tether_downstream6_ether", - "/sys/fs/bpf/tethering/prog_offload_schedcls_tether_downstream6_rawip", - "/sys/fs/bpf/tethering/prog_offload_schedcls_tether_upstream4_ether", - "/sys/fs/bpf/tethering/prog_offload_schedcls_tether_upstream4_rawip", - "/sys/fs/bpf/tethering/prog_offload_schedcls_tether_upstream6_ether", - "/sys/fs/bpf/tethering/prog_offload_schedcls_tether_upstream6_rawip", + TETHERING "map_offload_tether_dev_map", + TETHERING "map_offload_tether_downstream4_map", + TETHERING "map_offload_tether_downstream64_map", + TETHERING "map_offload_tether_downstream6_map", + TETHERING "map_offload_tether_error_map", + TETHERING "map_offload_tether_limit_map", + TETHERING "map_offload_tether_stats_map", + TETHERING "map_offload_tether_upstream4_map", + TETHERING "map_offload_tether_upstream6_map", + TETHERING "map_test_tether_downstream6_map", + TETHERING "prog_offload_schedcls_tether_downstream4_ether", + TETHERING "prog_offload_schedcls_tether_downstream4_rawip", + TETHERING "prog_offload_schedcls_tether_downstream6_ether", + TETHERING "prog_offload_schedcls_tether_downstream6_rawip", + TETHERING "prog_offload_schedcls_tether_upstream4_ether", + TETHERING "prog_offload_schedcls_tether_upstream4_rawip", + TETHERING "prog_offload_schedcls_tether_upstream6_ether", + TETHERING "prog_offload_schedcls_tether_upstream6_rawip", }; static const set REMOVED_S = { - "/sys/fs/bpf/prog_offload_schedcls_ingress_tether_ether", - "/sys/fs/bpf/prog_offload_schedcls_ingress_tether_rawip", + PLATFORM "map_offload_tether_ingress_map", + PLATFORM "map_offload_tether_limit_map", + PLATFORM "map_offload_tether_stats_map", + PLATFORM "prog_offload_schedcls_ingress_tether_ether", + PLATFORM "prog_offload_schedcls_ingress_tether_rawip", }; static const set INTRODUCED_T = {