tests: Add iio-buffer-accel test
This commit is contained in:
BIN
tests/iio-buffer-accel-data/orientation-left-up.bin
Normal file
BIN
tests/iio-buffer-accel-data/orientation-left-up.bin
Normal file
Binary file not shown.
BIN
tests/iio-buffer-accel-data/orientation-normal.bin
Normal file
BIN
tests/iio-buffer-accel-data/orientation-normal.bin
Normal file
Binary file not shown.
@@ -417,6 +417,72 @@ class Tests(dbusmock.DBusTestCase):
|
||||
|
||||
self.stop_daemon()
|
||||
|
||||
def test_iio_buffer_accel(self):
|
||||
'''iio buffer accel'''
|
||||
top_srcdir = os.getenv('top_srcdir', '.')
|
||||
mock_dev_data = self.testbed.get_root_dir() + '/iio-dev-data.bin'
|
||||
accel = self.testbed.add_device('iio', 'iio-buffer-accel0', None,
|
||||
['name', 'IIO Test Accelerometer',
|
||||
'buffer/enable', '0',
|
||||
'trigger/current_trigger', '',
|
||||
'scan_elements/in_accel_x_en', '0',
|
||||
'scan_elements/in_accel_x_index', '0',
|
||||
'scan_elements/in_accel_x_type', 'le:s16/32>>0',
|
||||
'scan_elements/in_accel_y_en', '0',
|
||||
'scan_elements/in_accel_y_index', '1',
|
||||
'scan_elements/in_accel_y_type', 'le:s16/32>>0',
|
||||
'scan_elements/in_accel_z_en', '0',
|
||||
'scan_elements/in_accel_z_index', '2',
|
||||
'scan_elements/in_accel_z_type', 'le:s16/32>>0',
|
||||
'scan_elements/in_timestamp_en', '1',
|
||||
'scan_elements/in_timestamp_index', '3',
|
||||
'scan_elements/in_timestamp_type', 'le:s64/64>>0'],
|
||||
['NAME', '"IIO Accelerometer"',
|
||||
'DEVNAME', '/dev/iio-buffer-accel-test',
|
||||
'IIO_SENSOR_PROXY_TYPE', 'iio-buffer-accel']
|
||||
)
|
||||
trigger = self.testbed.add_device('iio', 'trigger0', None,
|
||||
['name', 'accel_3d-dev0'],
|
||||
[]
|
||||
)
|
||||
self.start_daemon()
|
||||
self.assertEqual(self.get_dbus_property('HasAmbientLight'), False)
|
||||
self.assertEqual(self.get_dbus_property('HasAccelerometer'), True)
|
||||
|
||||
# Default values
|
||||
self.assertEqual(self.get_dbus_property('AccelerometerOrientation'), 'undefined')
|
||||
self.assertEqual(self.read_sysfs_attr(accel, 'buffer/enable'), b'1')
|
||||
self.assertEqual(self.read_sysfs_attr(accel, 'scan_elements/in_accel_x_en'), b'1')
|
||||
self.assertEqual(self.read_sysfs_attr(accel, 'scan_elements/in_accel_y_en'), b'1')
|
||||
self.assertEqual(self.read_sysfs_attr(accel, 'scan_elements/in_accel_z_en'), b'1')
|
||||
|
||||
data = self.read_file(top_srcdir + '/tests/iio-buffer-accel-data/orientation-normal.bin')
|
||||
with open(mock_dev_data,'wb') as mock_file:
|
||||
mock_file.write(data)
|
||||
self.proxy.ClaimAccelerometer()
|
||||
time.sleep(1)
|
||||
self.assertEqual(self.get_dbus_property('AccelerometerOrientation'), 'normal')
|
||||
os.remove(mock_dev_data)
|
||||
|
||||
time.sleep(1)
|
||||
self.assertEqual(self.get_dbus_property('AccelerometerOrientation'), 'normal')
|
||||
|
||||
data = self.read_file(top_srcdir + '/tests/iio-buffer-accel-data/orientation-left-up.bin')
|
||||
with open(mock_dev_data,'wb') as mock_file:
|
||||
mock_file.write(data)
|
||||
time.sleep(1)
|
||||
self.assertEqual(self.get_dbus_property('AccelerometerOrientation'), 'left-up')
|
||||
os.remove(mock_dev_data)
|
||||
|
||||
data = self.read_file(top_srcdir + '/tests/iio-buffer-accel-data/orientation-normal.bin')
|
||||
with open(mock_dev_data,'wb') as mock_file:
|
||||
mock_file.write(data)
|
||||
time.sleep(1)
|
||||
self.assertEqual(self.get_dbus_property('AccelerometerOrientation'), 'normal')
|
||||
os.remove(mock_dev_data)
|
||||
|
||||
self.stop_daemon()
|
||||
|
||||
#
|
||||
# Helper methods
|
||||
#
|
||||
|
Reference in New Issue
Block a user