-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Backup/add rng directive fpy pre rebase #5002
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
Nickg02
wants to merge
5
commits into
nasa:devel
from
Nickg02:backup/add-rng-directive-fpy-pre-rebase
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f09ebbf
Added stubbed push_rand directive definition and its servicing throug…
Nickg02 a27a52b
Added rng logic behind the directive
Nickg02 0dd6fab
Added the set_seed directive.
Nickg02 7a1fb2c
Changed PUSH_RAND to push a u32. It was mistakenly pushing a u8
Nickg02 6d5ba9b
Edited directive documentation for PUSH_RAND and SET_SEED
Nickg02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1463,6 +1463,72 @@ TEST_F(FpySequencerTester, pushTime) { | |
| ASSERT_EQ(err, DirectiveError::STACK_OVERFLOW); | ||
| } | ||
|
|
||
| TEST_F(FpySequencerTester, pushRand) { | ||
| FpySequencer_PushRandDirective directive; | ||
| DirectiveError err = DirectiveError::NO_ERROR; | ||
| Fw::Time testTime(TimeBase::TB_WORKSTATION_TIME, 7, 123, 456); | ||
| setTestTime(testTime); | ||
| std::mt19937 expectedRng; | ||
| std::seed_seq seedSeq{static_cast<U32>(testTime.getTimeBase()), | ||
| static_cast<U32>(testTime.getContext()), | ||
| testTime.getSeconds(), | ||
| testTime.getUSeconds()}; | ||
| expectedRng.seed(seedSeq); | ||
|
|
||
| tester_get_m_runtime_ptr()->stack.size = 0; | ||
| Signal result = tester_pushRand_directiveHandler(directive, err); | ||
| ASSERT_EQ(tester_get_m_runtime_ptr()->stack.size, sizeof(U32)); | ||
| ASSERT_EQ(result, Signal::stmtResponse_success); | ||
| ASSERT_EQ(err, DirectiveError::NO_ERROR); | ||
| ASSERT_EQ(tester_pop<U32>(), expectedRng()); | ||
|
|
||
| // make sure subsequent calls advance the existing RNG instead of reseeding on new time | ||
| setTestTime(Fw::Time(TimeBase::TB_WORKSTATION_TIME, 99, 999, 999)); | ||
| result = tester_pushRand_directiveHandler(directive, err); | ||
| ASSERT_EQ(result, Signal::stmtResponse_success); | ||
| ASSERT_EQ(err, DirectiveError::NO_ERROR); | ||
| ASSERT_EQ(tester_pop<U32>(), expectedRng()); | ||
|
|
||
| // check almost overflow | ||
| tester_get_m_runtime_ptr()->stack.size = Fpy::MAX_STACK_SIZE - sizeof(U32); | ||
| result = tester_pushRand_directiveHandler(directive, err); | ||
| ASSERT_EQ(result, Signal::stmtResponse_success); | ||
| ASSERT_EQ(tester_get_m_runtime_ptr()->stack.size, Fpy::MAX_STACK_SIZE); | ||
| ASSERT_EQ(err, DirectiveError::NO_ERROR); | ||
|
|
||
| // check overflow | ||
| tester_get_m_runtime_ptr()->stack.size = Fpy::MAX_STACK_SIZE; | ||
| result = tester_pushRand_directiveHandler(directive, err); | ||
| ASSERT_EQ(result, Signal::stmtResponse_failure); | ||
| ASSERT_EQ(err, DirectiveError::STACK_OVERFLOW); | ||
| } | ||
|
|
||
| TEST_F(FpySequencerTester, setSeed) { | ||
| FpySequencer_SetSeedDirective directive; | ||
| DirectiveError err = DirectiveError::NO_ERROR; | ||
| const U32 testSeed = 123456789U; | ||
| std::mt19937 expectedRng; | ||
| expectedRng.seed(testSeed); | ||
|
|
||
| tester_push<U32>(testSeed); | ||
| Signal result = tester_setSeed_directiveHandler(directive, err); | ||
| ASSERT_EQ(result, Signal::stmtResponse_success); | ||
| ASSERT_EQ(err, DirectiveError::NO_ERROR); | ||
| ASSERT_EQ(tester_get_m_runtime_ptr()->stack.size, 0); | ||
|
|
||
| // make sure the explicit seed overrides time-based initialization | ||
| setTestTime(Fw::Time(TimeBase::TB_WORKSTATION_TIME, 77, 888, 999)); | ||
| result = tester_pushRand_directiveHandler(FpySequencer_PushRandDirective(), err); | ||
| ASSERT_EQ(result, Signal::stmtResponse_success); | ||
| ASSERT_EQ(err, DirectiveError::NO_ERROR); | ||
| ASSERT_EQ(tester_pop<U32>(), expectedRng()); | ||
|
|
||
| // underflow | ||
| result = tester_setSeed_directiveHandler(directive, err); | ||
| ASSERT_EQ(result, Signal::stmtResponse_failure); | ||
| ASSERT_EQ(err, DirectiveError::STACK_UNDERFLOW); | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add testers for the deserialize_xyz behavior. see how pushTime does it |
||
| TEST_F(FpySequencerTester, getField) { | ||
| FpySequencer_GetFieldDirective directive(4, 2); // parent size 3, member size 2 | ||
| tester_push<U8>(123); | ||
|
|
@@ -4136,6 +4202,30 @@ TEST_F(FpySequencerTester, IntegrationPushTime) { | |
| ASSERT_CMD_RESPONSE(0, get_OPCODE_RUN(), 0, Fw::CmdResponse::OK); | ||
| } | ||
|
|
||
| TEST_F(FpySequencerTester, IntegrationPushRand) { | ||
| allocMem(); | ||
| // Sequence: PUSH_RAND, DISCARD(sizeof(U32)) | ||
| add_PUSH_RAND(); | ||
| add_DISCARD(sizeof(U32)); | ||
| writeAndRun(); | ||
| dispatchUntilState(State::IDLE); | ||
| ASSERT_CMD_RESPONSE_SIZE(1); | ||
| ASSERT_CMD_RESPONSE(0, get_OPCODE_RUN(), 0, Fw::CmdResponse::OK); | ||
| } | ||
|
|
||
| TEST_F(FpySequencerTester, IntegrationSetSeedPushRand) { | ||
| allocMem(); | ||
| // Sequence: PUSH_VAL(seed), SET_SEED, PUSH_RAND, DISCARD(sizeof(U32)) | ||
| add_PUSH_VAL<U32>(123456789U); | ||
| add_SET_SEED(); | ||
| add_PUSH_RAND(); | ||
| add_DISCARD(sizeof(U32)); | ||
| writeAndRun(); | ||
| dispatchUntilState(State::IDLE); | ||
| ASSERT_CMD_RESPONSE_SIZE(1); | ||
| ASSERT_CMD_RESPONSE(0, get_OPCODE_RUN(), 0, Fw::CmdResponse::OK); | ||
| } | ||
|
|
||
| TEST_F(FpySequencerTester, IntegrationGetField) { | ||
| allocMem(); | ||
| // Push a 2-byte "parent": [0xAA, 0xBB] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing function