Path: blob/main_old/src/tests/egl_tests/EGLFeatureControlTest.cpp
1693 views
//1// Copyright 2019 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//5// Tests the eglQueryStringiANGLE and eglQueryDisplayAttribANGLE functions exposed by the6// extension EGL_ANGLE_feature_control.78#include <gtest/gtest.h>910#include "libANGLE/Display.h"11#include "test_utils/ANGLETest.h"1213using namespace angle;1415class EGLFeatureControlTest : public ANGLETest16{17public:18void testSetUp() override { mDisplay = EGL_NO_DISPLAY; }1920void testTearDown() override21{22if (mDisplay != EGL_NO_DISPLAY)23{24eglTerminate(mDisplay);25}26}2728protected:29EGLDisplay mDisplay;3031bool initTest()32{33// http://anglebug.com/3629 This test sporadically times out on Win10/Intel34if (IsWindows() && IsIntel())35return false;3637EGLAttrib dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, GetParam().getRenderer(), EGL_NONE};38mDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE,39reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);40EXPECT_NE(mDisplay, EGL_NO_DISPLAY);4142EXPECT_EQ(eglInitialize(mDisplay, nullptr, nullptr), static_cast<EGLBoolean>(EGL_TRUE));4344EXPECT_TRUE(IsEGLClientExtensionEnabled("EGL_ANGLE_feature_control"));4546return true;47}48};4950// Ensure eglQueryStringiANGLE generates EGL_BAD_DISPLAY if the display passed in is invalid.51TEST_P(EGLFeatureControlTest, InvalidDisplay)52{53ANGLE_SKIP_TEST_IF(!initTest());54EXPECT_EQ(nullptr, eglQueryStringiANGLE(EGL_NO_DISPLAY, EGL_FEATURE_NAME_ANGLE, 0));55EXPECT_EGL_ERROR(EGL_BAD_DISPLAY);56}5758// Ensure eglQueryStringiANGLE generates EGL_BAD_PARAMETER if the index is negative.59TEST_P(EGLFeatureControlTest, NegativeIndex)60{61ANGLE_SKIP_TEST_IF(!initTest());62EXPECT_EQ(nullptr, eglQueryStringiANGLE(mDisplay, EGL_FEATURE_NAME_ANGLE, -1));63EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);64}6566// Ensure eglQueryStringiANGLE generates EGL_BAD_PARAMETER if the index is out of bounds.67TEST_P(EGLFeatureControlTest, IndexOutOfBounds)68{69ANGLE_SKIP_TEST_IF(!initTest());70egl::Display *display = static_cast<egl::Display *>(mDisplay);71EXPECT_EQ(nullptr, eglQueryStringiANGLE(mDisplay, EGL_FEATURE_NAME_ANGLE,72display->getFeatures().size()));73EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);74}7576// Ensure eglQueryStringiANGLE generates EGL_BAD_PARAMETER if the name is not one of the valid77// options specified in EGL_ANGLE_feature_control.78TEST_P(EGLFeatureControlTest, InvalidName)79{80ANGLE_SKIP_TEST_IF(!initTest());81EXPECT_EQ(nullptr, eglQueryStringiANGLE(mDisplay, 100, 0));82EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);83}8485// For each valid name and index in the feature description arrays, query the values and ensure86// that no error is generated, and that the values match the correct values frim ANGLE's display's87// FeatureList.88TEST_P(EGLFeatureControlTest, QueryAll)89{90ANGLE_SKIP_TEST_IF(!initTest());91egl::Display *display = static_cast<egl::Display *>(mDisplay);92angle::FeatureList features = display->getFeatures();93for (size_t i = 0; i < features.size(); i++)94{95EXPECT_STREQ(features[i]->name, eglQueryStringiANGLE(mDisplay, EGL_FEATURE_NAME_ANGLE, i));96EXPECT_STREQ(FeatureCategoryToString(features[i]->category),97eglQueryStringiANGLE(mDisplay, EGL_FEATURE_CATEGORY_ANGLE, i));98EXPECT_STREQ(features[i]->description,99eglQueryStringiANGLE(mDisplay, EGL_FEATURE_DESCRIPTION_ANGLE, i));100EXPECT_STREQ(features[i]->bug, eglQueryStringiANGLE(mDisplay, EGL_FEATURE_BUG_ANGLE, i));101EXPECT_STREQ(FeatureStatusToString(features[i]->enabled),102eglQueryStringiANGLE(mDisplay, EGL_FEATURE_STATUS_ANGLE, i));103EXPECT_STREQ(features[i]->condition,104eglQueryStringiANGLE(mDisplay, EGL_FEATURE_CONDITION_ANGLE, i));105ASSERT_EGL_SUCCESS();106}107}108109// Ensure eglQueryDisplayAttribANGLE returns the correct number of features when queried with110// attribute EGL_FEATURE_COUNT_ANGLE111TEST_P(EGLFeatureControlTest, FeatureCount)112{113ANGLE_SKIP_TEST_IF(!initTest());114egl::Display *display = static_cast<egl::Display *>(mDisplay);115EGLAttrib value = -1;116EXPECT_EQ(static_cast<EGLBoolean>(EGL_TRUE),117eglQueryDisplayAttribANGLE(mDisplay, EGL_FEATURE_COUNT_ANGLE, &value));118EXPECT_EQ(display->getFeatures().size(), static_cast<size_t>(value));119ASSERT_EGL_SUCCESS();120}121122// Submit a list of features to override when creating the display with eglGetPlatformDisplay, and123// ensure that the features are correctly overridden.124TEST_P(EGLFeatureControlTest, OverrideFeatures)125{126ANGLE_SKIP_TEST_IF(!initTest());127egl::Display *display = static_cast<egl::Display *>(mDisplay);128angle::FeatureList features = display->getFeatures();129130// Build lists of features to enable/disabled. Toggle features we know are ok to toggle based131// from this list.132std::vector<const char *> enabled = std::vector<const char *>();133std::vector<const char *> disabled = std::vector<const char *>();134std::vector<bool> shouldBe = std::vector<bool>();135std::vector<std::string> testedFeatures = {136"add_and_true_to_loop_condition", // Safe to toggle GL137"clamp_frag_depth", // Safe to toggle GL138"clamp_point_size", // Safe to toggle GL and Vulkan139"flip_viewport_y", // Safe to toggle on Vulkan140"zero_max_lod", // Safe to toggle on D3D141"expand_integer_pow_expressions", // Safe to toggle on D3D142"rewrite_unary_minus_operator", // Safe to toggle on D3D143};144for (size_t i = 0; i < features.size(); i++)145{146bool toggle = std::find(testedFeatures.begin(), testedFeatures.end(),147std::string(features[i]->name)) != testedFeatures.end();148if (features[i]->enabled ^ toggle)149{150enabled.push_back(features[i]->name);151}152else153{154disabled.push_back(features[i]->name);155}156// Save what we expect the feature status will be when checking later.157shouldBe.push_back(features[i]->enabled ^ toggle);158}159disabled.push_back(0);160enabled.push_back(0);161162// Terminate the old display (we just used it to collect features)163eglTerminate(mDisplay);164165// Create a new display with these overridden features.166EGLAttrib dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE,167GetParam().getRenderer(),168EGL_FEATURE_OVERRIDES_ENABLED_ANGLE,169reinterpret_cast<EGLAttrib>(enabled.data()),170EGL_FEATURE_OVERRIDES_DISABLED_ANGLE,171reinterpret_cast<EGLAttrib>(disabled.data()),172EGL_NONE};173EGLDisplay dpy_override = eglGetPlatformDisplay(174EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);175ASSERT_EGL_SUCCESS();176ASSERT_TRUE(dpy_override != EGL_NO_DISPLAY);177ASSERT_TRUE(eglInitialize(dpy_override, nullptr, nullptr) == EGL_TRUE);178179// Check that all features have the correct status (even the ones we toggled).180for (size_t i = 0; i < features.size(); i++)181{182EXPECT_STREQ(FeatureStatusToString(shouldBe[i]),183eglQueryStringiANGLE(dpy_override, EGL_FEATURE_STATUS_ANGLE, i));184}185}186187ANGLE_INSTANTIATE_TEST(EGLFeatureControlTest,188WithNoFixture(ES2_D3D9()),189WithNoFixture(ES2_D3D11()),190WithNoFixture(ES2_OPENGL()),191WithNoFixture(ES2_VULKAN()),192WithNoFixture(ES3_D3D11()),193WithNoFixture(ES3_OPENGL()));194195196