Skip to content
Snippets Groups Projects
Commit 4c2e8c65 authored by Dorota Czaplejewicz's avatar Dorota Czaplejewicz Committed by Martin Kepplinger
Browse files

pytests: Test i2c communication with cameras

parent 9289dc8a
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,10 @@ def _get_board_type():
return f.readline().strip().strip('\00')
def is_birch():
return _get_board_type() == 'Purism Librem 5r2'
def is_librem5():
return r'Purism Librem 5r' in _get_board_type()
......
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
@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')
@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')
@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."""
def regsetread(byte1, byte2):
# The driver should be at 0x18 according to the datasheet,
# so leaving this for easy change.
address = '0x0c'
return subprocess.check_output([
'i2ctransfer',
'-f', # don't let any loaded driver prevent the test
'-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')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment