libCom/test: Add epicsInlineTest

This commit is contained in:
Michael Davidsaver
2015-02-27 17:29:10 -05:00
parent b3bfac3f16
commit 84e9ff3bc5
6 changed files with 156 additions and 0 deletions

View File

@@ -22,6 +22,14 @@ epicsTypesTest_SRCS += epicsTypesTest.cpp
testHarness_SRCS += epicsTypesTest.cpp
TESTS += epicsTypesTest
TESTPROD_HOST += epicsInlineTest
epicsInlineTest_SRCS += epicsInlineTest1.c
epicsInlineTest_SRCS += epicsInlineTest2.c
epicsInlineTest_SRCS += epicsInlineTest3.cpp
epicsInlineTest_SRCS += epicsInlineTest4.cpp
testHarness_SRCS += $(epicsInlineTest_SRCS)
TESTS += epicsInlineTest
TESTPROD_HOST += epicsCalcTest
epicsCalcTest_SRCS += epicsCalcTest.cpp
testHarness_SRCS += epicsCalcTest.cpp

View File

@@ -0,0 +1,64 @@
/*************************************************************************\
* Copyright (c) 2015 Brookhaven Science Associates, as Operator of
* Brookhaven National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* This test checks the variations on inline function defintions.
*
* "static inline int func(void) {...}"
*
* Consistent meaning in C89, C99, and C++ (98 and 11).
* If not inline'd results in a private symbol in each compilation unit.
* Thus the non-inline'd version is duplicated in each compilation unit.
* However, definitions in different compilation units may be different.
*
* "inline int func(void) {...}"
* Warning: Not consistent, avoid use in headers meant for C or C++
*
* In C++ this may be safely defined in more than one compilation unit.
* Where not inlined it will result in a weak public symbol.
* Thus non-inline'd version isn't duplicated, but must be the same
* in all compilation units.
*
*/
#include "compilerSpecific.h"
#include "epicsUnitTest.h"
#include "testMain.h"
static EPICS_ALWAYS_INLINE int epicsInlineTestFn1(void)
{
return 1;
}
/* Fails to link in C99
inline int epicsInlineTestFn2(void)
{
return 42;
}
*/
void epicsInlineTest1(void)
{
testDiag("epicsInlineTest1()");
testOk1(epicsInlineTestFn1()==1);
/*testOk1(epicsInlineTestFn2()==42);*/
}
void epicsInlineTest2(void);
void epicsInlineTest3(void);
void epicsInlineTest4(void);
MAIN(epicsInlineTest)
{
testPlan(6);
testDiag("Test variation on inline int func()");
epicsInlineTest1();
epicsInlineTest2();
epicsInlineTest3();
epicsInlineTest4();
return testDone();
}

View File

@@ -0,0 +1,28 @@
/*************************************************************************\
* Copyright (c) 2015 Brookhaven Science Associates, as Operator of
* Brookhaven National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
#include "compilerSpecific.h"
#include "epicsUnitTest.h"
static EPICS_ALWAYS_INLINE int epicsInlineTestFn1(void)
{
return 2;
}
/* Fails to link in C99
inline int epicsInlineTestFn2(void)
{
return 42;
}
*/
void epicsInlineTest2(void)
{
testDiag("epicsInlineTest2()");
testOk1(epicsInlineTestFn1()==2);
/*testOk1(epicsInlineTestFn2()==42);*/
}

View File

@@ -0,0 +1,27 @@
/*************************************************************************\
* Copyright (c) 2015 Brookhaven Science Associates, as Operator of
* Brookhaven National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
#include "compilerSpecific.h"
#include "epicsUnitTest.h"
static EPICS_ALWAYS_INLINE int epicsInlineTestFn1(void)
{
return 3;
}
inline int epicsInlineTestFn2(void)
{
return 42;
}
extern "C"
void epicsInlineTest3(void)
{
testDiag("epicsInlineTest3()");
testOk1(epicsInlineTestFn1()==3);
testOk1(epicsInlineTestFn2()==42);
}

View File

@@ -0,0 +1,27 @@
/*************************************************************************\
* Copyright (c) 2015 Brookhaven Science Associates, as Operator of
* Brookhaven National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
#include "compilerSpecific.h"
#include "epicsUnitTest.h"
static EPICS_ALWAYS_INLINE int epicsInlineTestFn1(void)
{
return 4;
}
inline int epicsInlineTestFn2(void)
{
return 42;
}
extern "C"
void epicsInlineTest4(void)
{
testDiag("epicsInlineTest4()");
testOk1(epicsInlineTestFn1()==4);
testOk1(epicsInlineTestFn2()==42);
}

View File

@@ -44,6 +44,7 @@ int epicsThreadTest(void);
int epicsTimerTest(void);
int epicsTimeTest(void);
int epicsTypesTest(void);
int epicsInlineTest(void);
int macDefExpandTest(void);
int macLibTest(void);
int ringBytesTest(void);
@@ -92,6 +93,7 @@ void epicsRunLibComTests(void)
runTest(epicsThreadPrivateTest);
runTest(epicsTimeTest);
runTest(epicsTypesTest);
runTest(epicsInlineTest);
runTest(macDefExpandTest);
runTest(macLibTest);
runTest(ringBytesTest);