Skip to content

Commit

Permalink
revive ptrace #5983
Browse files Browse the repository at this point in the history
only: quality in software begins with proper practices like TDD
  • Loading branch information
rusefillc committed Feb 22, 2024
1 parent 178e1f3 commit a142308
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions firmware/console/binary/tooth_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void DisableToothLogger() {
setToothLogReady(false);

// Release the big buffer for another user
// C++ magic: here we are calling BigBufferHandle::operator=() with empty instance
bufferHandle = {};
buffers = nullptr;
}
Expand Down
6 changes: 6 additions & 0 deletions firmware/controllers/core/big_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ static BigBufferUser s_currentUser;
// we've only observed issue on F7 in -Os compiler configuration but technically all processors care
static uint32_t s_bigBuffer[BIG_BUFFER_SIZE / sizeof(uint32_t)];

#if EFI_UNIT_TEST
BigBufferUser &getBigBufferCurrentUser() {

This comment has been minimized.

Copy link
@mck1117

mck1117 Feb 29, 2024

Contributor

& is inappropriate here, you're just returning an enum

return s_currentUser;
}
#endif // EFI_UNIT_TEST

static void releaseBuffer(void* bufferPtr, BigBufferUser user) {
if (bufferPtr != &s_bigBuffer || user != s_currentUser) {
// todo: panic!
Expand Down
10 changes: 10 additions & 0 deletions unit_tests/tests/test_big_buffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "pch.h"

BigBufferUser &getBigBufferCurrentUser();

TEST(BigBuffer, CppMagic) {
BigBufferHandle h = getBigBuffer(BigBufferUser::ToothLogger);
ASSERT_EQ(getBigBufferCurrentUser(), BigBufferUser::ToothLogger);
h = {};
ASSERT_EQ(getBigBufferCurrentUser(), BigBufferUser::ToothLogger);
}
1 change: 1 addition & 0 deletions unit_tests/tests/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ TESTS_SRC_CPP = \
tests/test_change_engine_type.cpp \
tests/util/test_scaled_channel.cpp \
tests/util/test_timer.cpp \
tests/test_big_buffer.cpp \
tests/system/test_periodic_thread_controller.cpp \
tests/test_util.cpp \
tests/test_start_stop.cpp \
Expand Down

0 comments on commit a142308

Please sign in to comment.