Merge "AStatsEvent_overwriteTimestamp"
This commit is contained in:
commit
ea37af2c62
3 changed files with 27 additions and 0 deletions
|
|
@ -152,6 +152,7 @@ void AStatsEvent_addBoolAnnotation(AStatsEvent* event, uint8_t annotationId, boo
|
|||
void AStatsEvent_addInt32Annotation(AStatsEvent* event, uint8_t annotationId, int32_t value);
|
||||
|
||||
// Internal/test APIs. Should not be exposed outside of the APEX.
|
||||
void AStatsEvent_overwriteTimestamp(AStatsEvent* event, uint64_t timestampNs);
|
||||
uint32_t AStatsEvent_getAtomId(AStatsEvent* event);
|
||||
// Size is an output parameter.
|
||||
uint8_t* AStatsEvent_getBuffer(AStatsEvent* event, size_t* size);
|
||||
|
|
|
|||
|
|
@ -115,6 +115,14 @@ void AStatsEvent_setAtomId(AStatsEvent* event, uint32_t atomId) {
|
|||
event->numElements++;
|
||||
}
|
||||
|
||||
// Overwrites the timestamp populated in AStatsEvent_obtain with a custom
|
||||
// timestamp. Should only be called from test code.
|
||||
void AStatsEvent_overwriteTimestamp(AStatsEvent* event, uint64_t timestampNs) {
|
||||
memcpy(&event->buf[POS_TIMESTAMP + sizeof(uint8_t)], ×tampNs, sizeof(timestampNs));
|
||||
// Do not increment numElements because we already accounted for the timestamp
|
||||
// within AStatsEvent_obtain.
|
||||
}
|
||||
|
||||
// Side-effect: modifies event->errors if the buffer would overflow
|
||||
static bool overflows(AStatsEvent* event, size_t size) {
|
||||
if (event->size + size > MAX_EVENT_PAYLOAD) {
|
||||
|
|
|
|||
|
|
@ -318,3 +318,21 @@ TEST(StatsEventTest, TestOverflowError) {
|
|||
|
||||
AStatsEvent_release(event);
|
||||
}
|
||||
|
||||
TEST(StatsEventTest, TestOverwriteTimestamp) {
|
||||
uint32_t atomId = 100;
|
||||
int64_t expectedTimestamp = 0x123456789;
|
||||
AStatsEvent* event = AStatsEvent_obtain();
|
||||
AStatsEvent_setAtomId(event, atomId);
|
||||
AStatsEvent_overwriteTimestamp(event, expectedTimestamp);
|
||||
AStatsEvent_build(event);
|
||||
|
||||
uint8_t* buffer = AStatsEvent_getBuffer(event, NULL);
|
||||
|
||||
// Make sure that the timestamp is being overwritten.
|
||||
checkMetadata(&buffer, /*numElements=*/0, /*startTime=*/expectedTimestamp,
|
||||
/*endTime=*/expectedTimestamp, atomId);
|
||||
|
||||
EXPECT_EQ(AStatsEvent_getErrors(event), 0);
|
||||
AStatsEvent_release(event);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue