#include "gpu/ipc/service/gpu_channel.h"
#include <stdint.h>
#include "base/run_loop.h"
#include "base/test/test_simple_task_runner.h"
#include "build/build_config.h"
#include "gpu/ipc/common/command_buffer_id.h"
#include "gpu/ipc/common/gpu_channel.mojom.h"
#include "gpu/ipc/service/gpu_channel_manager.h"
#include "gpu/ipc/service/gpu_channel_test_common.h"
#include "ipc/constants.mojom.h"
namespace gpu {
class GpuChannelTest : public GpuChannelTestCommon {
public:
GpuChannelTest() : GpuChannelTestCommon(true ) {}
~GpuChannelTest() override = default;
};
TEST_F(GpuChannelTest, CreateOffscreenCommandBuffer) {
int32_t kClientId = 1;
GpuChannel* channel = CreateChannel(kClientId, true);
ASSERT_TRUE(channel);
int32_t kRouteId =
static_cast<int32_t>(GpuChannelReservedRoutes::kMaxValue) + 1;
auto init_params = mojom::CreateCommandBufferParams::New();
init_params->stream_id = 0;
init_params->stream_priority = SchedulingPriority::kNormal;
init_params->attribs =
mojom::ContextCreationAttribs::NewGles(mojom::GLESCreationAttribs::New());
init_params->active_url = GURL();
gpu::ContextResult result = gpu::ContextResult::kSuccess;
gpu::Capabilities capabilities;
gpu::GLCapabilities gl_capabilities;
CreateCommandBuffer(*channel, std::move(init_params), kRouteId,
GetSharedMemoryRegion(), &result, &capabilities,
&gl_capabilities);
EXPECT_EQ(result, gpu::ContextResult::kSuccess);
CommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId);
EXPECT_TRUE(stub);
}
class GpuChannelExitForContextLostTest : public GpuChannelTestCommon {
public:
GpuChannelExitForContextLostTest()
: GpuChannelTestCommon({EXIT_ON_CONTEXT_LOST} ,
true ) {}
};
TEST_F(GpuChannelExitForContextLostTest,
CreateFailsDuringLostContextShutdown_1) {
int32_t kClientId = 1;
GpuChannel* channel = CreateChannel(kClientId, false);
ASSERT_TRUE(channel);
channel_manager()->OnContextLost(-1 ,
false ,
error::ContextLostReason::kUnknown);
base::RunLoop().RunUntilIdle();
if (!channel_manager()->LookupChannel(kClientId))
return;
int32_t kRouteId =
static_cast<int32_t>(GpuChannelReservedRoutes::kMaxValue) + 1;
auto init_params = mojom::CreateCommandBufferParams::New();
init_params->stream_id = 0;
init_params->stream_priority = SchedulingPriority::kNormal;
init_params->attribs =
mojom::ContextCreationAttribs::NewGles(mojom::GLESCreationAttribs::New());
init_params->active_url = GURL();
gpu::ContextResult result = gpu::ContextResult::kSuccess;
gpu::Capabilities capabilities;
gpu::GLCapabilities gl_capabilities;
CreateCommandBuffer(*channel, std::move(init_params), kRouteId,
GetSharedMemoryRegion(), &result, &capabilities,
&gl_capabilities);
EXPECT_EQ(result, gpu::ContextResult::kTransientFailure);
EXPECT_FALSE(channel->LookupCommandBuffer(kRouteId));
}
TEST_F(GpuChannelExitForContextLostTest,
CreateFailsDuringLostContextShutdown_2) {
channel_manager()->OnContextLost(-1 ,
false ,
error::ContextLostReason::kUnknown);
int32_t kClientId = 1;
GpuChannel* channel = CreateChannel(kClientId, false);
ASSERT_TRUE(channel);
int32_t kRouteId =
static_cast<int32_t>(GpuChannelReservedRoutes::kMaxValue) + 1;
auto init_params = mojom::CreateCommandBufferParams::New();
init_params->stream_id = 0;
init_params->stream_priority = SchedulingPriority::kNormal;
init_params->attribs =
mojom::ContextCreationAttribs::NewGles(mojom::GLESCreationAttribs::New());
init_params->active_url = GURL();
gpu::ContextResult result = gpu::ContextResult::kSuccess;
gpu::Capabilities capabilities;
gpu::GLCapabilities gl_capabilities;
CreateCommandBuffer(*channel, std::move(init_params), kRouteId,
GetSharedMemoryRegion(), &result, &capabilities,
&gl_capabilities);
EXPECT_EQ(result, gpu::ContextResult::kTransientFailure);
EXPECT_FALSE(channel->LookupCommandBuffer(kRouteId));
}
}