Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: [#1478] Initial demo of self registration of tests for ut_assert. #1479

Closed
wants to merge 1 commit into from

Conversation

thesamprice
Copy link

Still needs cleaned up, but wanted to demo the possibility
More concerned if i could, than if i should.

Only got this working for 1 test, would need more cleanup.

mkdir build_osal_test
cd build_osal_test
cmake -DENABLE_UNIT_TESTS=true -DOSAL_SYSTEM_BSPTYPE=generic-linux -DOSAL_CONFIG_DEBUG_PERMISSIVE_MODE=TRUE ..

make bin-sem-test
./tests/bin-sem-test

Checklist (Please check before submitting)

Describe the contribution
A clear and concise description of what the contribution is.

  • Include explicitly what issue it addresses [e.g. Fixes #X]

Testing performed
Steps taken to test the contribution:

  1. Build steps '...'
  2. Execution steps '...'

Expected behavior changes
A clear and concise description of how this contribution will change behavior and level of impact.

  • API Change: xxx (if applicable)
  • Behavior Change: xxx (if applicable)
  • Or no impact to behavior

System(s) tested on

  • Hardware: [e.g. PC, SP0, MCP750]
  • OS: [e.g. Ubuntu 18.04, RTEMS 4.11, VxWorks 6.9]
  • Versions: [e.g. cFE 6.6, OSAL 4.2, PSP 1.3 for mcp750, any related apps or tools]

Additional context
Add any other context about the contribution here.

Third party code
If included, identify any third party code and provide text file of license

Contributor Info - All information REQUIRED for consideration of pull request
Full name and company/organization/center of all contributors ("Personal" if individual work)

  • Note CLAs apply to only software contributions.

@@ -230,6 +230,10 @@
UtTest_Run();
}

/* Defined in linker script */
extern UtTestRecord __start_utest_records;

Check warning

Code scanning / CppCheck

Comparing pointers that point to different objects Warning

Comparing pointers that point to different objects
@@ -230,6 +230,10 @@
UtTest_Run();
}

/* Defined in linker script */
extern UtTestRecord __start_utest_records;
extern UtTestRecord __stop_utest_records;

Check warning

Code scanning / CppCheck

Subtracting pointers that point to different objects Warning

Subtracting pointers that point to different objects
@@ -117,4 +117,32 @@
*/
void UtTest_Setup(void);


typedef void (*UTTestFunction)(void);

Check notice

Code scanning / CodeQL

Hidden pointer indirection Note

The typedef UTTestFunction hides pointer indirection.
Comment on lines +134 to +146
#define UTEST(suiteName, uTtestName) \
static void suiteName##_##uTtestName(void); \
static UtTestRecord Record_##suiteName##_##uTtestName \
__attribute__((section(".utest_records"), used)) = { \
.marker = 0xDeadBeaf, \
.testSuite = #suiteName, \
.functionName = #uTtestName, \
.testName = #suiteName #uTtestName, \
.fileName = __FILE__, \
.lineNumber = __LINE__, \
.functionPointer = suiteName##_##uTtestName \
}; \
static void suiteName##_##uTtestName(void)

Check notice

Code scanning / CodeQL

Undisciplined macro Note

The macro UTEST(suiteName,uTtestName) uses token pasting and is not allowed.
@@ -230,6 +230,10 @@
UtTest_Run();
}

/* Defined in linker script */
extern UtTestRecord __start_utest_records;

Check notice

Code scanning / CodeQL

Variable scope too large Note

The variable __start_utest_records is only accessed in
OS_Application_Startup
and should be scoped accordingly.
The variable __start_utest_records is only accessed in
OS_Application_Startup
and should be scoped accordingly.
@@ -230,6 +230,10 @@
UtTest_Run();
}

/* Defined in linker script */
extern UtTestRecord __start_utest_records;

Check warning

Code scanning / CodeQL

"extern" declaration in source file Warning

__start_utest_records should be declared only in a header file that is included as needed.
@@ -230,6 +230,10 @@
UtTest_Run();
}

/* Defined in linker script */
extern UtTestRecord __start_utest_records;
extern UtTestRecord __stop_utest_records;

Check notice

Code scanning / CodeQL

Variable scope too large Note

The variable __stop_utest_records is only accessed in
OS_Application_Startup
and should be scoped accordingly.
The variable __stop_utest_records is only accessed in
OS_Application_Startup
and should be scoped accordingly.
@@ -230,6 +230,10 @@
UtTest_Run();
}

/* Defined in linker script */
extern UtTestRecord __start_utest_records;
extern UtTestRecord __stop_utest_records;

Check warning

Code scanning / CodeQL

"extern" declaration in source file Warning

__stop_utest_records should be declared only in a header file that is included as needed.
Comment on lines +261 to +265
while (test < &__stop_utest_records) {
// printf(" Adding test %s\n", test->functionName);
UtTest_Add(test->functionPointer, NULL, NULL, test->functionName);
test++;
}

Check warning

Code scanning / CodeQL

Unbounded loop Warning

This loop does not have a fixed bound.

/* TODO PROBALBY a better spot for this */
UtTestRecord *test = &__start_utest_records;
// printf("Size of record is %d\n", sizeof(*test));

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
/* TODO PROBALBY a better spot for this */
UtTestRecord *test = &__start_utest_records;
// printf("Size of record is %d\n", sizeof(*test));
int num_records = (&__stop_utest_records - &__start_utest_records)/ sizeof(*test);

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable num_records is not used.
UtTestRecord *test = &__start_utest_records;
// printf("Size of record is %d\n", sizeof(*test));
int num_records = (&__stop_utest_records - &__start_utest_records)/ sizeof(*test);
// printf("Num records is %d \n",num_records);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
int num_records = (&__stop_utest_records - &__start_utest_records)/ sizeof(*test);
// printf("Num records is %d \n",num_records);
while (test < &__stop_utest_records) {
// printf(" Adding test %s\n", test->functionName);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
@thesamprice
Copy link
Author

Debugging included dumping the section, and looking at the marker to determine that it was padding out memory.

objdump -s -j .utest_records tests/bin-sem-test

@thesamprice
Copy link
Author

Closing MR, this is probably not portable with linker scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant