Skip to content

Commit c910db1

Browse files
authored
test(NODE-6017): add an s390x big endian test (#660)
1 parent 6a7ef5d commit c910db1

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

.evergreen/config.yml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ functions:
5050
args:
5151
- .evergreen/run-tests.sh
5252

53+
run big endian tests:
54+
- command: subprocess.exec
55+
type: test
56+
params:
57+
working_dir: src
58+
add_expansions_to_env: true
59+
binary: bash
60+
args:
61+
- .evergreen/run-big-endian-test.sh
62+
5363
run checks:
5464
- command: subprocess.exec
5565
type: test
@@ -236,7 +246,6 @@ tasks:
236246
- command: perf.send
237247
params:
238248
file: src/test/bench/etc/resultsCollectedMeans.json
239-
240249
- name: run-spec-benchmarks-node-18
241250
commands:
242251
- func: fetch source
@@ -257,16 +266,25 @@ tasks:
257266
NODE_LTS_VERSION: 20
258267
- func: install dependencies
259268
- func: run eslint plugin tests
269+
- name: node-tests-big-endian
270+
commands:
271+
- func: fetch source
272+
vars:
273+
NODE_LTS_VERSION: 20
274+
- func: install dependencies
275+
vars:
276+
NPM_OPTIONS: "--ignore-scripts"
277+
- func: run big endian tests
260278

261279
buildvariants:
262280
- name: linux
263281
display_name: RHEL 8.0
264282
run_on: rhel80-small
265283
tasks: [".node", ".web", "check-eslint-plugin"]
266-
# - name: linux-zseries
267-
# display_name: RHEL 8.3 zSeries
268-
# run_on: rhel83-zseries-small
269-
# tasks: [".node", ".web"]
284+
- name: linux-zseries
285+
display_name: RHEL 8.3 zSeries
286+
run_on: rhel83-zseries-small
287+
tasks: ["node-tests-big-endian"]
270288
- name: lint
271289
display_name: lint
272290
run_on: rhel80-small

.evergreen/run-big-endian-test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
4+
5+
npx mocha test/s390x/big_endian.test.ts

test/s390x/big_endian.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { expect } from 'chai';
2+
import { BSON } from '../../src/index';
3+
4+
const FLOAT = new Float64Array(1);
5+
const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
6+
7+
FLOAT[0] = -1;
8+
// Little endian [0, 0, 0, 0, 0, 0, 240, 191]
9+
// Big endian [191, 240, 0, 0, 0, 0, 0, 0]
10+
const isBigEndian = FLOAT_BYTES[7] === 0;
11+
12+
context(`handles big endianness correctly`, () => {
13+
before(function () {
14+
if (!isBigEndian) {
15+
throw new Error('expected to only run on big endian system');
16+
}
17+
});
18+
19+
const bsonWithFloat = Buffer.from(
20+
[
21+
'10000000', // 16 bytes in size
22+
'01', // double
23+
'6100', // 'a'
24+
'00'.repeat(6) + 'f0bf', // 8 byte LE float equal to -1
25+
'00' // doc terminator
26+
].join(''),
27+
'hex'
28+
);
29+
30+
it('deserialize should return -1', () => {
31+
const res = BSON.deserialize(bsonWithFloat);
32+
expect(res).to.have.property('a', -1);
33+
});
34+
35+
it('serialize should set bytes to -1 in little endian format', () => {
36+
const res = BSON.serialize({ a: new BSON.Double(-1) });
37+
expect(res).to.deep.equal(bsonWithFloat);
38+
});
39+
});

0 commit comments

Comments
 (0)