1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
|
/*
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights reserved.
* Copyright (c) 2015-2017 Cray Inc. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "gnix.h"
#include "gnix_wait.h"
#include <ofi_list.h>
#include <string.h>
#include <criterion/criterion.h>
#include "gnix_rdma_headers.h"
#include "common.h"
/* Note: Set to ~FI_NOTIFY_FLAGS_ONLY since this was written before api 1.5 */
static uint64_t mode_bits = ~FI_NOTIFY_FLAGS_ONLY;
static struct fid_fabric *fab;
static struct fi_info *hints;
static struct fi_info *fi;
static struct gnix_fid_wait *wait_priv;
static struct fi_wait_attr wait_attr;
static struct fid_wait *wait_set;
void wait_setup(void)
{
int ret = 0;
hints = fi_allocinfo();
cr_assert(hints, "fi_allocinfo");
hints->mode = mode_bits;
hints->domain_attr->mr_mode = GNIX_DEFAULT_MR_MODE;
hints->fabric_attr->prov_name = strdup("gni");
ret = fi_getinfo(fi_version(), NULL, 0, 0, hints, &fi);
cr_assert(!ret, "fi_getinfo");
ret = fi_fabric(fi->fabric_attr, &fab, NULL);
cr_assert(!ret, "fi_fabric");
}
void wait_teardown(void)
{
int ret = 0;
ret = fi_close(&wait_set->fid);
cr_assert(!ret, "failure in closing wait set.");
ret = fi_close(&fab->fid);
cr_assert(!ret, "failure in closing fabric.");
fi_freeinfo(fi);
fi_freeinfo(hints);
}
void setup_wait_type(enum fi_wait_obj wait_obj)
{
int ret;
wait_setup();
wait_attr.wait_obj = wait_obj;
ret = fi_wait_open(fab, &wait_attr, &wait_set);
cr_assert(!ret, "fi_wait_open");
wait_priv = container_of(wait_set, struct gnix_fid_wait, wait);
}
void unspec_setup(void)
{
setup_wait_type(FI_WAIT_UNSPEC);
}
void fd_setup(void)
{
setup_wait_type(FI_WAIT_FD);
}
void mutex_cond_setup(void)
{
setup_wait_type(FI_WAIT_MUTEX_COND);
}
Test(wait_creation, unspec, .init = unspec_setup, .fini = wait_teardown)
{
cr_expect_eq(wait_priv->type, FI_WAIT_UNSPEC);
cr_expect_eq(wait_priv->type, wait_attr.wait_obj);
cr_expect_eq(&wait_priv->fabric->fab_fid, fab);
cr_expect_eq(wait_priv->cond_type, FI_CQ_COND_NONE);
}
Test(wait_creation, fd, .init = fd_setup, .fini = wait_teardown,
.disabled = true)
{
cr_expect_eq(wait_priv->type, FI_WAIT_FD);
cr_expect_eq(wait_priv->type, wait_attr.wait_obj);
cr_expect_eq(&wait_priv->fabric->fab_fid, fab);
cr_expect_eq(wait_priv->cond_type, FI_CQ_COND_NONE);
}
Test(wait_creation, mutex_cond, .init = mutex_cond_setup, .fini = wait_teardown,
.disabled = true)
{
cr_expect_eq(wait_priv->type, FI_WAIT_MUTEX_COND);
cr_expect_eq(wait_priv->type, wait_attr.wait_obj);
cr_expect_eq(&wait_priv->fabric->fab_fid, fab);
cr_expect_eq(wait_priv->cond_type, FI_CQ_COND_NONE);
}
Test(wait_control, unspec, .init = unspec_setup, .fini = wait_teardown,
.disabled = true)
{
int fd;
int ret;
ret = fi_control(&wait_priv->wait.fid, FI_GETWAIT, &fd);
cr_expect_eq(FI_SUCCESS, ret, "fi_control failed.");
cr_expect_eq(wait_priv->fd[WAIT_READ], fd);
}
Test(wait_control, fd, .init = fd_setup, .fini = wait_teardown,
.disabled = true)
{
int fd;
int ret;
ret = fi_control(&wait_priv->wait.fid, FI_GETWAIT, &fd);
cr_expect_eq(FI_SUCCESS, ret, "fi_control failed.");
cr_expect_eq(wait_priv->fd[WAIT_READ], fd);
}
Test(wait_control, mutex_cond, .init = mutex_cond_setup, .fini = wait_teardown,
.disabled = true)
{
int ret;
struct fi_mutex_cond mutex_cond;
ret = fi_control(&wait_priv->wait.fid, FI_GETWAIT, &mutex_cond);
cr_expect_eq(FI_SUCCESS, ret, "fi_control failed.");
ret = memcmp(&wait_priv->mutex, mutex_cond.mutex,
sizeof(*mutex_cond.mutex));
cr_expect_eq(0, ret, "mutex compare failed.");
ret = memcmp(&wait_priv->cond, mutex_cond.cond,
sizeof(*mutex_cond.cond));
cr_expect_eq(0, ret, "cond compare failed.");
}
Test(wait_set, signal_multi, .init = unspec_setup)
{
int ret;
struct gnix_wait_entry *entry;
struct fid temp_wait = {
.fclass = FI_CLASS_CNTR
};
struct fid temp_wait2 = {
.fclass = FI_CLASS_CQ
};
cr_expect(slist_empty(&wait_priv->set),
"wait set is not initially empty.");
ret = _gnix_wait_set_add(&wait_priv->wait, &temp_wait);
cr_expect_eq(FI_SUCCESS, ret, "gnix_wait_set_add failed.");
ret = _gnix_wait_set_add(&wait_priv->wait, &temp_wait2);
cr_expect_eq(FI_SUCCESS, ret, "gnix_wait_set_add failed.");
cr_expect(!slist_empty(&wait_priv->set),
"wait set is empty after add.");
entry = container_of(wait_priv->set.head, struct gnix_wait_entry,
entry);
ret = memcmp(entry->wait_obj, &temp_wait, sizeof(temp_wait));
cr_expect_eq(0, ret, "wait objects are not equal.");
ret = fi_close(&wait_set->fid);
cr_expect_eq(-FI_EBUSY, ret);
ret = _gnix_wait_set_remove(&wait_priv->wait, &temp_wait);
cr_expect_eq(FI_SUCCESS, ret, "gnix_wait_set_remove failed.");
ret = _gnix_wait_set_remove(&wait_priv->wait, &temp_wait2);
cr_expect_eq(FI_SUCCESS, ret, "gnix_wait_set_remove failed.");
ret = fi_close(&wait_set->fid);
cr_expect_eq(FI_SUCCESS, ret, "fi_close on wait set failed.");
ret = fi_close(&fab->fid);
cr_expect_eq(FI_SUCCESS, ret, "failure in closing fabric.");
fi_freeinfo(fi);
fi_freeinfo(hints);
}
Test(wait_set, add, .init = unspec_setup)
{
int ret;
struct gnix_wait_entry *entry;
struct fid temp_wait = {
.fclass = FI_CLASS_CQ
};
cr_expect(slist_empty(&wait_priv->set),
"wait set is not initially empty.");
ret = _gnix_wait_set_add(&wait_priv->wait, &temp_wait);
cr_expect_eq(FI_SUCCESS, ret, "gnix_wait_set_add failed.");
cr_expect(!slist_empty(&wait_priv->set),
"wait set is empty after add.");
entry = container_of(wait_priv->set.head, struct gnix_wait_entry,
entry);
ret = memcmp(entry->wait_obj, &temp_wait, sizeof(temp_wait));
cr_expect_eq(0, ret, "wait objects are not equal.");
ret = fi_close(&wait_set->fid);
cr_expect_eq(-FI_EBUSY, ret);
ret = _gnix_wait_set_remove(&wait_priv->wait, &temp_wait);
cr_expect_eq(FI_SUCCESS, ret, "gnix_wait_set_remove failed.");
ret = fi_close(&wait_set->fid);
cr_expect_eq(FI_SUCCESS, ret, "fi_close on wait set failed.");
ret = fi_close(&fab->fid);
cr_expect_eq(FI_SUCCESS, ret, "failure in closing fabric.");
fi_freeinfo(fi);
fi_freeinfo(hints);
}
Test(wait_set, empty_remove, .init = unspec_setup)
{
int ret;
struct fid temp_wait = {
.fclass = FI_CLASS_CQ
};
cr_expect(slist_empty(&wait_priv->set));
ret = _gnix_wait_set_remove(&wait_priv->wait, &temp_wait);
cr_expect_eq(-FI_EINVAL, ret);
cr_expect(slist_empty(&wait_priv->set));
ret = fi_close(&wait_set->fid);
cr_expect_eq(FI_SUCCESS, ret, "fi_close on wait set failed.");
ret = fi_close(&fab->fid);
cr_expect_eq(FI_SUCCESS, ret, "fi_close on fabric failed.");
fi_freeinfo(fi);
fi_freeinfo(hints);
}
Test(wait_verify, invalid_type, .init = wait_setup)
{
int ret;
wait_attr.wait_obj = FI_WAIT_SET;
ret = fi_wait_open(fab, &wait_attr, &wait_set);
cr_expect_eq(-FI_EINVAL, ret,
"Requesting incorrect type FI_WAIT_SET succeeded.");
ret = fi_wait_open(fab, NULL, &wait_set);
cr_expect_eq(-FI_EINVAL, ret,
"Requesting verification with NULL attr succeeded.");
wait_attr.flags = 1;
ret = fi_wait_open(fab, &wait_attr, &wait_set);
cr_expect_eq(-FI_EINVAL, ret,
"Requesting verifications with flags set succeeded.");
}
Test(wait_signal, has_data, .init = unspec_setup)
{
int ret;
struct fid temp_wait = {
.fclass = FI_CLASS_CQ
};
cr_expect(slist_empty(&wait_priv->set),
"error");
ret = _gnix_wait_set_add(&wait_priv->wait, &temp_wait);
cr_expect_eq(FI_SUCCESS, ret, "gnix_wait_set_add failed.");
cr_expect(!slist_empty(&wait_priv->set),
"wait set is empty after add.");
_gnix_signal_wait_obj(&wait_priv->wait);
ret = fi_wait(&wait_priv->wait, 60);
cr_expect_eq(FI_SUCCESS, ret, "fi_wait test failed. %d", ret);
ret = _gnix_wait_set_remove(&wait_priv->wait, &temp_wait);
ret = fi_close(&wait_set->fid);
cr_expect_eq(FI_SUCCESS, ret, "fi_close on wait set failed.");
ret = fi_close(&fab->fid);
cr_expect_eq(FI_SUCCESS, ret, "fi_close on fabric failed.");
fi_freeinfo(fi);
fi_freeinfo(hints);
}
Test(wait_spin_adjust, set_val, .init = unspec_setup)
{
int ret;
int op = GNI_WAIT_THREAD_SLEEP;
struct fi_gni_ops_fab *gni_fabric_ops;
int32_t get_val, val;
ret = fi_open_ops(&fab->fid, FI_GNI_FAB_OPS_1,
0, (void **) &gni_fabric_ops, NULL);
cr_assert(ret == FI_SUCCESS, "fi_open_ops");
ret = gni_fabric_ops->get_val(&fab->fid, op, &get_val);
cr_assert(ret == FI_SUCCESS, "get_val");
cr_expect_eq(20, get_val, "Value returned does not match default");
val = 300;
ret = gni_fabric_ops->set_val(&fab->fid, op, &val);
cr_assert(ret == FI_SUCCESS, "set val");
ret = gni_fabric_ops->get_val(&fab->fid, op, &get_val);
cr_assert(val == get_val, "get val");
}
|