Karl Schultz | 929a100 | 2016-02-04 11:33:21 -0700 | [diff] [blame] | 1 | /* |
Jeremy Gebben | 018454b | 2022-07-08 14:48:50 -0600 | [diff] [blame] | 2 | * Copyright (c) 2015-2022 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2022 Valve Corporation |
| 4 | * Copyright (c) 2015-2022 LunarG, Inc. |
Karl Schultz | 929a100 | 2016-02-04 11:33:21 -0700 | [diff] [blame] | 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Karl Schultz | 929a100 | 2016-02-04 11:33:21 -0700 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Karl Schultz | 929a100 | 2016-02-04 11:33:21 -0700 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Karl Schultz | 929a100 | 2016-02-04 11:33:21 -0700 | [diff] [blame] | 17 | * |
| 18 | * Author: Chia-I Wu <olvaffe@gmail.com> |
| 19 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
| 20 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 21 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 22 | * Author: Mike Stroyan <mike@LunarG.com> |
| 23 | * Author: Tobin Ehlis <tobine@google.com> |
| 24 | * Author: Tony Barbour <tony@LunarG.com> |
| 25 | */ |
| 26 | |
Courtney Goeltzenleuchter | b7f5050 | 2014-08-12 14:09:50 -0600 | [diff] [blame] | 27 | #ifndef TEST_COMMON_H |
| 28 | #define TEST_COMMON_H |
| 29 | |
Jeremy Gebben | 018454b | 2022-07-08 14:48:50 -0600 | [diff] [blame] | 30 | #include <cassert> |
| 31 | #include <cstdio> |
| 32 | #include <cstdlib> |
| 33 | #include <cstring> |
| 34 | #include <thread> |
Courtney Goeltzenleuchter | b7f5050 | 2014-08-12 14:09:50 -0600 | [diff] [blame] | 35 | |
Mark Lobodzinski | 2031078 | 2020-02-28 14:25:17 -0700 | [diff] [blame] | 36 | #include "vk_layer_logging.h" |
| 37 | |
Ian Elliott | c11750d | 2015-10-30 13:24:12 -0600 | [diff] [blame] | 38 | #ifdef _WIN32 |
Mark Lobodzinski | 450e463 | 2015-11-24 12:04:15 -0700 | [diff] [blame] | 39 | // WinSock2.h must be included *BEFORE* windows.h |
| 40 | #include <winsock2.h> |
Ian Elliott | c11750d | 2015-10-30 13:24:12 -0600 | [diff] [blame] | 41 | #endif |
Mark Lobodzinski | faa9081 | 2015-11-25 13:26:15 -0700 | [diff] [blame] | 42 | |
Mark Lobodzinski | 103c58a | 2020-01-29 13:20:00 -0700 | [diff] [blame] | 43 | // sdk_platform header redefines NOMINMAX |
| 44 | #undef NOMINMAX |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 45 | #include <vulkan/vk_sdk_platform.h> |
Mark Lobodzinski | 6d4a6d9 | 2016-09-07 16:27:38 -0600 | [diff] [blame] | 46 | #include <vulkan/vulkan.h> |
Courtney Goeltzenleuchter | b7f5050 | 2014-08-12 14:09:50 -0600 | [diff] [blame] | 47 | |
Rémi Verschelde | 499f6df | 2020-04-01 16:17:19 +0200 | [diff] [blame] | 48 | #ifdef _MSC_VER |
Mark Lobodzinski | 6d4a6d9 | 2016-09-07 16:27:38 -0600 | [diff] [blame] | 49 | #pragma warning(push) |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 50 | /* |
| 51 | warnings 4251 and 4275 have to do with potential dll-interface mismatch |
| 52 | between library (gtest) and users. Since we build the gtest library |
| 53 | as part of the test build we know that the dll-interface will match and |
| 54 | can disable these warnings. |
| 55 | */ |
Mark Lobodzinski | 6d4a6d9 | 2016-09-07 16:27:38 -0600 | [diff] [blame] | 56 | #pragma warning(disable : 4251) |
| 57 | #pragma warning(disable : 4275) |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 58 | #endif |
Cody Northrop | 40354b8 | 2018-03-27 12:22:53 -0600 | [diff] [blame] | 59 | |
Mark Lobodzinski | 8bdb1f3 | 2018-03-27 17:14:34 -0600 | [diff] [blame] | 60 | // GTest and Xlib collide due to redefinitions of "None" and "Bool" |
| 61 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 62 | #pragma push_macro("None") |
| 63 | #pragma push_macro("Bool") |
| 64 | #undef None |
| 65 | #undef Bool |
| 66 | #endif |
| 67 | |
Cody Northrop | 40354b8 | 2018-03-27 12:22:53 -0600 | [diff] [blame] | 68 | // Use the NDK's header on Android |
| 69 | #ifndef __ANDROID__ |
Mark Lobodzinski | 42f743f | 2018-05-31 09:58:13 -0600 | [diff] [blame] | 70 | #include "gtest/gtest.h" |
Mark Lobodzinski | 8bdb1f3 | 2018-03-27 17:14:34 -0600 | [diff] [blame] | 71 | #else |
Mark Lobodzinski | 6d4a6d9 | 2016-09-07 16:27:38 -0600 | [diff] [blame] | 72 | #include "gtest/gtest.h" |
Mark Lobodzinski | 8bdb1f3 | 2018-03-27 17:14:34 -0600 | [diff] [blame] | 73 | #endif |
| 74 | |
| 75 | // Redefine Xlib definitions |
| 76 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 77 | #pragma pop_macro("Bool") |
| 78 | #pragma pop_macro("None") |
| 79 | #endif |
Cody Northrop | 40354b8 | 2018-03-27 12:22:53 -0600 | [diff] [blame] | 80 | |
Rémi Verschelde | 499f6df | 2020-04-01 16:17:19 +0200 | [diff] [blame] | 81 | #ifdef _MSC_VER |
Mark Lobodzinski | 6d4a6d9 | 2016-09-07 16:27:38 -0600 | [diff] [blame] | 82 | #pragma warning(pop) |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 83 | #endif |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 84 | #include "vktestbinding.h" |
Courtney Goeltzenleuchter | b7f5050 | 2014-08-12 14:09:50 -0600 | [diff] [blame] | 85 | |
Petr Kraus | 6bb16b4 | 2019-09-09 22:05:50 +0200 | [diff] [blame] | 86 | #define ASSERT_VK_SUCCESS(err) \ |
| 87 | { \ |
| 88 | const VkResult resolved_err = err; \ |
| 89 | ASSERT_EQ(VK_SUCCESS, resolved_err) << vk_result_string(resolved_err); \ |
| 90 | } |
Courtney Goeltzenleuchter | b7f5050 | 2014-08-12 14:09:50 -0600 | [diff] [blame] | 91 | |
Mark Lobodzinski | 6d4a6d9 | 2016-09-07 16:27:38 -0600 | [diff] [blame] | 92 | static inline const char *vk_result_string(VkResult err) { |
Courtney Goeltzenleuchter | b7f5050 | 2014-08-12 14:09:50 -0600 | [diff] [blame] | 93 | switch (err) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 94 | #define STR(r) \ |
| 95 | case r: \ |
Mark Lobodzinski | 6d4a6d9 | 2016-09-07 16:27:38 -0600 | [diff] [blame] | 96 | return #r |
| 97 | STR(VK_SUCCESS); |
| 98 | STR(VK_NOT_READY); |
| 99 | STR(VK_TIMEOUT); |
| 100 | STR(VK_EVENT_SET); |
| 101 | STR(VK_EVENT_RESET); |
Petr Kraus | 4a95f98 | 2020-03-10 01:04:00 +0100 | [diff] [blame] | 102 | STR(VK_INCOMPLETE); |
Mark Lobodzinski | 6d4a6d9 | 2016-09-07 16:27:38 -0600 | [diff] [blame] | 103 | STR(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 104 | STR(VK_ERROR_OUT_OF_DEVICE_MEMORY); |
Petr Kraus | 4a95f98 | 2020-03-10 01:04:00 +0100 | [diff] [blame] | 105 | STR(VK_ERROR_INITIALIZATION_FAILED); |
Mark Lobodzinski | 6d4a6d9 | 2016-09-07 16:27:38 -0600 | [diff] [blame] | 106 | STR(VK_ERROR_DEVICE_LOST); |
Mark Lobodzinski | 6d4a6d9 | 2016-09-07 16:27:38 -0600 | [diff] [blame] | 107 | STR(VK_ERROR_MEMORY_MAP_FAILED); |
Petr Kraus | 4a95f98 | 2020-03-10 01:04:00 +0100 | [diff] [blame] | 108 | STR(VK_ERROR_LAYER_NOT_PRESENT); |
| 109 | STR(VK_ERROR_EXTENSION_NOT_PRESENT); |
| 110 | STR(VK_ERROR_FEATURE_NOT_PRESENT); |
Mark Lobodzinski | 6d4a6d9 | 2016-09-07 16:27:38 -0600 | [diff] [blame] | 111 | STR(VK_ERROR_INCOMPATIBLE_DRIVER); |
Petr Kraus | 4a95f98 | 2020-03-10 01:04:00 +0100 | [diff] [blame] | 112 | STR(VK_ERROR_TOO_MANY_OBJECTS); |
| 113 | STR(VK_ERROR_FORMAT_NOT_SUPPORTED); |
| 114 | STR(VK_ERROR_FRAGMENTED_POOL); |
| 115 | STR(VK_ERROR_UNKNOWN); |
| 116 | STR(VK_ERROR_OUT_OF_POOL_MEMORY); |
| 117 | STR(VK_ERROR_INVALID_EXTERNAL_HANDLE); |
| 118 | STR(VK_ERROR_FRAGMENTATION); |
| 119 | STR(VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS); |
| 120 | STR(VK_ERROR_SURFACE_LOST_KHR); |
| 121 | STR(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR); |
| 122 | STR(VK_SUBOPTIMAL_KHR); |
| 123 | STR(VK_ERROR_OUT_OF_DATE_KHR); |
| 124 | STR(VK_ERROR_INCOMPATIBLE_DISPLAY_KHR); |
| 125 | STR(VK_ERROR_VALIDATION_FAILED_EXT); |
| 126 | STR(VK_ERROR_INVALID_SHADER_NV); |
| 127 | STR(VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT); |
| 128 | STR(VK_ERROR_NOT_PERMITTED_EXT); |
| 129 | STR(VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT); |
Courtney Goeltzenleuchter | b7f5050 | 2014-08-12 14:09:50 -0600 | [diff] [blame] | 130 | #undef STR |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 131 | default: |
| 132 | return "UNKNOWN_RESULT"; |
Courtney Goeltzenleuchter | b7f5050 | 2014-08-12 14:09:50 -0600 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
Mark Lobodzinski | 6d4a6d9 | 2016-09-07 16:27:38 -0600 | [diff] [blame] | 136 | static inline void test_error_callback(const char *expr, const char *file, unsigned int line, const char *function) { |
Chia-I Wu | a9a506a | 2014-12-27 22:04:00 +0800 | [diff] [blame] | 137 | ADD_FAILURE_AT(file, line) << "Assertion: `" << expr << "'"; |
| 138 | } |
| 139 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 140 | #endif // TEST_COMMON_H |