1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 #include <string>
20 
21 #include "chre/core/event.h"
22 #include "chre/platform/atomic.h"
23 #include "chre/platform/condition_variable.h"
24 #include "chre/platform/mutex.h"
25 #include "chre/platform/shared/bt_snoop_log.h"
26 #include "chre/platform/shared/log_buffer.h"
27 
28 using testing::ContainerEq;
29 
30 namespace chre {
31 
32 // TODO(b/146164384): Test that the onLogsReady callback is called
33 //                    asynchronously
34 
35 class TestLogBufferCallback : public LogBufferCallbackInterface {
36  public:
onLogsReady()37   void onLogsReady() {
38     // Do nothing
39   }
40 };
41 
42 static constexpr size_t kDefaultBufferSize = 1024;
43 
44 // Helpers
copyStringWithOffset(char * destination,const char * source,size_t sourceOffset)45 void copyStringWithOffset(char *destination, const char *source,
46                           size_t sourceOffset) {
47   size_t strlength = strlen(source + sourceOffset);
48   // +1 to copy nullbyte on the end
49   memcpy(destination, source + sourceOffset, strlength + 1);
50 }
51 
TEST(LogBuffer,HandleOneLogAndCopy)52 TEST(LogBuffer, HandleOneLogAndCopy) {
53   char buffer[kDefaultBufferSize];
54   constexpr size_t kOutBufferSize = 20;
55   char outBuffer[kOutBufferSize];
56   const char *testLogStr = "test";
57   char testedBuffer[kOutBufferSize];
58   TestLogBufferCallback callback;
59 
60   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
61   logBuffer.handleLog(LogBufferLogLevel::INFO, 0, testLogStr);
62   size_t numLogsDropped;
63   size_t bytesCopied =
64       logBuffer.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
65 
66   EXPECT_EQ(bytesCopied, strlen(testLogStr) + LogBuffer::kLogDataOffset + 1);
67   copyStringWithOffset(testedBuffer, outBuffer, LogBuffer::kLogDataOffset);
68   EXPECT_TRUE(strcmp(testedBuffer, testLogStr) == 0);
69 }
70 
TEST(LogBuffer,HandleTwoLogsAndCopy)71 TEST(LogBuffer, HandleTwoLogsAndCopy) {
72   char buffer[kDefaultBufferSize];
73   constexpr size_t kOutBufferSize = 30;
74   char outBuffer[kOutBufferSize];
75   const char *testLogStr = "test";
76   const char *testLogStr2 = "test2";
77   char testedBuffer[kOutBufferSize];
78   TestLogBufferCallback callback;
79 
80   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
81   logBuffer.handleLog(LogBufferLogLevel::INFO, 0, testLogStr);
82   logBuffer.handleLog(LogBufferLogLevel::INFO, 0, testLogStr2);
83   size_t numLogsDropped;
84   size_t bytesCopied =
85       logBuffer.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
86 
87   EXPECT_EQ(bytesCopied, strlen(testLogStr) + strlen(testLogStr2) +
88                              2 * LogBuffer::kLogDataOffset + 2);
89   copyStringWithOffset(testedBuffer, outBuffer, LogBuffer::kLogDataOffset);
90   EXPECT_TRUE(strcmp(testedBuffer, testLogStr) == 0);
91   copyStringWithOffset(testedBuffer, outBuffer,
92                        2 * LogBuffer::kLogDataOffset + strlen(testLogStr) + 1);
93   EXPECT_TRUE(strcmp(testedBuffer, testLogStr2) == 0);
94 }
95 
TEST(LogBuffer,FailOnMoreCopyThanHandle)96 TEST(LogBuffer, FailOnMoreCopyThanHandle) {
97   char buffer[kDefaultBufferSize];
98   constexpr size_t kOutBufferSize = 20;
99   char outBuffer[kOutBufferSize];
100   const char *testLogStr = "test";
101   TestLogBufferCallback callback;
102 
103   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
104   logBuffer.handleLog(LogBufferLogLevel::INFO, 0, testLogStr);
105   size_t numLogsDropped;
106   logBuffer.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
107   size_t bytesCopied =
108       logBuffer.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
109 
110   EXPECT_EQ(bytesCopied, 0);
111 }
112 
TEST(LogBuffer,FailOnHandleLargerLogThanBufferSize)113 TEST(LogBuffer, FailOnHandleLargerLogThanBufferSize) {
114   char buffer[kDefaultBufferSize];
115   constexpr size_t kOutBufferSize = 20;
116   char outBuffer[kOutBufferSize];
117   // Note the size of this log is too big to fit in the buffer that we are
118   // using for the LogBuffer object
119   std::string testLogStrStr(kDefaultBufferSize + 1, 'a');
120   TestLogBufferCallback callback;
121 
122   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
123   logBuffer.handleLog(LogBufferLogLevel::INFO, 0, testLogStrStr.c_str());
124   size_t numLogsDropped;
125   size_t bytesCopied =
126       logBuffer.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
127 
128   // Should not be able to read this log out because there should be no log in
129   // the first place
130   EXPECT_EQ(bytesCopied, 0);
131 }
132 
TEST(LogBuffer,StringLogOverwritten)133 TEST(LogBuffer, StringLogOverwritten) {
134   char buffer[kDefaultBufferSize];
135   constexpr size_t kOutBufferSize = 200;
136   char outBuffer[kOutBufferSize];
137   TestLogBufferCallback callback;
138   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
139 
140   constexpr size_t kLogPayloadSize = 100;
141   constexpr size_t kBufferUsePerLog = LogBuffer::kLogDataOffset +
142                                       LogBuffer::kStringLogOverhead +
143                                       kLogPayloadSize;
144   constexpr int kNumInsertions = 10;
145   constexpr int kNumLogDropsExpected =
146       kNumInsertions - kDefaultBufferSize / kBufferUsePerLog;
147   static_assert(kNumLogDropsExpected > 0);
148 
149   // This for loop adds 1060 (kNumInsertions * kBufferUsePerLog) bytes of data
150   // through the buffer which is > than 1024.
151   for (size_t i = 0; i < kNumInsertions; i++) {
152     std::string testLogStrStr(kLogPayloadSize, 'a' + i);
153     const char *testLogStr = testLogStrStr.c_str();
154     logBuffer.handleLog(LogBufferLogLevel::INFO, 0, testLogStr);
155   }
156   EXPECT_EQ(logBuffer.getBufferSize(),
157             (kNumInsertions - kNumLogDropsExpected) * kBufferUsePerLog);
158   EXPECT_EQ(logBuffer.getNumLogsDropped(), kNumLogDropsExpected);
159 
160   for (size_t i = logBuffer.getNumLogsDropped(); i < kNumInsertions; i++) {
161     // Should have read out the i-th from front test log string which a string
162     // log 'a' + i.
163     size_t numLogsDropped;
164     size_t bytesCopied =
165         logBuffer.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
166     EXPECT_TRUE(strcmp(outBuffer + LogBuffer::kLogDataOffset,
167                        std::string(kLogPayloadSize, 'a' + i).c_str()) == 0);
168     EXPECT_EQ(bytesCopied, kBufferUsePerLog);
169   }
170 }
171 
TEST(LogBuffer,TokenizedLogOverwritten)172 TEST(LogBuffer, TokenizedLogOverwritten) {
173   char buffer[kDefaultBufferSize];
174   TestLogBufferCallback callback;
175   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
176 
177   constexpr size_t kLogPayloadSize = 100;
178   constexpr size_t kBufferUsePerLog = LogBuffer::kLogDataOffset +
179                                       LogBuffer::kTokenizedLogOffset +
180                                       kLogPayloadSize;
181   constexpr int kNumInsertions = 10;
182   constexpr int kNumLogDropsExpected =
183       kNumInsertions - kDefaultBufferSize / kBufferUsePerLog;
184   static_assert(kNumLogDropsExpected > 0);
185 
186   // This for loop adds 1060 (kNumInsertions * kBufferUsePerLog) bytes of data
187   // through the buffer which is > than 1024.
188   for (size_t i = 0; i < kNumInsertions; i++) {
189     std::vector<uint8_t> testData(kLogPayloadSize, i);
190     logBuffer.handleEncodedLog(LogBufferLogLevel::INFO, 0, testData.data(),
191                                testData.size());
192   }
193   EXPECT_EQ(logBuffer.getBufferSize(),
194             (kNumInsertions - kNumLogDropsExpected) * kBufferUsePerLog);
195   EXPECT_EQ(logBuffer.getNumLogsDropped(), kNumLogDropsExpected);
196 
197   for (size_t i = logBuffer.getNumLogsDropped(); i < kNumInsertions; i++) {
198     // Should have read out the i-th from front test log data which is an
199     // integer i.
200     std::vector<uint8_t> outBuffer(kBufferUsePerLog, 0x77);
201     size_t numLogsDropped;
202     size_t bytesCopied =
203         logBuffer.copyLogs(outBuffer.data(), outBuffer.size(), &numLogsDropped);
204 
205     // Validate that the log size in Tokenized log header matches the expected
206     // log size.
207     EXPECT_EQ(outBuffer[LogBuffer::kLogDataOffset], kLogPayloadSize);
208 
209     outBuffer.erase(outBuffer.begin(), outBuffer.begin() +
210                                            LogBuffer::kLogDataOffset +
211                                            LogBuffer::kTokenizedLogOffset);
212     EXPECT_THAT(outBuffer,
213                 ContainerEq(std::vector<uint8_t>(kLogPayloadSize, i)));
214     EXPECT_EQ(bytesCopied, kBufferUsePerLog);
215   }
216 }
217 
TEST(LogBuffer,BtSnoopLogOverwritten)218 TEST(LogBuffer, BtSnoopLogOverwritten) {
219   char buffer[kDefaultBufferSize];
220   TestLogBufferCallback callback;
221   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
222 
223   constexpr size_t kLogPayloadSize = 100;
224   constexpr size_t kBufferUsePerLog = LogBuffer::kLogDataOffset +
225                                       LogBuffer::kBtSnoopLogOffset +
226                                       kLogPayloadSize;
227   constexpr int kNumInsertions = 10;
228   constexpr int kNumLogDropsExpected =
229       kNumInsertions - kDefaultBufferSize / kBufferUsePerLog;
230   static_assert(kNumLogDropsExpected > 0);
231 
232   // This for loop adds 1070 (kNumInsertions * kBufferUsePerLog) bytes of data
233   // through the buffer which is > than 1024.
234   for (size_t i = 0; i < kNumInsertions; i++) {
235     std::vector<uint8_t> testData(kLogPayloadSize, i);
236     logBuffer.handleBtLog(BtSnoopDirection::INCOMING_FROM_BT_CONTROLLER, 0,
237                           testData.data(), testData.size());
238   }
239   EXPECT_EQ(logBuffer.getBufferSize(),
240             (kNumInsertions - kNumLogDropsExpected) * kBufferUsePerLog);
241   EXPECT_EQ(logBuffer.getNumLogsDropped(), kNumLogDropsExpected);
242 
243   for (size_t i = logBuffer.getNumLogsDropped(); i < kNumInsertions; i++) {
244     // Should have read out the i-th from front test log data which is an
245     // integer i.
246     std::vector<uint8_t> outBuffer(kBufferUsePerLog, 0x77);
247     size_t numLogsDropped;
248     size_t bytesCopied =
249         logBuffer.copyLogs(outBuffer.data(), outBuffer.size(), &numLogsDropped);
250 
251     // Validate that the Bt Snoop log header matches the expected log direction
252     // and size.
253     constexpr int kBtSnoopLogHeaderSizeOffset = 1;
254     EXPECT_EQ(
255         static_cast<BtSnoopDirection>(outBuffer[LogBuffer::kLogDataOffset]),
256         BtSnoopDirection::INCOMING_FROM_BT_CONTROLLER);
257     EXPECT_EQ(
258         outBuffer[LogBuffer::kLogDataOffset + kBtSnoopLogHeaderSizeOffset],
259         kLogPayloadSize);
260 
261     outBuffer.erase(outBuffer.begin(), outBuffer.begin() +
262                                            LogBuffer::kLogDataOffset +
263                                            LogBuffer::kBtSnoopLogOffset);
264     EXPECT_THAT(outBuffer,
265                 ContainerEq(std::vector<uint8_t>(kLogPayloadSize, i)));
266     EXPECT_EQ(bytesCopied, kBufferUsePerLog);
267   }
268 }
269 
TEST(LogBuffer,NanoappTokenizedLogOverwritten)270 TEST(LogBuffer, NanoappTokenizedLogOverwritten) {
271   char buffer[kDefaultBufferSize];
272   TestLogBufferCallback callback;
273   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
274 
275   constexpr size_t kInstanceIdSize = 2;
276   constexpr size_t kLogPayloadSize = 100;
277   constexpr size_t kBufferUsePerLog = LogBuffer::kLogDataOffset +
278                                       LogBuffer::kNanoappTokenizedLogOffset +
279                                       kLogPayloadSize;
280   constexpr int kNumInsertions = 10;
281   constexpr int kNumLogDropsExpected =
282       kNumInsertions - kDefaultBufferSize / kBufferUsePerLog;
283   static_assert(kNumLogDropsExpected > 0);
284 
285   // This for loop adds 1080 (kNumInsertions * kBufferUsePerLog) bytes of data
286   // through the buffer which is > than 1024.
287   for (size_t i = 0; i < kNumInsertions; i++) {
288     std::vector<uint8_t> testData(kLogPayloadSize, i);
289     logBuffer.handleNanoappTokenizedLog(LogBufferLogLevel::INFO, 0,
290                                         chre::kSystemInstanceId,
291                                         testData.data(), testData.size());
292   }
293   EXPECT_EQ(logBuffer.getBufferSize(),
294             (kNumInsertions - kNumLogDropsExpected) * kBufferUsePerLog);
295   EXPECT_EQ(logBuffer.getNumLogsDropped(), kNumLogDropsExpected);
296 
297   for (size_t i = logBuffer.getNumLogsDropped(); i < kNumInsertions; i++) {
298     // Should have read out the i-th from front test log data which is an
299     // integer i.
300     std::vector<uint8_t> outBuffer(kBufferUsePerLog, 0x77);
301     size_t numLogsDropped;
302     size_t bytesCopied =
303         logBuffer.copyLogs(outBuffer.data(), outBuffer.size(), &numLogsDropped);
304 
305     // Validate that the log size in the nanoapp tokenized log header matches
306     // the expected log size.
307     EXPECT_EQ(outBuffer[LogBuffer::kLogDataOffset + kInstanceIdSize],
308               kLogPayloadSize);
309 
310     outBuffer.erase(outBuffer.begin(),
311                     outBuffer.begin() + LogBuffer::kLogDataOffset +
312                         LogBuffer::kNanoappTokenizedLogOffset);
313     EXPECT_THAT(outBuffer,
314                 ContainerEq(std::vector<uint8_t>(kLogPayloadSize, i)));
315     EXPECT_EQ(bytesCopied, kBufferUsePerLog);
316   }
317 }
318 
TEST(LogBuffer,CopyIntoEmptyBuffer)319 TEST(LogBuffer, CopyIntoEmptyBuffer) {
320   char buffer[kDefaultBufferSize];
321   constexpr size_t kOutBufferSize = 0;
322   char outBuffer[kOutBufferSize];
323   TestLogBufferCallback callback;
324   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
325 
326   logBuffer.handleLog(LogBufferLogLevel::INFO, 0, "test");
327   size_t numLogsDropped;
328   size_t bytesCopied =
329       logBuffer.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
330 
331   EXPECT_EQ(bytesCopied, 0);
332 }
333 
TEST(LogBuffer,NoCopyInfoBufferAfterHandleEmptyLog)334 TEST(LogBuffer, NoCopyInfoBufferAfterHandleEmptyLog) {
335   char buffer[kDefaultBufferSize];
336   constexpr size_t kOutBufferSize = 200;
337   char outBuffer[kOutBufferSize];
338   TestLogBufferCallback callback;
339   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
340 
341   logBuffer.handleLog(LogBufferLogLevel::INFO, 0, "");
342   size_t numLogsDropped;
343   size_t bytesCopied =
344       logBuffer.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
345 
346   EXPECT_EQ(bytesCopied, 0);
347 }
348 
TEST(LogBuffer,HandleLogOfNullBytes)349 TEST(LogBuffer, HandleLogOfNullBytes) {
350   char buffer[kDefaultBufferSize];
351   constexpr size_t kOutBufferSize = 200;
352   char outBuffer[kOutBufferSize];
353   TestLogBufferCallback callback;
354   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
355 
356   logBuffer.handleLog(LogBufferLogLevel::INFO, 0, "\0\0\0");
357   size_t numLogsDropped;
358   size_t bytesCopied =
359       logBuffer.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
360 
361   EXPECT_EQ(bytesCopied, 0);
362 }
363 
TEST(LogBuffer,TruncateLongLog)364 TEST(LogBuffer, TruncateLongLog) {
365   char buffer[kDefaultBufferSize];
366   constexpr size_t kOutBufferSize = 500;
367   char outBuffer[kOutBufferSize];
368   TestLogBufferCallback callback;
369   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
370   std::string testStr(LogBuffer::kLogMaxSize + 1, 'a');
371 
372   logBuffer.handleLog(LogBufferLogLevel::INFO, 0, testStr.c_str());
373   size_t numLogsDropped;
374   size_t bytesCopied =
375       logBuffer.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
376 
377   // Should truncate the logs down to the kLogMaxSize + kLogDataOffset by the
378   // time it is copied out.
379   EXPECT_EQ(bytesCopied, LogBuffer::kLogMaxSize + LogBuffer::kLogDataOffset);
380 }
381 
TEST(LogBuffer,WouldCauseOverflowTest)382 TEST(LogBuffer, WouldCauseOverflowTest) {
383   char buffer[kDefaultBufferSize];
384   TestLogBufferCallback callback;
385   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
386 
387   // With an empty buffer inserting an empty string (only null terminator)
388   // should not overflow ASSERT because if this fails the next ASSERT statement
389   // is undefined most likely.
390   ASSERT_FALSE(logBuffer.logWouldCauseOverflow(1));
391 
392   // This for loop adds 1000 bytes of data (kLogPayloadSize + kStringLogOverhead
393   // + kLogDataOffset). There is 24 bytes of space left in the buffer after this
394   // loop.
395   constexpr size_t kLogPayloadSize = 94;
396   for (size_t i = 0; i < 10; i++) {
397     std::string testLogStrStr(kLogPayloadSize, 'a');
398     const char *testLogStr = testLogStrStr.c_str();
399     logBuffer.handleLog(LogBufferLogLevel::INFO, 0, testLogStr);
400   }
401 
402   // This adds 18 (kLogPayloadSize + kStringLogOverhead + kLogDataOffset) bytes
403   // of data. After this log entry there is room enough for a log of character
404   // size 1.
405   constexpr size_t kLastLogPayloadSize = 12;
406   std::string testLogStrStr(kLastLogPayloadSize, 'a');
407   const char *testLogStr = testLogStrStr.c_str();
408   logBuffer.handleLog(LogBufferLogLevel::INFO, 0, testLogStr);
409 
410   // There should be just enough space for this log.
411   ASSERT_FALSE(logBuffer.logWouldCauseOverflow(1));
412 
413   // Inserting any more than a one char log should cause overflow.
414   ASSERT_TRUE(logBuffer.logWouldCauseOverflow(2));
415 }
416 
TEST(LogBuffer,TransferTest)417 TEST(LogBuffer, TransferTest) {
418   char buffer[kDefaultBufferSize];
419   const size_t kOutBufferSize = 10;
420   char outBuffer[kOutBufferSize];
421   size_t numLogsDropped;
422   TestLogBufferCallback callback;
423   LogBuffer logBufferFrom(&callback, buffer, kDefaultBufferSize);
424   LogBuffer logBufferTo(&callback, buffer, kDefaultBufferSize);
425 
426   const char *str1 = "str1";
427   const char *str2 = "str2";
428   const char *str3 = "str3";
429 
430   logBufferFrom.handleLog(LogBufferLogLevel::INFO, 0, str1);
431   logBufferFrom.handleLog(LogBufferLogLevel::INFO, 0, str2);
432   logBufferFrom.handleLog(LogBufferLogLevel::INFO, 0, str3);
433 
434   logBufferFrom.transferTo(logBufferTo);
435 
436   // The logs should have the text of each of the logs pushed onto the From
437   // buffer in FIFO ordering.
438   logBufferTo.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
439   ASSERT_TRUE(strcmp(outBuffer + LogBuffer::kLogDataOffset, str1) == 0);
440   logBufferTo.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
441   ASSERT_TRUE(strcmp(outBuffer + LogBuffer::kLogDataOffset, str2) == 0);
442   logBufferTo.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
443   ASSERT_TRUE(strcmp(outBuffer + LogBuffer::kLogDataOffset, str3) == 0);
444 
445   size_t bytesCopied =
446       logBufferTo.copyLogs(outBuffer, kOutBufferSize, &numLogsDropped);
447   // There should have been no logs left in the To buffer for that last copyLogs
448   ASSERT_EQ(bytesCopied, 0);
449 }
450 
TEST(LogBuffer,GetLogDataLengthTest)451 TEST(LogBuffer, GetLogDataLengthTest) {
452   char buffer[kDefaultBufferSize];
453 
454   TestLogBufferCallback callback;
455   LogBuffer logBuffer(&callback, buffer, kDefaultBufferSize);
456 
457   constexpr size_t kLogPayloadSize = 10;
458   constexpr size_t kBufferUseStringLog = LogBuffer::kLogDataOffset +
459                                          LogBuffer::kStringLogOverhead +
460                                          kLogPayloadSize;
461   constexpr size_t kBufferUseTokenizedLog = LogBuffer::kLogDataOffset +
462                                             LogBuffer::kTokenizedLogOffset +
463                                             kLogPayloadSize;
464   constexpr size_t kBufferUseBtSnoopLog = LogBuffer::kLogDataOffset +
465                                           LogBuffer::kBtSnoopLogOffset +
466                                           kLogPayloadSize;
467 
468   uint8_t mCurrentLogStartingIndex = 0;
469 
470   std::string testLogStr(kLogPayloadSize, 'a');
471   logBuffer.handleLog(LogBufferLogLevel::INFO, 0, testLogStr.c_str());
472   EXPECT_EQ(logBuffer.getLogDataLength(
473                 mCurrentLogStartingIndex + LogBuffer::kLogDataOffset,
474                 LogType::STRING),
475             LogBuffer::kStringLogOverhead + kLogPayloadSize);
476   mCurrentLogStartingIndex += kBufferUseStringLog;
477 
478   std::vector<uint8_t> testLogTokenized(kLogPayloadSize, 0x77);
479   logBuffer.handleEncodedLog(LogBufferLogLevel::INFO, 0,
480                              testLogTokenized.data(), testLogTokenized.size());
481   EXPECT_EQ(logBuffer.getLogDataLength(
482                 mCurrentLogStartingIndex + LogBuffer::kLogDataOffset,
483                 LogType::TOKENIZED),
484             LogBuffer::kTokenizedLogOffset + kLogPayloadSize);
485   mCurrentLogStartingIndex += kBufferUseTokenizedLog;
486 
487   std::vector<uint8_t> testLogBtSnoop(kLogPayloadSize, 0x77);
488   logBuffer.handleBtLog(BtSnoopDirection::INCOMING_FROM_BT_CONTROLLER, 0,
489                         testLogBtSnoop.data(), testLogBtSnoop.size());
490   EXPECT_EQ(logBuffer.getLogDataLength(
491                 mCurrentLogStartingIndex + LogBuffer::kLogDataOffset,
492                 LogType::BLUETOOTH),
493             LogBuffer::kBtSnoopLogOffset + kLogPayloadSize);
494   mCurrentLogStartingIndex += kBufferUseBtSnoopLog;
495 
496   std::vector<uint8_t> testLogNanoappTokenized(kLogPayloadSize, 0x77);
497   logBuffer.handleNanoappTokenizedLog(LogBufferLogLevel::INFO, 0,
498                                       kSystemInstanceId, testLogBtSnoop.data(),
499                                       testLogBtSnoop.size());
500   EXPECT_EQ(logBuffer.getLogDataLength(
501                 mCurrentLogStartingIndex + LogBuffer::kLogDataOffset,
502                 LogType::NANOAPP_TOKENIZED),
503             LogBuffer::kNanoappTokenizedLogOffset + kLogPayloadSize);
504 }
505 
506 // TODO(srok): Add multithreaded tests
507 
508 }  // namespace chre
509