blob: 891508daa3a2f690312c397822d83face5a24bf4 [file] [log] [blame]
Karl Schultz929a1002016-02-04 11:33:21 -07001/*
Jeremy Gebben018454b2022-07-08 14:48:50 -06002 * Copyright (c) 2015-2022 The Khronos Group Inc.
3 * Copyright (c) 2015-2022 Valve Corporation
4 * Copyright (c) 2015-2022 LunarG, Inc.
Karl Schultz929a1002016-02-04 11:33:21 -07005 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06006 * 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 Schultz929a1002016-02-04 11:33:21 -07009 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz929a1002016-02-04 11:33:21 -070011 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060012 * 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 Schultz929a1002016-02-04 11:33:21 -070017 *
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 Goeltzenleuchterb7f50502014-08-12 14:09:50 -060027#ifndef TEST_COMMON_H
28#define TEST_COMMON_H
29
Jeremy Gebben018454b2022-07-08 14:48:50 -060030#include <cassert>
31#include <cstdio>
32#include <cstdlib>
33#include <cstring>
34#include <thread>
Courtney Goeltzenleuchterb7f50502014-08-12 14:09:50 -060035
Mark Lobodzinski20310782020-02-28 14:25:17 -070036#include "vk_layer_logging.h"
37
Ian Elliottc11750d2015-10-30 13:24:12 -060038#ifdef _WIN32
Mark Lobodzinski450e4632015-11-24 12:04:15 -070039// WinSock2.h must be included *BEFORE* windows.h
40#include <winsock2.h>
Ian Elliottc11750d2015-10-30 13:24:12 -060041#endif
Mark Lobodzinskifaa90812015-11-25 13:26:15 -070042
Mark Lobodzinski103c58a2020-01-29 13:20:00 -070043// sdk_platform header redefines NOMINMAX
44#undef NOMINMAX
David Pinedo9316d3b2015-11-06 12:54:48 -070045#include <vulkan/vk_sdk_platform.h>
Mark Lobodzinski6d4a6d92016-09-07 16:27:38 -060046#include <vulkan/vulkan.h>
Courtney Goeltzenleuchterb7f50502014-08-12 14:09:50 -060047
Rémi Verschelde499f6df2020-04-01 16:17:19 +020048#ifdef _MSC_VER
Mark Lobodzinski6d4a6d92016-09-07 16:27:38 -060049#pragma warning(push)
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060050/*
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 Lobodzinski6d4a6d92016-09-07 16:27:38 -060056#pragma warning(disable : 4251)
57#pragma warning(disable : 4275)
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060058#endif
Cody Northrop40354b82018-03-27 12:22:53 -060059
Mark Lobodzinski8bdb1f32018-03-27 17:14:34 -060060// 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 Northrop40354b82018-03-27 12:22:53 -060068// Use the NDK's header on Android
69#ifndef __ANDROID__
Mark Lobodzinski42f743f2018-05-31 09:58:13 -060070#include "gtest/gtest.h"
Mark Lobodzinski8bdb1f32018-03-27 17:14:34 -060071#else
Mark Lobodzinski6d4a6d92016-09-07 16:27:38 -060072#include "gtest/gtest.h"
Mark Lobodzinski8bdb1f32018-03-27 17:14:34 -060073#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 Northrop40354b82018-03-27 12:22:53 -060080
Rémi Verschelde499f6df2020-04-01 16:17:19 +020081#ifdef _MSC_VER
Mark Lobodzinski6d4a6d92016-09-07 16:27:38 -060082#pragma warning(pop)
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060083#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060084#include "vktestbinding.h"
Courtney Goeltzenleuchterb7f50502014-08-12 14:09:50 -060085
Petr Kraus6bb16b42019-09-09 22:05:50 +020086#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 Goeltzenleuchterb7f50502014-08-12 14:09:50 -060091
Mark Lobodzinski6d4a6d92016-09-07 16:27:38 -060092static inline const char *vk_result_string(VkResult err) {
Courtney Goeltzenleuchterb7f50502014-08-12 14:09:50 -060093 switch (err) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070094#define STR(r) \
95 case r: \
Mark Lobodzinski6d4a6d92016-09-07 16:27:38 -060096 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 Kraus4a95f982020-03-10 01:04:00 +0100102 STR(VK_INCOMPLETE);
Mark Lobodzinski6d4a6d92016-09-07 16:27:38 -0600103 STR(VK_ERROR_OUT_OF_HOST_MEMORY);
104 STR(VK_ERROR_OUT_OF_DEVICE_MEMORY);
Petr Kraus4a95f982020-03-10 01:04:00 +0100105 STR(VK_ERROR_INITIALIZATION_FAILED);
Mark Lobodzinski6d4a6d92016-09-07 16:27:38 -0600106 STR(VK_ERROR_DEVICE_LOST);
Mark Lobodzinski6d4a6d92016-09-07 16:27:38 -0600107 STR(VK_ERROR_MEMORY_MAP_FAILED);
Petr Kraus4a95f982020-03-10 01:04:00 +0100108 STR(VK_ERROR_LAYER_NOT_PRESENT);
109 STR(VK_ERROR_EXTENSION_NOT_PRESENT);
110 STR(VK_ERROR_FEATURE_NOT_PRESENT);
Mark Lobodzinski6d4a6d92016-09-07 16:27:38 -0600111 STR(VK_ERROR_INCOMPATIBLE_DRIVER);
Petr Kraus4a95f982020-03-10 01:04:00 +0100112 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 Goeltzenleuchterb7f50502014-08-12 14:09:50 -0600130#undef STR
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700131 default:
132 return "UNKNOWN_RESULT";
Courtney Goeltzenleuchterb7f50502014-08-12 14:09:50 -0600133 }
134}
135
Mark Lobodzinski6d4a6d92016-09-07 16:27:38 -0600136static inline void test_error_callback(const char *expr, const char *file, unsigned int line, const char *function) {
Chia-I Wua9a506a2014-12-27 22:04:00 +0800137 ADD_FAILURE_AT(file, line) << "Assertion: `" << expr << "'";
138}
139
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700140#endif // TEST_COMMON_H