mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-12 06:08:24 +02:00
Automatic update from web-platform-testsMerge pull request #9606 from gsnedders/update_pywebsockets Update pywebsockets wpt-commits: 38811892842f1db4a029ee0d4d42764c5e12ae6d wpt-pr: 9606 wpt-commits: 38811892842f1db4a029ee0d4d42764c5e12ae6d wpt-pr: 9606 --HG-- rename : testing/web-platform/tests/tools/pywebsocket/src/COPYING => testing/web-platform/tests/tools/pywebsocket/LICENSE rename : testing/web-platform/tests/tools/pywebsocket/src/MANIFEST.in => testing/web-platform/tests/tools/pywebsocket/MANIFEST.in rename : testing/web-platform/tests/tools/pywebsocket/src/README => testing/web-platform/tests/tools/pywebsocket/README rename : testing/web-platform/tests/tools/pywebsocket/src/example/abort_handshake_wsh.py => testing/web-platform/tests/tools/pywebsocket/example/abort_handshake_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/example/abort_wsh.py => testing/web-platform/tests/tools/pywebsocket/example/abort_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/example/arraybuffer_benchmark.html => testing/web-platform/tests/tools/pywebsocket/example/arraybuffer_benchmark.html rename : testing/web-platform/tests/tools/pywebsocket/src/example/bench_wsh.py => testing/web-platform/tests/tools/pywebsocket/example/bench_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/example/benchmark_helper_wsh.py => testing/web-platform/tests/tools/pywebsocket/example/benchmark_helper_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/example/close_wsh.py => testing/web-platform/tests/tools/pywebsocket/example/close_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/example/console.html => testing/web-platform/tests/tools/pywebsocket/example/console.html rename : testing/web-platform/tests/tools/pywebsocket/src/example/cookie_wsh.py => testing/web-platform/tests/tools/pywebsocket/example/cookie_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/example/echo_client.py => testing/web-platform/tests/tools/pywebsocket/example/echo_client.py rename : testing/web-platform/tests/tools/pywebsocket/src/example/echo_noext_wsh.py => testing/web-platform/tests/tools/pywebsocket/example/echo_noext_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/example/echo_wsh.py => testing/web-platform/tests/tools/pywebsocket/example/echo_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/example/eventsource.cgi => testing/web-platform/tests/tools/pywebsocket/example/eventsource.cgi rename : testing/web-platform/tests/tools/pywebsocket/src/example/eventsource.html => testing/web-platform/tests/tools/pywebsocket/example/eventsource.html rename : testing/web-platform/tests/tools/pywebsocket/src/example/handler_map.txt => testing/web-platform/tests/tools/pywebsocket/example/handler_map.txt rename : testing/web-platform/tests/tools/pywebsocket/src/example/hsts_wsh.py => testing/web-platform/tests/tools/pywebsocket/example/hsts_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/example/internal_error_wsh.py => testing/web-platform/tests/tools/pywebsocket/example/internal_error_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/example/origin_check_wsh.py => testing/web-platform/tests/tools/pywebsocket/example/origin_check_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/example/pywebsocket.conf => testing/web-platform/tests/tools/pywebsocket/example/pywebsocket.conf rename : testing/web-platform/tests/tools/pywebsocket/src/example/special_headers.cgi => testing/web-platform/tests/tools/pywebsocket/example/special_headers.cgi rename : testing/web-platform/tests/tools/pywebsocket/src/mod_pywebsocket/__init__.py => testing/web-platform/tests/tools/pywebsocket/mod_pywebsocket/__init__.py rename : testing/web-platform/tests/tools/pywebsocket/src/mod_pywebsocket/_stream_base.py => testing/web-platform/tests/tools/pywebsocket/mod_pywebsocket/_stream_base.py rename : testing/web-platform/tests/tools/pywebsocket/src/mod_pywebsocket/_stream_hixie75.py => testing/web-platform/tests/tools/pywebsocket/mod_pywebsocket/_stream_hixie75.py rename : testing/web-platform/tests/tools/pywebsocket/src/mod_pywebsocket/dispatch.py => testing/web-platform/tests/tools/pywebsocket/mod_pywebsocket/dispatch.py rename : testing/web-platform/tests/tools/pywebsocket/src/mod_pywebsocket/fast_masking.i => testing/web-platform/tests/tools/pywebsocket/mod_pywebsocket/fast_masking.i rename : testing/web-platform/tests/tools/pywebsocket/src/mod_pywebsocket/handshake/__init__.py => testing/web-platform/tests/tools/pywebsocket/mod_pywebsocket/handshake/__init__.py rename : testing/web-platform/tests/tools/pywebsocket/src/mod_pywebsocket/handshake/_base.py => testing/web-platform/tests/tools/pywebsocket/mod_pywebsocket/handshake/_base.py rename : testing/web-platform/tests/tools/pywebsocket/src/mod_pywebsocket/handshake/hybi.py => testing/web-platform/tests/tools/pywebsocket/mod_pywebsocket/handshake/hybi.py rename : testing/web-platform/tests/tools/pywebsocket/src/mod_pywebsocket/handshake/hybi00.py => testing/web-platform/tests/tools/pywebsocket/mod_pywebsocket/handshake/hybi00.py rename : testing/web-platform/tests/tools/pywebsocket/src/mod_pywebsocket/http_header_util.py => testing/web-platform/tests/tools/pywebsocket/mod_pywebsocket/http_header_util.py rename : testing/web-platform/tests/tools/pywebsocket/src/mod_pywebsocket/msgutil.py => testing/web-platform/tests/tools/pywebsocket/mod_pywebsocket/msgutil.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/cert/cacert.pem => testing/web-platform/tests/tools/pywebsocket/test/cert/cacert.pem rename : testing/web-platform/tests/tools/pywebsocket/src/test/cert/cert.pem => testing/web-platform/tests/tools/pywebsocket/test/cert/cert.pem rename : testing/web-platform/tests/tools/pywebsocket/src/test/cert/client_cert.p12 => testing/web-platform/tests/tools/pywebsocket/test/cert/client_cert.p12 rename : testing/web-platform/tests/tools/pywebsocket/src/test/cert/key.pem => testing/web-platform/tests/tools/pywebsocket/test/cert/key.pem rename : testing/web-platform/tests/tools/pywebsocket/src/test/client_for_testing.py => testing/web-platform/tests/tools/pywebsocket/test/client_for_testing.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/endtoend_with_external_server.py => testing/web-platform/tests/tools/pywebsocket/test/endtoend_with_external_server.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/mock.py => testing/web-platform/tests/tools/pywebsocket/test/mock.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/mux_client_for_testing.py => testing/web-platform/tests/tools/pywebsocket/test/mux_client_for_testing.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/run_all.py => testing/web-platform/tests/tools/pywebsocket/test/run_all.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/set_sys_path.py => testing/web-platform/tests/tools/pywebsocket/test/set_sys_path.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/test_dispatch.py => testing/web-platform/tests/tools/pywebsocket/test/test_dispatch.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/test_endtoend.py => testing/web-platform/tests/tools/pywebsocket/test/test_endtoend.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/test_handshake.py => testing/web-platform/tests/tools/pywebsocket/test/test_handshake.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/test_handshake_hybi00.py => testing/web-platform/tests/tools/pywebsocket/test/test_handshake_hybi00.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/test_http_header_util.py => testing/web-platform/tests/tools/pywebsocket/test/test_http_header_util.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/test_memorizingfile.py => testing/web-platform/tests/tools/pywebsocket/test/test_memorizingfile.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/test_mock.py => testing/web-platform/tests/tools/pywebsocket/test/test_mock.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/test_stream.py => testing/web-platform/tests/tools/pywebsocket/test/test_stream.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/test_stream_hixie75.py => testing/web-platform/tests/tools/pywebsocket/test/test_stream_hixie75.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/test_util.py => testing/web-platform/tests/tools/pywebsocket/test/test_util.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/testdata/README => testing/web-platform/tests/tools/pywebsocket/test/testdata/README rename : testing/web-platform/tests/tools/pywebsocket/src/test/testdata/handlers/abort_by_user_wsh.py => testing/web-platform/tests/tools/pywebsocket/test/testdata/handlers/abort_by_user_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/testdata/handlers/blank_wsh.py => testing/web-platform/tests/tools/pywebsocket/test/testdata/handlers/blank_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/testdata/handlers/origin_check_wsh.py => testing/web-platform/tests/tools/pywebsocket/test/testdata/handlers/origin_check_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/testdata/handlers/sub/exception_in_transfer_wsh.py => testing/web-platform/tests/tools/pywebsocket/test/testdata/handlers/sub/exception_in_transfer_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/testdata/handlers/sub/no_wsh_at_the_end.py => testing/web-platform/tests/tools/pywebsocket/test/testdata/handlers/sub/no_wsh_at_the_end.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/testdata/handlers/sub/non_callable_wsh.py => testing/web-platform/tests/tools/pywebsocket/test/testdata/handlers/sub/non_callable_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/testdata/handlers/sub/plain_wsh.py => testing/web-platform/tests/tools/pywebsocket/test/testdata/handlers/sub/plain_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/testdata/handlers/sub/wrong_handshake_sig_wsh.py => testing/web-platform/tests/tools/pywebsocket/test/testdata/handlers/sub/wrong_handshake_sig_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/testdata/handlers/sub/wrong_transfer_sig_wsh.py => testing/web-platform/tests/tools/pywebsocket/test/testdata/handlers/sub/wrong_transfer_sig_wsh.py rename : testing/web-platform/tests/tools/pywebsocket/src/test/testdata/hello.pl => testing/web-platform/tests/tools/pywebsocket/test/testdata/hello.pl
214 lines
4.9 KiB
JavaScript
214 lines
4.9 KiB
JavaScript
// Copyright 2014 Google Inc. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the COPYING file or at
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
if (typeof importScripts !== "undefined") {
|
|
// Running on a worker
|
|
importScripts('util.js', 'util_worker.js');
|
|
}
|
|
|
|
// Namespace for holding globals.
|
|
var benchmark = {startTimeInMs: 0};
|
|
|
|
var sockets = [];
|
|
var numEstablishedSockets = 0;
|
|
|
|
var timerID = null;
|
|
|
|
function destroySocket(socket) {
|
|
socket.onopen = null;
|
|
socket.onmessage = null;
|
|
socket.onerror = null;
|
|
socket.onclose = null;
|
|
socket.close();
|
|
}
|
|
|
|
function destroyAllSockets() {
|
|
for (var i = 0; i < sockets.length; ++i) {
|
|
destroySocket(sockets[i]);
|
|
}
|
|
sockets = [];
|
|
}
|
|
|
|
function sendBenchmarkStep(size, config, isWarmUp) {
|
|
timerID = null;
|
|
|
|
var totalSize = 0;
|
|
var totalReplied = 0;
|
|
|
|
var onMessageHandler = function(event) {
|
|
if (!verifyAcknowledgement(config, event.data, size)) {
|
|
destroyAllSockets();
|
|
config.notifyAbort();
|
|
return;
|
|
}
|
|
|
|
totalReplied += size;
|
|
|
|
if (totalReplied < totalSize) {
|
|
return;
|
|
}
|
|
|
|
calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize,
|
|
isWarmUp);
|
|
|
|
runNextTask(config);
|
|
};
|
|
|
|
for (var i = 0; i < sockets.length; ++i) {
|
|
var socket = sockets[i];
|
|
socket.onmessage = onMessageHandler;
|
|
}
|
|
|
|
var dataArray = [];
|
|
|
|
while (totalSize < config.minTotal) {
|
|
var buffer = new ArrayBuffer(size);
|
|
|
|
fillArrayBuffer(buffer, 0x61);
|
|
|
|
dataArray.push(buffer);
|
|
totalSize += size;
|
|
}
|
|
|
|
benchmark.startTimeInMs = getTimeStamp();
|
|
|
|
totalSize = 0;
|
|
|
|
var socketIndex = 0;
|
|
var dataIndex = 0;
|
|
while (totalSize < config.minTotal) {
|
|
var command = ['send'];
|
|
command.push(config.verifyData ? '1' : '0');
|
|
sockets[socketIndex].send(command.join(' '));
|
|
sockets[socketIndex].send(dataArray[dataIndex]);
|
|
socketIndex = (socketIndex + 1) % sockets.length;
|
|
|
|
totalSize += size;
|
|
++dataIndex;
|
|
}
|
|
}
|
|
|
|
function receiveBenchmarkStep(size, config, isWarmUp) {
|
|
timerID = null;
|
|
|
|
var totalSize = 0;
|
|
var totalReplied = 0;
|
|
|
|
var onMessageHandler = function(event) {
|
|
var bytesReceived = event.data.byteLength;
|
|
if (bytesReceived != size) {
|
|
config.addToLog('Expected ' + size + 'B but received ' +
|
|
bytesReceived + 'B');
|
|
destroyAllSockets();
|
|
config.notifyAbort();
|
|
return;
|
|
}
|
|
|
|
if (config.verifyData && !verifyArrayBuffer(event.data, 0x61)) {
|
|
config.addToLog('Response verification failed');
|
|
destroyAllSockets();
|
|
config.notifyAbort();
|
|
return;
|
|
}
|
|
|
|
totalReplied += bytesReceived;
|
|
|
|
if (totalReplied < totalSize) {
|
|
return;
|
|
}
|
|
|
|
calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize,
|
|
isWarmUp);
|
|
|
|
runNextTask(config);
|
|
};
|
|
|
|
for (var i = 0; i < sockets.length; ++i) {
|
|
var socket = sockets[i];
|
|
socket.binaryType = 'arraybuffer';
|
|
socket.onmessage = onMessageHandler;
|
|
}
|
|
|
|
benchmark.startTimeInMs = getTimeStamp();
|
|
|
|
var socketIndex = 0;
|
|
while (totalSize < config.minTotal) {
|
|
sockets[socketIndex].send('receive ' + size);
|
|
socketIndex = (socketIndex + 1) % sockets.length;
|
|
|
|
totalSize += size;
|
|
}
|
|
}
|
|
|
|
function createSocket(config) {
|
|
// TODO(tyoshino): Add TCP warm up.
|
|
var url = config.prefixUrl;
|
|
|
|
config.addToLog('Connect ' + url);
|
|
|
|
var socket = new WebSocket(url);
|
|
socket.onmessage = function(event) {
|
|
config.addToLog('Unexpected message received. Aborting.');
|
|
};
|
|
socket.onerror = function() {
|
|
config.addToLog('Error');
|
|
};
|
|
socket.onclose = function(event) {
|
|
config.addToLog('Closed');
|
|
config.notifyAbort();
|
|
};
|
|
return socket;
|
|
}
|
|
|
|
function startBenchmark(config) {
|
|
clearTimeout(timerID);
|
|
destroyAllSockets();
|
|
|
|
numEstablishedSockets = 0;
|
|
|
|
for (var i = 0; i < config.numSockets; ++i) {
|
|
var socket = createSocket(config);
|
|
socket.onopen = function() {
|
|
config.addToLog('Opened');
|
|
|
|
++numEstablishedSockets;
|
|
|
|
if (numEstablishedSockets == sockets.length) {
|
|
runNextTask(config);
|
|
}
|
|
};
|
|
sockets.push(socket);
|
|
}
|
|
}
|
|
|
|
function getConfigString(config) {
|
|
return '(WebSocket' +
|
|
', ' + (typeof importScripts !== "undefined" ? 'Worker' : 'Main') +
|
|
', numSockets=' + config.numSockets +
|
|
', numIterations=' + config.numIterations +
|
|
', verifyData=' + config.verifyData +
|
|
', minTotal=' + config.minTotal +
|
|
', numWarmUpIterations=' + config.numWarmUpIterations +
|
|
')';
|
|
}
|
|
|
|
function batchBenchmark(config) {
|
|
config.addToLog('Batch benchmark');
|
|
config.addToLog(buildLegendString(config));
|
|
|
|
tasks = [];
|
|
clearAverageData();
|
|
addTasks(config, sendBenchmarkStep);
|
|
addResultReportingTask(config, 'Send Benchmark ' + getConfigString(config));
|
|
addTasks(config, receiveBenchmarkStep);
|
|
addResultReportingTask(config, 'Receive Benchmark ' +
|
|
getConfigString(config));
|
|
startBenchmark(config);
|
|
}
|
|
|
|
function cleanup() {
|
|
destroyAllSockets();
|
|
}
|