From bf7aeb8d5b2beafa2180d389ab84f52d3b16ba0c Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Thu, 30 Nov 2017 21:43:16 +0100 Subject: Improved the pre-processor's handling of defines; added a special nested defines test --- test/correctness/misc/preprocessor.cpp | 46 ++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'test/correctness/misc') 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(e.status())); + fprintf(stdout, "* ERROR: Compilation warnings/errors with pre-processed kernel, status %d\n", + e.status()); return false; } catch (const 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" -- cgit v1.2.3