-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: establish test/util.py and test/test_nmt.py (#503)
Give NMT tests their own file, and establish a util.py for the test suite for common stuff like the location of sample EDS files. Consistently use SAMPLE_EDS instead of EDS_PATH.
- Loading branch information
1 parent
c413eaf
commit 08eba81
Showing
8 changed files
with
92 additions
and
100 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import time | ||
import unittest | ||
|
||
import canopen | ||
from .util import SAMPLE_EDS | ||
|
||
|
||
class TestNmtSlave(unittest.TestCase): | ||
def setUp(self): | ||
self.network1 = canopen.Network() | ||
self.network1.connect("test", interface="virtual") | ||
self.remote_node = self.network1.add_node(2, SAMPLE_EDS) | ||
|
||
self.network2 = canopen.Network() | ||
self.network2.connect("test", interface="virtual") | ||
self.local_node = self.network2.create_node(2, SAMPLE_EDS) | ||
self.remote_node2 = self.network1.add_node(3, SAMPLE_EDS) | ||
self.local_node2 = self.network2.create_node(3, SAMPLE_EDS) | ||
|
||
def tearDown(self): | ||
self.network1.disconnect() | ||
self.network2.disconnect() | ||
|
||
def test_start_two_remote_nodes(self): | ||
self.remote_node.nmt.state = "OPERATIONAL" | ||
# Line below is just so that we are sure the client have received the command | ||
# before we do the check | ||
time.sleep(0.1) | ||
slave_state = self.local_node.nmt.state | ||
self.assertEqual(slave_state, "OPERATIONAL") | ||
|
||
self.remote_node2.nmt.state = "OPERATIONAL" | ||
# Line below is just so that we are sure the client have received the command | ||
# before we do the check | ||
time.sleep(0.1) | ||
slave_state = self.local_node2.nmt.state | ||
self.assertEqual(slave_state, "OPERATIONAL") | ||
|
||
def test_stop_two_remote_nodes_using_broadcast(self): | ||
# This is a NMT broadcast "Stop remote node" | ||
# ie. set the node in STOPPED state | ||
self.network1.send_message(0, [2, 0]) | ||
|
||
# Line below is just so that we are sure the slaves have received the command | ||
# before we do the check | ||
time.sleep(0.1) | ||
slave_state = self.local_node.nmt.state | ||
self.assertEqual(slave_state, "STOPPED") | ||
slave_state = self.local_node2.nmt.state | ||
self.assertEqual(slave_state, "STOPPED") | ||
|
||
def test_heartbeat(self): | ||
self.assertEqual(self.remote_node.nmt.state, "INITIALISING") | ||
self.assertEqual(self.local_node.nmt.state, "INITIALISING") | ||
self.local_node.nmt.state = "OPERATIONAL" | ||
self.local_node.sdo[0x1017].raw = 100 | ||
time.sleep(0.2) | ||
self.assertEqual(self.remote_node.nmt.state, "OPERATIONAL") | ||
|
||
self.local_node.nmt.stop_heartbeat() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import os | ||
|
||
|
||
DATATYPES_EDS = os.path.join(os.path.dirname(__file__), "datatypes.eds") | ||
SAMPLE_EDS = os.path.join(os.path.dirname(__file__), "sample.eds") |