-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #832, replace public API stubs with generated versions
The "built-in" logic from existing stubs is converted to a handler function and moved to a different source file. The generated stub references this function if it exists and uses it as a default handler, so the default behavior is not changed. In this pattern the stubs in this directory are strictly limited to the same public APIs that are defined in header files under src/os/inc. This has the side effect of removing some internal stubs required for coverage test. Those stubs will be reinstated in the coverage specific stubs where other internal functions are.
- Loading branch information
Showing
58 changed files
with
5,092 additions
and
4,448 deletions.
There are no files selected for viewing
This file contains 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 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,114 @@ | ||
/* | ||
* NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" | ||
* | ||
* Copyright (c) 2019 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 | ||
* | ||
* | ||
* Stub implementations for the functions defined in the OSAL API | ||
* | ||
* The stub implementation can be used for unit testing applications built | ||
* on top of OSAL. The stubs do not do any real function, but allow | ||
* the return code to be crafted such that error paths in the application | ||
* can be executed. | ||
*/ | ||
|
||
#include "osapi-binsem.h" /* OSAL public API for this subsystem */ | ||
#include "utstub-helpers.h" | ||
|
||
/* | ||
* ----------------------------------------------------------------- | ||
* Default handler implementation for 'OS_BinSemCreate' stub | ||
* ----------------------------------------------------------------- | ||
*/ | ||
void UT_DefaultHandler_OS_BinSemCreate(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) | ||
{ | ||
osal_id_t *sem_id = UT_Hook_GetArgValueByName(Context, "sem_id", osal_id_t *); | ||
int32 status; | ||
|
||
UT_Stub_GetInt32StatusCode(Context, &status); | ||
|
||
if (status == OS_SUCCESS) | ||
{ | ||
*sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_BINSEM); | ||
} | ||
else | ||
{ | ||
*sem_id = UT_STUB_FAKE_OBJECT_ID; | ||
} | ||
} | ||
|
||
/* | ||
* ----------------------------------------------------------------- | ||
* Default handler implementation for 'OS_BinSemGetInfo' stub | ||
* ----------------------------------------------------------------- | ||
*/ | ||
void UT_DefaultHandler_OS_BinSemGetInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) | ||
{ | ||
OS_bin_sem_prop_t *bin_prop = UT_Hook_GetArgValueByName(Context, "bin_prop", OS_bin_sem_prop_t *); | ||
int32 status; | ||
|
||
UT_Stub_GetInt32StatusCode(Context, &status); | ||
|
||
if (status == OS_SUCCESS && | ||
UT_Stub_CopyToLocal(UT_KEY(OS_BinSemGetInfo), bin_prop, sizeof(*bin_prop)) < sizeof(*bin_prop)) | ||
{ | ||
UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &bin_prop->creator); | ||
strncpy(bin_prop->name, "Name", sizeof(bin_prop->name) - 1); | ||
bin_prop->name[sizeof(bin_prop->name) - 1] = '\0'; | ||
} | ||
} | ||
|
||
/* | ||
* ----------------------------------------------------------------- | ||
* Default handler implementation for 'OS_BinSemDelete' stub | ||
* ----------------------------------------------------------------- | ||
*/ | ||
void UT_DefaultHandler_OS_BinSemDelete(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) | ||
{ | ||
osal_id_t sem_id = UT_Hook_GetArgValueByName(Context, "sem_id", osal_id_t); | ||
int32 status; | ||
|
||
UT_Stub_GetInt32StatusCode(Context, &status); | ||
|
||
if (status == OS_SUCCESS) | ||
{ | ||
UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_BINSEM, sem_id); | ||
} | ||
} | ||
|
||
/* | ||
* ----------------------------------------------------------------- | ||
* Default handler implementation for 'OS_BinSemGetIdByName' stub | ||
* ----------------------------------------------------------------- | ||
*/ | ||
void UT_DefaultHandler_OS_BinSemGetIdByName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) | ||
{ | ||
osal_id_t *sem_id = UT_Hook_GetArgValueByName(Context, "sem_id", osal_id_t *); | ||
int32 status; | ||
|
||
UT_Stub_GetInt32StatusCode(Context, &status); | ||
|
||
if (status == OS_SUCCESS && | ||
UT_Stub_CopyToLocal(UT_KEY(OS_BinSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) | ||
{ | ||
UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_BINSEM, sem_id); | ||
} | ||
} |
This file contains 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,167 @@ | ||
/* | ||
* NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" | ||
* | ||
* Copyright (c) 2019 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 | ||
* | ||
* Auto-Generated stub implementations for functions defined in osapi-binsem header | ||
*/ | ||
|
||
#include "osapi-binsem.h" | ||
#include "utgenstub.h" | ||
|
||
extern void UT_DefaultHandler_OS_BinSemCreate(void *, UT_EntryKey_t, const UT_StubContext_t *); | ||
extern void UT_DefaultHandler_OS_BinSemDelete(void *, UT_EntryKey_t, const UT_StubContext_t *); | ||
extern void UT_DefaultHandler_OS_BinSemGetIdByName(void *, UT_EntryKey_t, const UT_StubContext_t *); | ||
extern void UT_DefaultHandler_OS_BinSemGetInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); | ||
|
||
/* | ||
* ---------------------------------------------------- | ||
* Generated stub function for OS_BinSemCreate() | ||
* ---------------------------------------------------- | ||
*/ | ||
int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options) | ||
{ | ||
UT_GenStub_SetupReturnBuffer(OS_BinSemCreate, int32); | ||
|
||
UT_GenStub_AddParam(OS_BinSemCreate, osal_id_t *, sem_id); | ||
UT_GenStub_AddParam(OS_BinSemCreate, const char *, sem_name); | ||
UT_GenStub_AddParam(OS_BinSemCreate, uint32, sem_initial_value); | ||
UT_GenStub_AddParam(OS_BinSemCreate, uint32, options); | ||
|
||
UT_GenStub_Execute(OS_BinSemCreate, Basic, UT_DefaultHandler_OS_BinSemCreate); | ||
|
||
return UT_GenStub_GetReturnValue(OS_BinSemCreate, int32); | ||
} | ||
|
||
/* | ||
* ---------------------------------------------------- | ||
* Generated stub function for OS_BinSemDelete() | ||
* ---------------------------------------------------- | ||
*/ | ||
int32 OS_BinSemDelete(osal_id_t sem_id) | ||
{ | ||
UT_GenStub_SetupReturnBuffer(OS_BinSemDelete, int32); | ||
|
||
UT_GenStub_AddParam(OS_BinSemDelete, osal_id_t, sem_id); | ||
|
||
UT_GenStub_Execute(OS_BinSemDelete, Basic, UT_DefaultHandler_OS_BinSemDelete); | ||
|
||
return UT_GenStub_GetReturnValue(OS_BinSemDelete, int32); | ||
} | ||
|
||
/* | ||
* ---------------------------------------------------- | ||
* Generated stub function for OS_BinSemFlush() | ||
* ---------------------------------------------------- | ||
*/ | ||
int32 OS_BinSemFlush(osal_id_t sem_id) | ||
{ | ||
UT_GenStub_SetupReturnBuffer(OS_BinSemFlush, int32); | ||
|
||
UT_GenStub_AddParam(OS_BinSemFlush, osal_id_t, sem_id); | ||
|
||
UT_GenStub_Execute(OS_BinSemFlush, Basic, NULL); | ||
|
||
return UT_GenStub_GetReturnValue(OS_BinSemFlush, int32); | ||
} | ||
|
||
/* | ||
* ---------------------------------------------------- | ||
* Generated stub function for OS_BinSemGetIdByName() | ||
* ---------------------------------------------------- | ||
*/ | ||
int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name) | ||
{ | ||
UT_GenStub_SetupReturnBuffer(OS_BinSemGetIdByName, int32); | ||
|
||
UT_GenStub_AddParam(OS_BinSemGetIdByName, osal_id_t *, sem_id); | ||
UT_GenStub_AddParam(OS_BinSemGetIdByName, const char *, sem_name); | ||
|
||
UT_GenStub_Execute(OS_BinSemGetIdByName, Basic, UT_DefaultHandler_OS_BinSemGetIdByName); | ||
|
||
return UT_GenStub_GetReturnValue(OS_BinSemGetIdByName, int32); | ||
} | ||
|
||
/* | ||
* ---------------------------------------------------- | ||
* Generated stub function for OS_BinSemGetInfo() | ||
* ---------------------------------------------------- | ||
*/ | ||
int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop) | ||
{ | ||
UT_GenStub_SetupReturnBuffer(OS_BinSemGetInfo, int32); | ||
|
||
UT_GenStub_AddParam(OS_BinSemGetInfo, osal_id_t, sem_id); | ||
UT_GenStub_AddParam(OS_BinSemGetInfo, OS_bin_sem_prop_t *, bin_prop); | ||
|
||
UT_GenStub_Execute(OS_BinSemGetInfo, Basic, UT_DefaultHandler_OS_BinSemGetInfo); | ||
|
||
return UT_GenStub_GetReturnValue(OS_BinSemGetInfo, int32); | ||
} | ||
|
||
/* | ||
* ---------------------------------------------------- | ||
* Generated stub function for OS_BinSemGive() | ||
* ---------------------------------------------------- | ||
*/ | ||
int32 OS_BinSemGive(osal_id_t sem_id) | ||
{ | ||
UT_GenStub_SetupReturnBuffer(OS_BinSemGive, int32); | ||
|
||
UT_GenStub_AddParam(OS_BinSemGive, osal_id_t, sem_id); | ||
|
||
UT_GenStub_Execute(OS_BinSemGive, Basic, NULL); | ||
|
||
return UT_GenStub_GetReturnValue(OS_BinSemGive, int32); | ||
} | ||
|
||
/* | ||
* ---------------------------------------------------- | ||
* Generated stub function for OS_BinSemTake() | ||
* ---------------------------------------------------- | ||
*/ | ||
int32 OS_BinSemTake(osal_id_t sem_id) | ||
{ | ||
UT_GenStub_SetupReturnBuffer(OS_BinSemTake, int32); | ||
|
||
UT_GenStub_AddParam(OS_BinSemTake, osal_id_t, sem_id); | ||
|
||
UT_GenStub_Execute(OS_BinSemTake, Basic, NULL); | ||
|
||
return UT_GenStub_GetReturnValue(OS_BinSemTake, int32); | ||
} | ||
|
||
/* | ||
* ---------------------------------------------------- | ||
* Generated stub function for OS_BinSemTimedWait() | ||
* ---------------------------------------------------- | ||
*/ | ||
int32 OS_BinSemTimedWait(osal_id_t sem_id, uint32 msecs) | ||
{ | ||
UT_GenStub_SetupReturnBuffer(OS_BinSemTimedWait, int32); | ||
|
||
UT_GenStub_AddParam(OS_BinSemTimedWait, osal_id_t, sem_id); | ||
UT_GenStub_AddParam(OS_BinSemTimedWait, uint32, msecs); | ||
|
||
UT_GenStub_Execute(OS_BinSemTimedWait, Basic, NULL); | ||
|
||
return UT_GenStub_GetReturnValue(OS_BinSemTimedWait, int32); | ||
} |
Oops, something went wrong.