Skip to content

Commit f71f61f

Browse files
mDNS: test_app pytest migration
1 parent 5097065 commit f71f61f

File tree

5 files changed

+180
-43
lines changed

5 files changed

+180
-43
lines changed

.github/workflows/test_apps.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Build and Run Test apps
2+
3+
on:
4+
push:
5+
paths:
6+
- 'components/mdns/**'
7+
pull_request:
8+
paths:
9+
- 'components/mdns/**'
10+
11+
jobs:
12+
build_mdns_app:
13+
strategy:
14+
matrix:
15+
idf_ver: ["latest"]
16+
idf_target: ["esp32", "esp32s2", "esp32c3"]
17+
runs-on: ubuntu-20.04
18+
container: espressif/idf:${{ matrix.idf_ver }}
19+
steps:
20+
- name: Checkout esp-protocols
21+
uses: actions/checkout@v3
22+
with:
23+
submodules: recursive
24+
- name: Setup Build Environment
25+
working-directory: components/mdns/tests/test_apps
26+
run: |
27+
. ${IDF_PATH}/export.sh
28+
pip install dpkt pytest idf_build_apps pytest-embedded-serial-esp
29+
- name: Build ${{ matrix.example }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
30+
env:
31+
IDF_TARGET: ${{ matrix.idf_target }}
32+
shell: bash
33+
working-directory: components/mdns/tests/test_apps
34+
run: |
35+
. ${IDF_PATH}/export.sh
36+
python $IDF_PATH/tools/ci/ci_build_apps.py . --target ${{ matrix.idf_target }} -vv --pytest-apps
37+
- name: Merge binaries with IDF-${{ matrix.idf_ver }}
38+
working-directory: components/mdns/tests/test_apps/build_${{ matrix.idf_target }}_default
39+
env:
40+
IDF_TARGET: ${{ matrix.idf_target }}
41+
shell: bash
42+
run: |
43+
. ${IDF_PATH}/export.sh
44+
esptool.py --chip ${{ matrix.idf_target }} merge_bin --fill-flash-size 4MB -o flash_image.bin @flash_args
45+
- uses: actions/upload-artifact@v2
46+
with:
47+
name: examples_app_bin_${{ matrix.idf_target }}_${{ matrix.idf_ver }}
48+
path: |
49+
components/mdns/tests/test_apps/build_${{ matrix.idf_target }}_default/bootloader/bootloader.bin
50+
components/mdns/tests/test_apps/build_${{ matrix.idf_target }}_default/partition_table/partition-table.bin
51+
components/mdns/tests/test_apps/build_${{ matrix.idf_target }}_default/*.bin
52+
components/mdns/tests/test_apps/build_${{ matrix.idf_target }}_default/*.elf
53+
components/mdns/tests/test_apps/build_${{ matrix.idf_target }}_default/flasher_args.json
54+
components/mdns/tests/test_apps/build_${{ matrix.idf_target }}_default/config/sdkconfig.h
55+
components/mdns/tests/test_apps/build_${{ matrix.idf_target }}_default/config/sdkconfig.json
56+
if-no-files-found: error
57+
58+
run-target-mdns-app:
59+
strategy:
60+
matrix:
61+
idf_ver: ["latest"]
62+
idf_target: ["esp32"]
63+
name: Run mDNS Test apps on target
64+
needs: build_mdns_app
65+
runs-on:
66+
- self-hosted
67+
- ESP32-ETHERNET-KIT
68+
# Skip running on forks since it won't have access to secrets
69+
if: github.repository == 'espressif/esp-protocols'
70+
steps:
71+
- name: Clear repository
72+
run: sudo rm -fr $GITHUB_WORKSPACE && mkdir $GITHUB_WORKSPACE
73+
- uses: actions/checkout@v3
74+
- uses: actions/download-artifact@v2
75+
with:
76+
name: examples_app_bin_${{ matrix.idf_target }}_${{ matrix.idf_ver }}
77+
path: components/mdns/tests/test_apps/build
78+
- name: Install Python packages
79+
env:
80+
PIP_EXTRA_INDEX_URL: "https://www.piwheels.org/simple"
81+
run: |
82+
sudo apt-get install -y dnsutils
83+
- name: Download Test apps to target
84+
run: |
85+
python -m esptool --chip ${{ matrix.idf_target }} write_flash 0x0 components/mdns/tests/test_apps/build/flash_image.bin
86+
- name: Run Example Test on target
87+
working-directory: components/mdns/tests/test_apps
88+
run: |
89+
python -m pytest --log-cli-level DEBUG --junit-xml=./examples_results_${{ matrix.idf_target }}_${{ matrix.idf_ver }}.xml --target=${{matrix.idf_target}}
90+
- uses: actions/upload-artifact@v2
91+
if: always()
92+
with:
93+
name: test_apps_results_${{ matrix.idf_target }}_${{ matrix.idf_ver }}
94+
path: components/mdns/tests/test_apps/*.xml

components/mdns/tests/test_apps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ set(EXTRA_COMPONENT_DIRS ../../ ../../../../common_components/protocol_examples_
88

99
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
1010

11-
project(mdns)
11+
project(mdns_test_app)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[pytest]
2+
# only the files with prefix `pytest_` would be recognized as pytest test scripts.
3+
python_files = pytest_*.py
4+
5+
# ignore PytestExperimentalApiWarning for record_xml_attribute
6+
# set traceback to "short" to prevent the overwhelming tracebacks
7+
addopts =
8+
-s
9+
--embedded-services esp,idf
10+
--tb short
11+
--skip-check-coredump y
12+
13+
# ignore DeprecationWarning
14+
filterwarnings =
15+
ignore:Call to deprecated create function (.*)\(\):DeprecationWarning
16+
17+
# log related
18+
log_cli = True
19+
log_cli_level = INFO
20+
log_cli_format = %(asctime)s %(levelname)s %(message)s
21+
log_cli_date_format = %Y-%m-%d %H:%M:%S
22+
23+
log_file = test.log
24+
log_file_level = INFO
25+
log_file_format = %(asctime)s %(levelname)s %(message)s
26+
log_file_date_format = %Y-%m-%d %H:%M:%S

components/mdns/tests/test_apps/app_test.py renamed to components/mdns/tests/test_apps/pytest_mdns_app.py

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
import dpkt
1212
import dpkt.dns
13-
import ttfw_idf
14-
from tiny_test_fw.Utility import console_log
13+
import pytest
1514

1615
UDP_PORT = 5353
1716
MCAST_GRP = '224.0.0.251'
@@ -37,6 +36,7 @@
3736
esp_delegated_host_answered = Event()
3837

3938

39+
@pytest.mark.skip
4040
# Get query of ESP32-WebServer._http._tcp.local service
4141
def get_mdns_service_query(service): # type:(str) -> dpkt.dns.Msg
4242
dns = dpkt.dns.DNS()
@@ -49,10 +49,11 @@ def get_mdns_service_query(service): # type:(str) -> dpkt.dns.Msg
4949
arr.target = socket.inet_aton('127.0.0.1')
5050
arr.srvname = service
5151
dns.qd.append(arr)
52-
console_log('Created mdns service query: {} '.format(dns.__repr__()))
52+
print('Created mdns service query: {} '.format(dns.__repr__()))
5353
return dns.pack()
5454

5555

56+
@pytest.mark.skip
5657
# Get query of _server_.sub._http._tcp.local sub service
5758
def get_mdns_sub_service_query(sub_service): # type:(str) -> dpkt.dns.Msg
5859
dns = dpkt.dns.DNS()
@@ -65,22 +66,23 @@ def get_mdns_sub_service_query(sub_service): # type:(str) -> dpkt.dns.Msg
6566
arr.target = socket.inet_aton('127.0.0.1')
6667
arr.ptrname = sub_service
6768
dns.qd.append(arr)
68-
console_log('Created mdns subtype service query: {} '.format(
69-
dns.__repr__()))
69+
print('Created mdns subtype service query: {} '.format(dns.__repr__()))
7070
return dns.pack()
7171

7272

73+
@pytest.mark.skip
7374
# Get query for host resolution
7475
def get_dns_query_for_esp(esp_host): # type:(str) -> dpkt.dns.Msg
7576
dns = dpkt.dns.DNS()
7677
arr = dpkt.dns.DNS.RR()
7778
arr.cls = dpkt.dns.DNS_IN
7879
arr.name = esp_host + u'.local'
7980
dns.qd.append(arr)
80-
console_log('Created query for esp host: {} '.format(dns.__repr__()))
81+
print('Created query for esp host: {} '.format(dns.__repr__()))
8182
return dns.pack()
8283

8384

85+
@pytest.mark.skip
8486
# Get mdns answer for host resoloution
8587
def get_dns_answer_to_mdns(tester_host): # type:(str) -> dpkt.dns.Msg
8688
dns = dpkt.dns.DNS()
@@ -92,10 +94,11 @@ def get_dns_answer_to_mdns(tester_host): # type:(str) -> dpkt.dns.Msg
9294
arr.name = tester_host
9395
arr.ip = socket.inet_aton('127.0.0.1')
9496
dns.an.append(arr)
95-
console_log('Created answer to mdns query: {} '.format(dns.__repr__()))
97+
print('Created answer to mdns query: {} '.format(dns.__repr__()))
9698
return dns.pack()
9799

98100

101+
@pytest.mark.skip
99102
# Get mdns answer for service query
100103
def get_dns_answer_to_service_query(
101104
mdns_service): # type:(str) -> dpkt.dns.Msg
@@ -112,10 +115,11 @@ def get_dns_answer_to_service_query(
112115
arr.srvname = mdns_service
113116
arr.ip = socket.inet_aton('127.0.0.1')
114117
dns.an.append(arr)
115-
console_log('Created answer to mdns query: {} '.format(dns.__repr__()))
118+
print('Created answer to mdns query: {} '.format(dns.__repr__()))
116119
return dns.pack()
117120

118121

122+
@pytest.mark.skip
119123
def mdns_listener(esp_host): # type:(str) -> None
120124
print('mdns_listener thread started')
121125

@@ -145,48 +149,45 @@ def mdns_listener(esp_host): # type:(str) -> None
145149
# Receives queries from esp board and sends answers
146150
if len(dns.qd) > 0:
147151
if dns.qd[0].name == HOST_NAME:
148-
console_log('Received query: {} '.format(dns.__repr__()))
152+
print('Received query: {} '.format(dns.__repr__()))
149153
sock.sendto(get_dns_answer_to_mdns(HOST_NAME),
150154
(MCAST_GRP, UDP_PORT))
151155
if dns.qd[0].name == HOST_NAME:
152-
console_log('Received query: {} '.format(dns.__repr__()))
156+
print('Received query: {} '.format(dns.__repr__()))
153157
sock.sendto(get_dns_answer_to_mdns(HOST_NAME),
154158
(MCAST_GRP, UDP_PORT))
155159
if dns.qd[0].name == MDNS_HOST_SERVICE:
156-
print(dns.qd[0].name)
157-
console_log('Received query: {} '.format(dns.__repr__()))
160+
print('Received query: {} '.format(dns.__repr__()))
158161
sock.sendto(
159162
get_dns_answer_to_service_query(MDNS_HOST_SERVICE),
160163
(MCAST_GRP, UDP_PORT))
161164
# Receives answers from esp board and sets event flags for python test cases
162165
if len(dns.an) == 1:
163166
if dns.an[0].name.startswith(SERVICE_NAME):
164-
console_log('Received answer to service query: {}'.format(
167+
print('Received answer to service query: {}'.format(
165168
dns.__repr__()))
166169
esp_service_answered.set()
167170
if len(dns.an) > 1:
168171
if dns.an[1].name.startswith(SUB_SERVICE_NAME):
169-
console_log(
170-
'Received answer for sub service query: {}'.format(
171-
dns.__repr__()))
172+
print('Received answer for sub service query: {}'.format(
173+
dns.__repr__()))
172174
esp_sub_service_answered.set()
173175
if len(dns.an) > 0 and dns.an[0].type == dpkt.dns.DNS_A:
174176
if dns.an[0].name == esp_host + u'.local':
175-
console_log(
176-
'Received answer to esp32-mdns query: {}'.format(
177-
dns.__repr__()))
177+
print('Received answer to esp32-mdns query: {}'.format(
178+
dns.__repr__()))
178179
esp_host_answered.set()
179180
if dns.an[0].name == esp_host + u'-delegated.local':
180-
console_log(
181-
'Received answer to esp32-mdns-delegate query: {}'.
182-
format(dns.__repr__()))
181+
print('Received answer to esp32-mdns-delegate query: {}'.
182+
format(dns.__repr__()))
183183
esp_delegated_host_answered.set()
184184
except socket.timeout:
185185
break
186186
except dpkt.UnpackError:
187187
continue
188188

189189

190+
@pytest.mark.skip
190191
def create_socket(): # type:() -> socket.socket
191192
UDP_IP = '0.0.0.0'
192193
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -199,6 +200,7 @@ def create_socket(): # type:() -> socket.socket
199200
return sock
200201

201202

203+
@pytest.mark.skip
202204
def test_query_dns_http_service(service): # type: (str) -> None
203205
print('SRV: Query {}'.format(service))
204206
sock = create_socket()
@@ -212,6 +214,7 @@ def test_query_dns_http_service(service): # type: (str) -> None
212214
'Test has failed: did not receive mdns answer within timeout')
213215

214216

217+
@pytest.mark.skip
215218
def test_query_dns_sub_service(sub_service): # type: (str) -> None
216219
print('PTR: Query {}'.format(sub_service))
217220
sock = create_socket()
@@ -225,6 +228,7 @@ def test_query_dns_sub_service(sub_service): # type: (str) -> None
225228
'Test has failed: did not receive mdns answer within timeout')
226229

227230

231+
@pytest.mark.skip
228232
def test_query_dns_host(esp_host): # type: (str) -> None
229233
print('A: {}'.format(esp_host))
230234
sock = create_socket()
@@ -238,6 +242,7 @@ def test_query_dns_host(esp_host): # type: (str) -> None
238242
'Test has failed: did not receive mdns answer within timeout')
239243

240244

245+
@pytest.mark.skip
241246
def test_query_dns_host_delegated(esp_host): # type: (str) -> None
242247
print('A: {}'.format(esp_host))
243248
sock = create_socket()
@@ -251,29 +256,30 @@ def test_query_dns_host_delegated(esp_host): # type: (str) -> None
251256
'Test has failed: did not receive mdns answer within timeout')
252257

253258

254-
@ttfw_idf.idf_custom_test(env_tag='Example_WIFI', group='test-apps')
255-
def test_app_esp_mdns(env, _): # type: (ttfw_idf.TinyFW.Env, None) -> None
256-
dut1 = env.get_dut('mdns',
257-
'tools/test_apps/protocols/mdns',
258-
dut_class=ttfw_idf.ESP32DUT)
259+
@pytest.mark.esp32
260+
@pytest.mark.esp32s2
261+
@pytest.mark.esp32c3
262+
@pytest.mark.generic
263+
def test_app_esp_mdns(dut):
259264

260-
# 1. start mdns application
261-
dut1.start_app()
262-
# 2. get the dut host name (and IP address)
263-
specific_host = dut1.expect(
264-
re.compile(r'mdns hostname set to: \[([^\]]+)\]'), timeout=30)[0]
265+
# 1. get the dut host name (and IP address)
266+
specific_host = dut.expect(
267+
re.compile(b'mdns hostname set to: \[([^\]]+)\]'), # noqa: W605
268+
timeout=30).group(1).decode()
265269

266-
esp_ip = dut1.expect(
267-
re.compile(r' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'),
268-
timeout=30)
269-
print('Got IP={}'.format(esp_ip[0]))
270+
esp_ip = dut.expect(
271+
re.compile(
272+
b' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'), # noqa: W605
273+
timeout=30).group(1).decode()
274+
print('Got IP={}'.format(esp_ip))
270275

271276
mdns_responder = Thread(target=mdns_listener, args=(str(specific_host), ))
272277

273278
def start_case(case, desc, result): # type: (str, str, str) -> None
274279
print('Starting {}: {}'.format(case, desc))
275-
dut1.write(case)
276-
dut1.expect(re.compile(result), timeout=30)
280+
dut.write(case)
281+
res = bytes(result, encoding='utf8')
282+
dut.expect(re.compile(res), timeout=30)
277283

278284
try:
279285
# start dns listener thread
@@ -312,7 +318,3 @@ def start_case(case, desc, result): # type: (str, str, str) -> None
312318
finally:
313319
stop_mdns_listener.set()
314320
mdns_responder.join()
315-
316-
317-
if __name__ == '__main__':
318-
test_app_esp_mdns()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CONFIG_IDF_TARGET="esp32"
2+
CONFIG_MDNS_RESOLVE_TEST_SERVICES=y
3+
CONFIG_MDNS_ADD_MAC_TO_HOSTNAME=y
4+
CONFIG_MDNS_PUBLISH_DELEGATE_HOST=y
5+
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
6+
CONFIG_EXAMPLE_CONNECT_ETHERNET=y
7+
CONFIG_EXAMPLE_CONNECT_WIFI=n
8+
CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET=y
9+
CONFIG_EXAMPLE_ETH_PHY_IP101=y
10+
CONFIG_EXAMPLE_ETH_MDC_GPIO=23
11+
CONFIG_EXAMPLE_ETH_MDIO_GPIO=18
12+
CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5
13+
CONFIG_EXAMPLE_ETH_PHY_ADDR=1
14+
CONFIG_EXAMPLE_CONNECT_IPV6=y
15+
CONFIG_MDNS_BUTTON_GPIO=32

0 commit comments

Comments
 (0)