mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-13 10:51:35 +00:00
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:
parent
5204053954
commit
16ae3b8b95
@ -726,7 +726,7 @@ class MultiGeneratorFromDawnJSON(Generator):
|
|||||||
def add_commandline_arguments(self, parser):
|
def add_commandline_arguments(self, parser):
|
||||||
allowed_targets = [
|
allowed_targets = [
|
||||||
'dawn_headers', 'dawncpp_headers', 'dawncpp', 'dawn_proc',
|
'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',
|
parser.add_argument('--dawn-json',
|
||||||
@ -823,25 +823,25 @@ class MultiGeneratorFromDawnJSON(Generator):
|
|||||||
FileRender('api_cpp.cpp', 'emscripten-bits/' + api + '_cpp.cpp',
|
FileRender('api_cpp.cpp', 'emscripten-bits/' + api + '_cpp.cpp',
|
||||||
[RENDER_PARAMS_BASE, params_emscripten]))
|
[RENDER_PARAMS_BASE, params_emscripten]))
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('webgpu_struct_info.json',
|
FileRender('api_struct_info.json',
|
||||||
'emscripten-bits/webgpu_struct_info.json',
|
'emscripten-bits/' + api + '_struct_info.json',
|
||||||
[RENDER_PARAMS_BASE, params_emscripten]))
|
[RENDER_PARAMS_BASE, params_emscripten]))
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('library_webgpu_enum_tables.js',
|
FileRender('library_api_enum_tables.js',
|
||||||
'emscripten-bits/library_webgpu_enum_tables.js',
|
'emscripten-bits/library_' + api + '_enum_tables.js',
|
||||||
[RENDER_PARAMS_BASE, params_emscripten]))
|
[RENDER_PARAMS_BASE, params_emscripten]))
|
||||||
|
|
||||||
if 'mock_webgpu' in targets:
|
if 'mock_api' in targets:
|
||||||
mock_params = [
|
mock_params = [
|
||||||
RENDER_PARAMS_BASE, params_dawn, {
|
RENDER_PARAMS_BASE, params_dawn, {
|
||||||
'has_callback_arguments': has_callback_arguments
|
'has_callback_arguments': has_callback_arguments
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('mock_webgpu.h', 'src/dawn/mock_webgpu.h',
|
FileRender('mock_api.h', 'src/dawn/mock_' + api + '.h',
|
||||||
mock_params))
|
mock_params))
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('mock_webgpu.cpp', 'src/dawn/mock_webgpu.cpp',
|
FileRender('mock_api.cpp', 'src/dawn/mock_' + api + '.cpp',
|
||||||
mock_params))
|
mock_params))
|
||||||
|
|
||||||
if 'dawn_native_utils' in targets:
|
if 'dawn_native_utils' in targets:
|
||||||
|
@ -19,10 +19,11 @@
|
|||||||
//* https://github.com/emscripten-core/emscripten/blob/master/src/struct_info.json
|
//* 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": [],
|
"defines": [],
|
||||||
"structs": {
|
"structs": {
|
||||||
"WGPUChainedStruct": [
|
"{{metatdata.c_prefix}}ChainedStruct": [
|
||||||
"next",
|
"next",
|
||||||
"sType"
|
"sType"
|
||||||
],
|
],
|
@ -12,7 +12,8 @@
|
|||||||
//* See the License for the specific language governing permissions and
|
//* See the License for the specific language governing permissions and
|
||||||
//* limitations under the License.
|
//* limitations under the License.
|
||||||
|
|
||||||
#include "mock_webgpu.h"
|
{% set api = metadata.api.lower() %}
|
||||||
|
#include "mock_{{api}}.h"
|
||||||
|
|
||||||
using namespace testing;
|
using namespace testing;
|
||||||
|
|
||||||
@ -40,9 +41,8 @@ namespace {
|
|||||||
ProcTableAsClass::~ProcTableAsClass() {
|
ProcTableAsClass::~ProcTableAsClass() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcTableAsClass::GetProcTableAndDevice(DawnProcTable* table, WGPUDevice* device) {
|
{% set Prefix = metadata.proc_table_prefix %}
|
||||||
*device = GetNewDevice();
|
void ProcTableAsClass::GetProcTable({{Prefix}}ProcTable* table) {
|
||||||
|
|
||||||
{% for type in by_category["object"] %}
|
{% for type in by_category["object"] %}
|
||||||
{% for method in c_methods(type) %}
|
{% 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)}});
|
table->{{as_varName(type.name, method.name)}} = reinterpret_cast<{{as_cProc(type.name, method.name)}}>(Forward{{as_MethodSuffix(type.name, method.name)}});
|
@ -12,11 +12,15 @@
|
|||||||
//* See the License for the specific language governing permissions and
|
//* See the License for the specific language governing permissions and
|
||||||
//* limitations under the License.
|
//* limitations under the License.
|
||||||
|
|
||||||
#ifndef MOCK_WEBGPU_H
|
{% set API = metadata.api.upper() %}
|
||||||
#define MOCK_WEBGPU_H
|
{% set api = API.lower() %}
|
||||||
|
#ifndef MOCK_{{API}}_H
|
||||||
|
#define MOCK_{{API}}_H
|
||||||
|
|
||||||
#include <dawn/dawn_proc_table.h>
|
{% set Prefix = metadata.proc_table_prefix %}
|
||||||
#include <dawn/webgpu.h>
|
{% set prefix = Prefix.lower() %}
|
||||||
|
#include <dawn/{{prefix}}_proc_table.h>
|
||||||
|
#include <dawn/{{api}}.h>
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -28,7 +32,7 @@ class ProcTableAsClass {
|
|||||||
public:
|
public:
|
||||||
virtual ~ProcTableAsClass();
|
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)).
|
// 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.
|
// 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 %}
|
{% endfor %}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MOCK_WEBGPU_H
|
#endif // MOCK_{{API}}_H
|
@ -119,7 +119,7 @@ if (build_with_chromium) {
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
dawn_json_generator("mock_webgpu_gen") {
|
dawn_json_generator("mock_webgpu_gen") {
|
||||||
target = "mock_webgpu"
|
target = "mock_api"
|
||||||
outputs = [
|
outputs = [
|
||||||
"src/dawn/mock_webgpu.h",
|
"src/dawn/mock_webgpu.h",
|
||||||
"src/dawn/mock_webgpu.cpp",
|
"src/dawn/mock_webgpu.cpp",
|
||||||
|
@ -38,8 +38,8 @@ server::MemoryTransferService* WireTest::GetServerMemoryTransferService() {
|
|||||||
|
|
||||||
void WireTest::SetUp() {
|
void WireTest::SetUp() {
|
||||||
DawnProcTable mockProcs;
|
DawnProcTable mockProcs;
|
||||||
WGPUDevice mockDevice;
|
api.GetProcTable(&mockProcs);
|
||||||
api.GetProcTableAndDevice(&mockProcs, &mockDevice);
|
WGPUDevice mockDevice = api.GetNewDevice();
|
||||||
|
|
||||||
// This SetCallback call cannot be ignored because it is done as soon as we start the server
|
// This SetCallback call cannot be ignored because it is done as soon as we start the server
|
||||||
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(_, _, _)).Times(Exactly(1));
|
EXPECT_CALL(api, OnDeviceSetUncapturedErrorCallback(_, _, _)).Times(Exactly(1));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user