Skip to content

Commit a544143

Browse files
committed
Added if statements to guard against memory allocation failures that trickle down to other tests.
1 parent 3dda52d commit a544143

File tree

1 file changed

+87
-69
lines changed

1 file changed

+87
-69
lines changed

src/tests/unit/iso-fortran-binding/ISO_Fortran_binding_tests.c

Lines changed: 87 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,14 @@ int main (void)
414414
ind = CFI_establish ((CFI_cdesc_t *) &test6, NULL, attribute, type[i],
415415
elem_len, rank, extents);
416416
ind = CFI_allocate ((CFI_cdesc_t *) &test6, lower, upper, base_type_size);
417-
ind = CFI_deallocate ((CFI_cdesc_t *) &test6);
418-
if (ind != CFI_INVALID_ATTRIBUTE && test6.base_addr != NULL)
417+
if (ind == CFI_SUCCESS)
419418
{
420-
printf ("CFI_deallocate: failed to deallocate memory.\n");
421-
return 1;
419+
ind = CFI_deallocate ((CFI_cdesc_t *) &test6);
420+
if (ind != CFI_INVALID_ATTRIBUTE && test6.base_addr != NULL)
421+
{
422+
printf ("CFI_deallocate: failed to deallocate memory.\n");
423+
return 1;
424+
}
422425
}
423426
}
424427

@@ -459,6 +462,10 @@ int main (void)
459462
elem_len, rank, extents);
460463
tmp_ind = CFI_allocate ((CFI_cdesc_t *) &test7, lower, upper,
461464
base_type_size);
465+
if (tmp_ind != CFI_SUCCESS)
466+
{
467+
goto next_attribute4;
468+
}
462469
ind = CFI_is_contiguous ((CFI_cdesc_t *) &test7);
463470
if (ind != CFI_INVALID_RANK && rank == 0 &&
464471
tmp_ind != CFI_INVALID_ATTRIBUTE)
@@ -474,6 +481,7 @@ int main (void)
474481
return 1;
475482
}
476483
}
484+
next_attribute4:;
477485
}
478486

479487
/* Test CFI_address. */
@@ -875,7 +883,7 @@ int main (void)
875883
CFI_attribute_other, type[i], elem_len, rank,
876884
NULL);
877885
ind = CFI_allocate ((CFI_cdesc_t *) &source, lower, upper, elem_len);
878-
if (ind == CFI_ERROR_MEM_ALLOCATION)
886+
if (ind != CFI_SUCCESS)
879887
{
880888
goto next_type2;
881889
}
@@ -1036,44 +1044,48 @@ int main (void)
10361044
ind = CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_other,
10371045
type[3], elem_len, rank, NULL);
10381046
ind = CFI_allocate ((CFI_cdesc_t *) &source, lower, upper, elem_len);
1039-
for (int r = 0; r < rank; r++)
1040-
{
1041-
lower[r] = rank - r - 3;
1042-
strides[r] = r + 1;
1043-
upper[r] = lower[r] + extents[r] - 3;
1044-
}
1045-
ind = CFI_section ((CFI_cdesc_t *) &section, NULL, lower, upper, strides);
1046-
if (ind != CFI_INVALID_DESCRIPTOR)
1047-
{
1048-
printf ("CFI_section: failed to detect that source is NULL.\n");
1049-
return 1;
1050-
}
1051-
ind = CFI_section (NULL, (CFI_cdesc_t *) &source, lower, upper, strides);
1052-
if (ind != CFI_INVALID_DESCRIPTOR)
1047+
if (ind == CFI_SUCCESS)
10531048
{
1054-
printf ("CFI_section: failed to detect that section is NULL.\n");
1055-
return 1;
1056-
}
1057-
ind =
1058-
CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_allocatable,
1059-
type[3], elem_len, rank, NULL);
1060-
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1061-
upper, strides);
1062-
if (ind != CFI_INVALID_ATTRIBUTE)
1063-
{
1064-
printf ("CFI_section: failed to detect invalid attribute.\n");
1065-
return 1;
1066-
}
1067-
ind = CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_other,
1068-
type[3], elem_len, rank, NULL);
1069-
ind = CFI_deallocate ((CFI_cdesc_t *) &source);
1070-
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1071-
upper, strides);
1072-
if (ind != CFI_ERROR_BASE_ADDR_NULL)
1073-
{
1074-
printf ("CFI_section: failed to detect that the base address is NULL.\n");
1075-
return 1;
1049+
for (int r = 0; r < rank; r++)
1050+
{
1051+
lower[r] = rank - r - 3;
1052+
strides[r] = r + 1;
1053+
upper[r] = lower[r] + extents[r] - 3;
1054+
}
1055+
ind = CFI_section ((CFI_cdesc_t *) &section, NULL, lower, upper, strides);
1056+
if (ind != CFI_INVALID_DESCRIPTOR)
1057+
{
1058+
printf ("CFI_section: failed to detect that source is NULL.\n");
1059+
return 1;
1060+
}
1061+
ind = CFI_section (NULL, (CFI_cdesc_t *) &source, lower, upper, strides);
1062+
if (ind != CFI_INVALID_DESCRIPTOR)
1063+
{
1064+
printf ("CFI_section: failed to detect that section is NULL.\n");
1065+
return 1;
1066+
}
1067+
ind =
1068+
CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_allocatable,
1069+
type[3], elem_len, rank, NULL);
1070+
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1071+
upper, strides);
1072+
if (ind != CFI_INVALID_ATTRIBUTE)
1073+
{
1074+
printf ("CFI_section: failed to detect invalid attribute.\n");
1075+
return 1;
1076+
}
1077+
ind = CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_other,
1078+
type[3], elem_len, rank, NULL);
1079+
ind = CFI_deallocate ((CFI_cdesc_t *) &source);
1080+
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1081+
upper, strides);
1082+
if (ind != CFI_ERROR_BASE_ADDR_NULL)
1083+
{
1084+
printf ("CFI_section: failed to detect that the base address is NULL.\n");
1085+
return 1;
1086+
}
10761087
}
1088+
10771089
CFI_CDESC_T (0) section2, source2;
10781090
ind = CFI_establish ((CFI_cdesc_t *) &source2, &ind, CFI_attribute_other,
10791091
type[3], 0, 0, NULL);
@@ -1086,33 +1098,37 @@ int main (void)
10861098
printf ("CFI_section: failed to detect invalid rank.\n");
10871099
return 1;
10881100
}
1101+
10891102
ind = CFI_establish ((CFI_cdesc_t *) &source, NULL, CFI_attribute_allocatable,
10901103
type[3], 0, rank, extents);
10911104
ind = CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_other,
10921105
type[6], 0, rank, NULL);
10931106
ind = CFI_allocate ((CFI_cdesc_t *) &source, lower, upper, elem_len);
1094-
for (int r = 0; r < rank; r++)
1095-
{
1096-
lower[r] = rank - r - 3;
1097-
strides[r] = r + 1;
1098-
upper[r] = lower[r] + extents[r] - 3;
1099-
}
1100-
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1101-
upper, strides);
1102-
if (ind != CFI_INVALID_ELEM_LEN)
1107+
if (ind == CFI_SUCCESS)
11031108
{
1104-
printf ("CFI_section: failed to detect incompatible element lengths "
1105-
"between source and section.\n");
1106-
return 1;
1107-
}
1108-
ind = CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_other,
1109-
CFI_type_long, 0, rank, NULL);
1110-
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1111-
upper, strides);
1112-
if (ind != CFI_INVALID_TYPE)
1113-
{
1114-
printf ("CFI_section: failed to detect invalid type.\n");
1115-
return 1;
1109+
for (int r = 0; r < rank; r++)
1110+
{
1111+
lower[r] = rank - r - 3;
1112+
strides[r] = r + 1;
1113+
upper[r] = lower[r] + extents[r] - 3;
1114+
}
1115+
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1116+
upper, strides);
1117+
if (ind != CFI_INVALID_ELEM_LEN)
1118+
{
1119+
printf ("CFI_section: failed to detect incompatible element lengths "
1120+
"between source and section.\n");
1121+
return 1;
1122+
}
1123+
ind = CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_other,
1124+
CFI_type_long, 0, rank, NULL);
1125+
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1126+
upper, strides);
1127+
if (ind != CFI_INVALID_TYPE)
1128+
{
1129+
printf ("CFI_section: failed to detect invalid type.\n");
1130+
return 1;
1131+
}
11161132
}
11171133

11181134
for (int i = 1; i < CFI_MAX_RANK; i++)
@@ -1151,7 +1167,7 @@ int main (void)
11511167
CFI_establish ((CFI_cdesc_t *) &source, NULL,
11521168
CFI_attribute_allocatable, type[3], 0, rank, extents);
11531169
ind = CFI_allocate ((CFI_cdesc_t *) &source, lower, upper, elem_len);
1154-
if (ind == CFI_ERROR_MEM_ALLOCATION)
1170+
if (ind != CFI_SUCCESS)
11551171
{
11561172
continue;
11571173
}
@@ -1252,13 +1268,15 @@ int main (void)
12521268
ind = CFI_establish ((CFI_cdesc_t *) &section3, NULL, CFI_attribute_other,
12531269
type[3], 0, rank, NULL);
12541270
ind = CFI_allocate ((CFI_cdesc_t *) &source3, lower, upper, elem_len);
1255-
1256-
ind = CFI_section ((CFI_cdesc_t *) &section3, (CFI_cdesc_t *) &source3, upper,
1257-
lower, strides);
1258-
if (ind != CFI_SUCCESS && ind != CFI_INVALID_STRIDE)
1271+
if (ind == CFI_SUCCESS)
12591272
{
1260-
printf ("CFI_section: failed to detect invalid stride.\n");
1261-
return 1;
1273+
ind = CFI_section ((CFI_cdesc_t *) &section3, (CFI_cdesc_t *) &source3,
1274+
upper, lower, strides);
1275+
if (ind != CFI_SUCCESS && ind != CFI_INVALID_STRIDE)
1276+
{
1277+
printf ("CFI_section: failed to detect invalid stride.\n");
1278+
return 1;
1279+
}
12621280
}
12631281

12641282
/* CFI_select_part */

0 commit comments

Comments
 (0)