1
1
openmpi/opal/test/reachable/reachable_shared.h
William Zhang 4ebb37a26c opal/util: Change opal/util/if.h macro IF_NAMESIZE to OPAL_IF_NAMESIZE
Due to IF_NAMESIZE being a reused and conditionally defined macro,
issues could arise from macro mismatches. In particular, in cases where
opal/util/if.h is included, but net/if.h is not, IF_NAMESIZE will be 32.
If net/if.h is included on Linux systems, IF_NAMESIZE will be 16. This
can cause a mismatch when using the same macro on a system. Thus
different parts of the code can have differring ideas on the size of a
structure containing a char name[IF_NAMESIZE]. To avoid this error case,
we avoid reusing the IF_NAMESIZE macro and instead define our own as
OPAL_IF_NAMESIZE.

Signed-off-by: William Zhang <wilzhang@amazon.com>
2019-07-29 21:24:39 +00:00

72 строки
1.9 KiB
C

/*
* Copyright (c) 2017-XXXX Amazon.com, Inc. or its affiliates.
* All Rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef TEST_REACHABLE_SHARED
#define TEST_REACHABLE_SHARED 1
#include <assert.h>
#include "opal/runtime/opal.h"
#include "opal/mca/reachable/reachable.h"
#include "opal/util/if.h"
#include "opal/util/string_copy.h"
BEGIN_C_DECLS
/* Create and populate opal_if_t with information required by opal_reachable */
opal_if_t* create_if(int af_family, char *address, int mask, int bandwidth)
{
opal_if_t *interface = OBJ_NEW(opal_if_t);
opal_string_copy(interface->if_name, "interface0", OPAL_IF_NAMESIZE);
interface->af_family = af_family;
((struct sockaddr *)&(interface->if_addr))->sa_family = af_family;
if (AF_INET == af_family){
assert(1 == inet_pton(af_family, address, &((struct sockaddr_in *)&(interface->if_addr))->sin_addr));
} else if (AF_INET6 == af_family){
assert(1 == inet_pton(af_family, address, &((struct sockaddr_in6 *)&(interface->if_addr))->sin6_addr));
}
interface->if_mask = mask;
interface->if_bandwidth = bandwidth;
return interface;
}
/* Run a test between a pair of interfaces
* and clean up the memory afterwards.
* Return the weight between the pair of
* interfaces
*/
int run_single_test(opal_if_t *local_if, opal_if_t *remote_if)
{
opal_list_t *local_list = OBJ_NEW(opal_list_t);
opal_list_t *remote_list = OBJ_NEW(opal_list_t);
opal_list_append(local_list, &(local_if->super));
opal_list_append(remote_list, &(remote_if->super));
opal_reachable_t *results;
results = opal_reachable.reachable(local_list, remote_list);
OBJ_RELEASE(local_list);
OBJ_RELEASE(remote_list);
int result = results->weights[0][0];
/* release results */
OBJ_RELEASE(results);
return result;
}
END_C_DECLS
#endif