Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
*.so
*.build_profile
ibsim/ibsim

tests/mcast_storm
tests/query_many
tests/subnet_discover
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ addons:
- wget
- libibumad-dev
- libibmad-dev
- opensm
script:
- scripts/travis-checkpatch
- scripts/travis-build
- scripts/travis-runtest
- ./dist.sh
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
subdirs:= ibsim umad2sim
subdirs:= ibsim umad2sim tests

all clean dep install:
$(foreach dir, $(subdirs), make -C $(dir) $@ && ) echo "Done."
Expand Down
18 changes: 14 additions & 4 deletions ibsim/ibsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ static FILE *simout;
static int listen_to_port = IBSIM_DEFAULT_SERVER_PORT;
static int remote_mode = 0;
static char* socket_basename;
static int console = 1;

static size_t make_name(union name_t *name, uint32_t addr, unsigned short port,
const char *fmt, ...)
Expand Down Expand Up @@ -535,7 +536,8 @@ static int sim_init_console(FILE *out)
fprintf(simout, "MaxNetPorts = %d\n", maxnetports);
fprintf(simout, "MaxLinearCap = %d\n", maxlinearcap);
fprintf(simout, "MaxMcastCap = %d\n", maxmcastcap);
fprintf(simout, "sim%s> ", netstarted ? "" : " (inactive)");
if (console)
fprintf(simout, "sim%s> ", netstarted ? "" : " (inactive)");
fflush(simout);
return 0;
}
Expand Down Expand Up @@ -577,7 +579,8 @@ static int sim_run(int con_fd)
for (;;) {
FD_ZERO(&rfds);
FD_SET(simctl, &rfds);
FD_SET(con_fd, &rfds);
if (console)
FD_SET(con_fd, &rfds);
for (i = 0; i < IBSIM_MAX_CLIENTS; i++)
if (clients[i].pid)
FD_SET(clients[i].fd, &rfds);
Expand Down Expand Up @@ -664,7 +667,7 @@ static void usage(char *prog_name)
fprintf(stderr,
"Usage: %s [-f outfile -d(ebug) -p(arse_debug) -s(tart) -v(erbose) "
"-I(gnore_duplicate) -N nodes -S switches -P ports -L linearcap"
" -M mcastcap -r(emote_mode) -l(isten_to_port) <port>] <netfile>\n",
" -M mcastcap -r(emote_mode) -l(isten_to_port) <port> -n(o-console)] <netfile>\n",
prog_name);
fprintf(stderr, "%s %s\n", prog_name, IBSIM_VERSION);

Expand All @@ -677,7 +680,7 @@ int main(int argc, char **argv)
FILE *infile, *outfile;
int status;

static char const str_opts[] = "rf:dpvIsN:S:P:L:M:l:Vhu";
static char const str_opts[] = "rf:dpvIsN:S:P:L:M:l:Vhun";
static const struct option long_opts[] = {
{"remote", 0, NULL, 'r'},
{"file", 1, NULL, 'f'},
Expand All @@ -693,6 +696,7 @@ int main(int argc, char **argv)
{"parsedebug", 0, NULL, 'p'},
{"verbose", 0, NULL, 'v'},
{"Version", 0, NULL, 'V'},
{"no-console", 0, NULL, 'n'},
{"help", 0, NULL, 'h'},
{"usage", 0, NULL, 'u'},
{}
Expand Down Expand Up @@ -742,6 +746,9 @@ int main(int argc, char **argv)
case 'l':
listen_to_port = strtoul(optarg, NULL, 0);
break;
case 'n':
console = 0;
break;
case 'V':
default:
usage(argv[0]);
Expand All @@ -755,6 +762,9 @@ int main(int argc, char **argv)
if (outfname && (outfile = fopen(outfname, "w")) == NULL)
IBPANIC("can't open out file %s for write", outfname);

if (!console && !netstarted)
IBPANIC("Cannot disable console without starting "
"the network from the command line");
if (optind >= argc)
usage(argv[0]);

Expand Down
1 change: 0 additions & 1 deletion scripts/travis-build
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ fi

# Test out gcc-8
CC=gcc-8 CFLAGS="-Werror" make
make clean
25 changes: 25 additions & 0 deletions scripts/travis-runtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

PATH=/home/`whoami`/.local/bin:$PATH
DIR=$(readlink -f .)
# Stop on error
set -e
# Echo all commands to Travis log
set -x

./ibsim/ibsim -s net-examples/net --no-console &
IBSIM_PID=$!
# Give some time for the network to start
sleep 2

TMPDIR=$(mktemp -d)
LD_PRELOAD=$DIR/umad2sim/libumad2sim.so OSM_TMP_DIR=$TMPDIR OSM_CACHE_DIR=$TMPDIR opensm -f osm.log &
OSM_PID=$!
# Give time for the SM to start
sleep 2

LD_PRELOAD=$DIR/umad2sim/libumad2sim.so $DIR/tests/subnet_discover
LD_PRELOAD=$DIR/umad2sim/libumad2sim.so $DIR/tests/mcast_storm rereg joins leave

# Kill all pending processes
kill -9 $OSM_PID $IBSIM_PID
62 changes: 32 additions & 30 deletions tests/mcast_storm.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#ifdef NOISY_DEBUG
#define dbg(fmt, arg...) fprintf(stderr, "DBG: " fmt, ##arg )
#else
#define dbg(fmt, arg...)
#define dbg(fmt, arg...) (void)0
#endif

#define TMO 100
Expand Down Expand Up @@ -172,7 +172,7 @@ static uint64_t get_guid_ho(ibmad_gid_t gid)
{
uint64_t guid;
memcpy(&guid, &gid[8], sizeof(guid));
return ntohll(guid);
return be64toh(guid);
}

static int send_req(struct addr_data *a, uint8_t * umad, int len,
Expand Down Expand Up @@ -299,7 +299,7 @@ static int rereg_recv_all(struct addr_data *a, void *umad, int len,
uint8_t *mad;
uint64_t trid;
unsigned n, method, status;
int i;
unsigned i;

info("%s...\n", __func__);

Expand Down Expand Up @@ -346,7 +346,8 @@ static int rereg_query_all(struct addr_data *a, void *umad, int len,
{
uint8_t *mad;
unsigned method, status;
int i, ret;
unsigned i;
int ret;

info("%s...\n", __func__);

Expand Down Expand Up @@ -521,8 +522,8 @@ static int run_test(const struct test *t, struct test_data *td,

static void make_gid(ibmad_gid_t gid, uint64_t prefix, uint64_t guid)
{
prefix = ntohll(prefix);
guid = ntohll(guid);
prefix = be64toh(prefix);
guid = be64toh(guid);
memcpy(&gid[0], &prefix, 8);
memcpy(&gid[8], &guid, 8);
}
Expand All @@ -541,9 +542,9 @@ static int make_gids_list(ibmad_gid_t gid, unsigned n, struct gid_list **gid_lis
}

memcpy(&prefix, &gid[0], 8);
prefix = ntohll(prefix);
prefix = be64toh(prefix);
memcpy(&guid, &gid[8], 8);
guid = ntohll(guid);
guid = be64toh(guid);

for (i = 0; i <= n; i++)
make_gid(list[i].gid, prefix, guid++);
Expand Down Expand Up @@ -603,7 +604,7 @@ static int parse_gids_file(const char *guid_file, struct gid_list **gid_list)
FILE *f;
struct gid_list *list = NULL;
unsigned list_size = 0;
int i = 0;
unsigned i = 0;

f = fopen(guid_file, "r");
if (!f) {
Expand Down Expand Up @@ -639,7 +640,8 @@ static int parse_gids_file(const char *guid_file, struct gid_list **gid_list)

static void make_str_opts(char *p, unsigned size, const struct option *o)
{
int i, n = 0;
unsigned n;
int i;

for (n = 0; o->name && n + 2 + o->has_arg < size; o++) {
p[n++] = o->val;
Expand Down Expand Up @@ -679,32 +681,32 @@ static void usage(char *prog, const struct option *o, const struct test *t)
int main(int argc, char **argv)
{
const struct option long_opts [] = {
{"guidfile", 1, 0, 'g'},
{"mgidfile", 1, 0, 'm'},
{"GUID", 1, 0, 'G'},
{"MGID", 1, 0, 'M'},
{"ipv4", 0, 0, 'i'},
{"increment", 1, 0, 'I'},
{"qkey", 1, 0, 'q'},
{"mlid", 1, 0, 'z'},
{"mtu", 1, 0, 'y'},
{"tclass", 1, 0, 't'},
{"pkey", 1, 0, 'p'},
{"rate", 1, 0, 'r'},
{"sl", 1, 0, 's'},
{"flowlabel", 1, 0, 'f'},
{"joinstate", 1, 0, 'j'},
{"proxy", 0, 0, 'x'},
{"version", 0, 0, 'V'},
{"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"guidfile", 1, NULL, 'g'},
{"mgidfile", 1, NULL, 'm'},
{"GUID", 1, NULL, 'G'},
{"MGID", 1, NULL, 'M'},
{"ipv4", 0, NULL, 'i'},
{"increment", 1, NULL, 'I'},
{"qkey", 1, NULL, 'q'},
{"mlid", 1, NULL, 'z'},
{"mtu", 1, NULL, 'y'},
{"tclass", 1, NULL, 't'},
{"pkey", 1, NULL, 'p'},
{"rate", 1, NULL, 'r'},
{"sl", 1, NULL, 's'},
{"flowlabel", 1, NULL, 'f'},
{"joinstate", 1, NULL, 'j'},
{"proxy", 0, NULL, 'x'},
{"version", 0, NULL, 'V'},
{"verbose", 0, NULL, 'v'},
{"help", 0, NULL, 'h'},
{}
};
const struct test tests[] = {
{"rereg", run_port_rereg_test, "simulates port reregistration"},
{"joins", run_mcast_joins_test, "run a lot of join requests"},
{"leave", run_mcast_leave_test, "run a lot of leave requests"},
{0}
{NULL, NULL, NULL}
};

char opt_str[256];
Expand Down
19 changes: 10 additions & 9 deletions tests/query_many.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ static unsigned verbose = 0;
static const char *print_path(uint8_t path[], size_t path_cnt)
{
static char buf[256];
int i, n = 0;
size_t i;
int n = 0;
for (i = 0; i <= path_cnt; i++)
n += snprintf(buf + n, sizeof(buf) - n, "%u,", path[i]);
buf[n] = '\0';
Expand Down Expand Up @@ -246,14 +247,14 @@ static int umad_query(char *card_name, unsigned int port_num)
int main(int argc, char **argv)
{
const struct option long_opts[] = {
{"number", 1, 0, 'n'},
{"drpath", 1, 0, 'd'},
{"attribute", 1, 0, 'a'},
{"modifier", 1, 0, 'm'},
{"Card", 1, 0, 'C'},
{"Port", 1, 0, 'P'},
{"timeout", 1, 0, 't'},
{"retries", 1, 0, 'r'},
{"number", 1, NULL, 'n'},
{"drpath", 1, NULL, 'd'},
{"attribute", 1, NULL, 'a'},
{"modifier", 1, NULL, 'm'},
{"Card", 1, NULL, 'C'},
{"Port", 1, NULL, 'P'},
{"timeout", 1, NULL, 't'},
{"retries", 1, NULL, 'r'},
{}
};
char *card_name = NULL;
Expand Down
32 changes: 17 additions & 15 deletions tests/subnet_discover.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,19 @@ static unsigned max_hops = 0;
static const char *print_path(uint8_t path[], size_t path_cnt)
{
static char buf[256];
int i, n = 0;
unsigned i;
int n = 0;
for (i = 0; i <= path_cnt; i++)
n += snprintf(buf + n, sizeof(buf) - n, "%u,", path[i]);
buf[n] = '\0';
return buf;
}

static char dbg_buf[8192];
#define DBG_DUMP_FUNC(name) static void dbg_dump_##name(void *data) \
{ \
char buf[2048]; \
mad_dump_##name(buf, sizeof(buf), data, IB_SMP_DATA_SIZE); \
NOISE("### "#name":\n%s\n", buf); \
mad_dump_##name(dbg_buf, sizeof(dbg_buf), data, IB_SMP_DATA_SIZE); \
NOISE("### "#name":\n%s\n", dbg_buf); \
}

DBG_DUMP_FUNC(nodeinfo);
Expand Down Expand Up @@ -170,7 +171,7 @@ static void clean_from_tr_table(uint64_t trid)
tr_table[n] = NULL;
}

static void free_unresponded()
static void free_unresponded(void)
{
struct request_queue *q;
unsigned i;
Expand Down Expand Up @@ -260,7 +261,7 @@ static int recv_response(int fd, int agent, uint8_t * umad, size_t length)
if (ret < 0 || umad_status(umad)) {
ERROR("umad_recv failed: umad status %x: %s\n",
umad_status(umad), strerror(errno));
return len > umad_size() ? 1 : -1;
return (unsigned)len > umad_size() ? 1 : -1;
}

return 0;
Expand Down Expand Up @@ -399,7 +400,8 @@ static int process_node(void *umad, unsigned remote_id, int fd, int agent,
uint8_t *node_info = umad_get_mad(umad) + IB_SMP_DATA_OFFS;
unsigned port_num = mad_get_field(node_info, 0, IB_NODE_LOCAL_PORT_F);
unsigned node_is_new = 0;
int i, id;
unsigned i;
int id;

dbg_dump_nodeinfo(node_info);

Expand Down Expand Up @@ -561,7 +563,7 @@ static int umad_discover(char *card_name, unsigned int port_num)
return ret;
}

static void print_subnet()
static void print_subnet(void)
{
struct node *node;
struct port *local, *remote;
Expand Down Expand Up @@ -593,13 +595,13 @@ static void print_subnet()
int main(int argc, char **argv)
{
const struct option long_opts[] = {
{"Card", 1, 0, 'C'},
{"Port", 1, 0, 'P'},
{"maxsmps", 1, 0, 'n'},
{"timeout", 1, 0, 't'},
{"retries", 1, 0, 'r'},
{"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"Card", 1, NULL, 'C'},
{"Port", 1, NULL, 'P'},
{"maxsmps", 1, NULL, 'n'},
{"timeout", 1, NULL, 't'},
{"retries", 1, NULL, 'r'},
{"verbose", 0, NULL, 'v'},
{"help", 0, NULL, 'h'},
{}
};
char *card_name = NULL;
Expand Down