Skip to content

Commit 15e1fd2

Browse files
committed
Add test for correct bad malloc behavior
Signed-off-by: James Brodman <[email protected]>
1 parent 148185e commit 15e1fd2

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

sycl/test/usm/badmalloc.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %clangxx -fsycl %s -o %t1.out
2+
// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t1.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t1.out
5+
6+
//==----------------- badmalloc.cpp - Bad Mallocs test ---------------------==//
7+
//
8+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9+
// See https://llvm.org/LICENSE.txt for license information.
10+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
15+
// This test verifies that things fail in the proper way when they should.
16+
17+
#include <CL/sycl.hpp>
18+
19+
using namespace cl::sycl;
20+
21+
int main(int argc, char *argv[]) {
22+
queue q;
23+
24+
// Good size, bad type
25+
auto p = malloc(8, q, usm::alloc::unknown);
26+
assert(p == nullptr);
27+
28+
// Bad size, host
29+
p = malloc(-1, q, usm::alloc::host);
30+
assert(p == nullptr);
31+
32+
// Bad size, device
33+
p = malloc(-1, q, usm::alloc::device);
34+
assert(p == nullptr);
35+
36+
// Bad size, shared
37+
p = malloc(-1, q, usm::alloc::shared);
38+
assert(p == nullptr);
39+
40+
// Bad size, unknown
41+
p = malloc(-1, q, usm::alloc::unknown);
42+
assert(p == nullptr);
43+
44+
return 0;
45+
}

0 commit comments

Comments
 (0)