-
Notifications
You must be signed in to change notification settings - Fork 271
Add resource stats API #1522
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
Open
thesamprice
wants to merge
1
commit into
nasa:main
Choose a base branch
from
thesamprice:os-usage-stats
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add resource stats API #1522
Changes from all commits
Commits
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
100 changes: 100 additions & 0 deletions
100
src/unit-tests/oscore-test/ut_oscore_resource_stats_test.c
|
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. Should the unit test verify that resource used counter will never be greater than the max counter and that the resource used counter will never be less than zero (roll over to 0xFFFFFFFF) if a resource delete happens with zero resources currently allocated? |
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 |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /************************************************************************ | ||
| * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” | ||
| * | ||
| * Copyright (c) 2020 United States Government as represented by the | ||
| * Administrator of the National Aeronautics and Space Administration. | ||
| * All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. You may obtain | ||
| * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| ************************************************************************/ | ||
|
|
||
| /*================================================================================* | ||
| ** File: ut_oscore_resource_stats_test.c | ||
| ** Owner: Codex | ||
| ** Date: September 2025 | ||
| **================================================================================*/ | ||
|
|
||
| /*--------------------------------------------------------------------------------* | ||
| ** Includes | ||
| **--------------------------------------------------------------------------------*/ | ||
|
|
||
| #include "ut_oscore_resource_stats_test.h" | ||
|
|
||
| /*--------------------------------------------------------------------------------* | ||
| ** Local function definitions | ||
| **--------------------------------------------------------------------------------*/ | ||
|
|
||
| void UT_os_resource_stats_test(void) | ||
| { | ||
| OS_resource_stats_t stats_before; | ||
| OS_resource_stats_t stats_after; | ||
| osal_id_t queue_id = OS_OBJECT_ID_UNDEFINED; | ||
| osal_id_t binsem_id = OS_OBJECT_ID_UNDEFINED; | ||
| osal_id_t countsem_id = OS_OBJECT_ID_UNDEFINED; | ||
| osal_id_t mutex_id = OS_OBJECT_ID_UNDEFINED; | ||
| osal_blockcount_t queue_depth = OSAL_BLOCKCOUNT_C(4); | ||
| size_t queue_size = OSAL_SIZE_C(4); | ||
| uint32 queue_flags = 0; | ||
| uint32 sem_options = 0; | ||
| uint32 sem_init_val = 1; | ||
|
|
||
| UT_RETVAL(OS_GetResourceStats(NULL), OS_INVALID_POINTER); | ||
| UT_RETVAL(OS_GetResourceStats(&stats_before), OS_SUCCESS); | ||
|
|
||
| UtAssert_True(stats_before.tasks.total == OS_MAX_TASKS, "tasks total == OS_MAX_TASKS"); | ||
| UtAssert_True(stats_before.queues.total == OS_MAX_QUEUES, "queues total == OS_MAX_QUEUES"); | ||
| UtAssert_True(stats_before.bin_semaphores.total == OS_MAX_BIN_SEMAPHORES, | ||
| "bin semaphores total == OS_MAX_BIN_SEMAPHORES"); | ||
| UtAssert_True(stats_before.count_semaphores.total == OS_MAX_COUNT_SEMAPHORES, | ||
| "count semaphores total == OS_MAX_COUNT_SEMAPHORES"); | ||
| UtAssert_True(stats_before.mutexes.total == OS_MAX_MUTEXES, "mutexes total == OS_MAX_MUTEXES"); | ||
| UtAssert_True(stats_before.streams.total == OS_MAX_NUM_OPEN_FILES, "streams total == OS_MAX_NUM_OPEN_FILES"); | ||
| UtAssert_True(stats_before.dirs.total == OS_MAX_NUM_OPEN_DIRS, "dirs total == OS_MAX_NUM_OPEN_DIRS"); | ||
| UtAssert_True(stats_before.timebases.total == OS_MAX_TIMEBASES, "timebases total == OS_MAX_TIMEBASES"); | ||
| UtAssert_True(stats_before.timers.total == OS_MAX_TIMERS, "timers total == OS_MAX_TIMERS"); | ||
| UtAssert_True(stats_before.modules.total == OS_MAX_MODULES, "modules total == OS_MAX_MODULES"); | ||
| UtAssert_True(stats_before.filesystems.total == OS_MAX_FILE_SYSTEMS, "filesystems total == OS_MAX_FILE_SYSTEMS"); | ||
| UtAssert_True(stats_before.consoles.total == OS_MAX_CONSOLES, "consoles total == OS_MAX_CONSOLES"); | ||
| UtAssert_True(stats_before.condvars.total == OS_MAX_CONDVARS, "condvars total == OS_MAX_CONDVARS"); | ||
|
|
||
| UT_RETVAL(OS_BinSemCreate(&binsem_id, "ResStat_BinSem", sem_init_val, sem_options), OS_SUCCESS); | ||
| UT_RETVAL(OS_GetResourceStats(&stats_after), OS_SUCCESS); | ||
| UtAssert_True(stats_after.bin_semaphores.used == (stats_before.bin_semaphores.used + 1), | ||
| "bin semaphores used incremented"); | ||
| UT_RETVAL(OS_BinSemDelete(binsem_id), OS_SUCCESS); | ||
| UT_RETVAL(OS_GetResourceStats(&stats_after), OS_SUCCESS); | ||
| UtAssert_True(stats_after.bin_semaphores.used == stats_before.bin_semaphores.used, | ||
| "bin semaphores used restored"); | ||
|
|
||
| UT_RETVAL(OS_CountSemCreate(&countsem_id, "ResStat_CountSem", sem_init_val, sem_options), OS_SUCCESS); | ||
| UT_RETVAL(OS_GetResourceStats(&stats_after), OS_SUCCESS); | ||
| UtAssert_True(stats_after.count_semaphores.used == (stats_before.count_semaphores.used + 1), | ||
| "count semaphores used incremented"); | ||
| UT_RETVAL(OS_CountSemDelete(countsem_id), OS_SUCCESS); | ||
| UT_RETVAL(OS_GetResourceStats(&stats_after), OS_SUCCESS); | ||
| UtAssert_True(stats_after.count_semaphores.used == stats_before.count_semaphores.used, | ||
| "count semaphores used restored"); | ||
|
|
||
| UT_RETVAL(OS_MutSemCreate(&mutex_id, "ResStat_Mutex", sem_options), OS_SUCCESS); | ||
| UT_RETVAL(OS_GetResourceStats(&stats_after), OS_SUCCESS); | ||
| UtAssert_True(stats_after.mutexes.used == (stats_before.mutexes.used + 1), "mutexes used incremented"); | ||
| UT_RETVAL(OS_MutSemDelete(mutex_id), OS_SUCCESS); | ||
| UT_RETVAL(OS_GetResourceStats(&stats_after), OS_SUCCESS); | ||
| UtAssert_True(stats_after.mutexes.used == stats_before.mutexes.used, "mutexes used restored"); | ||
|
|
||
| UT_RETVAL(OS_QueueCreate(&queue_id, "ResStat_Queue", queue_depth, queue_size, queue_flags), OS_SUCCESS); | ||
| UT_RETVAL(OS_GetResourceStats(&stats_after), OS_SUCCESS); | ||
| UtAssert_True(stats_after.queues.used == (stats_before.queues.used + 1), "queues used incremented"); | ||
| UT_RETVAL(OS_QueueDelete(queue_id), OS_SUCCESS); | ||
| UT_RETVAL(OS_GetResourceStats(&stats_after), OS_SUCCESS); | ||
| UtAssert_True(stats_after.queues.used == stats_before.queues.used, "queues used restored"); | ||
| } | ||
|
|
43 changes: 43 additions & 0 deletions
43
src/unit-tests/oscore-test/ut_oscore_resource_stats_test.h
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 |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /************************************************************************ | ||
| * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” | ||
| * | ||
| * Copyright (c) 2020 United States Government as represented by the | ||
| * Administrator of the National Aeronautics and Space Administration. | ||
| * All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. You may obtain | ||
| * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| ************************************************************************/ | ||
|
|
||
| /** | ||
| * \file | ||
| * | ||
| * Owner: Codex | ||
| * Date: September 2025 | ||
| */ | ||
|
|
||
| #ifndef UT_OSCORE_RESOURCE_STATS_TEST_H | ||
| #define UT_OSCORE_RESOURCE_STATS_TEST_H | ||
|
|
||
| /*--------------------------------------------------------------------------------* | ||
| ** Includes | ||
| **--------------------------------------------------------------------------------*/ | ||
|
|
||
| #include "ut_os_support.h" | ||
|
|
||
| /*--------------------------------------------------------------------------------* | ||
| ** Function prototypes | ||
| **--------------------------------------------------------------------------------*/ | ||
|
|
||
| void UT_os_resource_stats_test(void); | ||
|
|
||
| /*--------------------------------------------------------------------------------*/ | ||
|
|
||
| #endif /* UT_OSCORE_RESOURCE_STATS_TEST_H */ |
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.
Check notice
Code scanning / CodeQL
Long function without assertion Note