-
Notifications
You must be signed in to change notification settings - Fork 703
Modifying sched_thread_local.c test to add corner cases. #3412
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,6 +114,23 @@ static void *thread_func(void *parameter) | |
| ASSERT(false); | ||
| } | ||
|
|
||
| printf("thread_func[%d]: TLS addr=%p\n", id, &g_tls_int); | ||
|
|
||
| /* In a broken system, all threads might point to the same static address */ | ||
|
|
||
| static void *g_first_thread_addr = NULL; | ||
| if (id == 0) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you try to print the "id" ? I think it never will be 0, if I'm not wrong (and I could be wrong) it starts from 1.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it does start from 0 based on the attached log (it is printed a few times)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. |
||
| { | ||
| g_first_thread_addr = (void *)&g_tls_int; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens when the threads are released from the synchronized barrier? There is no guarantee that the first thread will set This check doesn't work. |
||
| } | ||
| else if (g_first_thread_addr == (void *)&g_tls_int) | ||
| { | ||
| printf("ERROR: Thread %d shares address with Thread 0\n", id); | ||
| ASSERT(false); | ||
|
|
||
| /* Checking 0 and other addresses */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this comment. |
||
| } | ||
|
|
||
| printf("thread_func[%d]: setting value_short (at 0x%p) to %d\n", | ||
| id, &g_tls_short, value_short + id); | ||
|
|
||
|
|
@@ -159,6 +176,9 @@ void sched_thread_local_test(void) | |
| { | ||
| printf("sched_thread_local_test: pthread_barrier_init failed, " | ||
| "status=%d\n", status); | ||
| ASSERT(false); | ||
|
|
||
| /* the threads will call pthread_barrier_wait on an invalid object */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this comment. |
||
| } | ||
|
|
||
| for (i = 0; i < TEST_THREADS; i++) | ||
|
|
@@ -227,6 +247,16 @@ void sched_thread_local_test(void) | |
| printf("sched_thread_local_test: pthread_barrier_destroy failed, " | ||
| "status=%d\n", status); | ||
| } | ||
|
|
||
| /* Confirm main thread still have initial values */ | ||
|
|
||
| if (g_tls_int != INIT_VALUE) | ||
| { | ||
| printf("sched_thread_local_test: ERROR: Main thread TLS corrupted!\n"); | ||
| ASSERT(false); | ||
| } | ||
|
|
||
| printf("sched_thread_local_test: Main thread isolation confirmed.\n"); | ||
| } | ||
|
|
||
| #endif /* CONFIG_SCHED_THREAD_LOCAL */ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Biancaa-R all common code (that needs to work on old microcontrollers) should follow the C89. Please read the https://nuttx.apache.org/docs/latest/contributing/coding_style.html for more info about the NuttX coding style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other detail: g_ is used when you are defining a global variable, that is not the case here since you are defining it inside a function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure sir Ill read it and modify accordingly.