UNPKG

5.14 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright 2018 Google Inc. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * =============================================================================
17 */
18Object.defineProperty(exports, "__esModule", { value: true });
19// We import index.ts so that the Node backend gets registered.
20require("./index");
21var tf = require("@tensorflow/tfjs");
22// tslint:disable-next-line:no-imports-from-dist
23var jasmine_util = require("@tensorflow/tfjs-core/dist/jasmine_util");
24var yargs_1 = require("yargs");
25Error.stackTraceLimit = Infinity;
26// tslint:disable-next-line:no-require-imports
27var jasmineCtor = require('jasmine');
28// tslint:disable-next-line:no-require-imports
29process.on('unhandledRejection', function (e) {
30 throw e;
31});
32jasmine_util.setTestEnvs([{
33 name: 'test-tensorflow',
34 backendName: 'tensorflow',
35 flags: {},
36 isDataSync: true
37 }]);
38var IGNORE_LIST = [
39 // Always ignore version tests:
40 'version version',
41 'unreliable is true due to both auto gc and string tensors',
42 'unreliable is true due to auto gc',
43 // See https://github.com/tensorflow/tfjs/issues/161
44 'depthwiseConv2D',
45 'separableConv2d',
46 'complex64 memory',
47 // See https://github.com/tensorflow/tfjs-core/pull/1270
48 'depthToSpace test-tensorflow {} throws when blocksize < 2',
49 // tslint:disable-next-line:max-line-length
50 'depthToSpace test-tensorflow {} throws when CPU backend used with data format NCHW',
51 // See https://github.com/tensorflow/tfjs/issues/806
52 'scatterND test-tensorflow {} should work for 2d',
53 'scatterND test-tensorflow {} should work for simple 1d',
54 'scatterND test-tensorflow {} should work for multiple 1d',
55 'scatterND test-tensorflow {} should sum the duplicated indices',
56 'scatterND test-tensorflow {} should work for tensorLike input',
57 // https://github.com/tensorflow/tfjs/issues/1077
58 'maxPool test-tensorflow {} x=[2,2,3] f=[1,1] s=2 p=1 dimRoundingMode=floor',
59 'avgPool test-tensorflow {} x=[2,2,3] f=[1,1] s=2 p=1 dimRoundingMode=floor',
60 // tslint:disable-next-line:max-line-length
61 'avgPool3d test-tensorflow {} x=[1,2,2,2,1] f=[2,2,2] s=1 p=1 roundingMode=floor',
62 // tslint:disable-next-line:max-line-length
63 'maxPool3d test-tensorflow {} x=[1,2,2,2,1] f=[2,2,2] s=1 p=1 roundingMode=floor',
64 // libtensorflow doesn't support 6D ArgMax yet.
65 'argmax test-tensorflow {} 6D, axis=0', 'diag test-tensorflow {} complex',
66 'diag test-tensorflow {} bool',
67 // See https://github.com/tensorflow/tfjs/issues/1891
68 'conv2d test-tensorflow {} x=[2,1,2,2] f=[1,1,1,1] s=1 d=1 p=0 NCHW',
69 'conv2d test-tensorflow {} x=[1,2,2] f=[2,2,1,1] s=1 d=1 p=same NCHW',
70 'conv2d test-tensorflow {} x=[2,2,2] f=[2,2,2,1] s=1 d=1 p=same NCHW',
71 'conv2d test-tensorflow {} x=[2,1,2,2] f=[2,2,1,1] s=1 d=1 p=same NCHW',
72 'conv2d test-tensorflow {} gradient x=[1,1,3,3] f=[2,2,1,1] s=1 p=0 NCHW',
73 'conv2d test-tensorflow {} gradient x=[2,1,3,3] f=[2,2,1,1] s=1 p=0 NCHW',
74 'maxPoolWithArgmax'
75];
76if (process.platform === 'win32') {
77 // Ignore tensorboard on windows because tmp folder cleanup used in tests
78 // fails with tmp folder cleanup:
79 // https://github.com/tensorflow/tfjs/issues/1692
80 IGNORE_LIST.push('tensorboard');
81 IGNORE_LIST.push('tensorBoard');
82 // Windows has two failing tests:
83 // https://github.com/tensorflow/tfjs/issues/598
84 IGNORE_LIST.push('clip test-tensorflow {} propagates NaNs');
85 IGNORE_LIST.push('maxPool test-tensorflow {} [x=[3,3,1] f=[2,2] s=1 ignores NaNs');
86}
87var runner = new jasmineCtor();
88runner.loadConfig({ spec_files: ['src/**/*_test.ts'], random: false });
89// Also import tests from core.
90// tslint:disable-next-line: no-imports-from-dist
91require("@tensorflow/tfjs-core/dist/tests");
92if (process.env.JASMINE_SEED) {
93 runner.seed(process.env.JASMINE_SEED);
94}
95var env = jasmine.getEnv();
96var grepRegex = new RegExp(yargs_1.argv.grep);
97// Filter method that returns boolean, if a given test should return.
98env.specFilter = function (spec) {
99 // Filter based on the grep flag.
100 if (!grepRegex.test(spec.getFullName())) {
101 return false;
102 }
103 // Return false (skip the test) if the test is in the ignore list.
104 for (var i = 0; i < IGNORE_LIST.length; ++i) {
105 if (spec.getFullName().indexOf(IGNORE_LIST[i]) > -1) {
106 return false;
107 }
108 }
109 // Otherwise run the test.
110 return true;
111};
112// TODO(kreeger): Consider moving to C-code.
113console.log("Running tests against TensorFlow: " + tf.backend().binding.TF_Version);
114runner.execute();