-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/rokucommunity/roku-debug …
…into logging-updates
- Loading branch information
Showing
7 changed files
with
318 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { ListBreakpointsResponse } from './ListBreakpointsResponse'; | ||
|
||
//There's currently no difference between this response and the ListBreakpoints response | ||
export class AddBreakpointsResponse extends ListBreakpointsResponse { } |
133 changes: 133 additions & 0 deletions
133
src/debugProtocol/responses/ListBreakpointsResponse.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { createListBreakpointsResponse, getRandomBuffer } from './responseCreationHelpers.spec'; | ||
import { expect } from 'chai'; | ||
import { ListBreakpointsResponse } from './ListBreakpointsResponse'; | ||
import { ERROR_CODES } from '../Constants'; | ||
|
||
describe('ListBreakpointsResponse', () => { | ||
let response: ListBreakpointsResponse; | ||
beforeEach(() => { | ||
response = undefined; | ||
}); | ||
it('handles empty buffer', () => { | ||
response = new ListBreakpointsResponse(null); | ||
//Great, it didn't explode! | ||
expect(response.success).to.be.false; | ||
}); | ||
|
||
it('handles undersized buffers', () => { | ||
response = new ListBreakpointsResponse( | ||
getRandomBuffer(0) | ||
); | ||
expect(response.success).to.be.false; | ||
|
||
response = new ListBreakpointsResponse( | ||
getRandomBuffer(1) | ||
); | ||
expect(response.success).to.be.false; | ||
|
||
response = new ListBreakpointsResponse( | ||
getRandomBuffer(11) | ||
); | ||
expect(response.success).to.be.false; | ||
}); | ||
|
||
it('gracefully handles mismatched breakpoint count', () => { | ||
const bp1 = { | ||
breakpointId: 1, | ||
errorCode: ERROR_CODES.OK, | ||
hitCount: 0, | ||
success: true | ||
}; | ||
response = new ListBreakpointsResponse( | ||
createListBreakpointsResponse({ | ||
requestId: 1, | ||
num_breakpoints: 2, | ||
breakpoints: [bp1] | ||
}).toBuffer() | ||
); | ||
expect(response.success).to.be.false; | ||
expect(response.breakpoints).to.eql([bp1]); | ||
}); | ||
|
||
it('handles malformed breakpoint data', () => { | ||
const bp1 = { | ||
breakpointId: 1, | ||
errorCode: ERROR_CODES.OK, | ||
hitCount: 2, | ||
success: true | ||
}; | ||
response = new ListBreakpointsResponse( | ||
createListBreakpointsResponse({ | ||
requestId: 1, | ||
num_breakpoints: 2, | ||
breakpoints: [ | ||
bp1, | ||
{ | ||
//missing all other bp properties | ||
breakpointId: 1 | ||
} | ||
] | ||
}).toBuffer() | ||
); | ||
expect(response.success).to.be.false; | ||
expect(response.breakpoints).to.eql([bp1]); | ||
}); | ||
|
||
it('handles malformed breakpoint data', () => { | ||
const bp1 = { | ||
breakpointId: 0, | ||
errorCode: ERROR_CODES.OK, | ||
success: true | ||
}; | ||
response = new ListBreakpointsResponse( | ||
createListBreakpointsResponse({ | ||
requestId: 1, | ||
num_breakpoints: 2, | ||
breakpoints: [bp1] | ||
}).toBuffer() | ||
); | ||
expect(response.success).to.be.false; | ||
//hitcount should not be set when bpId is zero | ||
expect(response.breakpoints[0].hitCount).to.be.undefined; | ||
//the breakpoint should not be verified if bpId === 0 | ||
expect(response.breakpoints[0].isVerified).to.be.false; | ||
}); | ||
|
||
it('reads breakpoint data properly', () => { | ||
const bp1 = { | ||
breakpointId: 1, | ||
errorCode: ERROR_CODES.OK, | ||
hitCount: 0, | ||
success: true | ||
}; | ||
response = new ListBreakpointsResponse( | ||
createListBreakpointsResponse({ | ||
requestId: 1, | ||
breakpoints: [bp1] | ||
}).toBuffer() | ||
); | ||
expect(response.success).to.be.true; | ||
expect(response.breakpoints).to.eql([bp1]); | ||
expect(response.breakpoints[0].isVerified).to.be.true; | ||
}); | ||
|
||
it('reads breakpoint data properly', () => { | ||
const bp1 = { | ||
breakpointId: 1, | ||
errorCode: ERROR_CODES.NOT_STOPPED, | ||
hitCount: 0, | ||
success: true | ||
}; | ||
response = new ListBreakpointsResponse( | ||
createListBreakpointsResponse({ | ||
requestId: 1, | ||
breakpoints: [bp1] | ||
}).toBuffer() | ||
); | ||
expect( | ||
response.breakpoints[0].errorText | ||
).to.eql( | ||
ERROR_CODES[ERROR_CODES.NOT_STOPPED] | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { SmartBuffer } from 'smart-buffer'; | ||
import { ERROR_CODES } from '../Constants'; | ||
|
||
export class ListBreakpointsResponse { | ||
|
||
constructor(buffer: Buffer) { | ||
// The minimum size of a request | ||
if (buffer?.byteLength >= 12) { | ||
try { | ||
let bufferReader = SmartBuffer.fromBuffer(buffer); | ||
this.requestId = bufferReader.readUInt32LE(); // request_id | ||
|
||
// Any request id less then one is an update and we should not process it here | ||
if (this.requestId > 0) { | ||
this.errorCode = ERROR_CODES[bufferReader.readUInt32LE()]; | ||
this.numBreakpoints = bufferReader.readUInt32LE(); // num_breakpoints - The number of breakpoints in the breakpoints array. | ||
|
||
// build the list of BreakpointInfo | ||
for (let i = 0; i < this.numBreakpoints; i++) { | ||
let breakpointInfo = new BreakpointInfo(bufferReader); | ||
// All the necessary data was present, so keep this item | ||
this.breakpoints.push(breakpointInfo); | ||
} | ||
|
||
this.readOffset = bufferReader.readOffset; | ||
this.success = (this.breakpoints.length === this.numBreakpoints); | ||
} | ||
} catch (error) { | ||
// Could not parse | ||
} | ||
} | ||
} | ||
public success = false; | ||
public readOffset = 0; | ||
|
||
// response fields | ||
public requestId = -1; | ||
public numBreakpoints: number; | ||
public breakpoints = [] as BreakpointInfo[]; | ||
public data = -1; | ||
public errorCode: string; | ||
} | ||
|
||
export class BreakpointInfo { | ||
constructor(bufferReader: SmartBuffer) { | ||
// breakpoint_id - The ID assigned to the breakpoint. An ID greater than 0 indicates an active breakpoint. An ID of 0 denotes that the breakpoint has an error. | ||
this.breakpointId = bufferReader.readUInt32LE(); | ||
// error_code - Indicates whether the breakpoint was successfully returned. | ||
this.errorCode = bufferReader.readUInt32LE(); | ||
|
||
if (this.breakpointId > 0) { | ||
// This argument is only present if the breakpoint_id is valid. | ||
// ignore_count - Current state, decreases as breakpoint is executed. | ||
this.hitCount = bufferReader.readUInt32LE(); | ||
} | ||
this.success = true; | ||
} | ||
|
||
public get isVerified() { | ||
return this.breakpointId > 0; | ||
} | ||
public success = false; | ||
public breakpointId: number; | ||
public errorCode: number; | ||
/** | ||
* The textual description of the error code | ||
*/ | ||
public get errorText() { | ||
return ERROR_CODES[this.errorCode]; | ||
} | ||
public hitCount: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { ListBreakpointsResponse } from './ListBreakpointsResponse'; | ||
|
||
//There's currently no difference between this response and the ListBreakpoints response | ||
export class RemoveBreakpointsResponse extends ListBreakpointsResponse { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters