Skip to content

Commit 9a3d0e7

Browse files
committed
drivers/dstate.c, tests/driver_methods_utest.c: check that LB can be set and status set+commit+set+commit (without init in the middle) adds reported tokens [networkupstools#2934]
Signed-off-by: Jim Klimov <[email protected]>
1 parent 04a4023 commit 9a3d0e7

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

drivers/dstate.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,9 +1768,8 @@ int dstate_is_stale(void)
17681768
/* clean out the temp space for a new pass */
17691769
void status_init(void)
17701770
{
1771-
if (dstate_getinfo("driver.flag.ignorelb")) {
1772-
ignorelb = 1;
1773-
}
1771+
/* This does not normally change in driver run-time, but can in tests */
1772+
ignorelb = (dstate_getinfo("driver.flag.ignorelb") ? 1 : 0);
17741773

17751774
memset(status_buf, 0, sizeof(status_buf));
17761775
alarm_status = 0;

tests/driver_methods_utest.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ int main(int argc, char **argv) {
8585
status_set("OL BOOST");
8686
status_set("OB ");
8787
status_set(" BOOST");
88+
status_set(" LB"); /* Initial ignorelb==0 so this should get set */
8889
status_commit();
8990

9091
valueStr = dstate_getinfo("ups.status");
91-
report_0_means_pass(strcmp(valueStr, "OL BOOST OB"));
92+
report_0_means_pass(strcmp(valueStr, "OL BOOST OB LB"));
9293
printf(" test for ups.status: '%s'; got no duplicates?\n", NUT_STRARG(valueStr));
9394

9495
/* Test case #2 (built on top of #1)
@@ -104,7 +105,7 @@ int main(int argc, char **argv) {
104105
status_commit(); /* to register ALARM status */
105106

106107
valueStr = dstate_getinfo("ups.status");
107-
report_0_means_pass(strcmp(valueStr, "ALARM OL BOOST OB"));
108+
report_0_means_pass(strcmp(valueStr, "ALARM OL BOOST OB LB"));
108109
printf(" test for ups.status: '%s'; got alarm, no duplicates?\n", NUT_STRARG(valueStr));
109110

110111
/* Test case #3 (built on top of #2)
@@ -255,7 +256,7 @@ int main(int argc, char **argv) {
255256
status_init();
256257
status_set("OL BOOST");
257258
status_set("OB");
258-
status_set("LB"); /* Should be honoured */
259+
status_set("LB"); /* ignorelb should be honoured */
259260
status_commit();
260261

261262
valueStr = dstate_getinfo("ups.status");
@@ -327,6 +328,45 @@ int main(int argc, char **argv) {
327328
report_0_means_pass(strcmp(valueStr, "\0"));
328329
printf(" test for ups.status with alarm_ set, status_commit() before alarm_commit(): '%s'; got empty, no whitespace?\n", NUT_STRARG(valueStr));
329330

331+
/* Test cases #17+#18+#19+#20 (from scratch, checking data step by step)
332+
* Set and commit a status, then add and commit some more (without
333+
* a re-init). The resulting ups.status should contain all set tokens.
334+
*/
335+
/* NOTE: This is a flag, either present with any value (true) or absent */
336+
dstate_delinfo("driver.flag.ignorelb");
337+
338+
alarm_init();
339+
alarm_commit();
340+
status_init();
341+
status_set("OB");
342+
status_set("LB"); /* LB should be honoured when we do not ignorelb */
343+
344+
/* #17 */
345+
valueStr = dstate_getinfo("ups.status");
346+
report_0_means_pass(strcmp(valueStr, "\0"));
347+
printf(" test for ups.status empty after status_set() and before status_commit(): '%s'; got alarm, no duplicates?\n", NUT_STRARG(valueStr));
348+
349+
status_commit();
350+
351+
/* #18 */
352+
valueStr = dstate_getinfo("ups.status");
353+
report_0_means_pass(strcmp(valueStr, "OB LB"));
354+
printf(" test for ups.status with just OB and LB set via status_set() and committed: '%s'; got alarm, no duplicates?\n", NUT_STRARG(valueStr));
355+
356+
status_set("FSD");
357+
358+
/* #19 */
359+
valueStr = dstate_getinfo("ups.status");
360+
report_0_means_pass(strcmp(valueStr, "OB LB"));
361+
printf(" test for ups.status with next token set via status_set() but not yet committed: '%s'; got alarm, no duplicates?\n", NUT_STRARG(valueStr));
362+
363+
status_commit();
364+
365+
/* #20 */
366+
valueStr = dstate_getinfo("ups.status");
367+
report_0_means_pass(strcmp(valueStr, "OB LB FSD"));
368+
printf(" test for ups.status with FSD token set and now committed: '%s'; got alarm, no duplicates?\n", NUT_STRARG(valueStr));
369+
330370
/* Clear testing state before finishing. */
331371
alarm_init();
332372
alarm_commit();

0 commit comments

Comments
 (0)