|
| 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 | +// UNSUPPORTED: windows |
| 7 | + |
| 8 | +//==----------------- badmalloc.cpp - Bad Mallocs test ---------------------==// |
| 9 | +// |
| 10 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 11 | +// See https://llvm.org/LICENSE.txt for license information. |
| 12 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 13 | +// |
| 14 | +//===----------------------------------------------------------------------===// |
| 15 | + |
| 16 | + |
| 17 | +// This test verifies that things fail in the proper way when they should. |
| 18 | + |
| 19 | +#include <CL/sycl.hpp> |
| 20 | +#include <iostream> |
| 21 | + |
| 22 | +using namespace cl::sycl; |
| 23 | + |
| 24 | +int main(int argc, char *argv[]) { |
| 25 | + queue q; |
| 26 | + |
| 27 | + // Good size, bad type |
| 28 | + auto p = malloc(8, q, usm::alloc::unknown); |
| 29 | + if (p != nullptr) |
| 30 | + return 1; |
| 31 | + |
| 32 | + // Bad size, host |
| 33 | + p = malloc(-1, q, usm::alloc::host); |
| 34 | + std::cout << "p = " << p << std::endl; |
| 35 | + if (p != nullptr) |
| 36 | + return 2; |
| 37 | + p = malloc(-1, q, usm::alloc::device); |
| 38 | + std::cout << "p = " << p << std::endl; |
| 39 | + if (p != nullptr) |
| 40 | + return 3; |
| 41 | + p = malloc(-1, q, usm::alloc::shared); |
| 42 | + std::cout << "p = " << p << std::endl; |
| 43 | + if (p != nullptr) |
| 44 | + return 4; |
| 45 | + p = malloc(-1, q, usm::alloc::unknown); |
| 46 | + std::cout << "p = " << p << std::endl; |
| 47 | + if (p != nullptr) |
| 48 | + return 5; |
| 49 | + |
| 50 | + // Bad size, auto aligned |
| 51 | + p = aligned_alloc(0, -1, q, usm::alloc::host); |
| 52 | + std::cout << "p = " << p << std::endl; |
| 53 | + if (p != nullptr) |
| 54 | + return 6; |
| 55 | + p = aligned_alloc(0, -1, q, usm::alloc::device); |
| 56 | + std::cout << "p = " << p << std::endl; |
| 57 | + if (p != nullptr) |
| 58 | + return 7; |
| 59 | + p = aligned_alloc(0, -1, q, usm::alloc::shared); |
| 60 | + std::cout << "p = " << p << std::endl; |
| 61 | + if (p != nullptr) |
| 62 | + return 8; |
| 63 | + p = aligned_alloc(0, -1, q, usm::alloc::unknown); |
| 64 | + std::cout << "p = " << p << std::endl; |
| 65 | + if (p != nullptr) |
| 66 | + return 9; |
| 67 | + |
| 68 | + // Allocs of 0 undefined, but bad type |
| 69 | + p = aligned_alloc(4, 0, q, usm::alloc::unknown); |
| 70 | + std::cout << "p = " << p << std::endl; |
| 71 | + if (p != nullptr) |
| 72 | + return 10; |
| 73 | + |
| 74 | + return 0; |
| 75 | +} |
0 commit comments