22from __future__ import unicode_literals
33from builtins import str
44import re
5- import os
65import sys
76import ssl
87import paho .mqtt .client as mqtt
1110import string
1211import random
1312
14- try :
15- import IDF
16- except ImportError :
17- # this is a test case write with tiny-test-fw.
18- # to run test cases outside tiny-test-fw,
19- # we need to set environment variable `TEST_FW_PATH`,
20- # then get and insert `TEST_FW_PATH` to sys path before import FW module
21- test_fw_path = os .getenv ("TEST_FW_PATH" )
22- if test_fw_path and test_fw_path not in sys .path :
23- sys .path .insert (0 , test_fw_path )
24- import IDF
25-
26- import DUT
13+ from tiny_test_fw import DUT
14+ import ttfw_idf
2715
2816
2917event_client_connected = Event ()
@@ -52,6 +40,8 @@ def mqtt_client_task(client):
5240
5341def get_host_port_from_dut (dut1 , config_option ):
5442 value = re .search (r'\:\/\/([^:]+)\:([0-9]+)' , dut1 .app .get_sdkconfig ()[config_option ])
43+ if value is None :
44+ return None , None
5545 return value .group (1 ), int (value .group (2 ))
5646
5747
@@ -123,7 +113,7 @@ def test_single_config(dut, transport, qos, repeat, published):
123113 event_stop_client .clear ()
124114
125115
126- @IDF . idf_example_test (env_tag = "Example_WIFI" )
116+ @ttfw_idf . idf_custom_test (env_tag = "Example_WIFI" )
127117def test_weekend_mqtt_publish (env , extra_data ):
128118 # Using broker url dictionary for different transport
129119 global broker_host
@@ -137,13 +127,7 @@ def test_weekend_mqtt_publish(env, extra_data):
137127 3. Test evaluates python client received correct qos0 message
138128 4. Test ESP32 client received correct qos0 message
139129 """
140- dut1 = env .get_dut ("mqtt_publish" , "examples/protocols/mqtt/publish_test" )
141- # check and log bin size
142- binary_file = os .path .join (dut1 .app .binary_path , "mqtt_publish.bin" )
143- bin_size = os .path .getsize (binary_file )
144- IDF .log_performance ("mqtt_publish_bin_size" , "{}KB"
145- .format (bin_size // 1024 ))
146- IDF .check_performance ("mqtt_publish_size" , bin_size // 1024 )
130+ dut1 = env .get_dut ("mqtt_publish_connect_test" , "tools/test_apps/protocols/mqtt/publish_connect_test" )
147131 # Look for host:port in sdkconfig
148132 try :
149133 # python client subscribes to the topic to which esp client publishes and vice versa
@@ -158,13 +142,16 @@ def test_weekend_mqtt_publish(env, extra_data):
158142 raise
159143 dut1 .start_app ()
160144 try :
161- ip_address = dut1 .expect (re .compile (r" sta ip : ([^,]+), " ), timeout = 30 )
145+ ip_address = dut1 .expect (re .compile (r" IPv4 address : ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) " ), timeout = 30 )
162146 print ("Connected to AP with IP: {}" .format (ip_address ))
163147 except DUT .ExpectTimeout :
164148 print ('ENV_TEST_FAILURE: Cannot connect to AP' )
165149 raise
166150 for qos in [0 , 1 , 2 ]:
167151 for transport in ["tcp" , "ssl" , "ws" , "wss" ]:
152+ if broker_host [transport ] is None :
153+ print ('Skipping transport: {}...' .format (transport ))
154+ continue
168155 # simple test with empty message
169156 test_single_config (dut1 , transport , qos , 0 , 5 )
170157 # decide on broker what level of test will pass (local broker works the best)
@@ -188,4 +175,4 @@ def test_weekend_mqtt_publish(env, extra_data):
188175
189176
190177if __name__ == '__main__' :
191- test_weekend_mqtt_publish ()
178+ test_weekend_mqtt_publish (dut = ttfw_idf . ESP32QEMUDUT if sys . argv [ 1 :] == [ 'qemu' ] else ttfw_idf . ESP32DUT )
0 commit comments