import nrfdlModule, { Device, Error, Progress, // @ts-ignore nrfdlModule Is not a module } from '../../../index'; import { validateSchema } from './common/helpers'; require('../../../jasmine_shared.js'); /** * Test cases: * - negative test case to check if error is provided as expected * - ... other test cases based on the app's code * * Test API: * - createContext() * - enumerate() * - deviceControlGetProtectionStatus() * - deviceControlSetProtectionStatus() * - firmwareProgram() * - deviceControlRecover() * - getDeviceCoreInfo() * * Test Schema: * - Error * - DeviceInfo * - GetProtectionStatusResult * - Progress.CallbackParameters * - Progress.Operation * - Progress.OperationName * - Progress.OperationResult */ describe('Program firmware tests', () => { jasmine.DEFAULT_TIMEOUT_INTERVAL = 40000; const hex_path = './jlink_usb.hex'; // const nrf91_modem_zip_path = './mfw_nrf9160_1.2.2.zip'; const sdfu_path = './dfu_pkg.zip'; let context = 0; const jLinkDevices: Device[] = []; const nordicDfuDevices: Device[] = []; beforeAll(async () => { context = nrfdlModule.createContext({ plugins_dir: './Release' }); const jlink: Device[] = await nrfdlModule.enumerate(context, { jlink: true, }); jLinkDevices.push(...jlink); const nordicDfu: Device[] = await nrfdlModule.enumerate(context, { nordicDfu: true, }); nordicDfuDevices.push(...nordicDfu); }); afterAll(() => { nrfdlModule.releaseContext(context); }); /** * 1) Get error (negative result) * 2) See if error has property error_code (used in real code and must be changed to errorCode in the future) * 3) Test get/set protection status methods * TODO: NOTE that there are no protection_status anymore * 4) Property protection_status exists (used in real code and must be changed to protectionStatus in the future <-- NOTE!!! */ it('Firmware program get error (negative test)', async () => { expect(jLinkDevices.length).toBeGreaterThan(0); const jLinkDevice: Device | null = jLinkDevices.length > 0 ? jLinkDevices[0] : null; const protectionStatus = await nrfdlModule.deviceControlGetProtectionStatus(context, jLinkDevice.id); const schemaIsValid = await validateSchema('#/definitions/GetProtectionStatusResult', protectionStatus, true); expect(schemaIsValid).toBe(true); if (protectionStatus.protectionStatus === 'NRFDL_PROTECTION_STATUS_NONE') { // get protected device -> guarantee error await nrfdlModule.deviceControlSetProtectionStatus(context, jLinkDevice.id, 'NRFDL_PROTECTION_STATUS_ALL'); } await new Promise((resolve, reject) => nrfdlModule.firmwareProgram( context, jLinkDevice.id, nrfdlModule.NRFDL_FW_FILE, nrfdlModule.NRFDL_FW_INTEL_HEX, hex_path, async (err: Error | undefined) => { if (!err) { // test expects error reject(); return; } // can be replaced with validate schema, but error_code must be refactored first expect(err.error_code).toBeGreaterThanOrEqual(0); expect(err.message).not.toBe(''); expect(err.origin).not.toBe(''); // const errorSchemaIsValid = await validateSchema('#/definitions/Error', err); // expect(errorSchemaIsValid).toBe(true); resolve(); }, () => {} ) ); // cleanup - reset device await nrfdlModule.deviceControlRecover(context, jLinkDevice.id); const finalProtectionStatus = await nrfdlModule.deviceControlGetProtectionStatus(context, jLinkDevice.id); expect(finalProtectionStatus.protectionStatus).toEqual('NRFDL_PROTECTION_STATUS_NONE'); }); it('Test firmwareProgram() progress callback', async () => { expect(nordicDfuDevices.length).toBeGreaterThanOrEqual(1); await Promise.all( nordicDfuDevices.map( dev => new Promise((resolve, reject) => nrfdlModule.firmwareProgram( context, dev.id, nrfdlModule.NRFDL_FW_FILE, nrfdlModule.NRFDL_FW_SDFU_ZIP, sdfu_path, (err: Error) => { if (err) { reject(err); } resolve(null); }, async (progress: Progress.CallbackParameters) => { const schemaValid = await validateSchema( '#/definitions/Progress.CallbackParameters', progress, true ); expect(schemaValid).toBe(true); } ) ) ) ); }, 45000); });