Skip to content

Commit

Permalink
Tests: Verify some basic SDO record and array assumptions (#539)
Browse files Browse the repository at this point in the history
* Remove one of the sub-objects in a record for testing.

Adjust the EDS test accordingly, since the record length only counts
sub-objects that have an actual description.

* Flesh out the Pre-defined error field object in sample.eds.

Switch from CompactSubObj to actual sub-entries.  Leave out some of
the sub-entries, targeting specific SDO tests.

* Add test for SdoArray dynamically generated member variables.

* Add test for SdoArray length and iteration count.

* Add test for SdoRecord length and iteration count.

* Expect failure on last added test.
  • Loading branch information
acolomb committed Aug 17, 2024
1 parent 210374a commit 273bab1
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 8 deletions.
60 changes: 53 additions & 7 deletions test/sample.eds
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ DataType=0x0007
AccessType=ro
PDOMapping=0

[1018sub3]
ParameterName=Revision number
ObjectType=0x7
DataType=0x0007
AccessType=ro
PDOMapping=0
; [1018sub3] left out for testing

[1018sub4]
ParameterName=Serial number
Expand All @@ -123,11 +118,62 @@ SupportedObjects=3
[1003]
ParameterName=Pre-defined error field
ObjectType=0x8
CompactSubObj=255
SubNumber=9

[1003sub0]
ParameterName=Number of errors
ObjectType=0x7
DataType=0x0005
AccessType=rw
DefaultValue=3
PDOMapping=0

[1003sub1]
ParameterName=Pre-defined error field_1
ObjectType=0x7
DataType=0x0007
AccessType=ro
DefaultValue=0
PDOMapping=0

; [1003sub2] left out for testing

[1003sub3]
ParameterName=Pre-defined error field_3
ObjectType=0x7
DataType=0x0007
AccessType=ro
DefaultValue=0
PDOMapping=0

[1003sub4]
ParameterName=Pre-defined error field_4
ObjectType=0x7
DataType=0x0007
AccessType=ro
DefaultValue=0
PDOMapping=0

[1003sub5]
ParameterName=Pre-defined error field_5
ObjectType=0x7
DataType=0x0007
AccessType=ro
DefaultValue=0
PDOMapping=0

; [1003sub6] left out for testing

[1003sub7]
ParameterName=Pre-defined error field_7
ObjectType=0x7
DataType=0x0007
AccessType=ro
DefaultValue=0
PDOMapping=0

; [1003sub8] left out for testing

[1008]
ParameterName=Manufacturer device name
ObjectType=0x7
Expand Down
2 changes: 1 addition & 1 deletion test/test_eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_relative_variable(self):
def test_record(self):
record = self.od['Identity object']
self.assertIsInstance(record, canopen.objectdictionary.ODRecord)
self.assertEqual(len(record), 5)
self.assertEqual(len(record), 4)
self.assertEqual(record.index, 0x1018)
self.assertEqual(record.name, 'Identity object')
var = record['Vendor-ID']
Expand Down
39 changes: 39 additions & 0 deletions test/test_sdo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,45 @@
RX = 2


class TestSDOVariables(unittest.TestCase):
"""Some basic assumptions on the behavior of SDO variable objects.
Mostly what is stated in the API docs.
"""

def setUp(self):
node = canopen.LocalNode(1, SAMPLE_EDS)
self.sdo_node = node.sdo

@unittest.expectedFailure
def test_record_iter_length(self):
"""Assume the "highest subindex supported" entry is not counted.
Sub-objects without an OD entry should be skipped as well.
"""
record = self.sdo_node[0x1018]
subs = sum(1 for _ in iter(record))
self.assertEqual(len(record), 3)
self.assertEqual(subs, 3)

def test_array_iter_length(self):
"""Assume the "highest subindex supported" entry is not counted."""
array = self.sdo_node[0x1003]
subs = sum(1 for _ in iter(array))
self.assertEqual(len(array), 3)
self.assertEqual(subs, 3)
# Simulate more entries getting added dynamically
array[0].set_data(b'\x08')
subs = sum(1 for _ in iter(array))
self.assertEqual(subs, 8)

def test_array_members_dynamic(self):
"""Check if sub-objects missing from OD entry are generated dynamically."""
array = self.sdo_node[0x1003]
for var in array.values():
self.assertIsInstance(var, canopen.sdo.SdoVariable)


class TestSDO(unittest.TestCase):
"""
Test SDO traffic by example. Most are taken from
Expand Down

0 comments on commit 273bab1

Please sign in to comment.