summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2017-11-30 21:43:16 +0100
committerCedric Nugteren <web@cedricnugteren.nl>2017-11-30 21:43:16 +0100
commitbf7aeb8d5b2beafa2180d389ab84f52d3b16ba0c (patch)
tree002f71334b20d424f9d25568fe5251486b153079 /test
parent13eb772343c46109da0181db3bdc6fa436a9dcce (diff)
Improved the pre-processor's handling of defines; added a special nested defines test
Diffstat (limited to 'test')
-rw-r--r--test/correctness/misc/preprocessor.cpp46
1 files changed, 44 insertions, 2 deletions
diff --git a/test/correctness/misc/preprocessor.cpp b/test/correctness/misc/preprocessor.cpp
index 3f7a2e13..cea91116 100644
--- a/test/correctness/misc/preprocessor.cpp
+++ b/test/correctness/misc/preprocessor.cpp
@@ -24,6 +24,45 @@
namespace clblast {
// =================================================================================================
+bool TestDefines() {
+ const auto source1 =
+ R"(
+ #define VAR1
+ #define VAR2 32
+ #if VAR2 == 32
+ #ifndef VAR1
+ #define ERROR
+ #ifdef VAR1
+ #define ERROR
+ #endif
+ #else
+ #if VAR2 == 32 || VAR3 == 4
+ #define SUCCESS
+ #else
+ #define ERROR
+ #endif
+ #define SUCCESS
+ #endif
+ #endif
+ #ifndef VAR3
+ #define SUCCESS
+ #else
+ #define ERROR
+ #endif
+ )";
+ const auto expected1 =
+ " #define VAR1\n"
+ " #define VAR2 32\n"
+ " #define SUCCESS\n"
+ " #define SUCCESS\n"
+ " #define SUCCESS\n"
+ " \n";
+ const auto result1 = PreprocessKernelSource(source1);
+ return result1 == expected1;
+}
+
+// =================================================================================================
+
bool TestKernel(const Device& device, const Context& context,
const std::string &kernel_name, const std::string &kernel_source,
const Precision precision) {
@@ -42,8 +81,8 @@ bool TestKernel(const Device& device, const Context& context,
device, context, compiler_options, true);
return true;
} catch (const CLCudaAPIBuildError &e) {
- fprintf(stdout, "* ERROR: Compilation warnings/errors with pre-processed kernel, status %zu\n",
- static_cast<size_t>(e.status()));
+ fprintf(stdout, "* ERROR: Compilation warnings/errors with pre-processed kernel, status %d\n",
+ e.status());
return false;
} catch (const Error<std::runtime_error> &e) {
fprintf(stdout, "* ERROR: Pre-processor error, message:\n%s\n", e.what());
@@ -69,6 +108,9 @@ size_t RunPreprocessor(int argc, char *argv[], const bool silent, const Precisio
const auto device = Device(platform, device_id);
const auto context = Context(device);
+ // Basic tests
+ if (TestDefines()) { passed++; } else { errors++; }
+
// XAXPY
const auto xaxpy_sources =
"#define WPT 2\n"