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

Commit 960243db authored by Mike Yu's avatar Mike Yu
Browse files

Add test coverage for DnsResolverService::dump()

The thing that calling the dump() at the end of every integration test
can help reduce the possibility of resolver service crash when dump
is being called. This is important especially when bugreport is being
taken.

cd packages/modules/DnsResolver && atest

Change-Id: Iec114a4de4082314496c9f7a3769db51ef42d857
parent 0452b8cf
Loading
Loading
Loading
Loading
+14 −1
Original line number Original line Diff line number Diff line
@@ -163,7 +163,12 @@ class ResolverTest : public ::testing::Test {
    };
    };


    void SetUp() { mDnsClient.SetUp(); }
    void SetUp() { mDnsClient.SetUp(); }
    void TearDown() { mDnsClient.TearDown(); }
    void TearDown() {
        // Ensure the dump works at the end of each test.
        DumpResolverService();

        mDnsClient.TearDown();
    }


    void StartDns(test::DNSResponder& dns, const std::vector<DnsRecord>& records) {
    void StartDns(test::DNSResponder& dns, const std::vector<DnsRecord>& records) {
        for (const auto& r : records) {
        for (const auto& r : records) {
@@ -174,6 +179,14 @@ class ResolverTest : public ::testing::Test {
        dns.clearQueries();
        dns.clearQueries();
    }
    }


    void DumpResolverService() {
        unique_fd fd(open("/dev/null", O_WRONLY));
        EXPECT_EQ(mDnsClient.resolvService()->dump(fd, nullptr, 0), 0);

        const char* querylogCmd[] = {"querylog"};  // Keep it sync with DnsQueryLog::DUMP_KEYWORD.
        EXPECT_EQ(mDnsClient.resolvService()->dump(fd, querylogCmd, std::size(querylogCmd)), 0);
    }

    bool WaitForNat64Prefix(ExpectNat64PrefixStatus status,
    bool WaitForNat64Prefix(ExpectNat64PrefixStatus status,
                            std::chrono::milliseconds timeout = std::chrono::milliseconds(1000)) {
                            std::chrono::milliseconds timeout = std::chrono::milliseconds(1000)) {
        return sDnsMetricsListener->waitForNat64Prefix(status, timeout);
        return sDnsMetricsListener->waitForNat64Prefix(status, timeout);