chamelium: Calculate CRC from framebuffer instead of hardcoding it
PATCH 1/4 chamelium: Calculate CRC from framebuffer instead of hardcoding it
This introduces CRC calculation for reference frames, instead of using hardcoded values for them. The rendering of reference frames may differ from machine to machine, especially due to font rendering, and the frame itself may change with subsequent IGT changes.
These differences would cause the CRC checks to fail on different setups. This allows them to pass regardless of the setup.
--- lib/igt_chamelium.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_chamelium.h | 5 ++ tests/chamelium.c | 74 ++++++------------------ 3 files changed, 183 insertions(+), 56 deletions(-)
lib/igt_chamelium.c +160 -0
@@ -94,6 +94,14 @@ struct chamelium_frame_dump {struct chamelium_port *port; }; +struct chamelium_fb_crc { +int fd; +struct igt_fb *fb; + +pthread_t thread_id; +igt_crc_t *ret; +}; +struct chamelium {xmlrpc_env env;xmlrpc_client *client;
@@ -1003,6 +1011,158 @@ int chamelium_get_frame_limit(struct chamelium *chamelium,return ret; } +static uint32_t chamelium_xrgb_hash16 (unsigned char *buffer,int width, +int height,int k,int m) +{ +unsigned char r, g, b; +uint64_t sum =0 ; +uint64_t count =0 ; +uint64_t value; +uint32_t hash; +int index; +int i; + +for (i=0 ; i < width * height; i++) { +if ((i % m) != k) +continue ; + + index = i *4 ; + + r = buffer[index +2 ]; + g = buffer[index +1 ]; + b = buffer[index +0 ]; + + value = r | (g <<8 ) | (b <<16 ); + sum += ++count * value; + } + + hash = ((sum >>0 ) ^ (sum >>16 ) ^ (sum >>32 ) ^ (sum >>48 )) &0xffff ; + +return hash; +} + +/** +* chamelium_calculate_fb_crc: +* @fd: The drm file descriptor +* @fb: The framebuffer to calculate the CRC for +* +* Calculates a CRC for the provided framebuffer, the same way as the Chamelium. +* This calculates the CRC in a non-threaded fashion. +* +* Returns: The calculated CRC +*/ +igt_crc_t *chamelium_calculate_fb_crc (int fd,struct igt_fb *fb) +{ +igt_crc_t *ret; +cairo_t *cr; +cairo_surface_t *fb_surface; +unsigned char *buffer; +int n =4 ; +int w, h; +int i, j; + + ret =calloc (1 ,sizeof (igt_crc_t)); + +/* Get the cairo surface for the framebuffer */ + cr =igt_get_cairo_ctx (fd, fb); + fb_surface =cairo_get_target (cr); +cairo_surface_reference (fb_surface); +cairo_destroy (cr); + + buffer =cairo_image_surface_get_data (fb_surface); + w = fb->width; + h = fb->height; + +for (i =0 ; i < n; i++) { + j = n - i -1 ; + ret->crc[i] =chamelium_xrgb_hash16 (buffer, w, h, j, n); + } + + ret->n_words = n; +cairo_surface_destroy (fb_surface); + +return ret; +} + +static void *chamelium_calculate_fb_crc_thread (void *data) +{ +struct chamelium_fb_crc *fb_crc = (struct chamelium_fb_crc *) data; +cairo_t *cr; +cairo_surface_t *fb_surface; +unsigned char *buffer; +int n =4 ; +int w, h; +int i, j; + +/* Get the cairo surface for the framebuffer */ + cr =igt_get_cairo_ctx (fb_crc->fd, fb_crc->fb); + fb_surface =cairo_get_target (cr); +cairo_surface_reference (fb_surface); +cairo_destroy (cr); + + buffer =cairo_image_surface_get_data (fb_surface); + w = fb_crc->fb->width; + h = fb_crc->fb->height; + +for (i =0 ; i < n; i++) { + j = n - i -1 ; + fb_crc->ret->crc[i] =chamelium_xrgb_hash16 (buffer, w, h, j, n); + } + + fb_crc->ret->n_words = n; +cairo_surface_destroy (fb_surface); + +return NULL ; +} + +/** +* chamelium_calculate_fb_crc_launch: +* @fd: The drm file descriptor +* @fb: The framebuffer to calculate the CRC for +* +* Launches the CRC calculation for the provided framebuffer, the same way as +* the Chamelium. This calculates the CRC in a threaded fashion. +* Thread-related information is returned and should be passed to a subsequent +* call to chamelium_calculate_fb_crc_result. It should not be freed. +* +* Returns: An intermediate structure with thread-related information +*/ +struct chamelium_fb_crc *chamelium_calculate_fb_crc_launch (int fd, +struct igt_fb *fb) +{ +struct chamelium_fb_crc *fb_crc; + + fb_crc =calloc (1 ,sizeof (struct chamelium_fb_crc )); + fb_crc->ret =calloc (1 ,sizeof (igt_crc_t)); + fb_crc->fd = fd; + fb_crc->fb = fb; + +pthread_create (&fb_crc->thread_id,NULL , + chamelium_calculate_fb_crc_thread, fb_crc); + +return fb_crc; +} + +/** +* chamelium_calculate_fb_crc_result: +* @fb_crc: An intermediate structure with thread-related information +* +* Provides the result for the previously-launched CRC calculation. +* +* Returns: The calculated CRC +*/ +igt_crc_t *chamelium_calculate_fb_crc_result (struct chamelium_fb_crc *fb_crc) +{ +igt_crc_t *ret; + +pthread_join (fb_crc->thread_id,NULL ); + + ret = fb_crc->ret; +free (fb_crc); + +return ret; +} +static unsigned int chamelium_get_port_type (struct chamelium *chamelium,struct chamelium_port *port) {
lib/igt_chamelium.h +5 -0
@@ -36,6 +36,7 @@struct chamelium ;struct chamelium_port ;struct chamelium_frame_dump ; +struct chamelium_fb_crc ;struct chamelium *chamelium_init (int drm_fd);void chamelium_deinit (struct chamelium *chamelium);
@@ -92,6 +93,10 @@ struct chamelium_frame_dump *chamelium_port_dump_pixels(struct chamelium *chamelstruct chamelium_port *port, int x, int y, int w, int h); +igt_crc_t *chamelium_calculate_fb_crc (int fd,struct igt_fb *fb); +struct chamelium_fb_crc *chamelium_calculate_fb_crc_launch (int fd, +struct igt_fb *fb); +igt_crc_t *chamelium_calculate_fb_crc_result (struct chamelium_fb_crc *fb_crc);int chamelium_get_captured_frame_count (struct chamelium *chamelium); int chamelium_get_frame_limit(struct chamelium *chamelium, struct chamelium_port *port,
tests/chamelium.c +18 -56
119 lines not on this page · raw message
Signature · 6 lines
2.13.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/4 tests/ chamelium: Remove the frame dump tests
The frame dump tests provide no additional functionality over CRC tests and are considerably slower. Thus, these tests should be considered as poorer duplicates and removed.
--- tests/chamelium.c | 53 ----------------------------------------------------- 1 file changed, 53 deletions(-)
tests/chamelium.c +0 -53
@@ -498,53 +498,6 @@ next: }static void -test_display_frame_dump (data_t *data,struct chamelium_port *port) -{ -igt_display_t display; -igt_output_t *output; -igt_plane_t *primary; -struct igt_fb fb; -struct chamelium_frame_dump *frame; -drmModeModeInfo *mode; -drmModeConnector *connector; -int fb_id, i, j; - -reset_state (data, port); - - output =prepare_output (data, &display, port); - connector =chamelium_port_get_connector (data->chamelium, port, false); - primary =igt_output_get_plane_type (output,DRM_PLANE_TYPE_PRIMARY ); -igt_assert (primary); - -for (i =0 ; i < connector->count_modes; i++) { - mode = &connector->modes[i]; - fb_id =igt_create_color_pattern_fb (data->drm_fd, - mode->hdisplay, mode->vdisplay, -DRM_FORMAT_XRGB8888 , -LOCAL_DRM_FORMAT_MOD_NONE , -0 ,0 ,0 , &fb); -igt_assert (fb_id >0 ); - -enable_output (data, port, output, mode, &fb); - -igt_debug ("Reading frame dumps from Chamelium...\n" ); -chamelium_capture (data->chamelium, port,0 ,0 ,0 ,0 ,5 ); -for (j =0 ; j <5 ; j++) { - frame =chamelium_read_captured_frame ( - data->chamelium, j); -chamelium_assert_frame_eq (data->chamelium, frame, &fb); -chamelium_destroy_frame_dump (frame); - } - -disable_output (data, port, output); -igt_remove_fb (data->drm_fd, &fb); - } - -drmModeFreeConnector (connector); -igt_display_fini (&display); -} - -static void test_hpd_without_ddc (data_t *data,struct chamelium_port *port) {struct udev_monitor *mon =igt_watch_hotplug ();
@@ -697,9 +650,6 @@ igt_main connector_subtest("dp-crc-multiple", DisplayPort)test_display_crc_multiple (&data, port); - - connector_subtest("dp-frame-dump", DisplayPort) -test_display_frame_dump (&data, port); } igt_subtest_group {
@@ -754,9 +704,6 @@ igt_main connector_subtest("hdmi-crc-multiple", HDMIA)test_display_crc_multiple (&data, port); - - connector_subtest("hdmi-frame-dump", HDMIA) -test_display_frame_dump (&data, port); } igt_subtest_group {
Signature · 6 lines
2.13.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/4 lib/igt_chamelium: Add support for dumping chamelium frames to a png
In reply to Paul KocialkowskiThis introduces a chamelium_write_frame_to_png function that saves a Chamelium frame dump to a png file. This should be useful when a frame comparison with a reference fails.
--- lib/igt_chamelium.c | 32 ++++++++++++++++++++++++++++++++ lib/igt_chamelium.h | 3 +++ 2 files changed, 35 insertions(+)
lib/igt_chamelium.c +32 -0
@@ -978,6 +978,38 @@ void chamelium_assert_frame_eq(const struct chamelium *chamelium, "Chamelium frame dump didn't match reference image\n"); } +void chamelium_write_frame_to_png (const struct chamelium *chamelium, +const struct chamelium_frame_dump *dump, +const char *filename) +{ +cairo_surface_t *dump_surface; +pixman_image_t *image_bgr; +pixman_image_t *image_argb; +int w = dump->width, h = dump->height; +uint32_t *bits_bgr = (uint32_t *) dump->bgr; +unsigned char *bits_argb; +cairo_status_t status; + + image_bgr =pixman_image_create_bits ( + PIXMAN_b8g8r8, w, h, bits_bgr, +PIXMAN_FORMAT_BPP (PIXMAN_b8g8r8) /8 * w); + image_argb =convert_frame_format (image_bgr, PIXMAN_x8r8g8b8); +pixman_image_unref (image_bgr); + + bits_argb = (unsigned char *)pixman_image_get_data (image_argb); + + dump_surface =cairo_image_surface_create_for_data ( + bits_argb,CAIRO_FORMAT_ARGB32 , w, h, +PIXMAN_FORMAT_BPP (PIXMAN_x8r8g8b8) /8 * w); + + status =cairo_surface_write_to_png (dump_surface, filename); +cairo_surface_destroy (dump_surface); + +pixman_image_unref (image_argb); + +igt_assert (status ==CAIRO_STATUS_SUCCESS ); +} +/** * chamelium_get_frame_limit: * @chamelium: The Chamelium instance to use
lib/igt_chamelium.h +3 -0
@@ -105,6 +105,9 @@ int chamelium_get_frame_limit(struct chamelium *chamelium,void chamelium_assert_frame_eq (const struct chamelium *chamelium,const struct chamelium_frame_dump *dump,struct igt_fb *fb); +void chamelium_write_frame_to_png (const struct chamelium *chamelium, +const struct chamelium_frame_dump *dump, +const char *filename);void chamelium_destroy_frame_dump (struct chamelium_frame_dump *dump);#endif /* IGT_CHAMELIUM_H */
Signature · 6 lines
2.13.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/4 chamelium: Dump obtained and reference frames to png on crc error
In reply to Paul KocialkowskiWhen a CRC comparison error occurs, it is quite useful to get a dump of both the frame obtained from the chamelium and the reference in order to compare them.
This implements the frame dump, with a configurable path that enables the use of this feature.
--- lib/igt_chamelium.c | 21 +++++++++++ lib/igt_chamelium.h | 1 + lib/igt_debugfs.c | 20 ++++++++++ lib/igt_debugfs.h | 1 + tests/chamelium.c | 105 +++++++++++++++++++--------------------------------- 5 files changed, 82 insertions(+), 66 deletions(-)
lib/igt_chamelium.c +21 -0
@@ -57,6 +57,7 @@* |[<!-- language="plain" --> * [Chamelium] * URL=http://chameleon:9992 # The URL used for connecting to the Chamelium's RPC server +* FrameDumpPath=/tmp # The path to dump frames that fail comparison checks * * # The rest of the sections are used for defining connector mappings. * # This is required so any tests using the Chamelium know which connector
@@ -115,11 +116,26 @@ struct chamelium {struct chamelium_edid *edids;struct chamelium_port *ports;int port_count; + +char *frame_dump_path; };static struct chamelium *cleanup_instance;/** +* chamelium_get_frame_dump_path: +* @chamelium: The Chamelium instance to use +* +* Retrieves the path to dump frames to. +* +* Returns: a string with the frame dump path +*/ +char *chamelium_get_frame_dump_path (struct chamelium *chamelium) +{ +return chamelium->frame_dump_path; +} + +/** * chamelium_get_ports: * @chamelium: The Chamelium instance to use * @count: Where to store the number of ports
@@ -1330,6 +1346,11 @@ static bool chamelium_read_config(struct chamelium *chamelium, int drm_fd)return false; } + chamelium->frame_dump_path =g_key_file_get_string (igt_key_file, +"Chamelium" , +"FrameDumpPath" , + &error); +return chamelium_read_port_mappings (chamelium, drm_fd); }
lib/igt_chamelium.h +1 -0
@@ -42,6 +42,7 @@ struct chamelium *chamelium_init(int drm_fd);void chamelium_deinit (struct chamelium *chamelium);void chamelium_reset (struct chamelium *chamelium); +char *chamelium_get_frame_dump_path (struct chamelium *chamelium);struct chamelium_port **chamelium_get_ports (struct chamelium *chamelium,int *count);unsigned int chamelium_port_get_type (const struct chamelium_port *port);
lib/igt_debugfs.c +20 -0
@@ -282,6 +282,26 @@ bool igt_debugfs_search(int device, const char *filename, const char *substring)*/ /** +* igt_check_crc_equal: +* @a: first pipe CRC value +* @b: second pipe CRC value +* +* Compares two CRC values and return whether they match. +* +* Returns: A boolean indicating whether the CRC values match +*/ +bool igt_check_crc_equal (const igt_crc_t *a,const igt_crc_t *b) +{ +int i; + +for (i =0 ; i < a->n_words; i++) +if (a->crc[i] != b->crc[i]) +return false; + +return true; +} + +/** * igt_assert_crc_equal: * @a: first pipe CRC value * @b: second pipe CRC value
lib/igt_debugfs.h +1 -0
@@ -113,6 +113,7 @@ enum intel_pipe_crc_source { INTEL_PIPE_CRC_SOURCE_MAX, }; +bool igt_check_crc_equal (const igt_crc_t *a,const igt_crc_t *b);void igt_assert_crc_equal (const igt_crc_t *a,const igt_crc_t *b);char *igt_crc_to_string (igt_crc_t *crc);
tests/chamelium.c +39 -66
156 lines not on this page · raw message
Signature · 6 lines
2.13.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx