1 //===------- Offload API tests - gtest fixtures --==-----------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include <OffloadAPI.h> 10 #include <OffloadPrint.hpp> 11 #include <gtest/gtest.h> 12 13 #include "Environment.hpp" 14 15 #pragma once 16 17 #ifndef ASSERT_SUCCESS 18 #define ASSERT_SUCCESS(ACTUAL) ASSERT_EQ(OL_SUCCESS, ACTUAL) 19 #endif 20 21 // TODO: rework this so the EXPECTED/ACTUAL results are readable 22 #ifndef ASSERT_ERROR 23 #define ASSERT_ERROR(EXPECTED, ACTUAL) \ 24 do { \ 25 ol_result_t Res = ACTUAL; \ 26 ASSERT_TRUE(Res && (Res->Code == EXPECTED)); \ 27 } while (0) 28 #endif 29 30 #define RETURN_ON_FATAL_FAILURE(...) \ 31 __VA_ARGS__; \ 32 if (this->HasFatalFailure() || this->IsSkipped()) { \ 33 return; \ 34 } \ 35 (void)0 36 37 struct offloadTest : ::testing::Test { 38 // No special behavior now, but just in case we need to override it in future 39 }; 40 41 struct offloadPlatformTest : offloadTest { 42 void SetUp() override { 43 RETURN_ON_FATAL_FAILURE(offloadTest::SetUp()); 44 45 Platform = TestEnvironment::getPlatform(); 46 ASSERT_NE(Platform, nullptr); 47 } 48 49 ol_platform_handle_t Platform; 50 }; 51 52 struct offloadDeviceTest : offloadPlatformTest { 53 void SetUp() override { 54 RETURN_ON_FATAL_FAILURE(offloadPlatformTest::SetUp()); 55 56 uint32_t NumDevices; 57 ASSERT_SUCCESS(olGetDeviceCount(Platform, &NumDevices)); 58 if (NumDevices == 0) 59 GTEST_SKIP() << "No available devices on this platform."; 60 ASSERT_SUCCESS(olGetDevice(Platform, 1, &Device)); 61 } 62 63 ol_device_handle_t Device; 64 }; 65