We can't use "__attribute__((constructor))" for some init functions that run before main() at STM32L073RZ?
I've tried __attribute__((constructor)) on STM32F030R8T6 for running tests like Gtest framework by user-defined test. The code is shown as below:
#define TEST(name) \
void Test##name(void); \
__attribute__((constructor)) void LoadTest##name(){ \
RegisterTestFunction(Test##name); \
g_Signal++; \
} \
\
void Test##name(void) \
void RegisterTestFunction(TestFunctionProto pTf)
{
if(pTf == NULL)
{
return APPO_ERROR;
}
else if(StackGetSize(&g_TestFunctions) >= TEST_FUNCTIONS_MAX_NUM)
{
TestPrintf("Test Functions overflow!");
return APPO_ERROR;
}
return StackPush(&g_TestFunctions, pTf);
}
void RunAllTests(void)
{
TestFunctionProto tmp = NULL;
DebugPrintf("g_Signal = %d", g_Signal);
while(FALSE == StackIsEmpty(&g_TestFunctions))
{
tmp = (TestFunctionProto) StackPop(&g_TestFunctions);
tmp();
}
} Then I use TEST(***) to test my function like this:
TEST(Stack)
{
/*My test code*/
}In the main() function , I run the "RunAllTests()", I could see the Test function results by UART printing :
But when I use the same code on the STM32L073RZ chip , I can't run my tests!
The LoadTest##name() function cannot run before main() even if I use "__attribute__((constructor))" !!!!:persevering_face:
Anybody can help me?