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>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py index b7efbb0..ffee315 100644 --- a/generator/dawn_json_generator.py +++ b/generator/dawn_json_generator.py
@@ -726,7 +726,7 @@ 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 @@ 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:
diff --git a/generator/templates/webgpu_struct_info.json b/generator/templates/api_struct_info.json similarity index 92% rename from generator/templates/webgpu_struct_info.json rename to generator/templates/api_struct_info.json index 6dd38af..ff3a35c 100644 --- a/generator/templates/webgpu_struct_info.json +++ b/generator/templates/api_struct_info.json
@@ -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" ],
diff --git a/generator/templates/library_webgpu_enum_tables.js b/generator/templates/library_api_enum_tables.js similarity index 100% rename from generator/templates/library_webgpu_enum_tables.js rename to generator/templates/library_api_enum_tables.js
diff --git a/generator/templates/mock_webgpu.cpp b/generator/templates/mock_api.cpp similarity index 95% rename from generator/templates/mock_webgpu.cpp rename to generator/templates/mock_api.cpp index d25793b..bf8f871 100644 --- a/generator/templates/mock_webgpu.cpp +++ b/generator/templates/mock_api.cpp
@@ -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 @@ 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)}});
diff --git a/generator/templates/mock_webgpu.h b/generator/templates/mock_api.h similarity index 94% rename from generator/templates/mock_webgpu.h rename to generator/templates/mock_api.h index ea583fa..1c0a880 100644 --- a/generator/templates/mock_webgpu.h +++ b/generator/templates/mock_api.h
@@ -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 @@ 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 @@ {% endfor %} }; -#endif // MOCK_WEBGPU_H +#endif // MOCK_{{API}}_H
diff --git a/src/tests/BUILD.gn b/src/tests/BUILD.gn index 59544b3..db919f4 100644 --- a/src/tests/BUILD.gn +++ b/src/tests/BUILD.gn
@@ -119,7 +119,7 @@ ############################################################################### dawn_json_generator("mock_webgpu_gen") { - target = "mock_webgpu" + target = "mock_api" outputs = [ "src/dawn/mock_webgpu.h", "src/dawn/mock_webgpu.cpp",
diff --git a/src/tests/unittests/wire/WireTest.cpp b/src/tests/unittests/wire/WireTest.cpp index 557bba4..db64325 100644 --- a/src/tests/unittests/wire/WireTest.cpp +++ b/src/tests/unittests/wire/WireTest.cpp
@@ -38,8 +38,8 @@ 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));