Skip to content

Commit

Permalink
update test and fix unspecified error in keystone
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinafyi committed Sep 4, 2024
1 parent baa4937 commit 0dc560d
Show file tree
Hide file tree
Showing 5 changed files with 6,984 additions and 34 deletions.
89 changes: 56 additions & 33 deletions cypress/e2e/basicspec.cy.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,69 @@

const opcodes = [
{ asm: 'orr x1, x2, x3', big: '0xaa030041', little: '41 00 03 AA' },
{ asm: 'orr x1, x2, x5', big: '0xaa050041', little: '41 00 05 AA' },
{ asm: 'orr x1, x2, x10', big: '0xaa0a0041', little: '41 00 0A AA' },
];

describe('aslp-web tests', () => {
it('synchronises with big-endian input', () => {
// cy.intercept('GET', 'aslp.heap').as('heap');
cy.aslpweb().then(() => {
cy.getByLabel('big-endian').type('{selectall}0xaa030041').then(x => {
cy.getByLabel('assembly').should('have.value', 'orr x1, x2, x3');
cy.getByLabel('little-endian').should('have.value', '41 00 03 AA');
});
});
});
it('synchronises valid inputs', () => {
cy.aslpweb();

cy.getByLabel('big-endian').type('{selectall}' + opcodes[0].big);
cy.getByLabel('assembly').should('have.value', opcodes[0].asm);
cy.getByLabel('little-endian').should('have.value', opcodes[0].little);

cy.getByLabel('little-endian').type('{selectall}' + opcodes[1].little);
cy.getByLabel('big-endian').should('have.value', opcodes[1].big);
cy.getByLabel('assembly').should('have.value', opcodes[1].asm);

it('synchronises with little-endian input', () => {
cy.aslpweb().then(() => {
cy.getByLabel('little-endian').type('{selectall}41 00 03 AA').then(x => {
cy.getByLabel('big-endian').should('have.value', '0xaa030041');
cy.getByLabel('assembly').should('have.value', 'orr x1, x2, x3');
});
});
cy.getByLabel('assembly').type('{selectall}' + opcodes[2].asm);
cy.getByLabel('big-endian').should('have.value', opcodes[2].big);
cy.getByLabel('little-endian').should('have.value', opcodes[2].little);
});

it('synchronises with asm input', () => {
cy.aslpweb().then(() => {
cy.getByLabel('assembly').type('{selectall}orr x1, x2, x3').then(x => {
cy.getByLabel('big-endian').should('have.value', '0xaa030041');
cy.getByLabel('little-endian').should('have.value', '41 00 03 AA');
});
});
it('synchronises and rejects invalid inputs', () => {
cy.aslpweb();

cy.getByLabel('little-endian').type('{selectall}' + '41 00 0A AA 1');
cy.getByLabel('big-endian').should('have.value', '0x01aa0a0041');
cy.getByLabel('assembly').should('have.value', '');
cy.contains('bytes input:').should('be.visible').and('have.class', 'stderr');

cy.getByLabel('assembly').type('{selectall}' + 'an invalid assembly');
cy.getByLabel('big-endian').should('have.value', '');
cy.getByLabel('little-endian').should('have.value', '');
cy.contains('asm input:').should('be.visible').and('have.class', 'stderr');
});

it('disassembles', () => {
cy.aslpweb().then(() => {
cy.getByLabel('big-endian').type('{selectall}0xaa030041').then(x => {
cy.get('button[type=submit]').click().then(x => {
cy.get('#output').should('contain', 'aarch64_integer_logical_shiftedreg').and('contain', 'or_bits');
});
});
});
cy.aslpweb();
cy.getByLabel('big-endian').type('{selectall}0xaa030041');
cy.get('button[type=submit]').click();
cy.get('#output')
.should('contain', 'aarch64_integer_logical_shiftedreg')
.and('contain', 'or_bits');

cy.getByLabel('assembly').type('{selectall}' + 'add v0.4h, v0.4h, v0.4h');
cy.get('button[type=submit]').click();
cy.get('#output')
.should('contain', 'aarch64_vector_arithmetic_binary_uniform_add_wrapping_single_simd')
.and('not.contain', 'add_vec')
.and('contain', 'add_bits');

cy.getByLabel('vector').check({ force: true });
cy.get('button[type=submit]').click();
cy.get('#output')
.should('contain', 'aarch64_vector_arithmetic_binary_uniform_add_wrapping_single_simd')
.and('contain', 'add_vec');
});

it('parses options from url', () => {
cy.aslpweb('?opcode=0xaa030041&bytes=41+00+03+AA&asm=orr+x1%2C+x2%2C+x3&debug=1').then(() => {
cy.get('#output').should('contain', 'aarch64_integer_logical_shiftedreg').and('contain', 'or_bits').and('contain', 'dis_decode_case');
});
cy.aslpweb('?opcode=0xaa030041&bytes=41+00+03+AA&asm=orr+x1%2C+x2%2C+x3&debug=1');
cy.get('#output')
.should('contain', 'aarch64_integer_logical_shiftedreg')
.and('contain', 'or_bits')
.and('contain', 'dis_decode_case');
});

})
2 changes: 1 addition & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ Cypress.Commands.add('getByLabel', (label) => {

Cypress.Commands.add('aslpweb', (query) => {
cy.visit('http://localhost:10000/' + (query ?? ''));
return cy.contains('Loading').filter(':hidden');
return cy.contains('Loading').filter(':hidden', { timeout: 20000 });
})
46 changes: 46 additions & 0 deletions web/cache.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import './builder.bc.js';
import * as pako from './lib/pako.esm.mjs';

const IS_NODE = typeof self !== 'object';
const fs = IS_NODE ? await import('fs') : null;
const path = IS_NODE ? await import('path') : null;

export const marshal = () => {
if (!IS_NODE) throw Error("marshalling only supported on node");

console.log('marshalling aslp environment...');
const arr = pako.gzip(libASL_builder.marshal(libASL_builder.force()));

let marshalUrl;
if (IS_NODE) {
fs.writeFileSync('aslp.heap', Buffer.from(arr));
marshalUrl = path.resolve('.', 'aslp.heap');

} else {
marshalUrl = URL.createObjectURL(
new File(
[arr],
'aslp.heap',
{ lastModified: Date.now(), type: 'application/octet-stream' }));

}
console.log(marshalUrl);
};


export const unmarshal = async (/* ArrayBuffer */ buf) => {
try {
const arr = pako.ungzip(new Uint8Array(buf));

libASL_web.unmarshal(arr);
console.log(`heap loaded: ${arr.length} bytes, ${buf.byteLength} compressed`);

} catch (e) {
console.warn('failed to fetch heap');
console.warn(e);
}
};

if (IS_NODE) {
marshal();
}
Loading

0 comments on commit 0dc560d

Please sign in to comment.