Skip to content

Commit

Permalink
[test suite] changes from mega to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
psy0rz committed Feb 26, 2018
1 parent 21840d0 commit 04de145
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 19 deletions.
10 changes: 5 additions & 5 deletions test/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'port' : '/dev/serial/by-path/pci-0000:00:14.0-usb-0:3.1:1.0-port0',
'ip' : '192.168.13.91',
'flash_cmd' : 'esptool.py --port {port} -b 1500000 write_flash 0x0 .pioenvs/dev_ESP8266_4096/firmware.bin --flash_size=32m -p',
'build_cmd' : 'platformio run --environment dev_ESP8266_4096'
'build_cmd' : 'platformio run --environment dev_ESP8266_4096 -s'
},

# node 1
Expand All @@ -14,16 +14,16 @@
'port' : '/dev/serial/by-path/pci-0000:00:14.0-usb-0:3.2:1.0-port0',
'ip' : '192.168.13.92',
'flash_cmd' : 'esptool.py --port {port} -b 1500000 write_flash 0x0 .pioenvs/dev_ESP8266_4096/firmware.bin --flash_size=32m -p',
'build_cmd' : 'platformio run --environment dev_ESP8266_4096'
'build_cmd' : 'platformio run --environment dev_ESP8266_4096 -s'
},

# node 2
{
'type' : 'ESP-01S 1Mb PUYA flash',
'port' : '/dev/serial/by-path/pci-0000:00:14.0-usb-0:3.3:1.0-port0',
'ip' : '192.168.13.92',
'flash_cmd' : 'esptool.py --port {port} -b 1500000 write_flash 0x0 .pioenvs/dev_ESP8266_1024/firmware.bin --flash_size=detect -p',
'build_cmd' : 'platformio run --environment dev_ESP8266_1024'
'ip' : '192.168.13.93',
'flash_cmd' : 'esptool.py --port {port} -b 115200 write_flash 0x0 .pioenvs/dev_ESP8266PUYA_1024/firmware.bin --flash_size=1MB -p',
'build_cmd' : 'platformio run --environment dev_ESP8266PUYA_1024 -s'
},

# {
Expand Down
21 changes: 13 additions & 8 deletions test/controlleremu.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self):
self.start_mqtt()
self.start_http()
self.start_linebased()
self.log_enabled=True


def start_mqtt(self):
Expand All @@ -44,8 +45,9 @@ def start_mqtt(self):

self.mqtt_messages=Queue()
def mqtt_on_message(client, userdata, message):
logging.getLogger("mqtt").debug("Received message '" + str(message.payload) + "' on topic '"
+ message.topic + "' with QoS " + str(message.qos))
if self.log_enabled:
logging.getLogger("mqtt").debug("Received message '" + str(message.payload) + "' on topic '"
+ message.topic + "' with QoS " + str(message.qos))
self.mqtt_messages.put(message)

mqtt_client.on_message=mqtt_on_message
Expand All @@ -66,12 +68,12 @@ def start_http(self):
@bottle.post('<filename:path>')
@bottle.get('<filename:path>')
def urlhandler(filename):
logging.getLogger("http").debug(bottle.request.method+" "+str(dict(bottle.request.params)))
if self.log_enabled:
logging.getLogger("http").debug(bottle.request.method+" "+str(dict(bottle.request.params)))
self.http_requests.put(bottle.request.copy())



http_thread=threading.Thread(target=bottle.run, kwargs=dict(host='0.0.0.0', port=config.http_port, reloader=False))
http_thread=threading.Thread(target=bottle.run, kwargs=dict(host='0.0.0.0', port=config.http_port, reloader=False, quiet=True))
http_thread.daemon=True
http_thread.start()

Expand All @@ -92,15 +94,18 @@ def start_linebased(self):


def handle_connect(connection, client_address):
logging.getLogger("linebased").debug("Connect from "+str(client_address))
if self.log_enabled:
logging.getLogger("linebased").debug("Connect from "+str(client_address))

fh = connection.makefile()
for line in fh:
line=line.rstrip()
logging.getLogger("linebased").debug("Recv from "+str(client_address)+" :"+line)
if self.log_enabled:
logging.getLogger("linebased").debug("Recv from "+str(client_address)+" :"+line)
self.linebased_lines.put( ( client_address, line ) )

logging.getLogger("linebased").debug("Disconnect from "+str(client_address))
if self.log_enabled:
logging.getLogger("linebased").debug("Disconnect from "+str(client_address))

def wait_accept():
# Create a TCP/IP socket
Expand Down
2 changes: 1 addition & 1 deletion test/espcli
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Configure node 0, controller 1 as domoticz mqtt:
"""
return(docs)

parser = argparse.ArgumentParser(description='ESPEasy testing framework', epilog=get_epilog(), formatter_class=argparse.RawDescriptionHelpFormatter)
parser = argparse.ArgumentParser(description='ESPEasy testing CLI', epilog=get_epilog(), formatter_class=argparse.RawDescriptionHelpFormatter)

# parser.add_argument('--url', default='http://localhost:8080/rpc', help='url of rpc server to connect to. default: %(default)s')
# parser.add_argument('--user', default=None, help='user to login.')
Expand Down
1 change: 0 additions & 1 deletion test/espcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@

colorlog.basicConfig(level=logging.DEBUG)


logging.getLogger("requests.packages.urllib3.connectionpool").setLevel(logging.ERROR)
17 changes: 15 additions & 2 deletions test/esptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@
import shelve
import os
from espcore import *
import argparse
import util

### parse arguments

parser = argparse.ArgumentParser(description='ESPEasy testing framework', formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('--debug', action='store_true', help='enable http debugging output')
parser.add_argument('--no-resume', action='store_true', help='dont resume testing from where we left off last time')
parser.add_argument('--skip-power', action='store_true', help='skip tests that require powercycling.')
args = parser.parse_args()


if args.debug:
util.enable_http_debug()


### create node objects and espeasy objects
Expand All @@ -22,7 +35,7 @@
espeasy=[]

for n in config.nodes:
node.append(Node(n, "node"+str(len(node))))
node.append(Node(n, "node"+str(len(node)), skip_power=args.skip_power))
espeasy.append(EspEasy(node[-1]))


Expand All @@ -49,7 +62,7 @@
def step(title=""):
def step_dec(test):
"""add test step. test can resume from every test-step"""
if state['module'] and ( state['module'] != test.__module__ or state['name'] != test.__name__ or state['title'] != title):
if not args.no_resume and state['module'] and ( state['module'] != test.__module__ or state['name'] != test.__name__ or state['title'] != title):
log.debug("Skipping step "+title+": "+test.__module__ + "." + test.__name__ )
else:
state['module']=None
Expand Down
22 changes: 21 additions & 1 deletion test/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
class Node():


def __init__(self, config, id):
def __init__(self, config, id, skip_power=False):
self.log=logging.getLogger(id)
self.log.debug("{type} has ip {ip}".format(id=id, **config))
self._config=config
self._id=id
self._url="http://{ip}/".format(**self._config)
self._serial_initialized=False
self._skip_power=True

def serial_needed(self):
"""call this at least once if you need serial stuff"""
Expand Down Expand Up @@ -63,12 +64,21 @@ def reboot(self):

def powercycle(self):
"""powercycle the device"""
if self._skip_power:
self.log.warning("Skipping power cycle "+self._id)
return False


self.poweroff()
self.poweron()
return True

def poweroff(self):
"""power off device"""

if self._skip_power:
self.log.warning("Skipping power off "+self._id)
return False

#cant yet be done automaticly unfortunatly
self.log.info("Please power off node "+self._id)
Expand All @@ -84,10 +94,15 @@ def poweroff(self):
del self._serial

self.log.debug("Detected power off")
return True

def poweron(self):
"""power on device"""

if self._skip_power:
self.log.warning("Skipping power on"+self._id)
return False

self.log.info("Please power on node "+self._id)

done=False
Expand All @@ -100,6 +115,7 @@ def poweron(self):
time.sleep(0.1)

self.log.debug("Detected power on")
return True

def pingwifi(self, timeout=60):
"""waits until espeasy reponds via wifi"""
Expand Down Expand Up @@ -144,6 +160,7 @@ def serialcmd(self, command):
def build(self):
"""compile binary"""

self.log.debug("Building...")
subprocess.check_call(self._config['build_cmd'].format(**self._config), shell=True, cwd='..')


Expand All @@ -152,6 +169,7 @@ def flashserial(self):

self.serial_needed()

self.log.debug("Flashing...")
subprocess.check_call(self._config['flash_cmd'].format(**self._config), shell=True, cwd='..')

time.sleep(1)
Expand All @@ -162,6 +180,7 @@ def flashserial(self):
def serial(self):
"""open serial terminal to esp"""
self.serial_needed()
self.log.debug("Opening serial terminal")
subprocess.check_call("platformio serialports monitor --baud 115200 --port {port} --echo".format(**self._config), shell=True, cwd='..')
# print("JA")
# term=serial.tools.miniterm.Miniterm(self._serial)
Expand All @@ -173,6 +192,7 @@ def serial(self):
def erase(self):
"""erase flash via serial"""
self.serial_needed()
self.log.debug("Erasing...")
subprocess.check_call("esptool.py --port {port} -b 1500000 erase_flash".format(**self._config), shell=True, cwd='..')


Expand Down
4 changes: 3 additions & 1 deletion test/test002.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def test():
@step()
def powercycle():
"""test result on poweron"""
node[0].powercycle()
if not node[0].powercycle():
return

results=controller.recv_domoticz_mqtt(SENSOR_TYPE_SINGLE,2001)
test_in_range(results[0], -5,40)
results=controller.recv_domoticz_mqtt(SENSOR_TYPE_SINGLE,2002)
Expand Down
2 changes: 2 additions & 0 deletions test/testall
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

#runs all test modules

import glob
import importlib
import os
Expand Down

0 comments on commit 04de145

Please sign in to comment.