Skip to content

Commit

Permalink
cleanup(tests): add some exception in sinsp test framework
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <andreaterzolo3@gmail.com>
  • Loading branch information
Andreagit97 authored and poiana committed Nov 5, 2024
1 parent 41e4444 commit 1340321
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions userspace/libscap/scap_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ int32_t scap_event_encode_params_v(const struct scap_sized_buffer event_buf,
}
break;
default:
ASSERT(false);
snprintf(error,
SCAP_LASTERR_SIZE,
"unexpected param %d length %zu for event with type %d",
Expand Down
10 changes: 8 additions & 2 deletions userspace/libsinsp/test/sinsp_with_test_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ scap_evt* sinsp_with_test_input::create_event_v(uint64_t ts,

if(ret != SCAP_INPUT_TOO_SMALL) {
va_end(args2);
return nullptr;
throw std::runtime_error(std::string("cannot compute the size of the event: ") + error);
}

event_buf.buf = malloc(event_size);
Expand All @@ -127,7 +127,7 @@ scap_evt* sinsp_with_test_input::create_event_v(uint64_t ts,
free(event_buf.buf);
event_buf.size = 0;
va_end(args2);
return nullptr;
throw std::runtime_error(std::string("cannot encode the event: ") + error);
}

scap_evt* event = static_cast<scap_evt*>(event_buf.buf);
Expand All @@ -150,6 +150,12 @@ scap_evt* sinsp_with_test_input::add_event_v(uint64_t ts,
}

scap_evt* event = create_event_v(ts, tid, event_type, n, args);
if(event == nullptr) {
std::stringstream ss;
ss << "cannot create event type: " << event_type << ", ts: " << ts << ", tid: " << tid
<< ", n: " << n;
throw std::runtime_error(ss.str());
}

uint64_t evtoffset = m_events.size() - m_test_data.event_count;
m_events.push_back(event);
Expand Down

0 comments on commit 1340321

Please sign in to comment.