From c09bf3d50589c8eb95b322ef3e4eb8a288dacebe Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Fri, 28 Sep 2018 16:13:01 +0330 Subject: [PATCH] test-multithread, check the results on every iteration (#1194) --- test/api/test-multithread.c | 59 ++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/test/api/test-multithread.c b/test/api/test-multithread.c index 657188255..6881a00fc 100644 --- a/test/api/test-multithread.c +++ b/test/api/test-multithread.c @@ -43,9 +43,11 @@ const char *path = "/Library/Fonts/Tahoma.ttf"; #endif +int num_threads = 30; int num_iters = 200; hb_font_t *font; +hb_buffer_t *ref_buffer; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -57,6 +59,29 @@ fill_the_buffer (hb_buffer_t *buffer) hb_shape (font, buffer, NULL, 0); } +static void +validity_check (hb_buffer_t *buffer) { + if (hb_buffer_diff (ref_buffer, buffer, (hb_codepoint_t) -1, 0)) + { + fprintf (stderr, "One of the buffers was different from the reference.\n"); + char out[255]; + + hb_buffer_serialize_glyphs (buffer, 0, hb_buffer_get_length (ref_buffer), + out, sizeof (out), NULL, + font, HB_BUFFER_SERIALIZE_FORMAT_TEXT, + HB_BUFFER_SERIALIZE_FLAG_DEFAULT); + fprintf (stderr, "Actual: %s\n", out); + + hb_buffer_serialize_glyphs (ref_buffer, 0, hb_buffer_get_length (ref_buffer), + out, sizeof (out), NULL, + font, HB_BUFFER_SERIALIZE_FORMAT_TEXT, + HB_BUFFER_SERIALIZE_FLAG_DEFAULT); + fprintf (stderr, "Expected: %s\n", out); + + exit (1); + } +} + static void * thread_func (void *data) { @@ -70,6 +95,7 @@ thread_func (void *data) { hb_buffer_clear_contents (buffer); fill_the_buffer (buffer); + validity_check (buffer); } return 0; @@ -95,38 +121,12 @@ test_body () /* Let them loose! */ pthread_mutex_unlock (&mutex); - hb_buffer_t *ref_buffer = hb_buffer_create (); - fill_the_buffer (ref_buffer); - for (i = 0; i < num_threads; i++) { pthread_join (threads[i], NULL); - hb_buffer_t *buffer = buffers[i]; - hb_buffer_diff_flags_t diff = hb_buffer_diff (ref_buffer, buffer, (hb_codepoint_t) -1, 0); - if (diff) - { - fprintf (stderr, "One of the buffers (%d) was different from the reference.\n", i); - char out[255]; - - hb_buffer_serialize_glyphs (buffer, 0, hb_buffer_get_length (ref_buffer), - out, sizeof (out), NULL, - font, HB_BUFFER_SERIALIZE_FORMAT_TEXT, - HB_BUFFER_SERIALIZE_FLAG_DEFAULT); - fprintf (stderr, "Actual: %s\n", out); - - hb_buffer_serialize_glyphs (ref_buffer, 0, hb_buffer_get_length (ref_buffer), - out, sizeof (out), NULL, - font, HB_BUFFER_SERIALIZE_FORMAT_TEXT, - HB_BUFFER_SERIALIZE_FLAG_DEFAULT); - fprintf (stderr, "Expected: %s\n", out); - - exit (1); - } - hb_buffer_destroy (buffer); + hb_buffer_destroy (buffers[i]); } - hb_buffer_destroy (ref_buffer); - free (buffers); free (threads); } @@ -141,11 +141,16 @@ main (int argc, char **argv) hb_face_t *face = hb_face_create (blob, 0); font = hb_font_create (face); + ref_buffer = hb_buffer_create (); + fill_the_buffer (ref_buffer); + hb_ft_font_set_funcs (font); test_body (); hb_ot_font_set_funcs (font); test_body (); + hb_buffer_destroy (ref_buffer); + hb_font_destroy (font); hb_face_destroy (face); hb_blob_destroy (blob);