Skip to content

Commit bc10fd9

Browse files
committed
Address Brett's comments
1 parent 5a07940 commit bc10fd9

File tree

7 files changed

+157
-121
lines changed

7 files changed

+157
-121
lines changed

port/posix/posix_timeout.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,9 @@ int posixTimeout_Init(void* context, const void* config)
5656
return WH_ERROR_BADARGS;
5757
}
5858

59-
/* Already initialized? */
60-
if (ctx->initialized) {
61-
return WH_ERROR_OK;
62-
}
63-
6459
ctx->startUs = 0;
6560
ctx->timeoutUs = (cfg != NULL) ? cfg->timeoutUs : 0;
66-
ctx->started = 0;
61+
ctx->running = 0;
6762

6863
ctx->initialized = 1;
6964
return WH_ERROR_OK;
@@ -77,14 +72,9 @@ int posixTimeout_Cleanup(void* context)
7772
return WH_ERROR_BADARGS;
7873
}
7974

80-
/* Not initialized? */
81-
if (!ctx->initialized) {
82-
return WH_ERROR_OK;
83-
}
84-
8575
ctx->startUs = 0;
8676
ctx->timeoutUs = 0;
87-
ctx->started = 0;
77+
ctx->running = 0;
8878
ctx->initialized = 0;
8979

9080
return WH_ERROR_OK;
@@ -99,7 +89,7 @@ int posixTimeout_Set(void* context, uint64_t timeoutUs)
9989
}
10090

10191
if (!ctx->initialized) {
102-
return WH_ERROR_NOTREADY;
92+
return WH_ERROR_BADARGS;
10393
}
10494

10595
ctx->timeoutUs = timeoutUs;
@@ -116,11 +106,11 @@ int posixTimeout_Start(void* context)
116106
}
117107

118108
if (!ctx->initialized) {
119-
return WH_ERROR_NOTREADY;
109+
return WH_ERROR_BADARGS;
120110
}
121111

122112
ctx->startUs = _getMonotonicTimeUs();
123-
ctx->started = 1;
113+
ctx->running = 1;
124114

125115
return WH_ERROR_OK;
126116
}
@@ -134,11 +124,11 @@ int posixTimeout_Stop(void* context)
134124
}
135125

136126
if (!ctx->initialized) {
137-
return WH_ERROR_NOTREADY;
127+
return WH_ERROR_BADARGS;
138128
}
139129

140130
ctx->startUs = 0;
141-
ctx->started = 0;
131+
ctx->running = 0;
142132

143133
return WH_ERROR_OK;
144134
}
@@ -153,11 +143,11 @@ int posixTimeout_Expired(void* context, int* expired)
153143
}
154144

155145
if (!ctx->initialized) {
156-
return WH_ERROR_NOTREADY;
146+
return WH_ERROR_BADARGS;
157147
}
158148

159149
/* Not started or no timeout configured = not expired */
160-
if (!ctx->started || (ctx->timeoutUs == 0)) {
150+
if (!ctx->running || (ctx->timeoutUs == 0)) {
161151
*expired = 0;
162152
return WH_ERROR_OK;
163153
}

port/posix/posix_timeout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef struct posixTimeoutConfig_t {
4343
typedef struct posixTimeoutContext_t {
4444
uint64_t startUs; /* Snapshot of start time */
4545
uint64_t timeoutUs; /* Configured timeout duration */
46-
int started; /* 1 if timer is running, 0 otherwise */
46+
int running; /* 1 if timer is running, 0 otherwise */
4747
int initialized; /* 1 if initialized, 0 otherwise */
4848
} posixTimeoutContext;
4949

test/wh_test.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ int whTest_Unit(void)
7474
/* Component Tests */
7575
WH_TEST_ASSERT(0 == whTest_Flash_RamSim());
7676
WH_TEST_ASSERT(0 == whTest_NvmFlash());
77-
#ifdef WOLFHSM_CFG_ENABLE_TIMEOUT
78-
WH_TEST_ASSERT(0 == whTest_Timeout());
79-
#endif
8077
#ifdef WOLFHSM_CFG_LOGGING
8178
WH_TEST_ASSERT(0 == whTest_Log());
8279
#endif
@@ -124,6 +121,10 @@ int whTest_Unit(void)
124121

125122
#endif /* !WOLFHSM_CFG_NO_CRYPTO */
126123

124+
#if defined(WOLFHSM_CFG_ENABLE_TIMEOUT) && defined(WOLFHSM_CFG_TEST_POSIX)
125+
WH_TEST_ASSERT(0 == whTest_TimeoutPosix());
126+
#endif
127+
127128
return 0;
128129
}
129130
#endif /* WOLFHSM_CFG_ENABLE_CLIENT && WOLFHSM_CFG_ENABLE_SERVER */
@@ -157,6 +158,10 @@ int whTest_ClientConfig(whClientConfig* clientCfg)
157158
WH_TEST_RETURN_ON_FAIL(whTest_WolfCryptTestCfg(clientCfg));
158159
#endif /* WOLFHSM_CFG_TEST_WOLFCRYPTTEST */
159160

161+
#if defined(WOLFHSM_CFG_ENABLE_TIMEOUT)
162+
WH_TEST_RETURN_ON_FAIL(whTest_TimeoutClientConfig(clientCfg));
163+
#endif /* WOLFHSM_CFG_ENABLE_TIMEOUT */
164+
160165
return WH_ERROR_OK;
161166
}
162167

0 commit comments

Comments
 (0)