Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 41c311a4 authored by Mike Yu's avatar Mike Yu Committed by Automerger Merge Worker
Browse files

Test: Change to use test fixtures and log test life cycle am: a3b3e886

parents 911a24ba a3b3e886
Loading
Loading
Loading
Loading
+7 −3
Original line number Original line Diff line number Diff line
@@ -18,10 +18,14 @@


#include <gtest/gtest-spi.h>
#include <gtest/gtest-spi.h>


#include "resolv_test_base.h"

namespace android {
namespace android {
namespace netdutils {
namespace netdutils {


TEST(OperationLimiter, limits) {
class OperationLimiterTest : public ResolvTestBase {};

TEST_F(OperationLimiterTest, limits) {
    OperationLimiter<int> limiter(3);
    OperationLimiter<int> limiter(3);


    EXPECT_TRUE(limiter.start(42));
    EXPECT_TRUE(limiter.start(42));
@@ -50,7 +54,7 @@ TEST(OperationLimiter, limits) {
    limiter.finish(42);
    limiter.finish(42);
}
}


TEST(OperationLimiter, finishWithoutStart) {
TEST_F(OperationLimiterTest, finishWithoutStart) {
    OperationLimiter<int> limiter(1);
    OperationLimiter<int> limiter(1);


    // Will output a LOG(FATAL_WITHOUT_ABORT), but we have no way to probe this.
    // Will output a LOG(FATAL_WITHOUT_ABORT), but we have no way to probe this.
@@ -61,7 +65,7 @@ TEST(OperationLimiter, finishWithoutStart) {
    EXPECT_FALSE(limiter.start(42));
    EXPECT_FALSE(limiter.start(42));
}
}


TEST(OperationLimiter, destroyWithActiveOperations) {
TEST_F(OperationLimiterTest, destroyWithActiveOperations) {
    // The death message doesn't seem to be captured on Android.
    // The death message doesn't seem to be captured on Android.
    EXPECT_DEBUG_DEATH(
    EXPECT_DEBUG_DEATH(
            {
            {
+4 −3
Original line number Original line Diff line number Diff line
@@ -293,7 +293,10 @@ cc_test {
    test_suites: [
    test_suites: [
        "general-tests",
        "general-tests",
    ],
    ],
    defaults: ["netd_defaults"],
    defaults: [
        "netd_defaults",
        "resolv_test_defaults",
    ],
    header_libs: [
    header_libs: [
        "libnetd_resolv_internal_headers",
        "libnetd_resolv_internal_headers",
    ],
    ],
@@ -302,11 +305,9 @@ cc_test {
        "libcrypto_static",
        "libcrypto_static",
        "libdoh_ffi_for_test",
        "libdoh_ffi_for_test",
        "libgmock",
        "libgmock",
        "liblog",
        "libssl",
        "libssl",
    ],
    ],
    shared_libs: [
    shared_libs: [
        "libnetd_client",
        "libnetd_client",
    ],
    ],
    min_sdk_version: "29",
}
}
+5 −1
Original line number Original line Diff line number Diff line
@@ -26,6 +26,8 @@
#include <gmock/gmock-matchers.h>
#include <gmock/gmock-matchers.h>
#include <gtest/gtest.h>
#include <gtest/gtest.h>


#include "resolv_test_base.h"

static const char* GOOGLE_SERVER_IP = "8.8.8.8";
static const char* GOOGLE_SERVER_IP = "8.8.8.8";
static const int TIMEOUT_MS = 3000;
static const int TIMEOUT_MS = 3000;
constexpr int MAXPACKET = (8 * 1024);
constexpr int MAXPACKET = (8 * 1024);
@@ -35,7 +37,9 @@ std::mutex m;
std::condition_variable cv;
std::condition_variable cv;
unsigned int dnsNetId;
unsigned int dnsNetId;


TEST(DoHFFITest, SmokeTest) {
class DoHFFITest : public ResolvTestBase {};

TEST_F(DoHFFITest, SmokeTest) {
    getNetworkForDns(&dnsNetId);
    getNetworkForDns(&dnsNetId);
    // To ensure that we have a real network.
    // To ensure that we have a real network.
    ASSERT_GE(dnsNetId, MINIMAL_NET_ID) << "No available networks";
    ASSERT_GE(dnsNetId, MINIMAL_NET_ID) << "No available networks";
+6 −2
Original line number Original line Diff line number Diff line
@@ -16,12 +16,16 @@


#include <android-base/strings.h>
#include <android-base/strings.h>
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <resolv_stats_test_utils.h>
#include <stats.pb.h>
#include <stats.pb.h>


#include "resolv_stats_test_utils.h"
#include "resolv_test_base.h"

namespace android::net {
namespace android::net {


TEST(ResolvStatsUtils, NetworkDnsEventEq) {
class ResolvStatsUtilsTest : public ResolvTestBase {};

TEST_F(ResolvStatsUtilsTest, NetworkDnsEventEq) {
    NetworkDnsEventReported event1;
    NetworkDnsEventReported event1;
    // Following fields will not be verified during the test in proto NetworkDnsEventReported.
    // Following fields will not be verified during the test in proto NetworkDnsEventReported.
    // So don't need to config those values: event_type, return_code, latency_micros,
    // So don't need to config those values: event_type, return_code, latency_micros,
+4 −2
Original line number Original line Diff line number Diff line
@@ -867,7 +867,9 @@ TEST_F(ServerTest, State) {
    EXPECT_FALSE(s2.active());
    EXPECT_FALSE(s2.active());
}
}


TEST(QueryMapTest, Basic) {
class QueryMapTest : public ResolvTestBase {};

TEST_F(QueryMapTest, Basic) {
    DnsTlsQueryMap map;
    DnsTlsQueryMap map;


    EXPECT_TRUE(map.empty());
    EXPECT_TRUE(map.empty());
@@ -932,7 +934,7 @@ TEST(QueryMapTest, Basic) {
    EXPECT_EQ(bytevec(a2.begin() + 2, a2.end()), bytevec(d2.begin() + 2, d2.end()));
    EXPECT_EQ(bytevec(a2.begin() + 2, a2.end()), bytevec(d2.begin() + 2, d2.end()));
}
}


TEST(QueryMapTest, FillHole) {
TEST_F(QueryMapTest, FillHole) {
    DnsTlsQueryMap map;
    DnsTlsQueryMap map;
    std::vector<std::unique_ptr<DnsTlsQueryMap::QueryFuture>> futures(UINT16_MAX + 1);
    std::vector<std::unique_ptr<DnsTlsQueryMap::QueryFuture>> futures(UINT16_MAX + 1);
    for (uint32_t i = 0; i <= UINT16_MAX; ++i) {
    for (uint32_t i = 0; i <= UINT16_MAX; ++i) {