From 7a43cfacc19e73bf91ccda25ff7e0ef674f220bc Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Thu, 18 Apr 2019 12:36:42 +0200 Subject: [PATCH 01/12] tests: Do not use umad.h deprecated functions ntohll is deprecated in libibumad. Use the glibc function instead Signed-off-by: Nicolas Morey-Chaisemartin --- tests/mcast_storm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/mcast_storm.c b/tests/mcast_storm.c index 61f0348..072cb2a 100644 --- a/tests/mcast_storm.c +++ b/tests/mcast_storm.c @@ -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, @@ -521,8 +521,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); } @@ -541,9 +541,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++); From 68199eba28ef48d1ffc6153b5debb8271beae7d3 Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Thu, 18 Apr 2019 13:21:11 +0200 Subject: [PATCH 02/12] .gitignore: Add tests binaries Signed-off-by: Nicolas Morey-Chaisemartin --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5bd098a..f45b860 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ *.so *.build_profile ibsim/ibsim - +tests/mcast_storm +tests/query_many +tests/subnet_discover From a12e642b77b9052f4891686451e48a18acbe0d4c Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Thu, 18 Apr 2019 13:21:55 +0200 Subject: [PATCH 03/12] tests: Use NULL instread of 0 in all places where it used as a pointer Found by sparse Signed-off-by: Nicolas Morey-Chaisemartin --- tests/mcast_storm.c | 40 ++++++++++++++++++++-------------------- tests/query_many.c | 16 ++++++++-------- tests/subnet_discover.c | 14 +++++++------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/tests/mcast_storm.c b/tests/mcast_storm.c index 072cb2a..1bc8ef2 100644 --- a/tests/mcast_storm.c +++ b/tests/mcast_storm.c @@ -679,32 +679,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]; diff --git a/tests/query_many.c b/tests/query_many.c index 6e0b9f6..172620e 100644 --- a/tests/query_many.c +++ b/tests/query_many.c @@ -246,14 +246,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; diff --git a/tests/subnet_discover.c b/tests/subnet_discover.c index 44cd86e..5706a05 100644 --- a/tests/subnet_discover.c +++ b/tests/subnet_discover.c @@ -593,13 +593,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; From 986f88ab0cb39d64d420857d49a166e48698b9e9 Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Thu, 18 Apr 2019 13:23:31 +0200 Subject: [PATCH 04/12] tests: make function declaration ANSI Fixessparse warnings: subnet_discover.c:173:30: warning: non-ANSI function declaration of function 'free_unresponded' subnet_discover.c:564:26: warning: non-ANSI function declaration of function 'print_subnet' Signed-off-by: Nicolas Morey-Chaisemartin --- tests/subnet_discover.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/subnet_discover.c b/tests/subnet_discover.c index 5706a05..d2d234a 100644 --- a/tests/subnet_discover.c +++ b/tests/subnet_discover.c @@ -170,7 +170,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; @@ -561,7 +561,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; From d1246b1deef7e20882de2e9eebb61f9dbafc5d00 Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Thu, 18 Apr 2019 13:24:24 +0200 Subject: [PATCH 05/12] tests: fix signed vs unsigned comparisons Found by GCC -Wall -Wextra Signed-off-by: Nicolas Morey-Chaisemartin --- tests/mcast_storm.c | 10 ++++++---- tests/query_many.c | 3 ++- tests/subnet_discover.c | 8 +++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/mcast_storm.c b/tests/mcast_storm.c index 1bc8ef2..5f0413c 100644 --- a/tests/mcast_storm.c +++ b/tests/mcast_storm.c @@ -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__); @@ -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__); @@ -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) { @@ -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; diff --git a/tests/query_many.c b/tests/query_many.c index 172620e..7e1012c 100644 --- a/tests/query_many.c +++ b/tests/query_many.c @@ -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'; diff --git a/tests/subnet_discover.c b/tests/subnet_discover.c index d2d234a..8df5914 100644 --- a/tests/subnet_discover.c +++ b/tests/subnet_discover.c @@ -59,7 +59,8 @@ 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'; @@ -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; @@ -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); From 55c856170382253d2b0540540b8e42795d9a6e82 Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Thu, 18 Apr 2019 13:24:51 +0200 Subject: [PATCH 06/12] test: subnet_discover: Fix stack overflow Two issues here: - 2K on stack is a lot and app tends to segv in -O0 due to that. - libibmad is not honoring the size constraints on some mad_dump_xx. Increase buf to 8k to bypass this. Signed-off-by: Nicolas Morey-Chaisemartin --- tests/subnet_discover.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/subnet_discover.c b/tests/subnet_discover.c index 8df5914..ba7c7c2 100644 --- a/tests/subnet_discover.c +++ b/tests/subnet_discover.c @@ -67,11 +67,11 @@ static const char *print_path(uint8_t path[], size_t path_cnt) 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); From 61a6843800a86684fe9127bccf8c0d6984a3a111 Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Thu, 18 Apr 2019 13:26:16 +0200 Subject: [PATCH 07/12] tests: mcast_storm: make sure dbg macro is never empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This causes issues when doing if(x) dbg(...) sparse found one of these: mcast_storm.c:316:53: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body] dbg("MAD status %x, method %x\n", status, method); Signed-off-by: Nicolas Morey-Chaisemartin --- tests/mcast_storm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/mcast_storm.c b/tests/mcast_storm.c index 5f0413c..3fced41 100644 --- a/tests/mcast_storm.c +++ b/tests/mcast_storm.c @@ -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 From b7e538ad177b9e0c33570aacfa5bccacfd121cbe Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Thu, 18 Apr 2019 13:28:55 +0200 Subject: [PATCH 08/12] Makefile: add tests to all targets Signed-off-by: Nicolas Morey-Chaisemartin --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 665e186..cb698f2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -subdirs:= ibsim umad2sim +subdirs:= ibsim umad2sim tests all clean dep install: $(foreach dir, $(subdirs), make -C $(dir) $@ && ) echo "Done." From 3abc7e96197c979cd96298a7458231562b88d6a5 Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Thu, 18 Apr 2019 13:31:41 +0200 Subject: [PATCH 09/12] scripts: travis-build: keep last build so we can run tests --- scripts/travis-build | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/travis-build b/scripts/travis-build index bd4adf4..10fdb71 100755 --- a/scripts/travis-build +++ b/scripts/travis-build @@ -23,4 +23,3 @@ fi # Test out gcc-8 CC=gcc-8 CFLAGS="-Werror" make -make clean From c2de6c36f67e5863a6d5299af05c1696a0c77a01 Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Thu, 18 Apr 2019 13:47:25 +0200 Subject: [PATCH 10/12] ibsim: add --no-console option Allows to run ibsim in the background without stalling on readline calls Signed-off-by: Nicolas Morey-Chaisemartin --- ibsim/ibsim.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ibsim/ibsim.c b/ibsim/ibsim.c index 3bbc9fd..92563b3 100644 --- a/ibsim/ibsim.c +++ b/ibsim/ibsim.c @@ -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, ...) @@ -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; } @@ -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); @@ -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) ] \n", + " -M mcastcap -r(emote_mode) -l(isten_to_port) -n(o-console)] \n", prog_name); fprintf(stderr, "%s %s\n", prog_name, IBSIM_VERSION); @@ -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'}, @@ -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'}, {} @@ -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]); @@ -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]); From 2df85600a123d4b6e35b70d581d85f4db233da64 Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Thu, 18 Apr 2019 14:02:34 +0200 Subject: [PATCH 11/12] scripts: Add script to tun tests Signed-off-by: Nicolas Morey-Chaisemartin --- scripts/travis-runtest | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 scripts/travis-runtest diff --git a/scripts/travis-runtest b/scripts/travis-runtest new file mode 100755 index 0000000..1babcd5 --- /dev/null +++ b/scripts/travis-runtest @@ -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 From e9f2ed159ae6f178debb64fe25f6cbbdf20882d7 Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Thu, 18 Apr 2019 14:02:44 +0200 Subject: [PATCH 12/12] travis: enable running tests during travis build Signed-off-by: Nicolas Morey-Chaisemartin --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 337bd65..0fb8a8f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,9 @@ addons: - wget - libibumad-dev - libibmad-dev + - opensm script: - scripts/travis-checkpatch - scripts/travis-build + - scripts/travis-runtest - ./dist.sh