graphics_base.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. class GraphicsBase:
  2. def get_n_fb_crc(self, *, count=10, uniq=False, timeout=-1):
  3. """
  4. Return count DRM CRC from the framebuffer. If uniq is True,
  5. only unique CRCs are returned (which may be less than the
  6. requested cont).
  7. Returns a possibly empty list of integers.
  8. Set timeout to -1 for no timeout, or to a positive number for
  9. a timeout of that many seconds.
  10. """
  11. # DRM CRCs are exposed through a sysfs pseudo file
  12. try:
  13. self.debugfs_mounted
  14. except AttributeError:
  15. # Note: some init system (e.g. systemd) may have this already
  16. # mounted, so check beforehand
  17. self.assertRunOk("mountpoint /sys/kernel/debug/ || mount -t debugfs none /sys/kernel/debug/")
  18. self.debugfs_mounted = True
  19. # The first column is the frame number, the second column is the
  20. # CRC measure. We use "head" to get the needed CRC count.
  21. disp_crc_path = "/sys/kernel/debug/dri/0/crtc-0/crc/data"
  22. cmd = f"head -{count} {disp_crc_path}"
  23. # The DRM CRC sysfs pseudo file lines are terminated by '\n'
  24. # and '\0'. We remove the '\0' to have a text-only output.
  25. cmd += " | tr -d '\\000'"
  26. # Finally, we drop the frame counter, and keep only the second
  27. # column (CRC values)
  28. cmd += " | cut -f 2 -d ' '"
  29. if uniq:
  30. cmd += " | sort -u"
  31. output, exit_code = self.emulator.run(cmd, timeout=timeout)
  32. self.assertTrue(exit_code == 0, f"'{cmd}' failed with exit code {exit_code}")
  33. return [int(crc, 16) for crc in output]