Skip to content

Commit

Permalink
Fix leaks in callSingleTestFunction (#1224)
Browse files Browse the repository at this point in the history
The context and queue were not released when the test is not supported
in offline mode or the queue couldn't be created.

Inline test_missing_support_offline_cmpiler_ret macro, remove dead
parameter of check_functions_for_offline_compiler and slightly refactor
callSingleTestFunction to address leaks.

Signed-off-by: Marco Antognini <marco.antognini@arm.com>
  • Loading branch information
mantognini authored Jun 9, 2021
1 parent 3159985 commit 76ace61
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
15 changes: 7 additions & 8 deletions test_common/harness/errorHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "errorHelpers.h"

#include "parseParameters.h"
#include "testHarness.h"

#include <CL/cl_half.h>

Expand Down Expand Up @@ -690,21 +691,19 @@ const char *subtests_to_skip_with_offline_compiler[] = {
"library_function"
};

int check_functions_for_offline_compiler(const char *subtestname,
cl_device_id device)
bool check_functions_for_offline_compiler(const char *subtestname)
{
if (gCompilationMode != kOnline)
{
size_t nNotRequiredWithOfflineCompiler =
sizeof(subtests_to_skip_with_offline_compiler) / sizeof(char *);
size_t i;
for (i = 0; i < nNotRequiredWithOfflineCompiler; ++i)
ARRAY_SIZE(subtests_to_skip_with_offline_compiler);
for (size_t i = 0; i < nNotRequiredWithOfflineCompiler; ++i)
{
if (!strcmp(subtestname, subtests_to_skip_with_offline_compiler[i]))
{
return 1;
return false;
}
}
}
return 0;
}
return true;
}
18 changes: 1 addition & 17 deletions test_common/harness/errorHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,6 @@ static int vlog_win32(const char *format, ...);
"the device version! (from %s:%d)\n", \
msg, __FILE__, __LINE__);

#define test_missing_support_offline_cmpiler(errCode, msg) \
test_missing_support_offline_cmpiler_ret(errCode, msg, errCode)
// this macro should always return CL_SUCCESS, but print the skip message on
// test not supported with offline compiler
#define test_missing_support_offline_cmpiler_ret(errCode, msg, retValue) \
{ \
if (errCode != CL_SUCCESS) \
{ \
log_info("INFO: Subtest %s tests is not supported in offline " \
"compiler execution path! (from %s:%d)\n", \
msg, __FILE__, __LINE__); \
return TEST_SKIP; \
} \
}

// expected error code vs. what we got
#define test_failure_error(errCode, expectedErrCode, msg) \
test_failure_error_ret(errCode, expectedErrCode, msg, \
Expand Down Expand Up @@ -181,8 +166,7 @@ extern const char *GetAddressModeName(cl_addressing_mode mode);
extern const char *GetQueuePropertyName(cl_command_queue_properties properties);

extern const char *GetDeviceTypeName(cl_device_type type);
int check_functions_for_offline_compiler(const char *subtestname,
cl_device_id device);
bool check_functions_for_offline_compiler(const char *subtestname);
cl_int OutputBuildLogs(cl_program program, cl_uint num_devices,
cl_device_id *device_list);

Expand Down
12 changes: 9 additions & 3 deletions test_common/harness/testHarness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,14 @@ test_status callSingleTestFunction(test_definition test,
return TEST_SKIP;
}

if (!check_functions_for_offline_compiler(test.name))
{
log_info("Subtest %s tests is not supported in offline compiler "
"execution path!\n",
test.name);
return TEST_SKIP;
}

/* Create a context to work with, unless we're told not to */
if (!forceNoContextCreation)
{
Expand Down Expand Up @@ -812,14 +820,12 @@ test_status callSingleTestFunction(test_definition test,
if (queue == NULL)
{
print_error(error, "Unable to create testing command queue");
clReleaseContext(context);
return TEST_FAIL;
}
}

/* Run the test and print the result */
error = check_functions_for_offline_compiler(test.name, deviceToUse);
test_missing_support_offline_cmpiler(error, test.name);

if (test.func == NULL)
{
// Skip unimplemented test, can happen when all of the tests are
Expand Down

0 comments on commit 76ace61

Please sign in to comment.