Path: blob/main_old/src/tests/test_utils/angle_test_instantiate.h
1693 views
//1// Copyright 2014 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56// angle_test_instantiate.h: Adds support for filtering parameterized7// tests by platform, so we skip unsupported configs.89#ifndef ANGLE_TEST_INSTANTIATE_H_10#define ANGLE_TEST_INSTANTIATE_H_1112#include <gtest/gtest.h>1314#include "common/platform.h"1516namespace angle17{18struct SystemInfo;19struct PlatformParameters;2021// Operating systems22bool IsAndroid();23bool IsLinux();24bool IsOSX();25bool IsIOS();26bool IsOzone();27bool IsWindows();28bool IsWindows7();29bool IsFuchsia();3031// CPU architectures32bool IsARM64();3334// Android devices35bool IsNexus5X();36bool IsNexus9();37bool IsPixelXL();38bool IsPixel2();39bool IsPixel2XL();40bool IsPixel4();41bool IsNVIDIAShield();4243// GPU vendors.44bool IsIntel();45bool IsAMD();46bool IsARM();47bool IsNVIDIA();48bool IsQualcomm();4950// GPU devices.51bool IsSwiftshaderDevice();52bool IsIntelUHD630Mobile();5354// Compiler configs.55inline bool IsASan()56{57#if defined(ANGLE_WITH_ASAN)58return true;59#else60return false;61#endif // defined(ANGLE_WITH_ASAN)62}6364inline bool IsTSan()65{66#if defined(THREAD_SANITIZER)67return true;68#else69return false;70#endif // defined(THREAD_SANITIZER)71}7273bool IsPlatformAvailable(const PlatformParameters ¶m);7475// This functions is used to filter which tests should be registered,76// T must be or inherit from angle::PlatformParameters.77template <typename T>78std::vector<T> FilterTestParams(const T *params, size_t numParams)79{80std::vector<T> filtered;8182for (size_t i = 0; i < numParams; i++)83{84if (IsPlatformAvailable(params[i]))85{86filtered.push_back(params[i]);87}88}8990return filtered;91}9293template <typename T>94std::vector<T> FilterTestParams(const std::vector<T> ¶ms)95{96return FilterTestParams(params.data(), params.size());97}9899// Used to generate valid test names out of testing::PrintToStringParamName used in combined tests.100struct CombinedPrintToStringParamName101{102template <class ParamType>103std::string operator()(const testing::TestParamInfo<ParamType> &info) const104{105std::string name = testing::PrintToStringParamName()(info);106std::string sanitized;107for (const char c : name)108{109if (c == ',')110{111sanitized += '_';112}113else if (isalnum(c) || c == '_')114{115sanitized += c;116}117}118return sanitized;119}120};121122#define ANGLE_INSTANTIATE_TEST_PLATFORMS(testName, ...) \123testing::ValuesIn(::angle::FilterTestParams(testName##__VA_ARGS__##params, \124ArraySize(testName##__VA_ARGS__##params)))125126// Instantiate the test once for each extra argument. The types of all the127// arguments must match, and getRenderer must be implemented for that type.128#define ANGLE_INSTANTIATE_TEST(testName, first, ...) \129const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \130INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \131testing::PrintToStringParamName())132133#define ANGLE_INSTANTIATE_TEST_ARRAY(testName, valuesin) \134INSTANTIATE_TEST_SUITE_P(, testName, testing::ValuesIn(::angle::FilterTestParams(valuesin)), \135testing::PrintToStringParamName())136137#define ANGLE_ALL_TEST_PLATFORMS_ES1 \138ES1_D3D11(), ES1_OPENGL(), ES1_OPENGLES(), ES1_VULKAN(), ES1_VULKAN_SWIFTSHADER(), \139WithAsyncCommandQueueFeatureVulkan(ES1_VULKAN())140141#define ANGLE_ALL_TEST_PLATFORMS_ES2 \142ES2_D3D9(), ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN(), ES2_VULKAN_SWIFTSHADER(), \143ES2_METAL(), WithAsyncCommandQueueFeatureVulkan(ES2_VULKAN())144145#define ANGLE_ALL_TEST_PLATFORMS_ES3 \146ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES(), ES3_VULKAN(), ES3_VULKAN_SWIFTSHADER(), \147ES3_METAL(), WithAsyncCommandQueueFeatureVulkan(ES3_VULKAN())148149#define ANGLE_ALL_TEST_PLATFORMS_ES31 \150ES31_D3D11(), ES31_OPENGL(), ES31_OPENGLES(), ES31_VULKAN(), ES31_VULKAN_SWIFTSHADER(), \151WithAsyncCommandQueueFeatureVulkan(ES31_VULKAN())152153#define ANGLE_ALL_TEST_PLATFORMS_ES32 \154ES32_VULKAN(), WithAsyncCommandQueueFeatureVulkan(ES32_VULKAN())155156#define ANGLE_ALL_TEST_PLATFORMS_NULL ES2_NULL(), ES3_NULL(), ES31_NULL()157158// Instantiate the test once for each GLES1 platform159#define ANGLE_INSTANTIATE_TEST_ES1(testName) \160const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES1}; \161INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \162testing::PrintToStringParamName())163164// Instantiate the test once for each GLES2 platform165#define ANGLE_INSTANTIATE_TEST_ES2(testName) \166const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES2}; \167INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \168testing::PrintToStringParamName())169170#define ANGLE_INSTANTIATE_TEST_ES2_AND(testName, ...) \171const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES2, __VA_ARGS__}; \172INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \173testing::PrintToStringParamName())174175// Instantiate the test once for each GLES3 platform176#define ANGLE_INSTANTIATE_TEST_ES3(testName) \177const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES3}; \178INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \179testing::PrintToStringParamName())180181#define ANGLE_INSTANTIATE_TEST_ES3_AND(testName, ...) \182const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES3, __VA_ARGS__}; \183INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \184testing::PrintToStringParamName())185186// Instantiate the test once for each GLES31 platform187#define ANGLE_INSTANTIATE_TEST_ES31(testName) \188const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES31}; \189INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \190testing::PrintToStringParamName())191192#define ANGLE_INSTANTIATE_TEST_ES31_AND(testName, ...) \193const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES31, __VA_ARGS__}; \194INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \195testing::PrintToStringParamName())196197// Instantiate the test once for each GLES32 platform198#define ANGLE_INSTANTIATE_TEST_ES32(testName) \199const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES32}; \200INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \201testing::PrintToStringParamName())202203#define ANGLE_INSTANTIATE_TEST_ES32_AND(testName, ...) \204const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES32, __VA_ARGS__}; \205INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \206testing::PrintToStringParamName())207208// Multiple ES Version macros209#define ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(testName) \210const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES2, \211ANGLE_ALL_TEST_PLATFORMS_ES3}; \212INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \213testing::PrintToStringParamName())214215#define ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND(testName, ...) \216const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES2, \217ANGLE_ALL_TEST_PLATFORMS_ES3, __VA_ARGS__}; \218INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \219testing::PrintToStringParamName())220221#define ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND_ES31(testName) \222const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES2, \223ANGLE_ALL_TEST_PLATFORMS_ES3, \224ANGLE_ALL_TEST_PLATFORMS_ES31}; \225INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \226testing::PrintToStringParamName())227228#define ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND_ES31_AND_NULL(testName) \229const PlatformParameters testName##params[] = { \230ANGLE_ALL_TEST_PLATFORMS_ES2, ANGLE_ALL_TEST_PLATFORMS_ES3, ANGLE_ALL_TEST_PLATFORMS_ES31, \231ANGLE_ALL_TEST_PLATFORMS_NULL}; \232INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \233testing::PrintToStringParamName())234235#define ANGLE_INSTANTIATE_TEST_ES3_AND_ES31(testName) \236const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES3, \237ANGLE_ALL_TEST_PLATFORMS_ES31}; \238INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \239testing::PrintToStringParamName())240241#define ANGLE_INSTANTIATE_TEST_ES3_AND_ES31_AND(testName, ...) \242const PlatformParameters testName##params[] = {ANGLE_ALL_TEST_PLATFORMS_ES3, \243ANGLE_ALL_TEST_PLATFORMS_ES31, __VA_ARGS__}; \244INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \245testing::PrintToStringParamName())246247// Instantiate the test for a combination of N parameters and the248// enumeration of platforms in the extra args, similar to249// ANGLE_INSTANTIATE_TEST. The macros are defined only for the Ns250// currently in use, and can be expanded as necessary.251#define ANGLE_INSTANTIATE_TEST_COMBINE_1(testName, print, combine1, first, ...) \252const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \253INSTANTIATE_TEST_SUITE_P( \254, testName, testing::Combine(ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), combine1), print)255#define ANGLE_INSTANTIATE_TEST_COMBINE_4(testName, print, combine1, combine2, combine3, combine4, \256first, ...) \257const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \258INSTANTIATE_TEST_SUITE_P(, testName, \259testing::Combine(ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \260combine1, combine2, combine3, combine4), \261print)262#define ANGLE_INSTANTIATE_TEST_COMBINE_5(testName, print, combine1, combine2, combine3, combine4, \263combine5, first, ...) \264const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \265INSTANTIATE_TEST_SUITE_P(, testName, \266testing::Combine(ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \267combine1, combine2, combine3, combine4, combine5), \268print)269270// Checks if a config is expected to be supported by checking a system-based allow list.271bool IsConfigAllowlisted(const SystemInfo &systemInfo, const PlatformParameters ¶m);272273// Determines if a config is supported by trying to initialize it. Does274// not require SystemInfo.275bool IsConfigSupported(const PlatformParameters ¶m);276277// Returns shared test system information. Can be used globally in the278// tests.279SystemInfo *GetTestSystemInfo();280281// Returns a list of all enabled test platform names. For use in282// configuration enumeration.283std::vector<std::string> GetAvailableTestPlatformNames();284285// Active config (e.g. ES2_Vulkan).286void SetSelectedConfig(const char *selectedConfig);287bool IsConfigSelected();288289// Check whether texture swizzle is natively supported on Metal device.290bool IsMetalTextureSwizzleAvailable();291292// Check whether TEXTURE_3D target is supported for compressed formats on Metal device.293bool IsMetalCompressedTexture3DAvailable();294295extern bool gEnableANGLEPerTestCaptureLabel;296297// For use with ANGLE_INSTANTIATE_TEST_ARRAY298template <typename ParamsT>299using ModifierFunc = std::function<ParamsT(const ParamsT &)>;300301template <typename ParamsT>302std::vector<ParamsT> CombineWithFuncs(const std::vector<ParamsT> &in,303const std::vector<ModifierFunc<ParamsT>> &modifiers)304{305std::vector<ParamsT> out;306for (const ParamsT ¶msIn : in)307{308for (ModifierFunc<ParamsT> modifier : modifiers)309{310out.push_back(modifier(paramsIn));311}312}313return out;314}315316template <typename ParamT, typename RangeT, typename ModifierT>317std::vector<ParamT> CombineWithValues(const std::vector<ParamT> &in,318RangeT begin,319RangeT end,320ParamT combine(const ParamT &, ModifierT))321{322std::vector<ParamT> out;323for (const ParamT ¶msIn : in)324{325for (auto iter = begin; iter != end; ++iter)326{327out.push_back(combine(paramsIn, *iter));328}329}330return out;331}332333template <typename ParamT, typename ModifierT>334std::vector<ParamT> CombineWithValues(const std::vector<ParamT> &in,335const std::initializer_list<ModifierT> &modifiers,336ParamT combine(const ParamT &, ModifierT))337{338return CombineWithValues(in, modifiers.begin(), modifiers.end(), combine);339}340341template <typename ParamT, typename ModifiersT, typename ModifierT>342std::vector<ParamT> CombineWithValues(const std::vector<ParamT> &in,343const ModifiersT &modifiers,344ParamT combine(const ParamT &, ModifierT))345{346return CombineWithValues(in, std::begin(modifiers), std::end(modifiers), combine);347}348349template <typename ParamT, typename FilterFunc>350std::vector<ParamT> FilterWithFunc(const std::vector<ParamT> &in, FilterFunc filter)351{352std::vector<ParamT> out;353for (const ParamT ¶m : in)354{355if (filter(param))356{357out.push_back(param);358}359}360return out;361}362} // namespace angle363364#define ANGLE_SKIP_TEST_IF(COND) \365do \366{ \367if (COND) \368{ \369std::cout << "Test skipped: " #COND "." << std::endl; \370return; \371} \372} while (0)373374#endif // ANGLE_TEST_INSTANTIATE_H_375376377