blob: 88ad758c61e99579e40afe7c269aacdb58d322b5 [file] [log] [blame]
// Copyright 2022 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Tests for SyscallLock.
*/
import {SyscallLock} from '../js/syscall_lock.js';
describe('syscall_lock.js', () => {
/**
* If running on a web page, SharedArrayBuffers might not work.
*/
before(function() {
if (window.SharedArrayBuffer === undefined) {
console.warn('SharedArrayBuffer API not available');
this.skip();
}
});
/**
* Check BigInt is correctly serialized and deserialized.
*/
it('setData and getData BigInt', () => {
const buf = new SharedArrayBuffer(64 * 1024);
const lock = new SyscallLock(buf);
const data = {events: [{fd_read: {nwritten: BigInt(100)}}]};
lock.setData(data);
const deserialized = lock.getData();
assert.deepStrictEqual(deserialized, data);
});
/**
* Check TypedArray is correctly serialized and deserialized as an Array.
*/
it('setData and getData TypedArray', () => {
const typedArray = new Uint8Array([1, 2, 3, 4, 5]);
const buf = new SharedArrayBuffer(64 * 1024);
const lock = new SyscallLock(buf);
const data = {foo: [{bar: typedArray}]};
const expected = {foo: [{bar: Array.from(typedArray)}]};
lock.setData(data);
const deserialized = lock.getData();
assert.deepStrictEqual(deserialized, expected);
});
});