| 26 | } |
| 27 | |
| 28 | void test_threadPools_threadID() { |
| 29 | ThreadPools_CreatePools(READER_COUNT, WRITER_COUNT, UINT64_MAX); |
| 30 | |
| 31 | // verify thread count equals to the number of reader and writer threads |
| 32 | TEST_ASSERT(READER_COUNT + WRITER_COUNT == ThreadPools_ThreadCount()); |
| 33 | |
| 34 | volatile int thread_ids[READER_COUNT + WRITER_COUNT + 1] = {-1, -1, -1, -1, -1, -1}; |
| 35 | |
| 36 | // get main thread friendly id |
| 37 | thread_ids[0] = ThreadPools_GetThreadID(); |
| 38 | |
| 39 | // get reader threads friendly ids |
| 40 | for(int i = 0; i < READER_COUNT; i++) { |
| 41 | int offset = i + 1; |
| 42 | TEST_ASSERT(0 == |
| 43 | ThreadPools_AddWorkReader(get_thread_friendly_id, |
| 44 | (int*)(thread_ids + offset), false)); |
| 45 | } |
| 46 | |
| 47 | // get writer threads friendly ids |
| 48 | for(int i = 0; i < WRITER_COUNT; i++) { |
| 49 | int offset = i + READER_COUNT + 1; |
| 50 | TEST_ASSERT(0 == |
| 51 | ThreadPools_AddWorkWriter(get_thread_friendly_id, |
| 52 | (int*)(thread_ids + offset), 0)); |
| 53 | } |
| 54 | |
| 55 | // wait for all threads |
| 56 | for(int i = 0; i < READER_COUNT + WRITER_COUNT + 1; i++) { |
| 57 | while(thread_ids[i] == -1) { i = i; } |
| 58 | } |
| 59 | |
| 60 | // main thread |
| 61 | int main_thread_id = 0; |
| 62 | TEST_ASSERT(thread_ids[0] == main_thread_id); |
| 63 | |
| 64 | // reader thread ids should be > main thread id and < writer thread id |
| 65 | for(int i = 0; i < READER_COUNT; i++) { |
| 66 | TEST_ASSERT(thread_ids[i+1] >= main_thread_id); |
| 67 | TEST_ASSERT(thread_ids[i+1] <= thread_ids[1+READER_COUNT]); |
| 68 | } |
| 69 | |
| 70 | // writer thread ids should be > reader thread ids |
| 71 | for(int i = 0; i < WRITER_COUNT; i++) { |
| 72 | int offset = i + READER_COUNT + 1; |
| 73 | TEST_ASSERT(thread_ids[offset] >= thread_ids[1]); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | TEST_LIST = { |
| 78 | {"threadPools_threadID", test_threadPools_threadID}, |
nothing calls this directly
no test coverage detected