Skip to content

Commit 7094755

Browse files
authored
Fix stack value error detection (LLNL#511)
1 parent 93c073c commit 7094755

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

include/caliper/common/Variant.h

+5
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class Variant
128128
// vector<unsigned char> data() const;
129129

130130
friend bool operator == (const Variant& lhs, const Variant& rhs);
131+
friend bool operator != (const Variant& lhs, const Variant& rhs);
131132
friend bool operator < (const Variant& lhs, const Variant& rhs);
132133
friend bool operator > (const Variant& lhs, const Variant& rhs);
133134
};
@@ -136,6 +137,10 @@ inline bool operator == (const Variant& lhs, const Variant& rhs) {
136137
return cali_variant_eq(lhs.m_v, rhs.m_v);
137138
}
138139

140+
inline bool operator != (const Variant& lhs, const Variant& rhs) {
141+
return !cali_variant_eq(lhs.m_v, rhs.m_v);
142+
}
143+
139144
inline bool operator < (const Variant& lhs, const Variant& rhs) {
140145
return (cali_variant_compare(lhs.m_v, rhs.m_v) < 0);
141146
}

src/caliper/Caliper.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ log_stack_value_error(const Entry& current, Attribute attr, const Variant& expec
635635
error = "stack is empty";
636636
else {
637637
error = "current value is ";
638+
error.append(attr.name());
639+
error.append("=");
638640
error.append(current.value().to_string());
639641
}
640642

@@ -1063,12 +1065,7 @@ Caliper::end_with_value_check(const Attribute& attr, const Variant& data)
10631065

10641066
auto current = load_current_entry(attr, key, *blackboard, sG->allow_region_overlap);
10651067

1066-
if (current.entry.empty()) {
1067-
sT->stack_error = true;
1068-
return;
1069-
}
1070-
1071-
if (data != current.entry.value()) {
1068+
if (current.entry.empty() || data != current.entry.value()) {
10721069
log_stack_value_error(current.entry, attr, data);
10731070
sT->stack_error = true;
10741071
return;

test/cali-test.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ void test_unclosed_region()
247247
a.end();
248248
}
249249

250+
void test_empty_stack()
251+
{
252+
cali_end_region("empty_stack_test");
253+
}
254+
250255
int main(int argc, char* argv[])
251256
{
252257
cali_config_preset("CALI_CALIPER_ATTRIBUTE_PROPERTIES", "test-prop-preset=asvalue:process_scope");
@@ -255,8 +260,6 @@ int main(int argc, char* argv[])
255260

256261
test_instance();
257262

258-
CALI_CXX_MARK_FUNCTION;
259-
260263
const struct testcase_info_t {
261264
const char* name;
262265
void (*fn)();
@@ -273,12 +276,13 @@ int main(int argc, char* argv[])
273276
{ "config-after-init", test_config_after_init },
274277
{ "nesting-error", test_nesting_error },
275278
{ "unclosed-region", test_unclosed_region },
279+
{ "empty-stack", test_empty_stack },
276280
{ 0, 0 }
277281
};
278282

279283
{
280284
cali::Annotation::Guard
281-
g( cali::Annotation("cali-test").begin("checking") );
285+
g( cali::Annotation("cali-test", CALI_ATTR_NOMERGE).begin("checking") );
282286

283287
// check for missing/misspelled command line test cases
284288
for (int a = 1; a < argc; ++a) {
@@ -293,7 +297,7 @@ int main(int argc, char* argv[])
293297
}
294298

295299
cali::Annotation::Guard
296-
g( cali::Annotation("cali-test").begin("testing") );
300+
g( cali::Annotation("cali-test", CALI_ATTR_NOMERGE).begin("testing") );
297301

298302
for (const testcase_info_t* t = testcases; t->fn; ++t) {
299303
if (argc > 1) {
@@ -307,7 +311,7 @@ int main(int argc, char* argv[])
307311
}
308312

309313
cali::Annotation::Guard
310-
g( cali::Annotation("cali-test.test").begin(t->name) );
314+
g( cali::Annotation("cali-test.test", CALI_ATTR_NOMERGE).begin(t->name) );
311315

312316
print_padded(std::cout, t->name, 28) << " ... ";
313317
(*(t->fn))();

0 commit comments

Comments
 (0)