libCom/test: Add epicsInlineTest
This commit is contained in:
@@ -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
|
||||
|
||||
64
src/libCom/test/epicsInlineTest1.c
Normal file
64
src/libCom/test/epicsInlineTest1.c
Normal 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();
|
||||
}
|
||||
28
src/libCom/test/epicsInlineTest2.c
Normal file
28
src/libCom/test/epicsInlineTest2.c
Normal 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);*/
|
||||
}
|
||||
27
src/libCom/test/epicsInlineTest3.cpp
Normal file
27
src/libCom/test/epicsInlineTest3.cpp
Normal 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);
|
||||
}
|
||||
27
src/libCom/test/epicsInlineTest4.cpp
Normal file
27
src/libCom/test/epicsInlineTest4.cpp
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user