| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************/ | ||
| 2 | /* Copyright 2009-2024 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 | #include "unique_shmem.h" | ||
| 21 | #include "test_process.h" | ||
| 22 | |||
| 23 | #include "apis/dlb.h" | ||
| 24 | #include "apis/dlb_talp.h" | ||
| 25 | #include "support/env.h" | ||
| 26 | #include "support/mask_utils.h" | ||
| 27 | #include "talp/talp_mpi.h" | ||
| 28 | #include "LB_comm/shmem.h" | ||
| 29 | #include "LB_core/spd.h" | ||
| 30 | #include "LB_core/thread_ctx.h" | ||
| 31 | |||
| 32 | #include <float.h> | ||
| 33 | #include <limits.h> | ||
| 34 | #include <math.h> | ||
| 35 | #include <pthread.h> | ||
| 36 | #include <string.h> | ||
| 37 | #include <sys/wait.h> | ||
| 38 | #include <unistd.h> | ||
| 39 | |||
| 40 | |||
| 41 | struct data { | ||
| 42 | pthread_barrier_t barrier; | ||
| 43 | }; | ||
| 44 | |||
| 45 | 7 | static shmem_handler_t* open_shmem(void **shdata) { | |
| 46 | 14 | return shmem_init(shdata, | |
| 47 | 7 | &(const shmem_props_t) { | |
| 48 | .size = sizeof(struct data), | ||
| 49 | .name = "test", | ||
| 50 | .key = SHMEM_KEY, | ||
| 51 | }); | ||
| 52 | } | ||
| 53 | |||
| 54 | 1 | int main(int argc, char *argv[]) { | |
| 55 | 1 | char dlb_args[64] = "--talp --talp-external-profiler --shm-key="; | |
| 56 | 1 | strcat(dlb_args, SHMEM_KEY); | |
| 57 | 1 | dlb_setenv("DLB_ARGS", dlb_args, NULL, ENV_APPEND); | |
| 58 | |||
| 59 | /* Test DLB_TALP_Attach without any process */ | ||
| 60 | { | ||
| 61 | int ncpus, nelems, pidlist; | ||
| 62 | double mpi_time, useful_time; | ||
| 63 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Attach() == DLB_SUCCESS ); |
| 64 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetNumCPUs(&ncpus) == DLB_SUCCESS ); |
| 65 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( ncpus == mu_get_system_size() ); |
| 66 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetPidList(&pidlist, &nelems, 1) == DLB_SUCCESS ); |
| 67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nelems == 0 ); |
| 68 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetTimes(111, &mpi_time, &useful_time) == DLB_ERR_NOPROC ); |
| 69 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Detach() == DLB_SUCCESS ); |
| 70 | } | ||
| 71 | |||
| 72 | /* Test that an external process should not call these functions */ | ||
| 73 | { | ||
| 74 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Attach() == DLB_SUCCESS ); |
| 75 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionGetGlobal() == NULL ); |
| 76 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionRegister("Name") == NULL ); |
| 77 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionReset(DLB_GLOBAL_REGION) == DLB_ERR_NOTALP ); |
| 78 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStart(DLB_GLOBAL_REGION) == DLB_ERR_NOTALP ); |
| 79 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStop(DLB_GLOBAL_REGION) == DLB_ERR_NOTALP ); |
| 80 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionReport(DLB_GLOBAL_REGION) == DLB_ERR_NOTALP ); |
| 81 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionsUpdate() == DLB_ERR_NOTALP ); |
| 82 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_CollectPOPMetrics(NULL, NULL) == DLB_ERR_NOTALP ); |
| 83 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_CollectPOPNodeMetrics(NULL, NULL) == DLB_ERR_NOTALP ); |
| 84 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Detach() == DLB_SUCCESS ); |
| 85 | } | ||
| 86 | |||
| 87 | /* Test DLB_TALP_Attach after DLB_Init */ | ||
| 88 | { | ||
| 89 | // Check thread is NOT an observer and GetTimes are correct | ||
| 90 | double mpi_time, useful_time; | ||
| 91 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Init(0, 0, NULL) == DLB_SUCCESS ); |
| 92 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStart(DLB_GLOBAL_REGION) == DLB_NOUPDT ); |
| 93 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStop(DLB_GLOBAL_REGION) == DLB_SUCCESS ); |
| 94 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Attach() == DLB_SUCCESS ); |
| 95 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( !thread_is_observer() ); |
| 96 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetTimes(0, &mpi_time, &useful_time) == DLB_SUCCESS ); |
| 97 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( mpi_time < DBL_EPSILON ); |
| 98 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( useful_time > DBL_EPSILON ); |
| 99 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Detach() == DLB_SUCCESS ); |
| 100 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Finalize() == DLB_SUCCESS ); |
| 101 | |||
| 102 | // Save DLB_ARGS, set new one without --talp | ||
| 103 | 1 | char *dlb_args_env = getenv("DLB_ARGS"); | |
| 104 | 1 | size_t dlb_args_len = strlen(dlb_args_env) + 1; | |
| 105 | 1 | char *dlb_args_copy = malloc(sizeof(char) * dlb_args_len); | |
| 106 | 1 | memcpy(dlb_args_copy, dlb_args_env, dlb_args_len); | |
| 107 | 1 | char new_dlb_args[32] = "--shm-key="; | |
| 108 | 1 | strcat(new_dlb_args, SHMEM_KEY); | |
| 109 | 1 | dlb_setenv("DLB_ARGS", new_dlb_args, NULL, ENV_OVERWRITE_ALWAYS); | |
| 110 | |||
| 111 | // Check functions that cannot be called from 1st-party if not --talp | ||
| 112 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Init(0, 0, NULL) == DLB_SUCCESS ); |
| 113 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Attach() == DLB_SUCCESS ); |
| 114 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetTimes(0, &mpi_time, &useful_time) == DLB_ERR_NOTALP ); |
| 115 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Detach() == DLB_SUCCESS ); |
| 116 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Finalize() == DLB_SUCCESS ); |
| 117 | |||
| 118 | // Set DLB_ARGS with just --talp | ||
| 119 | 1 | dlb_setenv("DLB_ARGS", " --talp", NULL, ENV_APPEND); | |
| 120 | |||
| 121 | // Check functions that cannot be called from 1st-party if not --talp-external-profiler | ||
| 122 | dlb_node_times_t node_times; | ||
| 123 | dlb_node_metrics_t node_metrics; | ||
| 124 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Init(0, 0, NULL) == DLB_SUCCESS ); |
| 125 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Attach() == DLB_SUCCESS ); |
| 126 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetNodeTimes(DLB_GLOBAL_REGION, &node_times, NULL, 1) == DLB_ERR_NOSHMEM ); |
| 127 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_QueryPOPNodeMetrics(DLB_GLOBAL_REGION, &node_metrics) == DLB_ERR_NOSHMEM ); |
| 128 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Detach() == DLB_SUCCESS ); |
| 129 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Finalize() == DLB_SUCCESS ); |
| 130 | |||
| 131 | // Restore DLB_ARGS | ||
| 132 | 1 | dlb_setenv("DLB_ARGS", dlb_args_copy, NULL, ENV_OVERWRITE_ALWAYS); | |
| 133 | 1 | free(dlb_args_copy); | |
| 134 | |||
| 135 | // Check thread may be an observer again | ||
| 136 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Attach() == DLB_SUCCESS ); |
| 137 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( thread_is_observer() ); |
| 138 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Detach() == DLB_SUCCESS ); |
| 139 | } | ||
| 140 | |||
| 141 | /* Test DLB_TALP_Attach before other processes */ | ||
| 142 | { | ||
| 143 | struct data *shdata; | ||
| 144 | shmem_handler_t *handler; | ||
| 145 | |||
| 146 | // Parent process creates shmem and initializes barrier | ||
| 147 | 1 | handler = open_shmem((void**)&shdata); | |
| 148 | pthread_barrierattr_t attr; | ||
| 149 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrierattr_init(&attr) == 0 ); |
| 150 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrierattr_setpshared(&attr, PTHREAD_PROCESS_SHARED) == 0 ); |
| 151 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrier_init(&shdata->barrier, &attr, 2) == 0 ); |
| 152 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrierattr_destroy(&attr) == 0 ); |
| 153 | |||
| 154 | // Parent does TALP_Attach | ||
| 155 | int nelems, pidlist; | ||
| 156 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Attach() == DLB_SUCCESS ); |
| 157 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetPidList(&pidlist, &nelems, 1) == DLB_SUCCESS ); |
| 158 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nelems == 0 ); |
| 159 | |||
| 160 | // Fork | ||
| 161 | 1 | pid_t pid = fork(); | |
| 162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( pid >= 0 ); |
| 163 | 2 | bool child = pid == 0; | |
| 164 | 2 | bool parent = !child; | |
| 165 | |||
| 166 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (child) { |
| 167 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Init(0, 0, NULL) == DLB_SUCCESS ); |
| 168 | 1 | talp_mpi_init(thread_spd); | |
| 169 | 1 | handler = open_shmem((void**)&shdata); | |
| 170 | } | ||
| 171 | |||
| 172 | 2 | int error = pthread_barrier_wait(&shdata->barrier); | |
| 173 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
2 | assert(error == 0 || error == PTHREAD_BARRIER_SERIAL_THREAD); |
| 174 | |||
| 175 | // Parent process checks existing process with empty MPI and useful values | ||
| 176 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (parent) { |
| 177 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetPidList(&pidlist, &nelems, 1) == DLB_SUCCESS ); |
| 178 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( nelems == 1 && pidlist == pid); |
| 179 | double mpi_time, useful_time; | ||
| 180 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetTimes(pid, &mpi_time, &useful_time) == DLB_SUCCESS ); |
| 181 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( fabs(mpi_time) < 1e-6 && fabs(useful_time) < 1e-6 ); |
| 182 | } | ||
| 183 | |||
| 184 | 2 | error = pthread_barrier_wait(&shdata->barrier); | |
| 185 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
2 | assert(error == 0 || error == PTHREAD_BARRIER_SERIAL_THREAD); |
| 186 | |||
| 187 | // Child process simulates some time in computation | ||
| 188 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (child) { |
| 189 | 1 | usleep(1000); /* 1 ms */ | |
| 190 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionsUpdate() == DLB_SUCCESS ); |
| 191 | } | ||
| 192 | |||
| 193 | 2 | error = pthread_barrier_wait(&shdata->barrier); | |
| 194 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
2 | assert(error == 0 || error == PTHREAD_BARRIER_SERIAL_THREAD); |
| 195 | |||
| 196 | // Parent process checks times again | ||
| 197 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (parent) { |
| 198 | double mpi_time, useful_time; | ||
| 199 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetTimes(pid, &mpi_time, &useful_time) == DLB_SUCCESS ); |
| 200 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( fabs(mpi_time) < 1e-6 ); |
| 201 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( fabs(useful_time) > 1e-3 && fabs(useful_time) < 1 ); |
| 202 | } | ||
| 203 | |||
| 204 | 2 | error = pthread_barrier_wait(&shdata->barrier); | |
| 205 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
2 | assert(error == 0 || error == PTHREAD_BARRIER_SERIAL_THREAD); |
| 206 | |||
| 207 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (child) { |
| 208 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Finalize() == DLB_SUCCESS ); |
| 209 | 1 | shmem_finalize(handler, NULL); | |
| 210 | |||
| 211 | // We need to call _exit so that children don't call assert_shmem destructors | ||
| 212 | 1 | dlb_test__exit(EXIT_SUCCESS); | |
| 213 | } | ||
| 214 | /* if (child) _exit(EXIT_SUCCESS); */ | ||
| 215 | |||
| 216 | // Wait for all child processes | ||
| 217 | int wstatus; | ||
| 218 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
2 | while(wait(&wstatus) > 0) { |
| 219 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!WIFEXITED(wstatus)) |
| 220 | ✗ | exit(EXIT_FAILURE); | |
| 221 | 1 | int rc = WEXITSTATUS(wstatus); | |
| 222 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (rc != 0) { |
| 223 | ✗ | printf("Child return status: %d\n", rc); | |
| 224 | ✗ | exit(EXIT_FAILURE); | |
| 225 | } | ||
| 226 | } | ||
| 227 | |||
| 228 | // Parent process finalizes everything | ||
| 229 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrier_destroy(&shdata->barrier) == 0 ); |
| 230 | 1 | shmem_finalize(handler, NULL); | |
| 231 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Detach() == DLB_SUCCESS ); |
| 232 | } | ||
| 233 | |||
| 234 | /* Test DLB_TALP_Attach after other process has initialized */ | ||
| 235 | { | ||
| 236 | struct data *shdata; | ||
| 237 | shmem_handler_t *handler; | ||
| 238 | |||
| 239 | // Parent process creates shmem and initializes barrier | ||
| 240 | 1 | handler = open_shmem((void**)&shdata); | |
| 241 | pthread_barrierattr_t attr; | ||
| 242 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrierattr_init(&attr) == 0 ); |
| 243 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrierattr_setpshared(&attr, PTHREAD_PROCESS_SHARED) == 0 ); |
| 244 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrier_init(&shdata->barrier, &attr, 2) == 0 ); |
| 245 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrierattr_destroy(&attr) == 0 ); |
| 246 | |||
| 247 | // Fork | ||
| 248 | 1 | pid_t pid = fork(); | |
| 249 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( pid >= 0 ); |
| 250 | 2 | bool child = pid == 0; | |
| 251 | 2 | bool parent = !child; | |
| 252 | |||
| 253 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (child) { |
| 254 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Init(0, 0, NULL) == DLB_SUCCESS ); |
| 255 | 1 | handler = open_shmem((void**)&shdata); | |
| 256 | } | ||
| 257 | |||
| 258 | 2 | int error = pthread_barrier_wait(&shdata->barrier); | |
| 259 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
2 | assert(error == 0 || error == PTHREAD_BARRIER_SERIAL_THREAD); |
| 260 | |||
| 261 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (parent) { |
| 262 | // Parent does TALP_Attach | ||
| 263 | int nelems, pidlist; | ||
| 264 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Attach() == DLB_SUCCESS ); |
| 265 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetPidList(&pidlist, &nelems, 1) == DLB_SUCCESS ); |
| 266 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( nelems == 1 && pidlist == pid); |
| 267 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Detach() == DLB_SUCCESS ); |
| 268 | } | ||
| 269 | |||
| 270 | 2 | error = pthread_barrier_wait(&shdata->barrier); | |
| 271 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
2 | assert(error == 0 || error == PTHREAD_BARRIER_SERIAL_THREAD); |
| 272 | |||
| 273 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (child) { |
| 274 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Finalize() == DLB_SUCCESS ); |
| 275 | 1 | shmem_finalize(handler, NULL); | |
| 276 | |||
| 277 | // We need to call _exit so that children don't call assert_shmem destructors | ||
| 278 | 1 | dlb_test__exit(EXIT_SUCCESS); | |
| 279 | } | ||
| 280 | /* if (child) _exit(EXIT_SUCCESS); */ | ||
| 281 | |||
| 282 | // Wait for all child processes | ||
| 283 | int wstatus; | ||
| 284 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
2 | while(wait(&wstatus) > 0) { |
| 285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!WIFEXITED(wstatus)) |
| 286 | ✗ | exit(EXIT_FAILURE); | |
| 287 | 1 | int rc = WEXITSTATUS(wstatus); | |
| 288 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (rc != 0) { |
| 289 | ✗ | printf("Child return status: %d\n", rc); | |
| 290 | ✗ | exit(EXIT_FAILURE); | |
| 291 | } | ||
| 292 | } | ||
| 293 | |||
| 294 | // Parent process finalizes everything | ||
| 295 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrier_destroy(&shdata->barrier) == 0 ); |
| 296 | 1 | shmem_finalize(handler, NULL); | |
| 297 | } | ||
| 298 | |||
| 299 | /* Test DLB_TALP_GetNodeTimes and DLB_TALP_QueryPOPNodeMetrics */ | ||
| 300 | { | ||
| 301 | struct data *shdata; | ||
| 302 | shmem_handler_t *handler; | ||
| 303 | |||
| 304 | // Parent process creates shmem and initializes barrier | ||
| 305 | 1 | handler = open_shmem((void**)&shdata); | |
| 306 | pthread_barrierattr_t attr; | ||
| 307 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrierattr_init(&attr) == 0 ); |
| 308 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrierattr_setpshared(&attr, PTHREAD_PROCESS_SHARED) == 0 ); |
| 309 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrier_init(&shdata->barrier, &attr, 3) == 0 ); |
| 310 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrierattr_destroy(&attr) == 0 ); |
| 311 | |||
| 312 | // Parent does TALP_Attach | ||
| 313 | int nelems, pidlist; | ||
| 314 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Attach() == DLB_SUCCESS ); |
| 315 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetPidList(&pidlist, &nelems, 1) == DLB_SUCCESS ); |
| 316 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nelems == 0 ); |
| 317 | |||
| 318 | // Fork twice | ||
| 319 | 1 | pid_t pid2 = -1; | |
| 320 | 1 | pid_t pid1 = fork(); | |
| 321 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( pid1 >= 0 ); |
| 322 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (pid1 > 0) { |
| 323 | 1 | pid2 = fork(); | |
| 324 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( pid2 >= 0 ); |
| 325 | } | ||
| 326 |
4/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
3 | bool child = pid1 == 0 || pid2 == 0; |
| 327 | 3 | bool parent = !child; | |
| 328 | |||
| 329 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (child) { |
| 330 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_Init(0, 0, NULL) == DLB_SUCCESS ); |
| 331 | 2 | talp_mpi_init(thread_spd); | |
| 332 | 2 | handler = open_shmem((void**)&shdata); | |
| 333 | } | ||
| 334 | |||
| 335 | 3 | int error = pthread_barrier_wait(&shdata->barrier); | |
| 336 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
3 | assert(error == 0 || error == PTHREAD_BARRIER_SERIAL_THREAD); |
| 337 | |||
| 338 | // Children simulate some time in computation | ||
| 339 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (child) { |
| 340 | 2 | usleep(1000); /* 1 ms */ | |
| 341 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_MonitoringRegionsUpdate() == DLB_SUCCESS ); |
| 342 | } | ||
| 343 | |||
| 344 | 3 | error = pthread_barrier_wait(&shdata->barrier); | |
| 345 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
3 | assert(error == 0 || error == PTHREAD_BARRIER_SERIAL_THREAD); |
| 346 | |||
| 347 | // Parent process test API | ||
| 348 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if (parent) { |
| 349 | // Test DLB_TALP_GetNodeTimes | ||
| 350 | dlb_node_times_t node_times[2]; | ||
| 351 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetNodeTimes(DLB_GLOBAL_REGION, node_times, &nelems, 1) |
| 352 | == DLB_SUCCESS ); | ||
| 353 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nelems == 1); |
| 354 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1 | assert( node_times[0].pid == pid1 || node_times[0].pid == pid2 ); |
| 355 | |||
| 356 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetNodeTimes(DLB_GLOBAL_REGION, node_times, &nelems, 2) |
| 357 | == DLB_SUCCESS ); | ||
| 358 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nelems == 2); |
| 359 | |||
| 360 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_GetNodeTimes(DLB_GLOBAL_REGION, node_times, &nelems, INT_MAX ) |
| 361 | == DLB_SUCCESS ); | ||
| 362 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nelems == 2); |
| 363 | 1 | fprintf(stderr, "0 pid: %d\n", node_times[0].pid); | |
| 364 | 1 | fprintf(stderr, "1 pid: %d\n", node_times[1].pid); | |
| 365 | 1 | fprintf(stderr, "pid1: %d, pid2: %d\n", pid1, pid2); | |
| 366 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( node_times[0].pid == min_int(pid1, pid2) ); |
| 367 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( node_times[1].pid == max_int(pid1, pid2) ); |
| 368 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( node_times[0].mpi_time == 0 && node_times[1].mpi_time == 0 ); |
| 369 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( llabs(node_times[0].useful_time) > 1e6 |
| 370 | && llabs(node_times[0].useful_time) < 1e9 ); | ||
| 371 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( llabs(node_times[1].useful_time) > 1e6 |
| 372 | && llabs(node_times[1].useful_time) < 1e9 ); | ||
| 373 | |||
| 374 | // Test DLB_TALP_QueryPOPNodeMetrics | ||
| 375 | dlb_node_metrics_t node_metrics; | ||
| 376 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_QueryPOPNodeMetrics(DLB_GLOBAL_REGION, &node_metrics) |
| 377 | == DLB_SUCCESS ); | ||
| 378 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( node_metrics.processes_per_node == 2 ); |
| 379 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( node_metrics.total_mpi_time == 0 ); |
| 380 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( node_metrics.total_useful_time > 1e6 && node_metrics.total_useful_time < 2e9 ); |
| 381 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( fabs(node_metrics.communication_efficiency - 1.00) < 1e3 ); |
| 382 | } | ||
| 383 | |||
| 384 | 3 | error = pthread_barrier_wait(&shdata->barrier); | |
| 385 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
3 | assert(error == 0 || error == PTHREAD_BARRIER_SERIAL_THREAD); |
| 386 | |||
| 387 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (child) { |
| 388 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_Finalize() == DLB_SUCCESS ); |
| 389 | 2 | shmem_finalize(handler, NULL); | |
| 390 | |||
| 391 | // We need to call _exit so that children don't call assert_shmem destructors | ||
| 392 | 2 | dlb_test__exit(EXIT_SUCCESS); | |
| 393 | } | ||
| 394 | /* if (child) _exit(EXIT_SUCCESS); */ | ||
| 395 | |||
| 396 | // Wait for all child processes | ||
| 397 | int wstatus; | ||
| 398 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
|
3 | while(wait(&wstatus) > 0) { |
| 399 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!WIFEXITED(wstatus)) |
| 400 | ✗ | exit(EXIT_FAILURE); | |
| 401 | 2 | int rc = WEXITSTATUS(wstatus); | |
| 402 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (rc != 0) { |
| 403 | ✗ | printf("Child return status: %d\n", rc); | |
| 404 | ✗ | exit(EXIT_FAILURE); | |
| 405 | } | ||
| 406 | } | ||
| 407 | |||
| 408 | // Parent process finalizes everything | ||
| 409 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pthread_barrier_destroy(&shdata->barrier) == 0 ); |
| 410 | 1 | shmem_finalize(handler, NULL); | |
| 411 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_TALP_Detach() == DLB_SUCCESS ); |
| 412 | } | ||
| 413 | |||
| 414 | 1 | return 0; | |
| 415 | } | ||
| 416 |