test_libcamera.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import os
  2. import infra.basetest
  3. class TestLibCamera(infra.basetest.BRTest):
  4. # A specific configuration is needed for testing libcamera:
  5. # a kernel config fragment enables v4l2 vimc driver.
  6. # The libevent package is also enabled to have the libcamera "cam"
  7. # test application.
  8. kernel_fragment = \
  9. infra.filepath("tests/package/test_libcamera/linux-vimc.fragment")
  10. config = \
  11. f"""
  12. BR2_aarch64=y
  13. BR2_TOOLCHAIN_EXTERNAL=y
  14. BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
  15. BR2_LINUX_KERNEL=y
  16. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  17. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.76"
  18. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  19. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
  20. BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{kernel_fragment}"
  21. BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
  22. BR2_PACKAGE_LIBCAMERA=y
  23. BR2_PACKAGE_LIBCAMERA_PIPELINE_VIMC=y
  24. BR2_PACKAGE_LIBEVENT=y
  25. BR2_TARGET_ROOTFS_CPIO=y
  26. BR2_TARGET_ROOTFS_CPIO_GZIP=y
  27. # BR2_TARGET_ROOTFS_TAR is not set
  28. """
  29. def test_run(self):
  30. img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
  31. kern = os.path.join(self.builddir, "images", "Image")
  32. self.emulator.boot(arch="aarch64",
  33. kernel=kern,
  34. kernel_cmdline=["console=ttyAMA0"],
  35. options=["-M", "virt", "-cpu", "cortex-a57", "-m", "256M",
  36. "-initrd", img])
  37. self.emulator.login()
  38. # The Kernel config of this test has only one v4l2 vimc
  39. # driver. The camera index is expected to be #1.
  40. cam_idx = 1
  41. # We test libcamera with its simple "cam" application, by
  42. # requesting a list of available cameras.
  43. cmd = "cam --list"
  44. out, ret = self.emulator.run(cmd)
  45. self.assertEqual(ret, 0)
  46. # libcamera generates info messages. We filter only the
  47. # line(s) starting with our camera index.
  48. cam_line = [ln for ln in out if ln.startswith(f"{cam_idx}:")]
  49. # We should have the vimc camera in this line.
  50. self.assertIn("platform/vimc.0", cam_line[0])
  51. # List the camera information.
  52. cmd = f"cam --camera {cam_idx} --info"
  53. self.assertRunOk(cmd)
  54. # List the camera controls and check we have a brightness
  55. # control.
  56. cmd = f"cam --camera {cam_idx} --list-controls"
  57. out, ret = self.emulator.run(cmd)
  58. self.assertEqual(ret, 0)
  59. self.assertIn("Control: Brightness:", "\n".join(out))
  60. # List the camera properties and check we have a camera
  61. # "Model" property.
  62. cmd = f"cam --camera {cam_idx} --list-properties"
  63. out, ret = self.emulator.run(cmd)
  64. self.assertEqual(ret, 0)
  65. self.assertIn("Property: Model = ", "\n".join(out))
  66. # Capture few frames.
  67. cmd = f"cam --camera {cam_idx} --capture=5"
  68. cmd += " --stream width=160,height=120,role=video,pixelformat=RGB888"
  69. self.assertRunOk(cmd)