libCom/test: Added epicsEnvTest.c

VxWorks 6.x can make environment variables private to each
thread, which doesn't work too well.
A test failure on VxWorks explains how to change the image
configuration to fix this.
This commit is contained in:
Andrew Johnson
2013-12-16 12:48:25 -06:00
parent 88ae947c84
commit a50c66b6ff
4 changed files with 94 additions and 1 deletions
+8 -1
View File
@@ -1,5 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
@@ -14,6 +13,14 @@
<!-- Insert new items immediately below here ... -->
<h3>New test for environment variables</h3>
<p>A new test program epicsEnvTest has been added to the libCom tests which
checks environment variable APIs. It was written to confirm that threads see
environment variable values that have been set in their parent thread. VxWorks
6.x boot images must be configured with ENV_VAR_USE_HOOKS set to FALSE for the
correct behaviour to occur (a test failure on VxWorks explains this).</p>
<h3>Inclusion of &lt;top&gt;/cfg/* files refined</h3>
<p>The way the build system includes files installed in the &lt;top&gt;/cfg/*
+5
View File
@@ -37,6 +37,11 @@ epicsEllTest_SRCS += epicsEllTest.c
testHarness_SRCS += epicsEllTest.c
TESTS += epicsEllTest
TESTPROD_HOST += epicsEnvTest
epicsEnvTest_SRCS += epicsEnvTest.c
testHarness_SRCS += epicsEnvTest.c
TESTS += epicsEnvTest
TESTPROD_HOST += epicsErrlogTest
epicsErrlogTest_SRCS += epicsErrlogTest.c
testHarness_SRCS += epicsErrlogTest.c
+78
View File
@@ -0,0 +1,78 @@
/*************************************************************************\
* Copyright (c) 2013 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* epicsEnvTest.c */
/* Author: Andrew Johnson
* Date: 2013-12-13
*/
/* Check environment variable APIs.
* TODO: Add tests for envDefs.h routines.
*
* The thread test is needed on VxWorks 6.x, where the OS can be
* configured to maintain separate, totally independent sets
* of environment variables for each thread. This configuration
* is not supported by EPICS which expects child threads to at
* least inherit the partent thread's environment variables.
*/
#include <stdlib.h>
#include <string.h>
#include "envDefs.h"
#include "epicsThread.h"
#include "epicsUnitTest.h"
#include "testMain.h"
#define PARENT "Parent"
#define CHILD "Child"
static void child(void *arg)
{
const char *value = getenv(PARENT);
if (!testOk(value && (strcmp(value, PARENT) == 0),
"Child thread sees parent environment values")) {
#ifdef vxWorks
testDiag("VxWorks image needs ENV_VAR_USE_HOOKS configured as FALSE");
#else
testDiag("Check OS configuration, environment inheritance needed");
#endif
}
epicsEnvSet(CHILD, CHILD);
}
MAIN(epicsEnvTest)
{
unsigned int stackSize = epicsThreadGetStackSize(epicsThreadStackSmall);
const char *value;
testPlan(3);
epicsEnvSet(PARENT, PARENT);
value = getenv(PARENT);
if (!testOk(value && (strcmp(value, PARENT) == 0),
"epicsEnvSet correctly modifies environment"))
testAbort("environment variables not working");
epicsThreadCreate("child", 50, stackSize, child, NULL);
epicsThreadSleep(0.1);
value = getenv(CHILD);
if (value && (strcmp(value, CHILD) == 0))
testDiag("Child and parent threads share a common environment");
value = getenv(PARENT);
testOk(value && (strcmp(value, PARENT) == 0),
"PARENT environment variable not modified");
testDone();
return 0;
}
+3
View File
@@ -20,6 +20,7 @@ int epicsThreadTest(void);
int epicsTimerTest(void);
int epicsAlgorithm(void);
int epicsEllTest(void);
int epicsEnvTest(void);
int epicsErrlogTest(void);
int epicsCalcTest(void);
int epicsEventTest(void);
@@ -60,6 +61,8 @@ void epicsRunLibComTests(void)
runTest(epicsEllTest);
runTest(epicsEnvTest);
runTest(epicsErrlogTest);
runTest(epicsCalcTest);