- stub variable specific initialization and check
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
#define CPARS_PREFIX_STATIC_S "static"
|
||||
#define CPARS_PREFIX_EXTERN_S "extern"
|
||||
|
||||
#define CPARS_EXPRESSION_BASE "^[[:blank:]]*([ _\\*[:alnum:]]* +\\**)([_\\*[:alnum:]]+)"
|
||||
#define CPARS_EXPRESSION_BASE "^[[:blank:]]*([ _\\*[:alnum:]]* +\\**)([_\\*[:alnum:]\\[\\]]+)"
|
||||
|
||||
#define FUNCTION_BASE CPARS_EXPRESSION_BASE "[[:blank:]]*\\([[:blank:]]*"
|
||||
#define CPARS_REGEX_FUNCTION FUNCTION_BASE "(.*)\\)[[:blank:]\\{\\};]+[[:blank:]]*"
|
||||
|
@@ -38,6 +38,71 @@ STATIC bool isDatatypeVoid(char *aType)
|
||||
return true;
|
||||
}
|
||||
|
||||
STATIC bool isDatatypeStandard(cfile_variable_t *aVariable)
|
||||
{
|
||||
regex_t regXvariable;
|
||||
|
||||
if (0 > regcomp(®Xvariable, STUB_REGEX_STD_DATATYPE, (REG_EXTENDED)))
|
||||
{
|
||||
perror("Error regex\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (0 == regexec(®Xvariable, aVariable->dataType, 0, NULL, 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
STATIC void createVariableSpecificInit(const char* aVariableTemplate, FILE *aFile, cfile_variable_t *aVariable)
|
||||
{
|
||||
if (NULL != strstr(aVariable->dataType, "const"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (NULL != strstr(aVariable->dataType, "*"))
|
||||
{
|
||||
fprintf(aFile, aVariableTemplate, aVariable->name);
|
||||
fprintf(aFile, " = NULL;" NEWLINES);
|
||||
}
|
||||
else if (isDatatypeStandard(aVariable))
|
||||
{
|
||||
fprintf(aFile, aVariableTemplate, aVariable->name);
|
||||
fprintf(aFile, " = 0x55;" NEWLINES);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(aFile, "\t(void) memset(&");
|
||||
fprintf(aFile, aVariableTemplate, aVariable->name);
|
||||
fprintf(aFile, ",0x55,sizeof(%s)); /* %s */" NEWLINES, aVariable->name, aVariable->dataType);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void createVariableSpecificCheck(FILE *aFile, cfile_variable_t *aVariable)
|
||||
{
|
||||
if (NULL != strstr(aVariable->dataType, "const"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (NULL != strstr(aVariable->dataType, "*"))
|
||||
{
|
||||
fprintf(aFile, "\tCU_ASSERT_PTR_EQUAL(%s, "STUBVARIABLE_EXTENDED_S1");"NEWLINES, aVariable->name, aVariable->name);
|
||||
}
|
||||
else if (isDatatypeStandard(aVariable))
|
||||
{
|
||||
fprintf(aFile, "\tCU_ASSERT_EQUAL(%s, "STUBVARIABLE_EXTENDED_S1");"NEWLINES, aVariable->name, aVariable->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(aFile, "\tCU_ASSERT_MEMORY_CHECK(\"%s\", &%s, &"STUBVARIABLE_EXTENDED_S1", sizeof(%s));"NEWLINES, aVariable->name, aVariable->name, aVariable->name,
|
||||
aVariable->name);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int8_t createStubExpected(char *aNoSuffix, FILE *aFile, FILE *aHeader, cfile_variableList_t *aList)
|
||||
{
|
||||
cfile_variable_t *work = NULL;
|
||||
@@ -46,6 +111,11 @@ STATIC int8_t createStubExpected(char *aNoSuffix, FILE *aFile, FILE *aHeader, cf
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 == aList->amount)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
work = aList->head;
|
||||
while (work)
|
||||
{
|
||||
@@ -70,8 +140,7 @@ STATIC int8_t createStubExpected(char *aNoSuffix, FILE *aFile, FILE *aHeader, cf
|
||||
work = work->next;
|
||||
continue;
|
||||
}
|
||||
// TODO type specific initialization
|
||||
fprintf(aFile, "\t"STUBVARIABLE_EXTENDED_S1" = 0x55;"NEWLINES, work->name);
|
||||
createVariableSpecificInit("\t"STUBVARIABLE_EXTENDED_S1, aFile, work);
|
||||
work = work->next;
|
||||
}
|
||||
|
||||
@@ -88,6 +157,11 @@ STATIC int8_t createStubGlobals(char *aNoSuffix, FILE *aFile, FILE *aHeader, cfi
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 == aList->amount)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
work = aList->head;
|
||||
while (work)
|
||||
{
|
||||
@@ -111,8 +185,7 @@ STATIC int8_t createStubGlobals(char *aNoSuffix, FILE *aFile, FILE *aHeader, cfi
|
||||
work = work->next;
|
||||
continue;
|
||||
}
|
||||
// TODO type specific initialization
|
||||
fprintf(aFile, "\t%s = 0x55;"NEWLINES, work->name);
|
||||
createVariableSpecificInit("\t%s", aFile, work);
|
||||
work = work->next;
|
||||
}
|
||||
|
||||
@@ -135,6 +208,11 @@ STATIC int8_t createStubCheck(char *aNoSuffix, FILE *aFile, FILE *aHeader, cfile
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 == aList->amount)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
fprintf(aHeader, "void "STUBFUNCTION_CHECK_S1"();"NEWLINES NEWLINES, aNoSuffix);
|
||||
fprintf(aFile, "void "STUBFUNCTION_CHECK_S1"()"NEWLINES"{"NEWLINES, aNoSuffix);
|
||||
|
||||
@@ -146,8 +224,7 @@ STATIC int8_t createStubCheck(char *aNoSuffix, FILE *aFile, FILE *aHeader, cfile
|
||||
work = work->next;
|
||||
continue;
|
||||
}
|
||||
// TODO type specific initialization
|
||||
fprintf(aFile, "\tCU_ASSERT_EQUAL(%s, "STUBVARIABLE_EXTENDED_S1");"NEWLINES, work->name, work->name);
|
||||
createVariableSpecificCheck(aFile, work);
|
||||
work = work->next;
|
||||
}
|
||||
|
||||
@@ -403,6 +480,7 @@ STATIC int8_t createStub(char *aOutput, char *aNoSuffix, cfile_t *aCfile)
|
||||
fprintf(cfile, " * @details"NEWLINES" * This is a stub for CUnit.\\n"NEWLINES);
|
||||
fprintf(cfile, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
|
||||
fprintf(cfile, "#include <CUnit/CUnit.h>"NEWLINES);
|
||||
fprintf(cfile, "#include \"xasserts.h\""NEWLINES);
|
||||
fprintf(cfile, "#include \"xtypes.h\""NEWLINES);
|
||||
fprintf(cfile, "#include \"stub.h\""NEWLINES);
|
||||
fprintf(cfile, "#include \"stub_%s_user.h\""NEWLINES, aNoSuffix);
|
||||
|
@@ -54,4 +54,6 @@
|
||||
#define STUB_CONSOLE_PARSE_OK_S1 STUB_CONSOLE_GOBACK STUB_CONSOLE_OK " %s parsing..."
|
||||
#define STUB_CONSOLE_CREATE_ERROR_S2 "...stub creation failed\n"STUB_CONSOLE_FAIL " %s creation failed (%d)\n"
|
||||
#define STUB_CONSOLE_CREATE_OK_S1 "...stub created > %s\n"
|
||||
|
||||
#define STUB_REGEX_STD_DATATYPE "u*int[0-9]{1,2}_t|uchar"
|
||||
#endif /* STUBSER_STUBSER_LOC_H_ */
|
||||
|
Reference in New Issue
Block a user