Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea37af2c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "AStatsEvent_overwriteTimestamp"

parents 346e73b0 e41a6c62
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
+8 −0
Original line number Diff line number Diff line
@@ -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)], &timestampNs, 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) {
+18 −0
Original line number Diff line number Diff line
@@ -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);
}