Preserve ignored error snapshots
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "akerror.h"
|
||||
#include "err_capture.h"
|
||||
#include <string.h>
|
||||
|
||||
/* IGNORE logs and releases an error, then lets execution continue. */
|
||||
/* IGNORE snapshots and logs an error, releases its pool slot, then continues. */
|
||||
|
||||
akerr_ErrorContext *boom(void)
|
||||
{
|
||||
@@ -18,10 +19,14 @@ int main(void)
|
||||
(void)e;
|
||||
|
||||
/* More failures than the pool has slots must remain safe: a leaking
|
||||
* IGNORE used to exhaust the pool and terminate the process here. */
|
||||
* IGNORE used to exhaust the pool and terminate the process here. The
|
||||
* copied snapshot must also survive the slot being reused on the next
|
||||
* iteration. */
|
||||
for ( int i = 0; i < AKERR_MAX_ARRAY_ERROR + 1; i++ ) {
|
||||
IGNORE(boom());
|
||||
AKERR_CHECK(__akerr_last_ignored == NULL);
|
||||
AKERR_CHECK(__akerr_last_ignored.status == AKERR_VALUE);
|
||||
AKERR_CHECK(strcmp(__akerr_last_ignored.message,
|
||||
"this error is ignored on purpose") == 0);
|
||||
AKERR_CHECK(akerr_slots_in_use() == 0);
|
||||
}
|
||||
reached_after_ignore = 1;
|
||||
|
||||
@@ -90,6 +90,9 @@ static void one_checkout(akerr_ThreadArg *arg)
|
||||
static void *pool_body(void *raw)
|
||||
{
|
||||
akerr_ThreadArg *arg = raw;
|
||||
char expected[64];
|
||||
|
||||
snprintf(expected, sizeof(expected), "ignored by thread %d", arg->id);
|
||||
pthread_barrier_wait(arg->barrier);
|
||||
|
||||
for ( int i = 0; i < ITERATIONS; i++ ) {
|
||||
@@ -97,10 +100,21 @@ static void *pool_body(void *raw)
|
||||
one_checkout(arg);
|
||||
}
|
||||
|
||||
/* IGNORE's scratch pointer is thread-local while logging and cleared after
|
||||
/* IGNORE's snapshot is thread-local while logging and remains valid after
|
||||
* release. Concurrent ignored errors must all return their pool slots. */
|
||||
IGNORE(ignorable(arg));
|
||||
AKERR_TCHECK(arg, __akerr_last_ignored == NULL);
|
||||
AKERR_TCHECK(arg, __akerr_last_ignored.status == AKERR_IO);
|
||||
AKERR_TCHECK(arg, strcmp(__akerr_last_ignored.message, expected) == 0);
|
||||
|
||||
/* Reuse a slot after IGNORE and prove that the copied snapshot did not
|
||||
* become an alias for the newly acquired context. */
|
||||
akerr_ErrorContext *reused = akerr_next_error();
|
||||
AKERR_TCHECK(arg, reused != NULL);
|
||||
if ( reused != NULL ) {
|
||||
RELEASE_ERROR(reused);
|
||||
}
|
||||
AKERR_TCHECK(arg, __akerr_last_ignored.status == AKERR_IO);
|
||||
AKERR_TCHECK(arg, strcmp(__akerr_last_ignored.message, expected) == 0);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user