From 1fe24d3a74a9cd51c4a025cd0e78642f3e29df79 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 14 Jun 2019 18:05:12 -0400 Subject: Runtime Shared Library compilation and testing (#985) * Removed the need for VisualStudio specific CPPCompiler Improved the version parsing for gcc/clang Removed need for slang-unix-cpp-compiler-util.cpp/.h Remove binary before compiling in the compile c tests * Moved VisualStudio calcArgs into CPPCompilerUtil - as code is not windows specific. * Set up compile time version for gcc and clang * Fix compilation on OSX - use remove instead of unlink for file deletion. * On OSX - clang uses different string format. * Removed /bin/sh invoking as not required for OSX. * First pass working testing with shared libraries. --- tests/cpp-compiler/c-compile-shared-library.c | 25 +++++++++++++++++++++++ tests/cpp-compiler/c-compile.c | 10 +++++++++ tests/cpp-compiler/c-compile.c.expected | 6 ++++++ tests/cpp-compiler/cpp-compile-shared-library.cpp | 23 +++++++++++++++++++++ tests/cpp-compiler/cpp-compile.cpp | 9 ++++++++ tests/cpp-compiler/cpp-compile.cpp.expected | 6 ++++++ 6 files changed, 79 insertions(+) create mode 100644 tests/cpp-compiler/c-compile-shared-library.c create mode 100644 tests/cpp-compiler/c-compile.c create mode 100644 tests/cpp-compiler/c-compile.c.expected create mode 100644 tests/cpp-compiler/cpp-compile-shared-library.cpp create mode 100644 tests/cpp-compiler/cpp-compile.cpp create mode 100644 tests/cpp-compiler/cpp-compile.cpp.expected (limited to 'tests/cpp-compiler') diff --git a/tests/cpp-compiler/c-compile-shared-library.c b/tests/cpp-compiler/c-compile-shared-library.c new file mode 100644 index 000000000..8b6be6115 --- /dev/null +++ b/tests/cpp-compiler/c-compile-shared-library.c @@ -0,0 +1,25 @@ +//TEST(smoke):CPP_COMPILER_SHARED_LIBRARY: + +#include +#include +#include + +#if defined(_MSC_VER) +# define DLL_EXPORT __declspec(dllexport) +#else +//# define DLL_EXPORT +# define DLL_EXPORT __attribute__ ((dllexport)) __attribute__((__visibility__("default"))) +#endif + +#ifdef __cplusplus +#define EXTERN_C extern "C" +#else +#define EXTERN_C +#endif + +EXTERN_C DLL_EXPORT int test(int intValue, const char* textValue, char* outTextValue) +{ + strcpy(outTextValue, textValue); + return intValue; +} + diff --git a/tests/cpp-compiler/c-compile.c b/tests/cpp-compiler/c-compile.c new file mode 100644 index 000000000..75fdbdaa4 --- /dev/null +++ b/tests/cpp-compiler/c-compile.c @@ -0,0 +1,10 @@ +//TEST(smoke):CPP_COMPILER_EXECUTE: + +#include +#include + +int main(int argc, char** argv) +{ + printf("Hello World!\n"); + return 0; +} diff --git a/tests/cpp-compiler/c-compile.c.expected b/tests/cpp-compiler/c-compile.c.expected new file mode 100644 index 000000000..0e042b53b --- /dev/null +++ b/tests/cpp-compiler/c-compile.c.expected @@ -0,0 +1,6 @@ +result code = 0 +standard error = { +} +standard output = { +Hello World! +} diff --git a/tests/cpp-compiler/cpp-compile-shared-library.cpp b/tests/cpp-compiler/cpp-compile-shared-library.cpp new file mode 100644 index 000000000..8b70f258d --- /dev/null +++ b/tests/cpp-compiler/cpp-compile-shared-library.cpp @@ -0,0 +1,23 @@ +//TEST(smoke):CPP_COMPILER_SHARED_LIBRARY: + +//#include + +#include +#include +#include + +#include +using namespace std; + +#if defined(_MSC_VER) +# define DLL_EXPORT __declspec(dllexport) +#else +# define DLL_EXPORT __attribute__((__visibility__("default"))) +#endif + +extern "C" DLL_EXPORT int test(int intValue, const char* textValue, char* outTextValue) +{ + strcpy(outTextValue, textValue); + return intValue; +} + diff --git a/tests/cpp-compiler/cpp-compile.cpp b/tests/cpp-compiler/cpp-compile.cpp new file mode 100644 index 000000000..c3141a876 --- /dev/null +++ b/tests/cpp-compiler/cpp-compile.cpp @@ -0,0 +1,9 @@ +//TEST(smoke):CPP_COMPILER_EXECUTE: +#include +using namespace std; + +int main(int argc, char** argv) +{ + cout << "Hello World!" << endl; + return 0; +} diff --git a/tests/cpp-compiler/cpp-compile.cpp.expected b/tests/cpp-compiler/cpp-compile.cpp.expected new file mode 100644 index 000000000..0e042b53b --- /dev/null +++ b/tests/cpp-compiler/cpp-compile.cpp.expected @@ -0,0 +1,6 @@ +result code = 0 +standard error = { +} +standard output = { +Hello World! +} -- cgit v1.2.3