Skip to content

Commit 8dee731

Browse files
IlanTruanovskypcolberg
authored andcommitted
Fix DEADCODE Coverity issue
A typo was causing much of the code to be seen as deadcode. A loop was not looping the correct number of times. This commit makes changes so that the correct number of loop iterations are done. However, with just this change, the test will fail since clCreateContextFromType returns CL_INVALID_DEVICE on the iteration with ienv = 1, apitype = 1, and i = 0. The reasoning for why this happens in the test is as follows: 1. First, we set the environment to contain L_CONTEXT_OFFLINE_DEVICE_INTELFPGA=+a10_ref_small 2. Then, we initialize our 5 accelerators that we use in the test. Since we have L_CONTEXT_OFFLINE_DEVICE_INTELFPGA=+a10_ref_small in our environment, this is equivalent to adding a 6th offline accelerator to our system. 3. We then try to get our context by calling clCreateContextFromType. Note that we use CL_DEVICE_TYPE_ALL meaning we want all device types included in the context (i.e. doesn't matter if the devices are GPUs, CPUs, etc). 4. Inside the clCreateContextFromType call, we get our desired set of devices by calling clGetDeviceIDs and pass them to l_finalize_context. The devices that we get from clGetDeviceIDs include the offline device we added through the environment variable. 5. l_finalize_context calls l_init_context_with_devices with the same devices. 6. Finally, l_init_context_with_devices correctly errors out since we have a combination of present and absent (offline) devices. So, this commit also changes the code within the for loop to account for the differences between each iteration. These Coverity issues are fixed with this commit: test/acl_context_test.cpp:1116:9: Type: Logically dead code (DEADCODE) test/acl_context_test.cpp:1111:9: cond_const: Condition "apitype", taking false branch. Now the value of "apitype" is equal to 0. test/acl_context_test.cpp:1117:13: const: At condition "apitype", the value of "apitype" must be equal to 0. test/acl_context_test.cpp:1116:9: dead_error_condition: The condition "apitype" cannot be true. test/acl_context_test.cpp:1116:9: dead_error_line: Execution cannot reach the expression "clCreateContextFromType(props, 4294967295UL, notify_me, this, &status)" inside this statement: "context = (apitype ? clCrea...". test/acl_context_test.cpp:1125:11: Type: Logically dead code (DEADCODE) test/acl_context_test.cpp:1103:9: assignment: Assigning: "fixed_val" = "0L". test/acl_context_test.cpp:1124:13: const: At condition "fixed_val != 0L", the value of "fixed_val" must be equal to 0. test/acl_context_test.cpp:1124:9: dead_error_condition: The condition "fixed_val != 0L" cannot be true. test/acl_context_test.cpp:1125:11: dead_error_line: Execution cannot reach this statement: "if (!envvals[ienv].valid) {...".
1 parent 67e23e1 commit 8dee731

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

test/acl_context_test.cpp

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,11 +1097,9 @@ MT_TEST(Context, offline_device) {
10971097
}
10981098

10991099
syncThreads();
1100-
1101-
for (int apitype = 0; apitype < 1; apitype++) { // just do test by type.
1100+
for (int apitype = 0; apitype < 2; apitype++) { // just do test by type.
11021101
for (int i = 0; i < 2; i++) { // without/with platform.
11031102
int idx = 0;
1104-
cl_context_properties fixed_val = 0;
11051103
if (i) {
11061104
props[idx++] = CL_CONTEXT_PLATFORM;
11071105
props[idx++] = (cl_context_properties)m_platform;
@@ -1119,42 +1117,41 @@ MT_TEST(Context, offline_device) {
11191117
? clCreateContextFromType(props, CL_DEVICE_TYPE_ALL, notify_me,
11201118
this, &status)
11211119
: clCreateContext(props, 1, m_device, notify_me, this, &status);
1122-
ACL_LOCKED(acl_print_debug_msg(" fixed_val %d valid %d\n",
1123-
(int)fixed_val,
1124-
(int)envvals[ienv].valid));
1125-
if (fixed_val != 0) {
1126-
if (!envvals[ienv].valid) {
1127-
CHECK_EQUAL(CL_INVALID_VALUE, status);
1128-
continue;
1129-
}
1130-
if (envvals[ienv].str != 0) {
1131-
ACL_LOCKED(acl_print_debug_msg(" %s vs. %s \n", (char *)fixed_val,
1132-
envvals[ienv].str));
1133-
if (0 != strcmp((char *)fixed_val, envvals[ienv].str)) {
1134-
CHECK_EQUAL(CL_DEVICE_NOT_AVAILABLE, status);
1135-
continue;
1136-
}
1137-
}
1120+
ACL_LOCKED(acl_print_debug_msg("valid %d\n", (int)envvals[ienv].valid));
1121+
1122+
if (apitype && envvals[ienv].str) {
1123+
CHECK_EQUAL(CL_INVALID_DEVICE, status);
1124+
} else {
1125+
CHECK_EQUAL(CL_SUCCESS, status);
11381126
}
11391127

1140-
CHECK_EQUAL(CL_SUCCESS, status);
11411128
ACL_LOCKED(acl_print_debug_msg(" Got context %p\n", context));
11421129

11431130
cl_context_properties props_ret[20];
11441131
size_t size_ret = 0;
1145-
CHECK_EQUAL(CL_SUCCESS,
1146-
clGetContextInfo(context, CL_CONTEXT_PROPERTIES,
1147-
sizeof(props_ret), props_ret, &size_ret));
1148-
CHECK_EQUAL(sizeof(cl_context_properties) * idx, size_ret);
11491132

1150-
int idx_ret = 0;
1151-
if (i) {
1152-
CHECK_EQUAL(CL_CONTEXT_PLATFORM, props_ret[idx_ret++]);
1153-
CHECK_EQUAL((cl_context_properties)m_platform, props_ret[idx_ret++]);
1154-
}
1133+
if (apitype && envvals[ienv].str) {
1134+
CHECK_EQUAL(
1135+
CL_INVALID_CONTEXT,
1136+
clGetContextInfo(context, CL_CONTEXT_PROPERTIES,
1137+
sizeof(props_ret), props_ret,
1138+
&size_ret)); // props_ret and size_ret is not
1139+
// guaranteed to contain anything
1140+
} else {
1141+
CHECK_EQUAL(CL_SUCCESS, clGetContextInfo(
1142+
context, CL_CONTEXT_PROPERTIES,
1143+
sizeof(props_ret), props_ret, &size_ret));
1144+
CHECK_EQUAL(sizeof(cl_context_properties) * idx, size_ret);
1145+
int idx_ret = 0;
1146+
if (i) {
1147+
CHECK_EQUAL(CL_CONTEXT_PLATFORM, props_ret[idx_ret++]);
1148+
CHECK_EQUAL((cl_context_properties)m_platform,
1149+
props_ret[idx_ret++]);
1150+
}
11551151

1156-
CHECK_EQUAL(0, props_ret[idx_ret++]);
1157-
CHECK_EQUAL(idx, idx_ret);
1152+
CHECK_EQUAL(0, props_ret[idx_ret++]);
1153+
CHECK_EQUAL(idx, idx_ret);
1154+
}
11581155

11591156
syncThreads();
11601157
ACL_LOCKED(acl_print_debug_msg(" Releaseing context\n"));

0 commit comments

Comments
 (0)