diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/serial/serialPort_readable-manual.https.html | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/serial/serialPort_readable-manual.https.html')
-rw-r--r-- | testing/web-platform/tests/serial/serialPort_readable-manual.https.html | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/testing/web-platform/tests/serial/serialPort_readable-manual.https.html b/testing/web-platform/tests/serial/serialPort_readable-manual.https.html new file mode 100644 index 0000000000..4e49ef4061 --- /dev/null +++ b/testing/web-platform/tests/serial/serialPort_readable-manual.https.html @@ -0,0 +1,107 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <title></title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="resources/common.js"></script> + <script src="resources/manual.js"></script> + </head> + <body> + <p> + These tests require a device configured with the following Arduino sketch: + + <pre> +uint32_t seed = 0; +uint32_t bytesToSend = 0; + +uint8_t nextByte() { + seed = (1103515245 * seed + 12345) % 0x8000000; + return (seed >> 16) & 0xFF; +} + +void setup() { + Serial.begin(115200); +} + +void loop() { + if (!Serial) { + return; + } + + if (bytesToSend == 0) { + // Read the seed and number of bytes to send from the host as 32-bit + // little-endian values. + if (Serial.available() < 8) { + return; + } + + uint8_t buf[8]; + Serial.readBytes((char*)buf, sizeof buf); + seed = (uint32_t)buf[0] | + ((uint32_t)buf[1] << 8) | + ((uint32_t)buf[2] << 16) | + ((uint32_t)buf[3] << 24); + bytesToSend = (uint32_t)buf[4] | + ((uint32_t)buf[5] << 8) | + ((uint32_t)buf[6] << 16) | + ((uint32_t)buf[7] << 24); + } else { + uint8_t buf[64]; + uint32_t count = min(sizeof buf, bytesToSend); + for (uint32_t i = 0; i < count; ++i) { + buf[i] = nextByte(); + } + bytesToSend -= count; + Serial.write((char*)buf, count); + } +} + </pre> + </p> + <p> + <progress id='progress'></progress> + </p> + <script> + let seed = 10; + const length = 1024 * 1024 * 10; + + function next_byte() { + seed = (Math.imul(1103515245, seed) + 12345) % (1 << 31); + return (seed >> 16) & 0xFF; + } + + manual_serial_test(async (t, port) => { + await port.open({baudRate: 115200, bufferSize: 1024}); + + const config = new DataView(new ArrayBuffer(8)); + config.setUint32(0, seed, /*littleEndian=*/true); + config.setUint32(4, length, /*littleEndian=*/true); + + const writer = port.writable.getWriter(); + writer.write(config); + + const progress = document.getElementById('progress'); + progress.max = length; + progress.value = 0; + + const reader = port.readable.getReader(); + let bytesRead = 0; + while (bytesRead < length) { + const { value, done } = await reader.read(); + assert_false(done); + for (let i = 0; i < value.byteLength; ++i) { + assert_equals(value[i], next_byte(), + `mismatch at byte ${bytesRead + i}`); + } + bytesRead += value.byteLength; + progress.value = bytesRead; + } + + writer.releaseLock(); + reader.releaseLock(); + await port.close(); + }, `Reading ${length} bytes from the device succeeds.`); + </script> + </body> +</html> |