From 84e9ff3bc5236c36ed0fa741a67df4d1e595502f Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 27 Feb 2015 17:29:10 -0500 Subject: [PATCH] libCom/test: Add epicsInlineTest --- src/libCom/test/Makefile | 8 ++++ src/libCom/test/epicsInlineTest1.c | 64 +++++++++++++++++++++++++++ src/libCom/test/epicsInlineTest2.c | 28 ++++++++++++ src/libCom/test/epicsInlineTest3.cpp | 27 +++++++++++ src/libCom/test/epicsInlineTest4.cpp | 27 +++++++++++ src/libCom/test/epicsRunLibComTests.c | 2 + 6 files changed, 156 insertions(+) create mode 100644 src/libCom/test/epicsInlineTest1.c create mode 100644 src/libCom/test/epicsInlineTest2.c create mode 100644 src/libCom/test/epicsInlineTest3.cpp create mode 100644 src/libCom/test/epicsInlineTest4.cpp diff --git a/src/libCom/test/Makefile b/src/libCom/test/Makefile index 3a3d32a8f..e0c1b064c 100755 --- a/src/libCom/test/Makefile +++ b/src/libCom/test/Makefile @@ -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 diff --git a/src/libCom/test/epicsInlineTest1.c b/src/libCom/test/epicsInlineTest1.c new file mode 100644 index 000000000..e377e5f1d --- /dev/null +++ b/src/libCom/test/epicsInlineTest1.c @@ -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(); +} diff --git a/src/libCom/test/epicsInlineTest2.c b/src/libCom/test/epicsInlineTest2.c new file mode 100644 index 000000000..b787276fb --- /dev/null +++ b/src/libCom/test/epicsInlineTest2.c @@ -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);*/ +} diff --git a/src/libCom/test/epicsInlineTest3.cpp b/src/libCom/test/epicsInlineTest3.cpp new file mode 100644 index 000000000..9647be6dc --- /dev/null +++ b/src/libCom/test/epicsInlineTest3.cpp @@ -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); +} diff --git a/src/libCom/test/epicsInlineTest4.cpp b/src/libCom/test/epicsInlineTest4.cpp new file mode 100644 index 000000000..545b45ffd --- /dev/null +++ b/src/libCom/test/epicsInlineTest4.cpp @@ -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); +} diff --git a/src/libCom/test/epicsRunLibComTests.c b/src/libCom/test/epicsRunLibComTests.c index 5bf6cafd1..fe308b061 100644 --- a/src/libCom/test/epicsRunLibComTests.c +++ b/src/libCom/test/epicsRunLibComTests.c @@ -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);