Skip to content

Commit

Permalink
blink/ml: add unit tests for Model Loader user-facing path
Browse files Browse the repository at this point in the history
This CL adds blink unit tests for Web Model Loader API user facing code
path, with mocked Mojo interface implementations:

  - Unsupported MLContext
  - Load and compute
  - Load and invalid inputs

Also moves WebML unittests (which includes Model Loader API and Neural
Network API) target into ml/ directory.

Bug: 1379754
Change-Id: I70a237d160f0f6459f7072de884e21fd17a91d70
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3990676
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Honglin Yu <honglinyu@chromium.org>
Auto-Submit: Jiewei Qian <qjw@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1068970}
  • Loading branch information
wacky6 authored and Chromium LUCI CQ committed Nov 9, 2022
1 parent 91ca54c commit d1407c6
Show file tree
Hide file tree
Showing 5 changed files with 493 additions and 11 deletions.
10 changes: 1 addition & 9 deletions third_party/blink/renderer/modules/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import("//testing/libfuzzer/fuzzer_test.gni")
import("//third_party/blink/renderer/bindings/bindings.gni")
import("//third_party/blink/renderer/bindings/scripts/scripts.gni")
import("//third_party/blink/renderer/build/scripts/scripts.gni")
import("//third_party/blink/renderer/modules/ml/webnn/features.gni")
import("//third_party/blink/renderer/modules/modules.gni")
import("//third_party/webrtc/webrtc.gni")

Expand Down Expand Up @@ -521,8 +520,6 @@ source_set("unit_tests") {
"mediastream/video_track_adapter_unittest.cc",
"mediastream/webaudio_media_stream_audio_sink_test.cc",
"mediastream/webmediaplayer_ms_test.cc",
"ml/webnn/ml_graph_builder_test.cc",
"ml/webnn/ml_graph_builder_test.h",
"nfc/nfc_proxy_test.cc",
"notifications/notification_data_test.cc",
"notifications/notification_resources_loader_test.cc",
Expand Down Expand Up @@ -675,7 +672,7 @@ source_set("unit_tests") {
"//third_party/blink/renderer/modules/indexeddb:unit_tests",
"//third_party/blink/renderer/modules/mediarecorder:buildflags",
"//third_party/blink/renderer/modules/mediastream:test_support",
"//third_party/blink/renderer/modules/ml/webnn:buildflags",
"//third_party/blink/renderer/modules/ml:unit_tests",
"//third_party/blink/renderer/modules/peerconnection:test_support",
"//third_party/blink/renderer/modules/storage:unit_tests",
"//third_party/blink/renderer/modules/webcodecs:unit_tests",
Expand All @@ -699,11 +696,6 @@ source_set("unit_tests") {
deps += [ "//third_party/blink/renderer/modules/direct_sockets:unit_tests" ]
}

if (build_webnn_with_xnnpack) {
sources += [ "ml/webnn/ml_graph_xnnpack_test.cc" ]
deps += [ "//third_party/xnnpack" ]
}

data_deps = [
":accessibility_unittests_data",
":mediastream_unittests_data",
Expand Down
27 changes: 27 additions & 0 deletions third_party/blink/renderer/modules/ml/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//third_party/blink/renderer/modules/ml/webnn/features.gni")
import("//third_party/blink/renderer/modules/modules.gni")

blink_modules_sources("ml") {
Expand All @@ -20,3 +21,29 @@ blink_modules_sources("ml") {

deps = [ "//components/ml/mojom:mojom_blink" ]
}

source_set("unit_tests") {
testonly = true
sources = [
"ml_model_loader_test.cc",
"webnn/ml_graph_builder_test.cc",
"webnn/ml_graph_builder_test.h",
]

deps = [
"//components/ml/mojom:mojom_blink",
"//testing/gtest",
"//third_party/blink/public:test_headers",
"//third_party/blink/renderer/controller:blink_bindings_test_sources",
"//third_party/blink/renderer/core:unit_test_support",
"//third_party/blink/renderer/modules",
"//third_party/blink/renderer/platform",
"//third_party/blink/renderer/platform:test_support",
"//third_party/blink/renderer/platform/wtf",
]

if (build_webnn_with_xnnpack) {
sources += [ "webnn/ml_graph_xnnpack_test.cc" ]
deps += [ "//third_party/xnnpack" ]
}
}
2 changes: 1 addition & 1 deletion third_party/blink/renderer/modules/ml/ml_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace blink {
class ExecutionContext;
class ScriptState;

class MLModel final : public ScriptWrappable {
class MODULES_EXPORT MLModel final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();

public:
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/modules/ml/ml_model_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MLContext;
class ScriptState;
class ScriptPromiseResolver;

class MLModelLoader final : public ScriptWrappable {
class MODULES_EXPORT MLModelLoader final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();

public:
Expand Down

0 comments on commit d1407c6

Please sign in to comment.