Skip to content

Commit 065c22e

Browse files
author
Andrew Savonichev
authored
[SYCL] Fix devicelib assert LIT test (#1245)
Split PI_TRACE output and an assert error message into different files. Otherwise they sometimes interleave and fail to match. Signed-off-by: Andrew Savonichev <[email protected]>
1 parent f953fda commit 065c22e

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

sycl/test/devicelib/assert-windows.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
// explicitly. Since the test is going to crash, we'll have to follow a similar
1515
// approach as on Linux - call the test in a subprocess.
1616
//
17-
// RUN: env SYCL_PI_TRACE=1 SYCL_DEVICELIB_INHIBIT_NATIVE=1 SYCL_DEVICE_TYPE=CPU CL_CONFIG_USE_VECTORIZER=False %t.out >%t.stdout.fallback 2>%t.stderr.fallback
18-
// RUN: FileCheck %s --check-prefix=CHECK-MESSAGE --input-file %t.stdout.fallback
17+
// RUN: env SYCL_PI_TRACE=1 SYCL_DEVICELIB_INHIBIT_NATIVE=1 CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU %t.out >%t.stdout.pi.fallback
18+
// RUN: env SHOULD_CRASH=1 SYCL_DEVICELIB_INHIBIT_NATIVE=1 CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU %t.out >%t.stdout.msg.fallback
19+
//
20+
// RUN: FileCheck %s --check-prefix=CHECK-MESSAGE --input-file %t.stdout.msg.fallback
1921
// CHECK-MESSAGE: {{.*}}assert-windows.cpp:{{[0-9]+}}: (null): global id: [{{[0-3]}},0,0], local id: [{{[0-3]}},0,0] Assertion `accessorC[wiID] == 0 && "Invalid value"` failed.
2022
//
21-
// RUN: FileCheck %s --input-file %t.stdout.fallback --check-prefix=CHECK-FALLBACK
23+
// RUN: FileCheck %s --input-file %t.stdout.pi.fallback --check-prefix=CHECK-FALLBACK
2224
// CHECK-FALLBACK: ---> piProgramLink
2325

2426
#include <CL/sycl.hpp>
@@ -45,6 +47,8 @@ void simple_vadd(const std::array<T, N> &VA, const std::array<T, N> &VB,
4547
}
4648
});
4749

50+
int shouldCrash = getenv("SHOULD_CRASH") ? 1 : 0;
51+
4852
cl::sycl::range<1> numOfItems{N};
4953
cl::sycl::buffer<T, 1> bufferA(VA.data(), numOfItems);
5054
cl::sycl::buffer<T, 1> bufferB(VB.data(), numOfItems);
@@ -57,7 +61,9 @@ void simple_vadd(const std::array<T, N> &VA, const std::array<T, N> &VB,
5761

5862
cgh.parallel_for<class SimpleVaddT>(numOfItems, [=](cl::sycl::id<1> wiID) {
5963
accessorC[wiID] = accessorA[wiID] + accessorB[wiID];
60-
assert(accessorC[wiID] == 0 && "Invalid value");
64+
if (shouldCrash) {
65+
assert(accessorC[wiID] == 0 && "Invalid value");
66+
}
6167
});
6268
});
6369
deviceQueue.wait_and_throw();

sycl/test/devicelib/assert.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
// the message can still be buffered by stdio. We turn the bufferization
5757
// off explicitly.
5858
//
59+
// 4. We want to check both compilation flow in (1) and the message in (3),
60+
// but these messages can interleave and fail to match. To avoid this,
61+
// first run with SYCL_PI_TRACE and collect a trace, and then with
62+
// SHOULD_CRASH (without SYCL_PI_TRACE) to collect an error message.
63+
//
5964
// SYCL_DEVICELIB_INHIBIT_NATIVE=1 environment variable is used to force a mode
6065
// in SYCL Runtime, so it doesn't look into a device extensions list and always
6166
// link the fallback library.
@@ -70,12 +75,14 @@
7075
//
7176
// Overall this sounds stable enough. What could possibly go wrong?
7277
//
73-
// RUN: env SYCL_PI_TRACE=1 CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU EXPECTED_SIGNAL=SIGABRT SKIP_IF_NO_EXT=1 %t.out 2>%t.stderr.native >%t.stdout.native
78+
// RUN: env SYCL_PI_TRACE=1 SHOULD_CRASH=1 CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU EXPECTED_SIGNAL=SIGABRT SKIP_IF_NO_EXT=1 %t.out 2>%t.stderr.native >%t.stdout.native
7479
// RUN: FileCheck %s --input-file %t.stdout.native --check-prefixes=CHECK-NATIVE || FileCheck %s --input-file %t.stderr.native --check-prefix CHECK-NOTSUPPORTED
7580
// RUN: FileCheck %s --input-file %t.stderr.native --check-prefixes=CHECK-MESSAGE || FileCheck %s --input-file %t.stderr.native --check-prefix CHECK-NOTSUPPORTED
7681
//
77-
// RUN: env SYCL_PI_TRACE=1 SYCL_DEVICELIB_INHIBIT_NATIVE=cl_intel_devicelib_assert CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU EXPECTED_SIGNAL=SIGSEGV %t.out 2>%t.stderr.fallback >%t.stdout.fallback
78-
// RUN: FileCheck %s --input-file %t.stdout.fallback --check-prefixes=CHECK-FALLBACK,CHECK-MESSAGE
82+
// RUN: env SYCL_PI_TRACE=1 SYCL_DEVICELIB_INHIBIT_NATIVE=cl_intel_devicelib_assert CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU EXPECTED_SIGNAL=SIGSEGV %t.out >%t.stdout.pi.fallback
83+
// RUN: env SHOULD_CRASH=1 SYCL_DEVICELIB_INHIBIT_NATIVE=cl_intel_devicelib_assert CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU EXPECTED_SIGNAL=SIGSEGV %t.out >%t.stdout.msg.fallback
84+
// RUN: FileCheck %s --input-file %t.stdout.pi.fallback --check-prefixes=CHECK-FALLBACK
85+
// RUN: FileCheck %s --input-file %t.stdout.msg.fallback --check-prefixes=CHECK-MESSAGE
7986
//
8087
// CHECK-NATIVE: ---> piProgramBuild
8188
// CHECK-FALLBACK: ---> piProgramLink
@@ -134,6 +141,8 @@ void simple_vadd(const std::array<T, N> &VA, const std::array<T, N> &VB,
134141
exit(EXIT_SKIP_TEST);
135142
}
136143

144+
int shouldCrash = getenv("SHOULD_CRASH") ? 1 : 0;
145+
137146
cl::sycl::range<1> numOfItems{N};
138147
cl::sycl::buffer<T, 1> bufferA(VA.data(), numOfItems);
139148
cl::sycl::buffer<T, 1> bufferB(VB.data(), numOfItems);
@@ -146,7 +155,9 @@ void simple_vadd(const std::array<T, N> &VA, const std::array<T, N> &VB,
146155

147156
cgh.parallel_for<class SimpleVaddT>(numOfItems, [=](cl::sycl::id<1> wiID) {
148157
accessorC[wiID] = accessorA[wiID] + accessorB[wiID];
149-
assert(accessorC[wiID] == 0 && "Invalid value");
158+
if (shouldCrash) {
159+
assert(accessorC[wiID] == 0 && "Invalid value");
160+
}
150161
});
151162
});
152163
deviceQueue.wait_and_throw();
@@ -160,9 +171,19 @@ int main() {
160171
if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SKIP_TEST) {
161172
return 0;
162173
}
163-
if (!WIFSIGNALED(status)) {
164-
fprintf(stderr, "error: process did not terminate by a signal\n");
165-
return 1;
174+
if (getenv("SHOULD_CRASH")) {
175+
if (!WIFSIGNALED(status)) {
176+
fprintf(stderr, "error: process did not terminate by a signal\n");
177+
return 1;
178+
}
179+
} else {
180+
if (WIFSIGNALED(status)) {
181+
fprintf(stderr, "error: process should not terminate\n");
182+
return 1;
183+
}
184+
// We should not check anything if the child finished successful and this
185+
// was expected.
186+
return 0;
166187
}
167188
int sig = WTERMSIG(status);
168189
int expected = 0;

0 commit comments

Comments
 (0)