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

Commit 71c0a047 authored by Hungming Chen's avatar Hungming Chen Committed by android-build-merger
Browse files

resolv_gold_test: Add top 10 US websites test data

am: 2a56a621

Change-Id: I81ed627557f74f30ad51982d82b0bf67dc65a7d0
parents dca663d3 2a56a621
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -40,6 +40,12 @@ using android::netdutils::ScopedAddrinfo;
using std::chrono::milliseconds;

const std::string kTestDataPath = android::base::GetExecutableDirectory() + "/testdata/";
const std::vector<std::string> kGoldFilesGetAddrInfo = {
        "getaddrinfo.topsite.google.pbtxt",    "getaddrinfo.topsite.youtube.pbtxt",
        "getaddrinfo.topsite.amazon.pbtxt",    "getaddrinfo.topsite.yahoo.pbtxt",
        "getaddrinfo.topsite.facebook.pbtxt",  "getaddrinfo.topsite.reddit.pbtxt",
        "getaddrinfo.topsite.wikipedia.pbtxt", "getaddrinfo.topsite.ebay.pbtxt",
        "getaddrinfo.topsite.netflix.pbtxt",   "getaddrinfo.topsite.bing.pbtxt"};

// Fixture test class definition.
class TestBase : public ::testing::Test {
@@ -136,8 +142,7 @@ class ResolvGetAddrInfo : public TestBase {};
class ResolvGoldTest : public TestBase, public ::testing::WithParamInterface<std::string> {};

// GetAddrInfo tests.
INSTANTIATE_TEST_SUITE_P(GetAddrInfo, ResolvGoldTest,
                         ::testing::Values(std::string("getaddrinfo.topsite.google.pbtxt")),
INSTANTIATE_TEST_SUITE_P(GetAddrInfo, ResolvGoldTest, ::testing::ValuesIn(kGoldFilesGetAddrInfo),
                         [](const ::testing::TestParamInfo<std::string>& info) {
                             std::string name = info.param;
                             std::replace_if(
+157 −0
Original line number Diff line number Diff line

# Resolv Gold Test
The "Resolv Gold Test" targets to run automatically in presubmit, as a change
detector to ensure that the resolver doesn't send the query or parse the
response unexpectedly.

## Build testing pbtext
The testing pbtext is built manually so far. Fill expected API parameters to
'config' and expected answers to 'result' in pbtext. Then, record the
corresponding DNS query and response packets. Fill the packets with the \x
formatting into 'query' and 'response' in pbtext. Perhaps have a mechanism
to generate the pbtxt automatically in the future.

### Using 'ping' utility to be an example for building pbtext
Here demonstrates how the pbtext is built.

1. Enable resolver debug log level to VERBOSE (0)
```
$ adb shell service call dnsresolver 10 i32 0
```
2. Ping a website
```
$ adb shell ping www.google.com
```
3. Get bugreport
```
$ adb bugreport
```
4. Search the log pattern as the follows in bugreport
```
# API arguments
resolv  : logArguments: argv[0]=gethostbyname
resolv  : logArguments: argv[1]=0
resolv  : logArguments: argv[2]=www.google.com
resolv  : logArguments: argv[3]=2

# Query packet
resolv  : ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29827
resolv  : ;; flags: rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
resolv  : ;; QUERY SECTION:
resolv  : ;;    www.google.com, type = A, class = IN
resolv  :
resolv  : Hex dump:
resolv  : 7483010000010000000000000377777706676f6f676c6503636f6d0000010001

# Response packet
resolv  : ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29827
resolv  : ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
resolv  : ;; QUERY SECTION:
resolv  : ;;    www.google.com, type = A, class = IN
resolv  :
resolv  : ;; ANSWER SECTION:
resolv  : ;; www.google.com.        2m19s IN A  172.217.160.100
resolv  :
resolv  : Hex dump:
resolv  : 7483818000010001000000000377777706676f6f676c6503636f6d0000010001
resolv  : c00c000100010000008b0004acd9a064
```

5. Convert the logging into pbtext. Then, Clear the 'id' which is 0x7483 in
this example from 'query' and 'response' because 'id' is regenerated per
session. The follows is result pbtext.
```
config {
    call: CALL_GETHOSTBYNAME
    hostbyname {
        host: "www.google.com."
        family: GT_AF_INET
    };
}
result {
    return_code: GT_EAI_NO_ERROR
    addresses: "172.217.160.100"
}
packet_mapping {
    query:    "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x06\x67\x6f\x6f\x67\x6c\x65\x03\x63\x6f\x6d\x00\x00\x01\x00\x01"
    response: "\x00\x00\x81\x80\x00\x01\x00\x01\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x06\x67\x6f\x6f\x67\x6c\x65\x03\x63\x6f\x6d\x00\x00\x01\x00\x01"
              "\xc0\x0c\x00\x01\x00\x01\x00\x00\x00\x8b\x00\x04\xac\xd9\xa0\x64"
}
```

## Decode packets in pbtext
You can invoke the [scapy](https://scapy.net) of python module to extract
binary packet record in pbtext file. Here are the instructions and example
for parsing packet.

### Instructions
Run the following instruction to decode.
```
$ python
>>> from scapy import all as scapy
>>> scapy.DNS("<paste_hex_string>").show2()
```

### Example
Using 'getaddrinfo.topsite.youtube.pbtxt' to be an example here.

1. Find the packet record 'query' or 'response' in .pbtext file.
```
query:    "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77"
          "\x07\x79\x6f\x75\x74\x75\x62\x65\x03\x63\x6f\x6d\x00\x00\x1c\x00"
          "\x01"
```
2. Run the following instruction.

Start python
```
$ python
```
Import scapy
```
>>> from scapy import all as scapy
```
Assign the binary packet to be decoded into a variable. Beware of using
backslash '\\' for new line if required
```
>>> raw_packet=\
    "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77" \
    "\x07\x79\x6f\x75\x74\x75\x62\x65\x03\x63\x6f\x6d\x00\x00\x1c\x00" \
    "\x01"
```
Decode packet
```
>>> scapy.DNS(raw_packet).show2()
###[ DNS ]###
  id        = 0
  qr        = 0
  opcode    = QUERY
  aa        = 0
  tc        = 0
  rd        = 1
  ra        = 0
  z         = 0
  ad        = 0
  cd        = 0
  rcode     = ok
  qdcount   = 1
  ancount   = 0
  nscount   = 0
  arcount   = 0
  \qd        \
   |###[ DNS Question Record ]###
   |  qname     = 'www.youtube.com.'
   |  qtype     = AAAA
   |  qclass    = IN
  an        = None
  ns        = None
  ar        = None
```

## Running the tests
Run the following instruction to test.
```
atest resolv_gold_test
```
 No newline at end of file
+45 −0
Original line number Diff line number Diff line
# Location: Taipei, Taiwan
# Network: Wifi, GoogleGuest
# Date: 23 SEP 2019

config {
    call: CALL_GETADDRINFO
    addrinfo {
        host: "www.amazon.com."
        family: GT_AF_UNSPEC
        socktype: GT_SOCK_DGRAM
        protocol: GT_IPPROTO_IP
        ai_flags: 1024
    };
}
result {
    return_code: GT_EAI_NO_ERROR
    addresses: "64:ff9b::d23:9aa5"
    addresses: "104.124.254.132"
}
packet_mapping {
    query:    "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x06\x61\x6d\x61\x7a\x6f\x6e\x03\x63\x6f\x6d\x00\x00\x1c\x00\x01"
    response: "\x00\x00\x81\x80\x00\x01\x00\x03\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x06\x61\x6d\x61\x7a\x6f\x6e\x03\x63\x6f\x6d\x00\x00\x1c\x00\x01"
              "\xc0\x0c\x00\x05\x00\x01\x00\x00\x03\x45\x00\x0a\x03\x77\x77\x77"
              "\x03\x63\x64\x6e\xc0\x10\xc0\x2c\x00\x05\x00\x01\x00\x00\x00\x06"
              "\x00\x1f\x0e\x64\x33\x61\x67\x34\x68\x75\x6b\x6b\x68\x36\x32\x79"
              "\x6e\x0a\x63\x6c\x6f\x75\x64\x66\x72\x6f\x6e\x74\x03\x6e\x65\x74"
              "\x00\xc0\x42\x00\x1c\x00\x01\x00\x00\x00\x3b\x00\x10\x00\x64\xff"
              "\x9b\x00\x00\x00\x00\x00\x00\x00\x00\x0d\x23\x9a\xa5"
}
packet_mapping {
    query:    "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x06\x61\x6d\x61\x7a\x6f\x6e\x03\x63\x6f\x6d\x00\x00\x01\x00\x01"
    response: "\x00\x00\x81\x80\x00\x01\x00\x04\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x06\x61\x6d\x61\x7a\x6f\x6e\x03\x63\x6f\x6d\x00\x00\x01\x00\x01"
              "\xc0\x0c\x00\x05\x00\x01\x00\x00\x00\xbe\x00\x0a\x03\x77\x77\x77"
              "\x03\x63\x64\x6e\xc0\x10\xc0\x2c\x00\x05\x00\x01\x00\x00\x00\x20"
              "\x00\x1c\x03\x77\x77\x77\x06\x61\x6d\x61\x7a\x6f\x6e\x03\x63\x6f"
              "\x6d\x07\x65\x64\x67\x65\x6b\x65\x79\x03\x6e\x65\x74\x00\xc0\x42"
              "\x00\x05\x00\x01\x00\x00\x01\x10\x00\x18\x06\x65\x31\x35\x33\x31"
              "\x36\x03\x65\x32\x32\x0a\x61\x6b\x61\x6d\x61\x69\x65\x64\x67\x65"
              "\xc0\x59\xc0\x6a\x00\x01\x00\x01\x00\x00\x00\x13\x00\x04\x68\x7c"
              "\xfe\x84"
}
 No newline at end of file
+48 −0
Original line number Diff line number Diff line
# Location: Taipei, Taiwan
# Network: Wifi, GoogleGuest
# Date: 23 SEP 2019

config {
    call: CALL_GETADDRINFO
    addrinfo {
        host: "www.bing.com."
        family: GT_AF_UNSPEC
        socktype: GT_SOCK_DGRAM
        protocol: GT_IPPROTO_IP
        ai_flags: 1024
    };
}
result {
    return_code: GT_EAI_NO_ERROR
    addresses: "2620:1ec:c11::200"
    addresses: "204.79.197.200"
    addresses: "13.107.21.200"
}
packet_mapping {
    query:    "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x04\x62\x69\x6e\x67\x03\x63\x6f\x6d\x00\x00\x1c\x00\x01"
    response: "\x00\x00\x81\x80\x00\x01\x00\x03\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x04\x62\x69\x6e\x67\x03\x63\x6f\x6d\x00\x00\x1c\x00\x01\xc0\x0c"
              "\x00\x05\x00\x01\x00\x00\x0b\x41\x00\x2a\x06\x61\x2d\x30\x30\x30"
              "\x31\x0a\x61\x2d\x61\x66\x64\x65\x6e\x74\x72\x79\x03\x6e\x65\x74"
              "\x0e\x74\x72\x61\x66\x66\x69\x63\x6d\x61\x6e\x61\x67\x65\x72\x03"
              "\x6e\x65\x74\x00\xc0\x2a\x00\x05\x00\x01\x00\x00\x00\x04\x00\x17"
              "\x0b\x64\x75\x61\x6c\x2d\x61\x2d\x30\x30\x30\x31\x08\x61\x2d\x6d"
              "\x73\x65\x64\x67\x65\xc0\x4f\xc0\x60\x00\x1c\x00\x01\x00\x00\x00"
              "\x01\x00\x10\x26\x20\x01\xec\x0c\x11\x00\x00\x00\x00\x00\x00\x00"
              "\x00\x02\x00"
}
packet_mapping {
    query:    "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x04\x62\x69\x6e\x67\x03\x63\x6f\x6d\x00\x00\x01\x00\x01"
    response: "\x00\x00\x81\x80\x00\x01\x00\x04\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x04\x62\x69\x6e\x67\x03\x63\x6f\x6d\x00\x00\x01\x00\x01\xc0\x0c"
              "\x00\x05\x00\x01\x00\x00\x0c\x69\x00\x2a\x06\x61\x2d\x30\x30\x30"
              "\x31\x0a\x61\x2d\x61\x66\x64\x65\x6e\x74\x72\x79\x03\x6e\x65\x74"
              "\x0e\x74\x72\x61\x66\x66\x69\x63\x6d\x61\x6e\x61\x67\x65\x72\x03"
              "\x6e\x65\x74\x00\xc0\x2a\x00\x05\x00\x01\x00\x00\x00\x0d\x00\x17"
              "\x0b\x64\x75\x61\x6c\x2d\x61\x2d\x30\x30\x30\x31\x08\x61\x2d\x6d"
              "\x73\x65\x64\x67\x65\xc0\x4f\xc0\x60\x00\x01\x00\x01\x00\x00\x00"
              "\x2c\x00\x04\xcc\x4f\xc5\xc8\xc0\x60\x00\x01\x00\x01\x00\x00\x00"
              "\x2c\x00\x04\x0d\x6b\x15\xc8"
}
+44 −0
Original line number Diff line number Diff line
# Location: Taipei, Taiwan
# Network: Wifi, GoogleGuest
# Date: 23 SEP 2019

config {
    call: CALL_GETADDRINFO
    addrinfo {
        host: "www.ebay.com."
        family: GT_AF_UNSPEC
        socktype: GT_SOCK_DGRAM
        protocol: GT_IPPROTO_IP
        ai_flags: 1024
    };
}
result {
    return_code: GT_EAI_NO_ERROR
    addresses: "64:ff9b::685d:168"
    addresses: "104.93.1.104"
}
packet_mapping {
    query:    "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x04\x65\x62\x61\x79\x03\x63\x6f\x6d\x00\x00\x1c\x00\x01"
    response: "\x00\x00\x81\x80\x00\x01\x00\x03\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x04\x65\x62\x61\x79\x03\x63\x6f\x6d\x00\x00\x1c\x00\x01\xc0\x0c"
              "\x00\x05\x00\x01\x00\x00\x00\x0b\x00\x1f\x08\x73\x6c\x6f\x74\x39"
              "\x34\x32\x38\x04\x65\x62\x61\x79\x03\x63\x6f\x6d\x07\x65\x64\x67"
              "\x65\x6b\x65\x79\x03\x6e\x65\x74\x00\xc0\x2a\x00\x05\x00\x01\x00"
              "\x00\x07\xe6\x00\x15\x05\x65\x39\x34\x32\x38\x01\x62\x0a\x61\x6b"
              "\x61\x6d\x61\x69\x65\x64\x67\x65\xc0\x44\xc0\x55\x00\x1c\x00\x01"
              "\x00\x00\x00\x13\x00\x10\x00\x64\xff\x9b\x00\x00\x00\x00\x00\x00"
              "\x00\x00\x68\x5d\x01\x68"
}
packet_mapping {
    query:    "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x04\x65\x62\x61\x79\x03\x63\x6f\x6d\x00\x00\x01\x00\x01"
    response: "\x00\x00\x81\x80\x00\x01\x00\x03\x00\x00\x00\x00\x03\x77\x77\x77"
              "\x04\x65\x62\x61\x79\x03\x63\x6f\x6d\x00\x00\x01\x00\x01\xc0\x0c"
              "\x00\x05\x00\x01\x00\x00\x00\x76\x00\x1f\x08\x73\x6c\x6f\x74\x39"
              "\x34\x32\x38\x04\x65\x62\x61\x79\x03\x63\x6f\x6d\x07\x65\x64\x67"
              "\x65\x6b\x65\x79\x03\x6e\x65\x74\x00\xc0\x2a\x00\x05\x00\x01\x00"
              "\x00\x08\x28\x00\x15\x05\x65\x39\x34\x32\x38\x01\x62\x0a\x61\x6b"
              "\x61\x6d\x61\x69\x65\x64\x67\x65\xc0\x44\xc0\x55\x00\x01\x00\x01"
              "\x00\x00\x00\x13\x00\x04\x68\x5d\x01\x68"
}
Loading