1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111

content / test / data / gpu / webgpu-caching.html [blame]

<!DOCTYPE html>
<html>

<head>
  <title>WebGPU caching test</title>
  <style type="text/css">
    .nomargin {
      margin: 0px auto;
    }
  </style>

  <script type="module">
    import { webGpuUnitTests } from './webgpu-unittest-utils.js';

    function finish(success, errors) {
        if (!success) {
            console.error(errors.join('\n'));
            errors.forEach(e => domAutomationController.log(e));
            domAutomationController.send('FAILED');
        } else {
            console.log('SUCCESS');
            domAutomationController.send('SUCCESS');
        }
    }

    async function main() {
        const parsedString = new URLSearchParams(window.location.search);

        // Get the test parameters.
        const testId = parsedString.get('testId');
        const hostname = parsedString.get('hostname');
        const worker_string = parsedString.get('worker');
        const use_worker =
              (worker_string != null) ? worker_string == 'true' : false;
        const runs_string = parsedString.get('runs');
        const runs = (runs_string != null) ? parseInt(runs_string) : 1;
        const iframe_string = parsedString.get('iframe');
        const is_iframe =
              (iframe_string != null) ? iframe_string == 'true' : false;

        // If we pass an explicit hostname, then forward the parameters inside
        // an iframe at the hostname.
        if (hostname != null) {
            parsedString.delete('hostname');
            parsedString.set('iframe', 'true');
            const iframe = document.createElement('iframe');
            const path = window.location.pathname;
            const search = parsedString.toString();
            const port = window.location.port;
            iframe.src = `http://${hostname}:${port}${path}?${search}`;
            document.body.append(iframe);

            const [success, errors] = await (new Promise(
                resolve => {
                    window.addEventListener('message',
                                            e => {
                                                resolve(e.data);
                                                },
                                            { once: true })
                }
            ));
            finish(success, errors);
            return;
        }

        var success = true;
        var errors = [];
        for (let i = 0; i < runs; i++) {
            if (!use_worker) {
                const [run_success, run_errors] =
                      await webGpuUnitTests.runTest(testId);
                success = success && run_success;
                errors = errors.concat(run_errors);
            } else {
                const worker = new Worker(
                    './webgpu-unittest-worker.js',
                    { type: 'module' }
                );
                const promise = new Promise(
                    resolve => {
                        worker.addEventListener('message',
                                                e => {
                                                    resolve(e.data);
                                                },
                                                { once: true })
                    }
                );
                worker.postMessage({ testId });
                const [run_success, run_errors] = await promise;
                success = success && run_success;
                errors = errors.concat(run_errors);
            }
        }

        if (is_iframe) {
            // In this case, we are an iframe embedded inside a parent, so
            // post the results back to the parent to be handled.
            parent.postMessage([success, errors], '*');
        } else {
            finish(success, errors);
        }
    }

    await main();
  </script>
</head>

<body>
</body>

</html>