test: atInitTest added.

This commit is contained in:
Jerzy Jamroz
2025-06-11 11:55:51 +02:00
committed by Andrew Johnson
parent 6683d81eb9
commit 455978d9fb
2 changed files with 71 additions and 0 deletions

View File

@@ -256,6 +256,11 @@ osiSockTest_SRCS += osiSockTest.c
testHarness_SRCS += osiSockTest.c
TESTS += osiSockTest
TESTPROD_HOST += atInitTest
atInitTest_SRCS += atInitTest.cpp
TESTS += atInitTest
testHarness_SRCS += atInitTest.cpp
TESTPROD_HOST += testexecname
testexecname_SRCS += testexecname.c
# no point in including in testHarness. Not implemented for RTEMS/vxWorks.

View File

@@ -0,0 +1,66 @@
#include <epicsThread.h>
#include <epicsUnitTest.h>
#include <initHooks.h>
#include <iocsh.h>
#include <libComRegister.h>
#include <stdlib.h>
#include <string.h>
#include <testMain.h>
void atInitTestEnv(const char *varName, const char *varValue)
{
const char *val = getenv(varName);
testOk(val && strcmp(val, varValue) == 0,
"%s=%s", varName, val ? val : "(null)");
}
MAIN(atInitTest)
{
testPlan(12);
libComRegister();
// Reset environment variables
iocshCmd("epicsEnvSet \"ATINIT_TEST_VAR\" \"BeforeIocInit\"");
iocshCmd("epicsEnvSet \"ATINIT_TEST_VAR_ONE\" \"BeforeIocInit\"");
iocshCmd("epicsEnvSet \"ATINIT_TEST_VAR_TWO\" \"BeforeIocInit\"");
printf("Test if the variables are 'BeforeIocInit'.\n");
atInitTestEnv("ATINIT_TEST_VAR", "BeforeIocInit");
atInitTestEnv("ATINIT_TEST_VAR_ONE", "BeforeIocInit");
atInitTestEnv("ATINIT_TEST_VAR_TWO", "BeforeIocInit");
// Basic test
iocshCmd("atInit \"epicsEnvSet ATINIT_TEST_VAR AfterIocInit\"");
iocshCmd("atInit \"epicsEnvSet ATINIT_TEST_VAR_ONE AfterIocInit\"");
iocshCmd("atInit \"epicsEnvSet ATINIT_TEST_VAR_TWO AfterIocInit\"");
iocshCmd("atInit \"date\"");
epicsThreadSleep(1.0);
// Verify error handling and robustness
iocshCmd("atInit \"nonexistentCommand arg1 arg2\"");
iocshCmd("atInit \"\""); // empty string
iocshCmd("atInit \" \""); // only spaces
printf("Test if the variables are 'BeforeIocInit' after execution 'atInit'.\n");
atInitTestEnv("ATINIT_TEST_VAR", "BeforeIocInit");
atInitTestEnv("ATINIT_TEST_VAR_ONE", "BeforeIocInit");
atInitTestEnv("ATINIT_TEST_VAR_TWO", "BeforeIocInit");
// Simulate iocInit
initHookAnnounce(initHookAfterIocRunning);
printf("=== iocInit Simulation ===\n");
epicsThreadSleep(1.0);
// Verify the results
printf("Test if the variables are 'AfterIocInit' after 'iocInit'.\n");
atInitTestEnv("ATINIT_TEST_VAR", "AfterIocInit");
atInitTestEnv("ATINIT_TEST_VAR_ONE", "AfterIocInit");
atInitTestEnv("ATINIT_TEST_VAR_TWO", "AfterIocInit");
testPass("Command 'date' executed");
testPass("Invalid command did not crash IOC");
testPass("Empty atInit commands do not cause failure");
return testDone();
}