summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkev.h2
-rw-r--r--test/pkev.cpp102
2 files changed, 104 insertions, 0 deletions
diff --git a/pkev.h b/pkev.h
index 3e01d83..826e5d2 100644
--- a/pkev.h
+++ b/pkev.h
@@ -209,6 +209,7 @@ pk_ev_register_ev(pk_ev_mgr_id_T evmgr, void *user_ev_data)
new_size = PK_MAX(2, PK_MIN(255, pk_ev_mstr.mgrs[evmgr]->rn_ev * PK_EV_GROW_RATIO));
if (new_size == pk_ev_mstr.mgrs[evmgr]->rn_ev) {
PK_LOG_ERR("[pkev.h] need more room, but failed to grow ev count.\n");
+ mtx_unlock(&pk_ev_mstr.mtxs[evmgr]);
exit(1);
}
mgr = pk_ev_inner_ev_mgr_create(new_size, pk_ev_mstr.mgrs[evmgr]->rn_cb);
@@ -234,6 +235,7 @@ pk_ev_register_cb(pk_ev_mgr_id_T evmgr, pk_ev_id_T evid, pk_ev_cb_fn *cb, void *
new_size = PK_MAX(2, PK_MIN(255, pk_ev_mstr.mgrs[evmgr]->rn_cb * PK_EV_GROW_RATIO));
if (new_size == pk_ev_mstr.mgrs[evmgr]->rn_cb) {
PK_LOG_ERR("[pkev.h] need more room, but failed to grow cb count.\n");
+ mtx_unlock(&pk_ev_mstr.mtxs[evmgr]);
exit(1);
}
mgr = pk_ev_inner_ev_mgr_create(pk_ev_mstr.mgrs[evmgr]->rn_ev, new_size);
diff --git a/test/pkev.cpp b/test/pkev.cpp
index a1a3036..652f020 100644
--- a/test/pkev.cpp
+++ b/test/pkev.cpp
@@ -3,10 +3,27 @@
#include "../pkmacros.h"
+#include <csetjmp>
#include <cstdio>
#include <future>
#include <thread>
+static bool expected_exit = false;
+static bool caught = false;
+static jmp_buf jmp_env;
+// https://stackoverflow.com/questions/64190847/how-to-catch-a-call-to-exit-for-unit-testing
+// stub function
+void
+exit(int code)
+{
+ if (expected_exit) {
+ caught = true;
+ longjmp(jmp_env, 1);
+ } else {
+ _exit(code);
+ }
+}
+
struct ev {
pk_ev_mgr_id_T evmgr;
pk_ev_id_T evid;
@@ -160,5 +177,90 @@ int main(int argc, char *argv[])
if (any_false == true) exit(1);
}
+ // overload cbs and evs (enforce uint8_t limits)
+ do
+ {
+ int r;
+ const uint64_t cb_count = 256;
+ const uint64_t ev_count = 1;
+ struct ev evs[ev_count] = {{0}};
+ const pk_ev_mgr_id_T evmgr = test_setup();
+
+ r = setjmp(jmp_env);
+ if (r == 1) {
+ if (expected_exit == true && caught == true) {
+ expected_exit = false;
+ caught = false;
+ pk_ev_teardown();
+ PK_LOGV_INF("%s: successfully caught err.\n", __FILE__);
+ fflush(stdout);
+ fflush(stderr);
+ break;
+ } else {
+ goto uncaught_err;
+ }
+ }
+
+ for (i = 0; i < ev_count; ++i) {
+ evs[i].evmgr = evmgr;
+ evs[i].evid = pk_ev_register_ev(evmgr, NULL);
+ for (ii = 0; ii < cb_count; ++ii) {
+ caught = false;
+ expected_exit = true;
+ pk_ev_register_cb(evmgr, evs[i].evid, &stress_cb, NULL);
+ expected_exit = false;
+ caught = false;
+ }
+ }
+ goto uncaught_err;
+ }
+ while(false);
+
+ // overload cbs and evs (enforce uint8_t limits)
+ do
+ {
+ int r;
+ const uint64_t cb_count = 1;
+ const uint64_t ev_count = 256;
+ struct ev evs[ev_count] = {{0}};
+ const pk_ev_mgr_id_T evmgr = test_setup();
+
+ r = setjmp(jmp_env);
+ if (r == 1) {
+ if (expected_exit == true && caught == true) {
+ expected_exit = false;
+ caught = false;
+ pk_ev_teardown();
+ PK_LOGV_INF("%s: successfully caught err.\n", __FILE__);
+ fflush(stdout);
+ fflush(stderr);
+ break;
+ } else {
+ goto uncaught_err;
+ }
+ }
+
+ for (i = 0; i < ev_count; ++i) {
+ evs[i].evmgr = evmgr;
+ caught = false;
+ expected_exit = true;
+ evs[i].evid = pk_ev_register_ev(evmgr, NULL);
+ expected_exit = false;
+ caught = false;
+ for (ii = 0; ii < cb_count; ++ii) {
+ pk_ev_register_cb(evmgr, evs[i].evid, &stress_cb, NULL);
+ }
+ }
+
+ goto uncaught_err;
+
+ }
+ while(false);
+
return 0;
+uncaught_err:
+ PK_LOGV_ERR("%s: failed to catch err.\n", __FILE__);
+ fflush(stdout);
+ fflush(stderr);
+ return 1;
}