Commit c72a002c authored by Martin Kepplinger's avatar Martin Kepplinger
Browse files

pytests: test_cameras: update to runtime pm sysfs interface

in newer kernels camera drivers with proper runtime pm are loaded by default.
parent 6b27170a
from contextlib import contextmanager
import subprocess
import glob
import os
import pytest
from . import boardtype
def are_cameras_enabled():
for result in glob.iglob('/sys/class/regulator/*/'):
with open(os.path.join(result, "name")) as f:
if "CAMERA" in f.read():
with open(os.path.join(result, "state")) as g:
if "enabled" in g.read():
return True
return False
def set_power(on):
value = 'on' if on else 'auto'
address = '10' if boardtype.is_birch() else '2d'
with open('/sys/bus/i2c/devices/2-0020/power/control', 'w') as f:
f.write(value)
with open('/sys/bus/i2c/devices/3-00' + address + '/power/control', 'w') as f:
f.write(value)
@contextmanager
def power_up():
set_power(True)
try:
yield
finally:
set_power(False)
@pytest.mark.skipif(
boardtype.is_birch(),
reason="Birch is missing the connection to the shutdown line.")
@pytest.mark.skipif(not boardtype.is_librem5(), reason="Not a phone")
@pytest.mark.skipif(not are_cameras_enabled(), reason="Cameras disabled")
def test_selfie_camera_i2c():
# TODO: bringup depends on the kernel
readout = subprocess.check_output([
'i2ctransfer',
'-f', # don't let the loaded driver prevent the test
'-y', '2',
'w2@0x20', '0x0f', '0x16', 'r2'])
assert(readout == b'0x46 0x08\n')
with power_up():
# TODO: bringup depends on the kernel
readout = subprocess.check_output([
'i2ctransfer',
'-f', # don't let the loaded driver prevent the test
'-y', '2',
'w2@0x20', '0x0f', '0x16', 'r2'])
assert(readout == b'0x46 0x08\n')
@pytest.mark.skipif(not boardtype.is_librem5(), reason="Not a phone")
@pytest.mark.skipif(not are_cameras_enabled(), reason="Cameras disabled")
def test_big_camera_i2c():
address = '0x10' if boardtype.is_birch() else '0x2d'
readout = subprocess.check_output([
'i2ctransfer',
'-f', # don't let the loaded driver prevent the test
'-y', '3',
'w2@' + address, '0x00', '0x00', 'r2'])
assert(readout == b'0x30 0xc6\n')
with power_up():
address = '0x10' if boardtype.is_birch() else '0x2d'
readout = subprocess.check_output([
'i2ctransfer',
'-f', # don't let the loaded driver prevent the test
'-y', '3',
'w2@' + address, '0x00', '0x00', 'r2'])
assert(readout == b'0x30 0xc6\n')
@pytest.mark.skipif(not boardtype.is_librem5(), reason="Not a phone")
@pytest.mark.skipif(not are_cameras_enabled(), reason="Cameras disabled")
def test_big_camera_focus_driver():
"""Tests the focus driver based on observed behaviour."""
......@@ -59,13 +64,14 @@ def test_big_camera_focus_driver():
'-y', '3',
'w2@' + address, byte1, byte2, 'r2'])
# Set config bits.
readout = regsetread('0x00', '0x0f')
assert(readout == b'0x00 0x0f\n')
# Switch to "Ringing setting" mode,
# which probably means "Change settings".
readout = regsetread('0xec', '0xa3')
assert(readout == b'0x00 0x00\n')
# Switch back to drive mode.
readout = regsetread('0xdc', '0x51')
assert(readout == b'0x00 0x0f\n')
with power_up():
# Set config bits.
readout = regsetread('0x00', '0x0f')
assert(readout == b'0x00 0x0f\n')
# Switch to "Ringing setting" mode,
# which probably means "Change settings".
readout = regsetread('0xec', '0xa3')
assert(readout == b'0x00 0x00\n')
# Switch back to drive mode.
readout = regsetread('0xdc', '0x51')
assert(readout == b'0x00 0x0f\n')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment