| 1 |
/* |
| 2 |
* (C) Copyright 2024- ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
#include <functional> |
| 11 |
#include <iostream> |
| 12 |
#include <utility> |
| 13 |
#include <vector> |
| 14 |
|
| 15 |
#include "hic/hic.h" |
| 16 |
|
| 17 |
// ----------------------------------------------------------------------------- |
| 18 |
|
| 19 |
int test_hicMalloc() { |
| 20 |
std::cout << "--- " << __FUNCTION__ << std::endl; |
| 21 |
void* p; |
| 22 |
HIC_CALL(hicMalloc(&p, 8)); |
| 23 |
HIC_CALL(hicFree(p)); |
| 24 |
std::cout << "--- " << __FUNCTION__ << " SUCCEEDED " << std::endl; |
| 25 |
return 0; // success |
| 26 |
} |
| 27 |
|
| 28 |
// ----------------------------------------------------------------------------- |
| 29 |
|
| 30 |
int test_hicMallocManaged() { |
| 31 |
std::cout << "--- " << __FUNCTION__ << std::endl; |
| 32 |
void* p; |
| 33 |
HIC_CALL(hicMallocManaged(&p, 8)); |
| 34 |
HIC_CALL(hicFree(p)); |
| 35 |
std::cout << "--- " << __FUNCTION__ << " SUCCEEDED " << std::endl; |
| 36 |
return 0; // success |
| 37 |
} |
| 38 |
|
| 39 |
// ----------------------------------------------------------------------------- |
| 40 |
|
| 41 |
std::vector<std::function<int()>> tests = { |
| 42 |
test_hicMalloc, |
| 43 |
test_hicMallocManaged, |
| 44 |
}; |
| 45 |
|
| 46 |
int main(int argc, char* argv[]) { |
| 47 |
int num_devices = 0; |
| 48 |
hicGetDeviceCount(&num_devices); |
| 49 |
if (num_devices == 0) { |
| 50 |
std::ignore = hicGetLastError(); |
| 51 |
std::cout << "TEST IGNORED, hicGetDeviceCount -> 0" << std::endl; |
| 52 |
return 0; |
| 53 |
} |
| 54 |
std::cout << "hicGetDeviceCount -> " << num_devices << std::endl; |
| 55 |
int error = 0; |
| 56 |
for (auto& test : tests) { |
| 57 |
try { |
| 58 |
error += test(); |
| 59 |
} |
| 60 |
catch (std::exception& e) { |
| 61 |
error += 1; |
| 62 |
std::cout << e.what() << std::endl; |
| 63 |
} |
| 64 |
} |
| 65 |
return error; |
| 66 |
} |