Skip to content
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

Move Edu program status history to FRAM #328

Merged
merged 23 commits into from
Oct 21, 2024
Merged

Conversation

jeromehue
Copy link
Contributor

@jeromehue jeromehue commented Oct 1, 2024

Description

Move EDU program status history to FRAM by using the fram::RingArray to store program status history entries. Additionally, improve the unit test for RingArray with the addition of a custom type RingArray test case.

Fixes #204

@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2024

Codecov Report

Attention: Patch coverage is 99.08676% with 2 lines in your changes missing coverage. Please review.

Please upload report for BASE (master@a21effb). Learn more about missing BASE report.

Files with missing lines Patch % Lines
Sts1CobcSw/FileSystem/LfsWrapper.cpp 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master     #328   +/-   ##
=========================================
  Coverage          ?   87.27%           
=========================================
  Files             ?       37           
  Lines             ?     1352           
  Branches          ?       50           
=========================================
  Hits              ?     1180           
  Misses            ?      172           
  Partials          ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jeromehue jeromehue force-pushed the move-edu-proghistory-fram branch from 0593f19 to 3f90355 Compare October 1, 2024 17:37
@jeromehue jeromehue requested a review from PatrickKa October 1, 2024 17:45
Copy link
Contributor

@PatrickKa PatrickKa left a comment

Choose a reason for hiding this comment

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

  • Unit tests should be as self-contained as possible. Therefore, please remove the dependency on the EDU code and test RingArray with a custom type that is defined right in the source file.

Sts1CobcSw/Edu/ProgramStatusHistory.hpp Outdated Show resolved Hide resolved
Sts1CobcSw/Edu/ProgramStatusHistory.cpp Outdated Show resolved Hide resolved
Comment on lines 22 to 26
auto entry = programStatusHistory.Get(i);
if(entry.startTime == startTime and entry.programId == programId)
{
programStatusHistory.vals[i].status = newStatus;
entry.status = newStatus;
programStatusHistory.Set(i, entry);
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized that this is not thread-safe in the sense that someone might call PushBack() between Get() and Set(). This would mean that the index i might point to a different location/entry. We somehow need to ensure that getting and setting the entry is atomic. The only way that I can think of right now that would achieve that is to add RingArray<T>::FindAndReplace(predicate, newData/Element/Entry) where predicate is a callable that takes a T const & and returns something convertible to bool.

Sts1CobcSw/Edu/ProgramStatusHistory.hpp Outdated Show resolved Hide resolved
@PatrickKa PatrickKa marked this pull request as ready for review October 19, 2024 11:38
jeromehue and others added 19 commits October 20, 2024 15:33
Add a new RingArray programStatusHistory variable,
and a new update() method for it.
The only missing thing is to test that the fram is correctly written,
i.e something like `Require(fram::ram::memory[address] == value)`.
Remove useless variables and clang-format comments.
Remove dependency to Edu module.
- Shorten `FindAndReplace()` signature
- Rename `ComputeSize()` to `FramSize()`
- Add some comments
Also fix the test since the cache entries remain even after resetting
the FRAM memory to zero.
Since `RingArray` uses the Thread-safe Interface pattern, public
functions must not call other public functions because that would lead
to recursive locking. Rodos' semaphores might support that but I think
it is cleaner and easier to reason about if we stick to the pattern and
ensure that we only ever enter the semaphore once.

`FindAndReplace()` used `Get()` and `Set()` so I had to make private
implementation functions (`DoGet()` and `DoSet()`) for them that do all
the work except for creating the `ScopeProtector`.
There was a warning about a narrowing conversion from 64 to 32 bits, so
I changed the underlying type of `RingArray::RingIndex` from
`std::size_t` to that of `fram::Size` which is `std::uint32_t`.
@PatrickKa PatrickKa force-pushed the move-edu-proghistory-fram branch from 516a364 to 17a700c Compare October 20, 2024 15:35
@PatrickKa PatrickKa self-requested a review October 21, 2024 20:51
@PatrickKa PatrickKa merged commit 36adb18 into master Oct 21, 2024
6 checks passed
@PatrickKa PatrickKa deleted the move-edu-proghistory-fram branch October 21, 2024 20:51
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.

Move EDU program status history to FRAM
3 participants