nwnss: cover audited fsm and latch runtimes
This commit is contained in:
@@ -599,7 +599,7 @@ even if it already compiles or has indirect test coverage.
|
||||
|
||||
| Status | Kind | Test coverage | File | Notes |
|
||||
|---|---:|---|---|---|
|
||||
| AUDITED | ORIG+FIX/PORT | link smoke | `src/nwnss/library/fsm/fsmnw.c` | Compared with original `public_core/library/fsm/fsmnw.c`; ready-queue/mailbox logic kept. Userspace port disables kernel worker threads (`NUM_FSM_THREADS=0`) and initializes a local interrupt mailbox; other changes are include-path fixes and callback casts. |
|
||||
| AUDITED | ORIG+FIX/PORT | nwnss.fsm | `src/nwnss/library/fsm/fsmnw.c` | Compared with original `public_core/library/fsm/fsmnw.c`; ready-queue/mailbox logic kept. Userspace port disables kernel worker threads (`NUM_FSM_THREADS=0`) and initializes a local interrupt mailbox; tests cover startup/shutdown, ready-queue FIFO draining, counters, empty drain behavior, and mailbox release. Other changes are include-path fixes and callback casts. |
|
||||
|
||||
### Sources: library/guid
|
||||
|
||||
@@ -617,8 +617,8 @@ even if it already compiles or has indirect test coverage.
|
||||
|
||||
| Status | Kind | Test coverage | File | Notes |
|
||||
|---|---:|---|---|---|
|
||||
| AUDITED | ORIG+FIX | link smoke | `src/nwnss/library/latch/intlatch.c` | Compared with original `public_core/library/latch/intlatch.c`; latch wait logic kept. Differences are include-path normalization and trailing whitespace. |
|
||||
| AUDITED | ORIG+FIX | link smoke | `src/nwnss/library/latch/latch.c` | Compared with original `public_core/library/latch/latch.c`; debug/latch body kept. Differences are include-path normalization, kernel header removal for userspace build, and whitespace cleanup. |
|
||||
| AUDITED | ORIG+FIX | nwnss.latch | `src/nwnss/library/latch/intlatch.c` | Compared with original `public_core/library/latch/intlatch.c`; latch wait logic kept. Tests cover internal init, exclusive latch, and release on the non-waiting path. Differences are include-path normalization and trailing whitespace. |
|
||||
| AUDITED | ORIG+FIX | nwnss.latch | `src/nwnss/library/latch/latch.c` | Compared with original `public_core/library/latch/latch.c`; debug/latch body kept. Tests cover shared/exclusive init, shared count transitions, up/down conversion, conditional latch/unlatch, no-wait exclusive acquisition, and final free-state invariants. Differences are include-path normalization, kernel header removal for userspace build, and whitespace cleanup. |
|
||||
|
||||
### Sources: library/misc
|
||||
|
||||
|
||||
@@ -1,36 +1,97 @@
|
||||
#include <include/fsm.h>
|
||||
#include <public/zError.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
extern STATUS fsmStart(void);
|
||||
extern void fsmWorkToDo(void);
|
||||
extern void fsmStop(void);
|
||||
extern unsigned FsmMax;
|
||||
extern unsigned NumFsmThreads;
|
||||
extern unsigned MaxFsmThreads;
|
||||
|
||||
#define CHECK(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
return 1; \
|
||||
return EXIT_FAILURE; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int fsm_ran;
|
||||
static int fsm_order;
|
||||
static int fsm_trace[4];
|
||||
static int fsm_failed;
|
||||
|
||||
static void test_action(FsmLite_s *fsm)
|
||||
{
|
||||
fsm_ran += (int)fsm->param.count;
|
||||
}
|
||||
|
||||
static void ordered_action(FsmLite_s *fsm)
|
||||
{
|
||||
if (fsm_order >= 4) {
|
||||
fsm_failed = 1;
|
||||
return;
|
||||
}
|
||||
fsm_trace[fsm_order++] = (int)fsm->param.count;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FsmLite_s fsm;
|
||||
FsmLite_s fsm_a;
|
||||
FsmLite_s fsm_b;
|
||||
FsmLite_s fsm_c;
|
||||
|
||||
CHECK(fsmStart() == zOK);
|
||||
CHECK(FsmReadyQ == NULL);
|
||||
CHECK(NumFsmThreads == 0);
|
||||
CHECK(MaxFsmThreads == 0);
|
||||
|
||||
FSMLITE_INIT(&fsm, "test", 1);
|
||||
CHECK(fsm.action == NULL);
|
||||
CHECK(fsm.param.user == 0);
|
||||
#if NSS_DEBUG IS_ENABLED
|
||||
CHECK(fsm.type != NULL);
|
||||
CHECK(fsm.instance == 1);
|
||||
#endif
|
||||
|
||||
fsm.param.count = 7;
|
||||
FSM_ACTIVATE(&fsm, test_action);
|
||||
CHECK(fsm_ran == 0);
|
||||
CHECK(FsmReadyQ != NULL);
|
||||
fsmWorkToDo();
|
||||
CHECK(fsm_ran == 7);
|
||||
fsmStop();
|
||||
CHECK(FsmReadyQ == NULL);
|
||||
CHECK(NumFsmThreads == 0);
|
||||
CHECK(MaxFsmThreads >= 1);
|
||||
CHECK(FsmMax >= 1);
|
||||
|
||||
return 0;
|
||||
FSMLITE_INIT(&fsm_a, "order", 10);
|
||||
FSMLITE_INIT(&fsm_b, "order", 11);
|
||||
FSMLITE_INIT(&fsm_c, "order", 12);
|
||||
fsm_a.param.count = 1;
|
||||
fsm_b.param.count = 2;
|
||||
fsm_c.param.count = 3;
|
||||
FSM_ACTIVATE(&fsm_a, ordered_action);
|
||||
FSM_ACTIVATE(&fsm_b, ordered_action);
|
||||
FSM_ACTIVATE(&fsm_c, ordered_action);
|
||||
CHECK(fsm_order == 0);
|
||||
fsmWorkToDo();
|
||||
CHECK(!fsm_failed);
|
||||
CHECK(fsm_order == 3);
|
||||
CHECK(fsm_trace[0] == 1);
|
||||
CHECK(fsm_trace[1] == 2);
|
||||
CHECK(fsm_trace[2] == 3);
|
||||
CHECK(FsmMax >= 3);
|
||||
CHECK(FsmReadyQ == NULL);
|
||||
|
||||
fsmWorkToDo();
|
||||
CHECK(fsm_order == 3);
|
||||
CHECK(NumFsmThreads == 0);
|
||||
|
||||
fsmStop();
|
||||
/* fsmStop releases the mailbox storage; it intentionally does not
|
||||
* clear the original NSS mailbox pointers. */
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include <include/latch.h>
|
||||
#include <library/intlatch.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define CHECK(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
return 1; \
|
||||
return EXIT_FAILURE; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -15,24 +16,51 @@ int main(void)
|
||||
|
||||
INIT_LATCH(&latch);
|
||||
CHECK(LATCH_FREE(&latch));
|
||||
CHECK(!IS_LATCHED(&latch));
|
||||
CHECK(GET_LATCH_TYPE(&latch) == NOTLATCHED);
|
||||
|
||||
S_LATCH(&latch);
|
||||
CHECK(IS_SLATCHED(&latch));
|
||||
CHECK(IS_LATCHED(&latch));
|
||||
CHECK(IS_LAST_SLATCH(&latch));
|
||||
CHECK(GET_LATCH_TYPE(&latch) == SLATCHED);
|
||||
ADD_LATCH(&latch);
|
||||
CHECK(latch.count == 2);
|
||||
CHECK(!IS_LAST_SLATCH(&latch));
|
||||
UNS_LATCH(&latch);
|
||||
CHECK(latch.count == 1);
|
||||
UNS_LATCH(&latch);
|
||||
CHECK(LATCH_FREE(&latch));
|
||||
|
||||
INIT_S_LATCH(&latch, 3);
|
||||
CHECK(IS_SLATCHED(&latch));
|
||||
CHECK(latch.count == 3);
|
||||
UNS_LATCH(&latch);
|
||||
CHECK(latch.count == 2);
|
||||
UNS_LATCH(&latch);
|
||||
CHECK(latch.count == 1);
|
||||
UN_LATCH(&latch);
|
||||
CHECK(LATCH_FREE(&latch));
|
||||
|
||||
X_NOWAIT(&latch, nowait);
|
||||
CHECK(nowait == NOWAIT);
|
||||
CHECK(IS_XLATCHED(&latch));
|
||||
CHECK(GET_LATCH_TYPE(&latch) == XLATCHED);
|
||||
DOWN_LATCH(&latch);
|
||||
CHECK(IS_SLATCHED(&latch));
|
||||
CHECK(GET_LATCH_TYPE(&latch) == SLATCHED);
|
||||
UN_LATCH(&latch);
|
||||
CHECK(LATCH_FREE(&latch));
|
||||
|
||||
COND_LATCH(&latch, SLATCHED);
|
||||
CHECK(IS_SLATCHED(&latch));
|
||||
COND_UNLATCH(&latch, SLATCHED);
|
||||
CHECK(LATCH_FREE(&latch));
|
||||
COND_LATCH(&latch, NOTLATCHED);
|
||||
CHECK(LATCH_FREE(&latch));
|
||||
COND_UNLATCH(&latch, NOTLATCHED);
|
||||
CHECK(LATCH_FREE(&latch));
|
||||
|
||||
LB__internalInitLatch(&latch);
|
||||
CHECK(LATCH_FREE(&latch));
|
||||
LB__internalXLatch(&latch);
|
||||
@@ -40,5 +68,5 @@ int main(void)
|
||||
LB__internalUnXLatch(&latch);
|
||||
CHECK(LATCH_FREE(&latch));
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user