Logging life cycle of each test
It's helpful for debugging each test to observe the behavior
between each test.
Sample log:
I netd_unit_test: started: BandwidthControllerTest#TestSetupIptablesHooks
I netd_unit_test: finished: BandwidthControllerTest#TestSetupIptablesHooks
Bug: 223731710
Test: cd system/netd then atest
Change-Id: I7e50c8393f0ffe1a9f37abc6dbfc7be0cdbb8285
(cherry picked from commit 1c64f0849fc2f63dc33d11baa70a062581797175)
Merged-In: I7e50c8393f0ffe1a9f37abc6dbfc7be0cdbb8285
diff --git a/server/InterfaceControllerTest.cpp b/server/InterfaceControllerTest.cpp
index 006018d..8075431 100644
--- a/server/InterfaceControllerTest.cpp
+++ b/server/InterfaceControllerTest.cpp
@@ -22,6 +22,7 @@
#include <gtest/gtest.h>
#include <netdutils/MockSyscalls.h>
+#include <netdutils/NetNativeTestBase.h>
#include <netdutils/Utils.h>
#include "InterfaceController.h"
@@ -66,7 +67,7 @@
} // namespace
-class StablePrivacyTest : public testing::Test {
+class StablePrivacyTest : public NetNativeTestBase {
protected:
void expectOpenFile(const std::string& path, const Fd fd, int err) {
if (err == 0) {
@@ -179,7 +180,7 @@
EXPECT_NE(ok, enableStablePrivacyAddresses(kTestIface));
}
-class GetIfaceListTest : public testing::Test {};
+class GetIfaceListTest : public NetNativeTestBase {};
TEST_F(GetIfaceListTest, IfaceNames) {
StatusOr<std::vector<std::string>> ifaceNames = getIfaceNames();
diff --git a/server/IptablesBaseTest.h b/server/IptablesBaseTest.h
index abe3f84..bfcc71a 100644
--- a/server/IptablesBaseTest.h
+++ b/server/IptablesBaseTest.h
@@ -18,9 +18,11 @@
#include <deque>
+#include <netdutils/NetNativeTestBase.h>
+
#include "NetdConstants.h"
-class IptablesBaseTest : public ::testing::Test {
+class IptablesBaseTest : public NetNativeTestBase {
public:
IptablesBaseTest();
diff --git a/server/IptablesRestoreControllerTest.cpp b/server/IptablesRestoreControllerTest.cpp
index a05c76d..cecdf4d 100644
--- a/server/IptablesRestoreControllerTest.cpp
+++ b/server/IptablesRestoreControllerTest.cpp
@@ -32,6 +32,7 @@
#include <android-base/strings.h>
#include <log/log.h>
#include <netdutils/MockSyscalls.h>
+#include <netdutils/NetNativeTestBase.h>
#include <netdutils/Stopwatch.h>
#include "NetdConstants.h"
@@ -55,7 +56,7 @@
using testing::Return;
using testing::StrictMock;
-class IptablesRestoreControllerTest : public ::testing::Test {
+class IptablesRestoreControllerTest : public NetNativeTestBase {
public:
IptablesRestoreController con;
int mDefaultMaxRetries = con.MAX_RETRIES;
diff --git a/server/NFLogListenerTest.cpp b/server/NFLogListenerTest.cpp
index 88ab2c6..878c988 100644
--- a/server/NFLogListenerTest.cpp
+++ b/server/NFLogListenerTest.cpp
@@ -25,6 +25,7 @@
#include <linux/netfilter/nfnetlink_log.h>
#include <netdutils/MockSyscalls.h>
+#include <netdutils/NetNativeTestBase.h>
#include "NFLogListener.h"
using ::testing::_;
@@ -58,7 +59,7 @@
MOCK_METHOD1(registerSkErrorHandler, void(const SkErrorHandler& handler));
};
-class NFLogListenerTest : public testing::Test {
+class NFLogListenerTest : public NetNativeTestBase {
protected:
NFLogListenerTest() {
EXPECT_CALL(*mNLListener, subscribe(kNFLogPacketMsgType, _))
diff --git a/server/SockDiagTest.cpp b/server/SockDiagTest.cpp
index 49601aa..864d08d 100644
--- a/server/SockDiagTest.cpp
+++ b/server/SockDiagTest.cpp
@@ -24,6 +24,7 @@
#include <linux/inet_diag.h>
#include <gtest/gtest.h>
+#include <netdutils/NetNativeTestBase.h>
#include "Fwmark.h"
#include "NetdConstants.h"
@@ -33,7 +34,7 @@
namespace android {
namespace net {
-class SockDiagTest : public ::testing::Test {
+class SockDiagTest : public NetNativeTestBase {
protected:
static bool isLoopbackSocket(const inet_diag_msg *msg) {
return SockDiag::isLoopbackSocket(msg);
diff --git a/server/XfrmControllerTest.cpp b/server/XfrmControllerTest.cpp
index e7f5cfc..f1c3807 100644
--- a/server/XfrmControllerTest.cpp
+++ b/server/XfrmControllerTest.cpp
@@ -41,6 +41,7 @@
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <gtest/gtest.h>
+#include <netdutils/NetNativeTestBase.h>
#include "Fwmark.h"
#include "NetdConstants.h"
@@ -127,7 +128,7 @@
EXPECT_EQ(expected, actualStr);
}
-class XfrmControllerTest : public ::testing::Test {
+class XfrmControllerTest : public NetNativeTestBase {
public:
testing::StrictMock<netdutils::ScopedMockSyscalls> mockSyscalls;
};
diff --git a/tests/binder_test.cpp b/tests/binder_test.cpp
index bc1e739..40e5759 100644
--- a/tests/binder_test.cpp
+++ b/tests/binder_test.cpp
@@ -58,6 +58,7 @@
#include <com/android/internal/net/IOemNetd.h>
#include <cutils/multiuser.h>
#include <gtest/gtest.h>
+#include <netdutils/NetNativeTestBase.h>
#include <netutils/ifc.h>
#include <utils/Errors.h>
#include "Fwmark.h"
@@ -175,7 +176,7 @@
{// 2001:db8:cafe::8888
.u6_addr8 = {0x20, 0x01, 0x0d, 0xb8, 0xca, 0xfe, 0, 0, 0, 0, 0, 0, 0, 0, 0x88, 0x88}}};
-class NetdBinderTest : public ::testing::Test {
+class NetdBinderTest : public NetNativeTestBase {
public:
NetdBinderTest() {
sp<IServiceManager> sm = android::defaultServiceManager();
@@ -4792,7 +4793,7 @@
}
}
-class MDnsBinderTest : public ::testing::Test {
+class MDnsBinderTest : public NetNativeTestBase {
public:
MDnsBinderTest() {
sp<IServiceManager> sm = android::defaultServiceManager();
diff --git a/tests/bpf_base_test.cpp b/tests/bpf_base_test.cpp
index 60741b7..52311c4 100644
--- a/tests/bpf_base_test.cpp
+++ b/tests/bpf_base_test.cpp
@@ -33,6 +33,7 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include <netdutils/NetNativeTestBase.h>
#include "bpf/BpfMap.h"
#include "bpf/BpfUtils.h"
@@ -48,7 +49,7 @@
constexpr uid_t TEST_UID = UID_MAX - 1;
constexpr uint32_t TEST_TAG = 42;
-class BpfBasicTest : public testing::Test {
+class BpfBasicTest : public NetNativeTestBase {
protected:
BpfBasicTest() {}
};
diff --git a/tests/sock_diag_test.cpp b/tests/sock_diag_test.cpp
index 8ee9908..5d142dc 100644
--- a/tests/sock_diag_test.cpp
+++ b/tests/sock_diag_test.cpp
@@ -21,6 +21,7 @@
#include <linux/inet_diag.h>
#include <gtest/gtest.h>
+#include <netdutils/NetNativeTestBase.h>
#include "NetdConstants.h"
#include "SockDiag.h"
@@ -29,7 +30,7 @@
#define NUM_SOCKETS 500
-class SockDiagTest : public ::testing::Test {
+class SockDiagTest : public NetNativeTestBase {
};
uint16_t bindAndListen(int s) {