Skip to content

Commit

Permalink
test: extent ALPAKA_CHECK to show better error messages
Browse files Browse the repository at this point in the history
To know where a test fails the line and file can be very usefull.
  • Loading branch information
psychocoderHPC committed Aug 1, 2022
1 parent 31993fc commit db3e11b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions include/alpaka/test/Check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,33 @@

#pragma once

#include <alpaka/core/BoostPredef.hpp>

#include <cstdio>

// TODO: SYCL doesn't have a way to detect if we're looking at device or host code. This needs a workaround so that
// SYCL and other back-ends are compatible.
#ifdef ALPAKA_ACC_SYCL_ENABLED
# define ALPAKA_CHECK(success, expression) \
# define ALPAKA_CHECK_DO(file, line, success, expression) \
do \
{ \
if(!(expression)) \
{ \
acc.cout << "ALPAKA_CHECK failed because '!(" << #expression << ")'\n"; \
acc.cout << "ALPAKA_CHECK failed because '!(" << #expression << ")' in " << file << ":" << line \
<< "\n"; \
success = false; \
} \
} while(0)
#else
# define ALPAKA_CHECK(success, expression) \
# define ALPAKA_CHECK_DO(file, line, success, expression) \
do \
{ \
if(!(expression)) \
{ \
printf("ALPAKA_CHECK failed because '!(%s)'\n", #expression); \
printf("ALPAKA_CHECK failed because '!(%s)' in %s:%d\n", #expression, file, line); \
success = false; \
} \
} while(0)
#endif

#define ALPAKA_CHECK(success, expression) ALPAKA_CHECK_DO(__FILE__, __LINE__, success, expression)

0 comments on commit db3e11b

Please sign in to comment.