From 558b85acde009fc817b04cdf1239e26cbd286155 Mon Sep 17 00:00:00 2001 From: Jacob Minshall Date: Mon, 21 Apr 2014 11:54:44 -0700 Subject: [PATCH 1/3] arduino: allow different boards to be set from the wtfconfig We have the mc200_dbg and gmc200_dbg boards which need to be set depending on which one is connected. --- platform/arduino/wtfconfig.py | 3 ++- tests/arduino.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/platform/arduino/wtfconfig.py b/platform/arduino/wtfconfig.py index 9892f44..bc66ce1 100644 --- a/platform/arduino/wtfconfig.py +++ b/platform/arduino/wtfconfig.py @@ -6,6 +6,7 @@ # path to arduino directory... must be changed IDE = "/home/jacob/dev/arduino_project/MeshableMCU/arduino-1.5.6-r2" +BOARD = "gmc200_dbg" arduino_comm = wtf.comm.Serial(port="/dev/ttyUSB2", prompt="") arduino_comm.name = "arduino" @@ -20,4 +21,4 @@ sta = wtf.node.ap.Hostapd(sta_ssh, [iface], ops=ops) wtf.conf = wtf.config("arduino", comm=arduino_comm, nodes=[sta], - name="arduino mc200 tests", data={'IDE': IDE}) + name="arduino mc200 tests", data={'IDE': IDE, 'BOARD': BOARD}) diff --git a/tests/arduino.py b/tests/arduino.py index d1e2e6c..582807a 100644 --- a/tests/arduino.py +++ b/tests/arduino.py @@ -38,6 +38,10 @@ def setUpClass(cls): cls.IDE = wtfconfig.data['IDE'] else: cls.IDE = '' + if 'BOARD' in wtfconfig.data: + cls.BOARD = wtfconfig.data['BOARD'] + else: + cls.BOARD = 'mc200_dbg' # set up a fake X server for a computer without one... if not 'DISPLAY' in cls.env or cls.env['DISPLAY'] == '': @@ -81,7 +85,7 @@ def build_and_upload(self, build_path): self.fail("You do not have the correct arduino ide directory path set") ret = Popen(["./arduino", "--upload", "--board", - "cozybit:mc200:mc200_dbg", "-v", "--pref", + "cozybit:mc200:%s" % self.BOARD, "-v", "--pref", "build.path=" + self.build_dir, "--port", self.cereal.port, build_path], env=self.env) ret.wait() From b4353375fb1fd8a70a8b0741969d51bf7d381f95 Mon Sep 17 00:00:00 2001 From: Jacob Minshall Date: Mon, 21 Apr 2014 15:29:18 -0700 Subject: [PATCH 2/3] arduino: stop ap before starting it only, and remove timeout The timeout is handled by pxssh, which already has a 30 second timeout. This is enough for the wifi tests. --- tests/arduino.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/arduino.py b/tests/arduino.py index 582807a..c1a0980 100644 --- a/tests/arduino.py +++ b/tests/arduino.py @@ -101,6 +101,7 @@ def setup_run(self, path, write=None): def start_hostapd(self, apconf): """ Set hostap.conf and init/start node """ + self.stop_hostapd() self.AP.config = apconf self.AP.init() self.AP.start() @@ -254,12 +255,9 @@ def test_14_string_to_int(self): def test_15_connect_wifi_no_password(self): self.start_hostapd(ap.APConfig(ssid="wtf-arduino-ap")) self.setup_run(os.getcwd() + '/platform/arduino/SimpleWiFi/SimpleWiFi.ino') - # set to 20 incase connection takes longer than 10 seconds - time.sleep(20) self.ffd.expect(re.escape("You're connected to the network")); # [1-9] first so we don't match 0.0.0.0 with d+.d+.d+.d+ self.ffd.expect(re.escape("the ip is ") + r'[1-9]\d+\.\d+\.\d+\.\d+') - self.stop_hostapd() def test_16_connect_wifi_with_password(self): self.start_hostapd(ap.APConfig(ssid="wtf-arduino-pass-ap", @@ -268,9 +266,6 @@ def test_16_connect_wifi_with_password(self): password="thisisasecret", encrypt=ap.ENCRYPT_CCMP)) self.setup_run(os.getcwd() + '/platform/arduino/SimpleWiFiPass/SimpleWiFiPass.ino') - # set to 20 incase connection takes longer than 10 seconds - time.sleep(20) self.ffd.expect(re.escape("You're connected to the password protected network")); # [1-9] first so we don't match 0.0.0.0 with d+.d+.d+.d+ self.ffd.expect(re.escape("the ip is ") + r'[1-9]\d+\.\d+\.\d+\.\d+') - self.stop_hostapd() From ad50d1368ae97d0a6e227f635341b46d9206ebfe Mon Sep 17 00:00:00 2001 From: Jacob Minshall Date: Tue, 22 Apr 2014 16:31:37 -0700 Subject: [PATCH 3/3] add function for LinuxNode to start udhcpd with a generated conf Call this function now within the arduino test to assure a dhcp lease since the tests look for an assigned IP address. --- tests/arduino.py | 5 +---- wtf/node/__init__.py | 18 +++++++++++++++++- wtf/node/ap.py | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/arduino.py b/tests/arduino.py index c1a0980..8cb26a1 100644 --- a/tests/arduino.py +++ b/tests/arduino.py @@ -101,15 +101,12 @@ def setup_run(self, path, write=None): def start_hostapd(self, apconf): """ Set hostap.conf and init/start node """ - self.stop_hostapd() + self.AP.stop() self.AP.config = apconf self.AP.init() self.AP.start() time.sleep(5) - def stop_hostapd(self): - self.AP.stop() - def test_01_string_addition_operators(self): self.setup_run('./examples/08.Strings/StringAdditionOperator/' 'StringAdditionOperator.ino') diff --git a/wtf/node/__init__.py b/wtf/node/__init__.py index e1afab3..36b2c48 100644 --- a/wtf/node/__init__.py +++ b/wtf/node/__init__.py @@ -4,8 +4,9 @@ """WTF network node definitions.""" import os -import time from collections import namedtuple +from textwrap import dedent +import time from wtf.util import CapData from wtf.util import PerfConf @@ -622,3 +623,18 @@ def bond(self, ifaces, ip): for iface in ifaces: self._cmd_or_die("ip addr flush " + iface.name) self._cmd_or_die("ifenslave bond0 " + iface.name) + + def start_udhcpd(self): + """Start udhcpd, assumes it is on the system""" + n = 10 + for iface in self.iface: + self.set_ip(iface.name, "192.168.%d.1" % n) + dhcp_conf = dedent(""" + start 192.168.%d.10 + end 192.168.%d.100 + interface %s + """ % (n, n, iface.name)) + self.comm.send_cmd("killall udhcpd") + self._cmd_or_die("echo -e \"" + dhcp_conf + "\">/tmp/udhcp.conf") + self._cmd_or_die("udhcpd /tmp/udhcp.conf") + n += 1 diff --git a/wtf/node/ap.py b/wtf/node/ap.py index 0c27d20..0d38834 100644 --- a/wtf/node/ap.py +++ b/wtf/node/ap.py @@ -81,6 +81,7 @@ def start(self): raise node.InsufficientConfigurationError() self._configure() self._cmd_or_die("hostapd -B /tmp/hostapd.conf") + self.start_udhcpd() def stop(self): node.LinuxNode.stop(self)