aboutsummaryrefslogtreecommitdiff
path: root/tests/testdata/README.md
blob: 4ebd2b0e70a863a6a18785304929cc243887b1d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# 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
```