| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************/ | ||
| 2 | /* Copyright 2009-2025 Barcelona Supercomputing Center */ | ||
| 3 | /* */ | ||
| 4 | /* This file is part of the DLB library. */ | ||
| 5 | /* */ | ||
| 6 | /* DLB is free software: you can redistribute it and/or modify */ | ||
| 7 | /* it under the terms of the GNU Lesser General Public License as published by */ | ||
| 8 | /* the Free Software Foundation, either version 3 of the License, or */ | ||
| 9 | /* (at your option) any later version. */ | ||
| 10 | /* */ | ||
| 11 | /* DLB is distributed in the hope that it will be useful, */ | ||
| 12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | ||
| 13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | ||
| 14 | /* GNU Lesser General Public License for more details. */ | ||
| 15 | /* */ | ||
| 16 | /* You should have received a copy of the GNU Lesser General Public License */ | ||
| 17 | /* along with DLB. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 18 | /*********************************************************************************/ | ||
| 19 | |||
| 20 | |||
| 21 | #include "unique_shmem.h" | ||
| 22 | |||
| 23 | #include "apis/dlb.h" | ||
| 24 | #include "apis/dlb_talp.h" | ||
| 25 | #include "talp/regions.h" | ||
| 26 | #include "talp/sample.h" | ||
| 27 | #include "LB_core/spd.h" | ||
| 28 | #include "LB_core/thread_ctx.h" | ||
| 29 | |||
| 30 | #include <assert.h> | ||
| 31 | #include <pthread.h> | ||
| 32 | #include <string.h> | ||
| 33 | |||
| 34 | |||
| 35 | 1 | static void* test_observer_thread(void* arg) { | |
| 36 | |||
| 37 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_SetObserverRole(true) == DLB_SUCCESS ); |
| 38 | |||
| 39 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStart(DLB_GLOBAL_REGION) == DLB_ERR_PERM ); |
| 40 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStop(DLB_GLOBAL_REGION) == DLB_ERR_PERM ); |
| 41 | |||
| 42 | 1 | return NULL; | |
| 43 | } | ||
| 44 | |||
| 45 | 1 | static void* test_unknown_thread(void* arg) { | |
| 46 | |||
| 47 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStart(DLB_GLOBAL_REGION) == DLB_ERR_PERM ); |
| 48 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStop(DLB_GLOBAL_REGION) == DLB_ERR_PERM ); |
| 49 | |||
| 50 | 1 | return NULL; | |
| 51 | } | ||
| 52 | |||
| 53 | 1 | static void* test_worker_thread(void* arg) { | |
| 54 | |||
| 55 | 1 | spd_enter_dlb(NULL); | |
| 56 | 1 | thread_ctx_set_worker(); | |
| 57 | 1 | talp_sample_record_cpuid(thread_spd->talp_info); | |
| 58 | 1 | talp_sample_set_state(thread_spd->talp_info, TALP_STATE_USEFUL); | |
| 59 | |||
| 60 | 1 | dlb_monitor_t *region1 = arg; | |
| 61 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStart(region1) == DLB_SUCCESS ); |
| 62 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStop(region1) == DLB_SUCCESS ); |
| 63 | |||
| 64 | 1 | return NULL; | |
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | 1 | int main(int argc, char *argv[]) { | |
| 69 | 1 | char options[64] = "--talp=papi --shm-key="; | |
| 70 | 1 | strcat(options, SHMEM_KEY); | |
| 71 | |||
| 72 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Init(0, 0, options) == DLB_SUCCESS ); |
| 73 | 1 | dlb_monitor_t *global_region = DLB_MonitoringRegionGetGlobal(); | |
| 74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_region != NULL ); |
| 75 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_is_started(global_region) ); |
| 76 | |||
| 77 | /* Test that an observer thread cannot manage regions */ | ||
| 78 | { | ||
| 79 | pthread_t thread; | ||
| 80 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_create(&thread, NULL, test_observer_thread, NULL) == 0 ); |
| 81 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_join(thread, NULL) == 0 ); |
| 82 | } | ||
| 83 | |||
| 84 | /* Test that an unknown thread cannot manage them either */ | ||
| 85 | { | ||
| 86 | pthread_t thread; | ||
| 87 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_create(&thread, NULL, test_unknown_thread, NULL) == 0 ); |
| 88 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_join(thread, NULL) == 0 ); |
| 89 | } | ||
| 90 | |||
| 91 | /* Test that a new thread can start a region created by another thread. | ||
| 92 | * (note that it becomes a thread-local open region, then it's flushed | ||
| 93 | * to the process-wide region) */ | ||
| 94 | { | ||
| 95 | 1 | dlb_monitor_t *region1 = DLB_MonitoringRegionRegister("Region 1"); | |
| 96 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( !region_is_started(region1) ); |
| 97 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( region1->num_measurements == 0 ); |
| 98 | |||
| 99 | pthread_t thread; | ||
| 100 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_create(&thread, NULL, test_worker_thread, region1) == 0 ); |
| 101 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_join(thread, NULL) == 0 ); |
| 102 | |||
| 103 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( !region_is_started(region1) ); |
| 104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( region1->num_cpus == 1 ); |
| 105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( region1->num_measurements == 1 ); |
| 106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( region1->useful_time > 0 ); |
| 107 | } | ||
| 108 | |||
| 109 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Finalize() == DLB_SUCCESS ); |
| 110 | 1 | return 0; | |
| 111 | } | ||
| 112 |