Initializing expected parameter in declaration and after each instance run to ensure reproducibility.

Assert for invalid STUB_PASS values
This commit is contained in:
2018-09-05 08:24:30 +00:00
parent 6d894b634e
commit f64696daac
2 changed files with 40 additions and 5 deletions

View File

@@ -88,7 +88,7 @@ STATIC void createVariableSpecificInit(const char* aVariableTemplate, FILE *aFil
{ {
fprintf(aFile, "\t(void) memset("); fprintf(aFile, "\t(void) memset(");
fprintf(aFile, aVariableTemplate, aVariable->name); fprintf(aFile, aVariableTemplate, aVariable->name);
fprintf(aFile, ", 0x55, sizeof(%s)); /* %s */" NEWLINES, aVariable->name, aVariable->dataType); fprintf(aFile, ", "STUBDEFAULT_VALUE_VARIABLE_S", sizeof(%s)); /* %s */" NEWLINES, aVariable->name, aVariable->dataType);
} }
else else
{ {
@@ -102,13 +102,13 @@ STATIC void createVariableSpecificInit(const char* aVariableTemplate, FILE *aFil
{ {
fprintf(aFile, "\t"); fprintf(aFile, "\t");
fprintf(aFile, aVariableTemplate, aVariable->name); fprintf(aFile, aVariableTemplate, aVariable->name);
fprintf(aFile, " = 0x55;" NEWLINES); fprintf(aFile, " = "STUBDEFAULT_VALUE_VARIABLE_S";" NEWLINES);
} }
else else
{ {
fprintf(aFile, "\t(void) memset(&"); fprintf(aFile, "\t(void) memset(&");
fprintf(aFile, aVariableTemplate, aVariable->name); fprintf(aFile, aVariableTemplate, aVariable->name);
fprintf(aFile, ", 0x55, sizeof(%s)); /* %s */" NEWLINES, aVariable->name, aVariable->dataType); fprintf(aFile, ", "STUBDEFAULT_VALUE_VARIABLE_S", sizeof(%s)); /* %s */" NEWLINES, aVariable->name, aVariable->dataType);
} }
} }
@@ -168,6 +168,8 @@ STATIC void createParameterSpecificCheck(FILE *aFile, cfunction_t *aFunction, cf
fprintf(aFile, STUBINIT_PARAM_PARAMETER_S1", "STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1, aParameterIndex, aFunction->name, fprintf(aFile, STUBINIT_PARAM_PARAMETER_S1", "STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1, aParameterIndex, aFunction->name,
aFunction->name, aParameterIndex); aFunction->name, aParameterIndex);
fprintf(aFile, ");"NEWLINES); fprintf(aFile, ");"NEWLINES);
fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1" = (%s) "STUBDEFAULT_VALUE_POINTER_S";" NEWLINES, aFunction->name,
aFunction->name, aParameterIndex, aParameter->dataType);
} }
else if (NULL != strstr(aParameter->dataType, "*") && NULL != strstr(aParameter->dataType, "char")) else if (NULL != strstr(aParameter->dataType, "*") && NULL != strstr(aParameter->dataType, "char"))
{ {
@@ -193,6 +195,10 @@ STATIC void createParameterSpecificCheck(FILE *aFile, cfunction_t *aFunction, cf
fprintf(aFile, ");" NEWLINES); fprintf(aFile, ");" NEWLINES);
fprintf(aFile, "\t}" NEWLINES); fprintf(aFile, "\t}" NEWLINES);
} }
fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1" = (%s) "STUBDEFAULT_VALUE_POINTER_S";" NEWLINES, aFunction->name,
aFunction->name, aParameterIndex, aParameter->dataType);
fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1"_size = "STUBDEFAULT_VALUE_POINTERSIZE_S";" NEWLINES,
aFunction->name, aFunction->name, aParameterIndex);
} }
else if (NULL != strstr(aParameter->dataType, "*") || NULL != aParameter->array) else if (NULL != strstr(aParameter->dataType, "*") || NULL != aParameter->array)
{ {
@@ -218,6 +224,10 @@ STATIC void createParameterSpecificCheck(FILE *aFile, cfunction_t *aFunction, cf
fprintf(aFile, ");" NEWLINES); fprintf(aFile, ");" NEWLINES);
fprintf(aFile, "\t}" NEWLINES); fprintf(aFile, "\t}" NEWLINES);
} }
fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1" = (%s) "STUBDEFAULT_VALUE_POINTER_S";" NEWLINES, aFunction->name,
aFunction->name, aParameterIndex, aParameter->dataType);
fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1"_size = "STUBDEFAULT_VALUE_POINTERSIZE_S";" NEWLINES,
aFunction->name, aFunction->name, aParameterIndex);
} }
else if (isDatatypeStandard(aParameter->dataType)) else if (isDatatypeStandard(aParameter->dataType))
{ {
@@ -225,6 +235,8 @@ STATIC void createParameterSpecificCheck(FILE *aFile, cfunction_t *aFunction, cf
fprintf(aFile, STUBINIT_PARAM_PARAMETER_S1", "STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1, aParameterIndex, aFunction->name, fprintf(aFile, STUBINIT_PARAM_PARAMETER_S1", "STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1, aParameterIndex, aFunction->name,
aFunction->name, aParameterIndex); aFunction->name, aParameterIndex);
fprintf(aFile, ");"NEWLINES); fprintf(aFile, ");"NEWLINES);
fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1" = (%s) "STUBDEFAULT_VALUE_VARIABLE_S";" NEWLINES, aFunction->name,
aFunction->name, aParameterIndex, aParameter->dataType);
} }
else else
{ {
@@ -232,6 +244,8 @@ STATIC void createParameterSpecificCheck(FILE *aFile, cfunction_t *aFunction, cf
fprintf(aFile, "&"STUBINIT_PARAM_PARAMETER_S1", &"STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1, aParameterIndex, aFunction->name, fprintf(aFile, "&"STUBINIT_PARAM_PARAMETER_S1", &"STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1, aParameterIndex, aFunction->name,
aFunction->name, aParameterIndex); aFunction->name, aParameterIndex);
fprintf(aFile, ", sizeof("STUBINIT_PARAM_PARAMETER_S1"));"NEWLINES, aParameterIndex); fprintf(aFile, ", sizeof("STUBINIT_PARAM_PARAMETER_S1"));"NEWLINES, aParameterIndex);
fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1" = (%s) "STUBDEFAULT_VALUE_VARIABLE_S";" NEWLINES, aFunction->name,
aFunction->name, aParameterIndex, aParameter->dataType);
} }
} }
@@ -466,9 +480,16 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *a
// initialize _size parameter to 1 (default to check addresses) // initialize _size parameter to 1 (default to check addresses)
if (CPARAMETER_TYPE_FUNCPTR != parameter->type && (parameter->array || NULL != strstr(parameter->dataType, "*"))) if (CPARAMETER_TYPE_FUNCPTR != parameter->type && (parameter->array || NULL != strstr(parameter->dataType, "*")))
{ {
fprintf(aFile, "\t[0 ... %u]."STUBPARAMETER_PARAM_S1" = (%s) 0x55," NEWLINES, STUB_INSTANCES_AMOUNT - 1, parameterIndex, parameter->dataType); fprintf(aFile, "\t[0 ... %u]."STUBPARAMETER_PARAM_S1" = (%s) "STUBDEFAULT_VALUE_POINTER_S"," NEWLINES, STUB_INSTANCES_AMOUNT - 1, parameterIndex,
parameter->dataType);
fprintf(aFile, "\t[0 ... %u]."STUBPARAMETER_PARAM_S1"_size = 1," NEWLINES, STUB_INSTANCES_AMOUNT - 1, parameterIndex); fprintf(aFile, "\t[0 ... %u]."STUBPARAMETER_PARAM_S1"_size = 1," NEWLINES, STUB_INSTANCES_AMOUNT - 1, parameterIndex);
} }
else
{
fprintf(aFile, "\t[0 ... %u]."STUBPARAMETER_PARAM_S1" = (%s) "STUBDEFAULT_VALUE_VARIABLE_S"," NEWLINES, STUB_INSTANCES_AMOUNT - 1, parameterIndex,
parameter->dataType);
}
++parameterIndex; ++parameterIndex;
parameter = parameter->next; parameter = parameter->next;
} }
@@ -636,8 +657,12 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *a
fprintf(aFile, "\t\tCU_FAIL(\"Inadvertent %s() call.\");"NEWLINES"\t\tbreak;"NEWLINES, aFunction->name); fprintf(aFile, "\t\tCU_FAIL(\"Inadvertent %s() call.\");"NEWLINES"\t\tbreak;"NEWLINES, aFunction->name);
fprintf(aFile, "\tcase STUB_CALL_PASS:" NEWLINES); fprintf(aFile, "\tcase STUB_CALL_PASS:" NEWLINES);
fprintf(aFile, "\t\tCU_PASS(\"%s() called.\");"NEWLINES"\t\tbreak;"NEWLINES, aFunction->name); fprintf(aFile, "\t\tCU_PASS(\"%s() called.\");"NEWLINES"\t\tbreak;"NEWLINES, aFunction->name);
fprintf(aFile, "\tdefault:"NEWLINES"\t\tbreak;"NEWLINES); fprintf(aFile, "\tdefault:"NEWLINES);
fprintf(aFile, "\t\tCU_FAIL_OUTPUT_LESS(\"Invalid STUB_CALL test value: \","STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_CALLTEST_S", \"%%u\");"NEWLINES,
aFunction->name, aFunction->name);
fprintf(aFile, "\t\tbreak;"NEWLINES);
fprintf(aFile, "\t}" NEWLINES); fprintf(aFile, "\t}" NEWLINES);
fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_CALLTEST_S" = STUB_CALL_FAIL;" NEWLINES, aFunction->name, aFunction->name);
parameter = aFunction->parameter.head; parameter = aFunction->parameter.head;
parameterIndex = 'a'; parameterIndex = 'a';
@@ -647,6 +672,11 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *a
++parameterIndex; ++parameterIndex;
parameter = parameter->next; parameter = parameter->next;
} }
if (pointerAvailable)
{
fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_POINTERHANDLING_S" = " STUBPARAMETER_POINTERHANDLING_ADDRESS_S ";" NEWLINES,
aFunction->name, aFunction->name);
}
if (!isDatatypeVoid(aFunction->dataType)) if (!isDatatypeVoid(aFunction->dataType))
{ {

View File

@@ -44,6 +44,11 @@
#define STUBINIT_PARAM_RETURN_S "aReturnValue" #define STUBINIT_PARAM_RETURN_S "aReturnValue"
#define STUBINIT_PARAM_POINTERHANDLING_S "aPointerHandling" #define STUBINIT_PARAM_POINTERHANDLING_S "aPointerHandling"
#define STUBDEFAULT_VALUE_FUNCTIONPOINTER_S "0x55"
#define STUBDEFAULT_VALUE_POINTER_S "0x55"
#define STUBDEFAULT_VALUE_POINTERSIZE_S "1"
#define STUBDEFAULT_VALUE_VARIABLE_S "0x55"
#define STUBFUNCTION_USER_INITEXPECTED_S1 "stub_%s_user_initExpected" // stub_testfunction_initExpected #define STUBFUNCTION_USER_INITEXPECTED_S1 "stub_%s_user_initExpected" // stub_testfunction_initExpected
#define STUBFUNCTION_USER_INITGLOBALS_S1 "stub_%s_user_initGlobals" // stub_testfunction_initGlobals #define STUBFUNCTION_USER_INITGLOBALS_S1 "stub_%s_user_initGlobals" // stub_testfunction_initGlobals
#define STUBFUNCTION_USER_CHECK_S1 "stub_%s_user_checkGlobals" // stub_testfunction_checkGlobals #define STUBFUNCTION_USER_CHECK_S1 "stub_%s_user_checkGlobals" // stub_testfunction_checkGlobals