Make the templates of mocking api flexible

Rename mock_webgpu to mock_api and define the function "GetProcTableAndDevice" to "GetProcTable" for removing the special arguments "WGPUDevice* device" that can be got with "GetNewDevice()".

BUG=dawn:1201

Change-Id: I4fc47e4497ba4b6d280cc8af8605f1d93f43497e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/72761
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Junwei Fu <junwei.fu@intel.com>
This commit is contained in:
fujunwei 2021-12-15 04:35:26 +00:00 committed by Dawn LUCI CQ
parent 5204053954
commit 16ae3b8b95
7 changed files with 28 additions and 23 deletions

View File

@ -726,7 +726,7 @@ class MultiGeneratorFromDawnJSON(Generator):
def add_commandline_arguments(self, parser):
allowed_targets = [
'dawn_headers', 'dawncpp_headers', 'dawncpp', 'dawn_proc',
'mock_webgpu', 'dawn_wire', "dawn_native_utils"
'mock_api', 'dawn_wire', "dawn_native_utils"
]
parser.add_argument('--dawn-json',
@ -823,25 +823,25 @@ class MultiGeneratorFromDawnJSON(Generator):
FileRender('api_cpp.cpp', 'emscripten-bits/' + api + '_cpp.cpp',
[RENDER_PARAMS_BASE, params_emscripten]))
renders.append(
FileRender('webgpu_struct_info.json',
'emscripten-bits/webgpu_struct_info.json',
FileRender('api_struct_info.json',
'emscripten-bits/' + api + '_struct_info.json',
[RENDER_PARAMS_BASE, params_emscripten]))
renders.append(
FileRender('library_webgpu_enum_tables.js',
'emscripten-bits/library_webgpu_enum_tables.js',
FileRender('library_api_enum_tables.js',
'emscripten-bits/library_' + api + '_enum_tables.js',
[RENDER_PARAMS_BASE, params_emscripten]))
if 'mock_webgpu' in targets:
if 'mock_api' in targets:
mock_params = [
RENDER_PARAMS_BASE, params_dawn, {
'has_callback_arguments': has_callback_arguments
}
]
renders.append(
FileRender('mock_webgpu.h', 'src/dawn/mock_webgpu.h',
FileRender('mock_api.h', 'src/dawn/mock_' + api + '.h',
mock_params))
renders.append(
FileRender('mock_webgpu.cpp', 'src/dawn/mock_webgpu.cpp',
FileRender('mock_api.cpp', 'src/dawn/mock_' + api + '.cpp',
mock_params))
if 'dawn_native_utils' in targets:

View File

@ -19,10 +19,11 @@
//* https://github.com/emscripten-core/emscripten/blob/master/src/struct_info.json
//*
{
"file": "webgpu/webgpu.h",
{% set api = metadata.api.lower() %}
"file": "{api}/{api}.h",
"defines": [],
"structs": {
"WGPUChainedStruct": [
"{{metatdata.c_prefix}}ChainedStruct": [
"next",
"sType"
],

View File

@ -12,7 +12,8 @@
//* See the License for the specific language governing permissions and
//* limitations under the License.
#include "mock_webgpu.h"
{% set api = metadata.api.lower() %}
#include "mock_{{api}}.h"
using namespace testing;
@ -40,9 +41,8 @@ namespace {
ProcTableAsClass::~ProcTableAsClass() {
}
void ProcTableAsClass::GetProcTableAndDevice(DawnProcTable* table, WGPUDevice* device) {
*device = GetNewDevice();
{% set Prefix = metadata.proc_table_prefix %}
void ProcTableAsClass::GetProcTable({{Prefix}}ProcTable* table) {
{% for type in by_category["object"] %}
{% for method in c_methods(type) %}
table->{{as_varName(type.name, method.name)}} = reinterpret_cast<{{as_cProc(type.name, method.name)}}>(Forward{{as_MethodSuffix(type.name, method.name)}});

View File

@ -12,11 +12,15 @@
//* See the License for the specific language governing permissions and
//* limitations under the License.
#ifndef MOCK_WEBGPU_H
#define MOCK_WEBGPU_H
{% set API = metadata.api.upper() %}
{% set api = API.lower() %}
#ifndef MOCK_{{API}}_H
#define MOCK_{{API}}_H
#include <dawn/dawn_proc_table.h>
#include <dawn/webgpu.h>
{% set Prefix = metadata.proc_table_prefix %}
{% set prefix = Prefix.lower() %}
#include <dawn/{{prefix}}_proc_table.h>
#include <dawn/{{api}}.h>
#include <gmock/gmock.h>
#include <memory>
@ -28,7 +32,7 @@ class ProcTableAsClass {
public:
virtual ~ProcTableAsClass();
void GetProcTableAndDevice(DawnProcTable* table, WGPUDevice* device);
void GetProcTable({{Prefix}}ProcTable* table);
// Creates an object that can be returned by a mocked call as in WillOnce(Return(foo)).
// It returns an object of the write type that isn't equal to any previously returned object.
@ -131,4 +135,4 @@ class MockProcTable : public ProcTableAsClass {
{% endfor %}
};
#endif // MOCK_WEBGPU_H
#endif // MOCK_{{API}}_H

View File

@ -119,7 +119,7 @@ if (build_with_chromium) {
###############################################################################
dawn_json_generator("mock_webgpu_gen") {
target = "mock_webgpu"
target = "mock_api"
outputs = [
"src/dawn/mock_webgpu.h",
"src/dawn/mock_webgpu.cpp",

View File

@ -38,8 +38,8 @@ server::MemoryTransferService* WireTest::GetServerMemoryTransferService() {
void WireTest::SetUp() {
DawnProcTable mockProcs;
WGPUDevice mockDevice;
api.GetProcTableAndDevice(&mockProcs, &mockDevice);
api.GetProcTable(&mockProcs);
WGPUDevice mockDevice = api.GetNewDevice();
// This SetCallback call cannot be ignored because it is done as soon as we start the server
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(_, _, _)).Times(Exactly(1));