Skip to content

Pj/easier to test #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

Pj/easier to test #1

wants to merge 6 commits into from

Conversation

philj404
Copy link
Owner

@philj404 philj404 commented Jun 5, 2021

This is for a backwards-compatible enhancement to the MemoryUsage library.

At this time MemoryUsage is basically a set of macros to collect usage information as text through Serial.print().

I would like to have more direct access to the numerical values. This gives me more flexibility in using the values. With these changes:

  • Duplicate code (such as (__brkval == 0 ? (int)&__heap_start : (int)__brkval) to get heap end) is gathered into single (inline) functions. This helps ensure all code using that value will calculate it the same way.
  • A sketch can print values in decimal or hex (or both)
  • A sketch can customize the output text
  • A sketch can send output to somewhere other than Serial
  • A sketch can do more than just print the information collected. For example a sketch could safely restart itself if it detected a memory leak.

This pull request includes Locoduino#4 , so if you want both PRs, you only need to review/approve this one.

/// Checks the first undecorated byte.
uint16_t mu_StackCount(void)
{
uint8_t *p = (__brkval == 0 ? (uint8_t *) &__heap_start : __brkval);

while (*p == STACK_CANARY && (int) p <= SP)
while (*p == STACK_CANARY && p <= (uint8_t *) SP)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes a type conversion warning. Probably harmless but distracting

//
// Memory addresses
//
namespace MU {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New namespace "MU". It may not really be necessary, but I thought the library might be heading in that direction with mu_StackCount() and mu_stack_size. I left those alone to ensure these changes are backwards-compatible.

//
#include <MemoryUsage.h>

#include <AUnit.h>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this new MemoryUsageTest.ino sketch depends on the AUnit library as well as MemoryUsage. Only this sketch's tests need AUnit. Legacy code should still work fine.

@philj404 philj404 marked this pull request as ready for review June 5, 2021 21:21
@philj404
Copy link
Owner Author

philj404 commented Jun 5, 2021

Oops. This pull request is for merging to master in the wrong fork! Creating another PR; will close this one out when I've copied over the relevant info.

@philj404 philj404 closed this Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant