-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #832, add "handler" feature to utassert stub API
Adds the concept of a "handler" function to UT assert. A handler is basically the custom logic that exists between the hook function and the return to the stub caller. In current UT stubs, this is hard coded, and it generally comprises setting output parameters and translating return values as needed. This concept adds the basic plumbing to allow the handler to be configured just like a hook function already does. The difference is that the handler is directly responsible for setting all outputs. This also includes a script to auto-generate stub functions that match this pattern. Given an API header file, the script extracts the declarations, and generates a source file with stub definitions that rely on a separate handler to deal with the needed outputs. Note this initial commit only adds the basic framework. It does not change any existing stubs or tests, and is fully backward compatible, as it is a new feature and it is a no-op unless actually configured/used by the stub or test case. Follow on commits will update the stubs to use this pattern.
- Loading branch information
Showing
4 changed files
with
948 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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 | ||
* | ||
* Provides a set of macros to facilitate generating stub code | ||
* | ||
* These macros are primarily used in the code generated by the "generate_stubs.pl" script | ||
*/ | ||
|
||
#ifndef UTGENSTUB_H | ||
#define UTGENSTUB_H | ||
|
||
#include "common_types.h" | ||
#include "utstubs.h" | ||
|
||
/** | ||
* Helper macro to set up a return buffer in a generated stub | ||
* | ||
* Registers a buffer that the hook/handler can fill. This works | ||
* with any return data type, not just int32. | ||
* | ||
* \param FuncName The name of the function | ||
* \param ReturnType The type of return value | ||
*/ | ||
#define UT_GenStub_SetupReturnBuffer(FuncName, ReturnType) \ | ||
UT_Stub_RegisterExpectedReturn(UT_KEY(FuncName), sizeof(ReturnType)) | ||
|
||
/** | ||
* Helper macro to get the return value from the handler | ||
* | ||
* Gets the value exported from the hook/handler | ||
* | ||
* \param FuncName The name of the function | ||
* \param ReturnType The type of return value | ||
*/ | ||
#define UT_GenStub_GetReturnValue(FuncName, ReturnType) \ | ||
(*(ReturnType *)UT_Stub_GetReturnValuePtr(UT_KEY(FuncName), sizeof(ReturnType))) | ||
|
||
/** | ||
* Helper macro to add a local parameter to the current context | ||
* | ||
* This makes the parameter accessible from hook/handler functions | ||
* | ||
* \param FuncName The name of the function | ||
* \param ParamType The type of the parameter | ||
* \param ParamName The name of the parameter | ||
*/ | ||
#define UT_GenStub_AddParam(FuncName, ParamType, ParamName) \ | ||
UT_Stub_RegisterContextWithMetaData(UT_KEY(FuncName), #ParamName, UT_STUBCONTEXT_ARG_TYPE_INDIRECT, &(ParamName), \ | ||
sizeof(ParamType)) | ||
|
||
/** | ||
* Helper macro to execute the actual stub handler | ||
* | ||
* Additional arguments are passed through | ||
* | ||
* \param FuncName The name of the function | ||
* \param Type The type of handler to execute (Va or Basic) | ||
*/ | ||
#define UT_GenStub_Execute(FuncName, Type, ...) UT_Execute##Type##Handler(UT_KEY(FuncName), #FuncName, __VA_ARGS__); | ||
|
||
#endif /* UTGENSTUB_H */ |
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
Oops, something went wrong.