Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stack value error detection #511

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/caliper/common/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class Variant
// vector<unsigned char> data() const;

friend bool operator == (const Variant& lhs, const Variant& rhs);
friend bool operator != (const Variant& lhs, const Variant& rhs);
friend bool operator < (const Variant& lhs, const Variant& rhs);
friend bool operator > (const Variant& lhs, const Variant& rhs);
};
Expand All @@ -136,6 +137,10 @@ inline bool operator == (const Variant& lhs, const Variant& rhs) {
return cali_variant_eq(lhs.m_v, rhs.m_v);
}

inline bool operator != (const Variant& lhs, const Variant& rhs) {
return !cali_variant_eq(lhs.m_v, rhs.m_v);
}

inline bool operator < (const Variant& lhs, const Variant& rhs) {
return (cali_variant_compare(lhs.m_v, rhs.m_v) < 0);
}
Expand Down
9 changes: 3 additions & 6 deletions src/caliper/Caliper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ log_stack_value_error(const Entry& current, Attribute attr, const Variant& expec
error = "stack is empty";
else {
error = "current value is ";
error.append(attr.name());
error.append("=");
error.append(current.value().to_string());
}

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

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

if (current.entry.empty()) {
sT->stack_error = true;
return;
}

if (data != current.entry.value()) {
if (current.entry.empty() || data != current.entry.value()) {
log_stack_value_error(current.entry, attr, data);
sT->stack_error = true;
return;
Expand Down
14 changes: 9 additions & 5 deletions test/cali-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ void test_unclosed_region()
a.end();
}

void test_empty_stack()
{
cali_end_region("empty_stack_test");
}

int main(int argc, char* argv[])
{
cali_config_preset("CALI_CALIPER_ATTRIBUTE_PROPERTIES", "test-prop-preset=asvalue:process_scope");
Expand All @@ -255,8 +260,6 @@ int main(int argc, char* argv[])

test_instance();

CALI_CXX_MARK_FUNCTION;

const struct testcase_info_t {
const char* name;
void (*fn)();
Expand All @@ -273,12 +276,13 @@ int main(int argc, char* argv[])
{ "config-after-init", test_config_after_init },
{ "nesting-error", test_nesting_error },
{ "unclosed-region", test_unclosed_region },
{ "empty-stack", test_empty_stack },
{ 0, 0 }
};

{
cali::Annotation::Guard
g( cali::Annotation("cali-test").begin("checking") );
g( cali::Annotation("cali-test", CALI_ATTR_NOMERGE).begin("checking") );

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

cali::Annotation::Guard
g( cali::Annotation("cali-test").begin("testing") );
g( cali::Annotation("cali-test", CALI_ATTR_NOMERGE).begin("testing") );

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

cali::Annotation::Guard
g( cali::Annotation("cali-test.test").begin(t->name) );
g( cali::Annotation("cali-test.test", CALI_ATTR_NOMERGE).begin(t->name) );

print_padded(std::cout, t->name, 28) << " ... ";
(*(t->fn))();
Expand Down
Loading