Skip the bpf native tests on old devices

For older devices that doesn't have bpf support, skip the bpf native
tests so we don't get false alarms. Fixed some compiler warning and
added the clang-format check.

Test: ./libnetdbpf_test/libnetdbpf_test
Bug: 119526856
Change-Id: Icb73a8ee9b9dff9a0da28b96578e1245f1f3724f
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..a74b62a
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,16 @@
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+# Please keep this file in sync with system/core/.clang-format-4
+#
+BasedOnStyle: Google
+AccessModifierOffset: -2
+AllowShortFunctionsOnASingleLine: Inline
+BreakBeforeTernaryOperators: true
+ColumnLimit: 100
+CommentPragmas: NOLINT:.*
+DerivePointerAlignment: false
+IndentWidth: 4
+ContinuationIndentWidth: 8
+PointerAlignment: Left
+SpaceAfterCStyleCast: true
+TabWidth: 4
+UseTab: Never
diff --git a/Android.bp b/Android.bp
index deaf71e..7d635d1 100644
--- a/Android.bp
+++ b/Android.bp
@@ -13,6 +13,8 @@
         "android-*",
         "cert-*",
         "clang-analyzer-security*",
+	"-cert-err34-c",
+        "clang-analyzer-security*",
         // Disabling due to many unavoidable warnings from POSIX API usage.
         "-google-runtime-int",
     ],
diff --git a/libbpf_android/BpfMapTest.cpp b/libbpf_android/BpfMapTest.cpp
index d0bd79e..02c7ee4 100644
--- a/libbpf_android/BpfMapTest.cpp
+++ b/libbpf_android/BpfMapTest.cpp
@@ -55,6 +55,8 @@
     int mMapFd;
 
     void SetUp() {
+        SKIP_IF_BPF_NOT_SUPPORTED;
+
         if (!access(PINNED_MAP_PATH, R_OK)) {
             EXPECT_EQ(0, remove(PINNED_MAP_PATH));
         }
@@ -63,6 +65,8 @@
     }
 
     void TearDown() {
+        SKIP_IF_BPF_NOT_SUPPORTED;
+
         if (!access(PINNED_MAP_PATH, R_OK)) {
             EXPECT_EQ(0, remove(PINNED_MAP_PATH));
         }
@@ -107,6 +111,8 @@
 };
 
 TEST_F(BpfMapTest, constructor) {
+    SKIP_IF_BPF_NOT_SUPPORTED;
+
     BpfMap<uint32_t, uint32_t> testMap1;
     checkMapInvalid(testMap1);
 
@@ -120,6 +126,8 @@
 }
 
 TEST_F(BpfMapTest, basicHelpers) {
+    SKIP_IF_BPF_NOT_SUPPORTED;
+
     BpfMap<uint32_t, uint32_t> testMap(mMapFd);
     uint32_t key = TEST_KEY1;
     uint32_t value_write = TEST_VALUE1;
@@ -134,6 +142,8 @@
 }
 
 TEST_F(BpfMapTest, reset) {
+    SKIP_IF_BPF_NOT_SUPPORTED;
+
     BpfMap<uint32_t, uint32_t> testMap;
     testMap.reset(mMapFd);
     uint32_t key = TEST_KEY1;
@@ -147,6 +157,8 @@
 }
 
 TEST_F(BpfMapTest, moveConstructor) {
+    SKIP_IF_BPF_NOT_SUPPORTED;
+
     BpfMap<uint32_t, uint32_t> testMap1(mMapFd);
     BpfMap<uint32_t, uint32_t> testMap2;
     testMap2 = std::move(testMap1);
@@ -157,6 +169,8 @@
 }
 
 TEST_F(BpfMapTest, pinnedToPath) {
+    SKIP_IF_BPF_NOT_SUPPORTED;
+
     BpfMap<uint32_t, uint32_t> testMap1(mMapFd);
     EXPECT_OK(testMap1.pinToPath(PINNED_MAP_PATH));
     EXPECT_EQ(0, access(PINNED_MAP_PATH, R_OK));
@@ -171,6 +185,8 @@
 }
 
 TEST_F(BpfMapTest, SetUpMap) {
+    SKIP_IF_BPF_NOT_SUPPORTED;
+
     BpfMap<uint32_t, uint32_t> testMap1;
     EXPECT_OK(testMap1.getOrCreate(TEST_MAP_SIZE, PINNED_MAP_PATH, BPF_MAP_TYPE_HASH));
     EXPECT_EQ(0, access(PINNED_MAP_PATH, R_OK));
@@ -188,6 +204,8 @@
 }
 
 TEST_F(BpfMapTest, iterate) {
+    SKIP_IF_BPF_NOT_SUPPORTED;
+
     BpfMap<uint32_t, uint32_t> testMap(mMapFd);
     populateMap(TEST_MAP_SIZE, testMap);
     int totalCount = 0;
@@ -206,6 +224,8 @@
 }
 
 TEST_F(BpfMapTest, iterateWithValue) {
+    SKIP_IF_BPF_NOT_SUPPORTED;
+
     BpfMap<uint32_t, uint32_t> testMap(mMapFd);
     populateMap(TEST_MAP_SIZE, testMap);
     int totalCount = 0;
@@ -226,6 +246,8 @@
 }
 
 TEST_F(BpfMapTest, mapIsEmpty) {
+    SKIP_IF_BPF_NOT_SUPPORTED;
+
     BpfMap<uint32_t, uint32_t> testMap(mMapFd);
     expectMapEmpty(testMap);
     uint32_t key = TEST_KEY1;
@@ -256,6 +278,8 @@
 }
 
 TEST_F(BpfMapTest, mapClear) {
+    SKIP_IF_BPF_NOT_SUPPORTED;
+
     BpfMap<uint32_t, uint32_t> testMap(mMapFd);
     populateMap(TEST_MAP_SIZE, testMap);
     auto isEmpty = testMap.isEmpty();