Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
Improve test coverage in ccl_abstract_wrapper.c
Browse files Browse the repository at this point in the history
Relates to issue #33, add coverage to:
- Wrapper info cache lookup
- Info request error
- Get info size, ccl_wrapper_get_info_size() function
- Check that wrapper memory was not yet released
  • Loading branch information
nunofachada committed Jun 11, 2019
1 parent b926a05 commit e683781
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 40 deletions.
33 changes: 33 additions & 0 deletions tests/lib/test_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ static void create_info_destroy_test() {
g_assert_cmphex(GPOINTER_TO_UINT(context), ==,
GPOINTER_TO_UINT(ccl_context_unwrap(ctx)));

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy stuff. */
ccl_buffer_destroy(b);
ccl_context_destroy(ctx);
Expand Down Expand Up @@ -137,6 +140,9 @@ static void ref_unref_test() {
/* Check that buffer ref count is 1. */
g_assert_cmpuint(1, ==, ccl_wrapper_ref_count((CCLWrapper *) b));

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy stuff. */
ccl_buffer_unref(b);
ccl_context_destroy(ctx);
Expand Down Expand Up @@ -193,6 +199,9 @@ static void wrap_unwrap_test() {
/* Check that buffer ref count is 1. */
g_assert_cmpuint(1, ==, ccl_wrapper_ref_count((CCLWrapper *) b));

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy stuff. */
ccl_buffer_destroy(b);
ccl_context_destroy(ctx);
Expand Down Expand Up @@ -267,6 +276,9 @@ static void read_write_test() {
for (guint i = 0; i < CCL_TEST_BUFFER_SIZE; ++i)
g_assert_cmpuint(h_in[i], ==, h_out[i]);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Free stuff. */
ccl_buffer_destroy(b);
ccl_queue_destroy(q);
Expand Down Expand Up @@ -335,6 +347,9 @@ static void copy_test() {
for (guint i = 0; i < CCL_TEST_BUFFER_SIZE; ++i)
g_assert_cmpuint(h1[i], ==, h2[i]);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Free stuff. */
ccl_buffer_destroy(b1);
ccl_buffer_destroy(b2);
Expand Down Expand Up @@ -398,6 +413,9 @@ static void map_unmap_test() {
(CCLMemObj *) b, q, h_out, NULL, &err);
g_assert_no_error(err);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Free stuff. */
ccl_buffer_destroy(b);
ccl_queue_destroy(q);
Expand Down Expand Up @@ -456,6 +474,9 @@ static void destructor_callback_test() {
(CCLMemObj *) b, destructor_callback, &test_var, &err);
g_assert_no_error(err);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy buffer. */
ccl_buffer_destroy(b);

Expand Down Expand Up @@ -541,6 +562,9 @@ static void rect_read_write_copy_test() {
for (cl_uint i = 0; i < CCL_TEST_BUFFER_SIZE * CCL_TEST_BUFFER_SIZE; ++i)
g_assert_cmpuint(h1[i], ==, h2[i]);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Free stuff. */
ccl_buffer_destroy(b1);
ccl_buffer_destroy(b2);
Expand Down Expand Up @@ -629,6 +653,9 @@ static void create_from_region_test() {
g_assert_cmpuint(
hsubbuf[i], ==, hbuf[i + siz_subbuf / sizeof(cl_ulong)]);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy stuff. */
ccl_buffer_destroy(buf);
ccl_buffer_destroy(subbuf);
Expand Down Expand Up @@ -717,6 +744,9 @@ static void fill_test() {
for (guint j = 0; j < 8; ++j)
g_assert_cmpuint(h[i].s[j], ==, pattern.s[j]);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Free stuff. */
ccl_buffer_destroy(b);
ccl_queue_destroy(q);
Expand Down Expand Up @@ -797,6 +827,9 @@ static void migrate_test() {
ccl_queue_finish(q, &err);
g_assert_no_error(err);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Free stuff. */
ccl_buffer_destroy(b);
ccl_queue_destroy(q);
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/test_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ static void create_info_destroy_test() {
g_assert_no_error(err);
g_assert_cmpuint(num_devices, >, 0);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Free context and set filters to NULL. */
ccl_context_destroy(ctx);

Expand Down Expand Up @@ -767,6 +770,9 @@ static void ref_unref_test() {
* enclosing context. */
g_assert_cmpuint(ccl_wrapper_ref_count((CCLWrapper *) d), ==, 1);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Unref device. */
ccl_device_unref(d);

Expand Down Expand Up @@ -835,6 +841,9 @@ static void get_supported_image_formats_test() {
image_formats++;
}

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy context. */
ccl_context_destroy(c);
}
Expand Down Expand Up @@ -878,6 +887,9 @@ static void device_container_test() {
ccl_context_get_num_devices(ctx, &err);
g_assert_no_error(err);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy context. */
ccl_context_destroy(ctx);

Expand Down
6 changes: 4 additions & 2 deletions tests/lib/test_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,13 @@ static void sub_devices_test() {
ctprop);
}

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy stuff. */
ccl_context_destroy(ctx);

/* Confirm that memory allocated by wrappers has been properly
* freed. */
/* Confirm that memory allocated by wrappers has been properly freed. */
g_assert(ccl_wrapper_memcheck());

#else
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/test_devsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ static void devices_new_destroy_test() {
/* Check that devs is not null. */
g_assert_cmphex(GPOINTER_TO_UINT(devs), !=, GPOINTER_TO_UINT(NULL));

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy object containing device wrappers for all OpenCL devices in the
* system. */
ccl_devsel_devices_destroy(devs);
Expand All @@ -78,4 +81,3 @@ int main(int argc, char ** argv) {

return g_test_run();
}

15 changes: 15 additions & 0 deletions tests/lib/test_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ static void create_info_destroy_test() {
/* Check that start time occurs before end time. */
g_assert_cmpuint(*((cl_ulong *) info->value), <=, time_end);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Release wrappers. */
ccl_event_destroy(evt);
ccl_buffer_destroy(buf);
Expand Down Expand Up @@ -224,6 +227,9 @@ static void user_event_test() {
g_assert_no_error(err);
g_assert_cmpint(exec_status, ==, CL_COMPLETE);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy stuff. */
ccl_event_destroy(uevt);
ccl_context_destroy(ctx);
Expand Down Expand Up @@ -305,6 +311,9 @@ static void callback_test() {
ccl_queue_finish(cq, &err);
g_assert_no_error(err);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Release wrappers. */
ccl_buffer_destroy(buf);
ccl_queue_destroy(cq);
Expand Down Expand Up @@ -420,6 +429,9 @@ static void name_test() {
evt_name = ccl_event_get_final_name(evt);
g_assert_cmpstr("UNMAP_MEM_OBJECT", ==, evt_name);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Release wrappers. */
ccl_buffer_destroy(buf);
ccl_queue_destroy(cq);
Expand Down Expand Up @@ -530,6 +542,9 @@ static void event_wait_lists_test() {
ccl_event_wait_list_clear(&ewl);
g_assert(ewl == NULL);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Release wrappers. */
ccl_buffer_destroy(buf);
ccl_queue_destroy(cq1);
Expand Down
8 changes: 7 additions & 1 deletion tests/lib/test_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ static void context_with_image_support_teardown(
CCL_UNUSED(user_data);

/* If context was created, release it. */
if (*ctx_fixt != NULL)
if (*ctx_fixt != NULL) {

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Release context. */
ccl_context_destroy(*ctx_fixt);
}

/* Confirm that memory allocated by wrappers has been properly
* freed. */
Expand Down
24 changes: 16 additions & 8 deletions tests/lib/test_kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ static void create_info_destroy_test() {
ccl_buffer_destroy(buf);
}

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy the command queue. */
ccl_queue_destroy(cq);

Expand Down Expand Up @@ -353,12 +356,14 @@ static void ref_unref_test() {
g_assert_cmphex(
GPOINTER_TO_UINT(krnl1), ==, GPOINTER_TO_UINT(krnl2));

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy remaining stuff. */
ccl_program_destroy(prg);
ccl_context_destroy(ctx);

/* Confirm that memory allocated by wrappers has been properly
* freed. */
/* Confirm that memory allocated by wrappers has been properly freed. */
g_assert(ccl_wrapper_memcheck());
}

Expand Down Expand Up @@ -644,11 +649,13 @@ static void suggest_worksizes_test() {

#endif

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy stuff. */
ccl_context_destroy(ctx);

/* Confirm that memory allocated by wrappers has been properly
* freed. */
/* Confirm that memory allocated by wrappers has been properly freed. */
g_assert(ccl_wrapper_memcheck());
}

Expand Down Expand Up @@ -1066,8 +1073,7 @@ static void args_test() {
g_assert_cmpfloat(c, ==, *((cl_char *) ccl_arg_value(arg_test)));
ccl_arg_destroy(arg_test);

/* Confirm that memory allocated by wrappers has been properly
* freed. */
/* Confirm that memory allocated by wrappers has been properly freed. */
g_assert(ccl_wrapper_memcheck());
}

Expand Down Expand Up @@ -1178,13 +1184,15 @@ static void native_test() {
for (i = 0; i < CCL_TEST_KERNEL_NATIVE_BUF_SIZE; ++i)
g_assert_cmpint(hbuf[i] + 1, ==, hbuf_out[i]);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

/* Destroy stuff. */
ccl_buffer_destroy(buf);
ccl_queue_destroy(cq);
ccl_context_destroy(ctx);

/* Confirm that memory allocated by wrappers has been properly
* freed. */
/* Confirm that memory allocated by wrappers has been properly freed. */
g_assert(ccl_wrapper_memcheck());
}

Expand Down
Loading

0 comments on commit e683781

Please sign in to comment.