diff --git a/gtests/net/packetdrill/run_system_call.c b/gtests/net/packetdrill/run_system_call.c index 8a71505f52c667ee310421e372647fea75387169..3f25f5b30b3e883b65e3847e46945de703cd41ae 100644 --- a/gtests/net/packetdrill/run_system_call.c +++ b/gtests/net/packetdrill/run_system_call.c @@ -346,6 +346,31 @@ static int s32_bracketed_arg(struct expression_list *args, return get_s32(list->expression, value, error); } +/* Return the value of the argument with the given index, and verify + * that it has the expected type: a list with a single integer. + */ +#ifdef __FreeBSD__ +static int u32_bracketed_arg(struct expression_list *args, + int index, u32 *value, char **error) +{ + struct expression_list *list; + struct expression *expression; + + expression = get_arg(args, index, error); + if (expression == NULL) + return STATUS_ERR; + if (check_type(expression, EXPR_LIST, error)) + return STATUS_ERR; + list = expression->value.list; + if (expression_list_length(list) != 1) { + asprintf(error, + "Expected [<integer>] but got multiple elements"); + return STATUS_ERR; + } + return get_u32(list->expression, value, error); +} +#endif + /* Return STATUS_OK iff the argument with the given index is an * ellipsis (...). */ @@ -3691,8 +3716,7 @@ static int syscall_sctp_recvv(struct state *state, struct syscall_spec *syscall, struct iovec *iov; struct sockaddr *from = NULL; struct expression *iovec_expr_list, *iovcnt_expr, *addr_expr, *fromlen_expr; - struct expression *infolen_expr, *info_expr, *infotype_expr, *flags_expr; - struct expression *infolen_list_expr, *infotype_list_expr, *flags_list_expr; + struct expression *info_expr, *infotype_expr, *flags_expr; struct sctp_recvv_rn recvv_rn; struct sctp_rcvinfo rcvinfo; struct sctp_nxtinfo nxtinfo; @@ -3724,15 +3748,9 @@ static int syscall_sctp_recvv(struct state *state, struct syscall_spec *syscall, } else { return STATUS_ERR; } - infolen_list_expr = get_arg(args, 6, error); - if (infolen_list_expr->type == EXPR_LIST) { - if (check_arg_count(infolen_list_expr->value.list, 1, error)) { - return STATUS_ERR; - } - } - infolen_expr = get_arg(infolen_list_expr->value.list, 0, error); - if (get_u32(infolen_expr, &infolen, error)) + if (u32_bracketed_arg(args, 6, &infolen, error)) { return STATUS_ERR; + } infotype = 0; flags = 0; addr_expr = get_arg(args, 3, error); @@ -3759,17 +3777,13 @@ static int syscall_sctp_recvv(struct state *state, struct syscall_spec *syscall, } } free(from); - infotype_list_expr = get_arg(args, 7, error); - if (infotype_list_expr->type != EXPR_ELLIPSIS) { - if (check_arg_count(infotype_list_expr->value.list, 1, error)) { - return STATUS_ERR; - } - infotype_expr = get_arg(infotype_list_expr->value.list, 0, error); + + infotype_expr = get_arg(args, 7, error); + if (infotype_expr->type != EXPR_ELLIPSIS) { s32 script_infotype; + if (s32_bracketed_arg(args, 7, &script_infotype, error)) + return STATUS_ERR; - if (get_s32(infotype_expr, &script_infotype, error)) { - return STATUS_ERR; - } if (infotype != script_infotype) { asprintf(error, "sctp_recvv infotype: expected: %u actual: %u", script_infotype, infotype); @@ -3814,13 +3828,12 @@ static int syscall_sctp_recvv(struct state *state, struct syscall_spec *syscall, return STATUS_ERR; break; } - flags_list_expr = get_arg(args, 8, error); - if (flags_list_expr->type != EXPR_ELLIPSIS) { - if (check_arg_count(flags_list_expr->value.list, 1, error)) - return STATUS_ERR; - flags_expr = get_arg(flags_list_expr->value.list, 0, error); + flags_expr = get_arg(args, 8, error); + if (flags_expr->type != EXPR_ELLIPSIS) { s32 script_flags; - if (get_s32(flags_expr, &script_flags, error)) { + if (s32_bracketed_arg(args, 8, &script_flags, error)) + return STATUS_ERR; + if (flags != script_flags) { asprintf(error, "sctp_recvv flags bad return value. expected %d, actual %d", script_flags, flags); return STATUS_ERR; diff --git a/gtests/net/packetdrill/tests/bsd/sctp/sctp_recvv.pkt b/gtests/net/packetdrill/tests/bsd/sctp/sctp_recvv.pkt index f454604c19823a6143483b9fde65f1593ae5af23..b7c6f9283a2f454add5f1f9e64bb9d31420e7b0f 100644 --- a/gtests/net/packetdrill/tests/bsd/sctp/sctp_recvv.pkt +++ b/gtests/net/packetdrill/tests/bsd/sctp/sctp_recvv.pkt @@ -16,18 +16,18 @@ //base test +0.0 < sctp: DATA[flgs=BE, len=1016, tsn=1, sid=0, ssn=0, ppid=0] * > sctp: SACK[flgs=0, cum_tsn=1, a_rwnd=..., gaps=[], dups=[]] -+0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, ..., 20, NULL, [0], [SCTP_RECVV_NOINFO], [0]) = 1000 ++0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, ..., 20, NULL, [0], [SCTP_RECVV_NOINFO], [MSG_EOR]) = 1000 //base test with sockaddr +0.0 < sctp: DATA[flgs=BE, len=1016, tsn=2, sid=0, ssn=1, ppid=0] * > sctp: SACK[flgs=0, cum_tsn=2, a_rwnd=..., gaps=[], dups=[]] +0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, {sa_family=AF_INET, sin_port=htons(8080), sin_addr=inet_addr("192.0.2.1")}, -16, NULL, [0], [SCTP_RECVV_NOINFO], [0]) = 1000 +16, NULL, [0], [SCTP_RECVV_NOINFO], [MSG_EOR]) = 1000 //base test with NULL sockaddr +0.0 < sctp: DATA[flgs=BE, len=1016, tsn=3, sid=0, ssn=2, ppid=0] * > sctp: SACK[flgs=0, cum_tsn=3, a_rwnd=..., gaps=[], dups=[]] -+0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, NULL, 0, NULL, [0], [SCTP_RECVV_NOINFO], [0]) = 1000 ++0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, NULL, 0, NULL, [0], [SCTP_RECVV_NOINFO], [MSG_EOR]) = 1000 //base SCTP_RECVV_RCVINFO +0.0 setsockopt(3, IPPROTO_SCTP, SCTP_RECVRCVINFO, [1], 4) = 0 @@ -35,7 +35,7 @@ +0.0 < sctp: DATA[flgs=BE, len=1016, tsn=4, sid=0, ssn=3, ppid=0] * > sctp: SACK[flgs=0, cum_tsn=4, a_rwnd=..., gaps=[], dups=[]] +0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, ..., 16, {rcv_sid=0, rcv_ssn=3, rcv_flags=0, rcv_ppid=htonl(0), rcv_tsn=4, rcv_cumtsn=4, rcv_context=0}, -[28], [SCTP_RECVV_RCVINFO], [0]) = 1000 +[28], [SCTP_RECVV_RCVINFO], [MSG_EOR]) = 1000 //base SCTP_RECVV_NXTINFO +0.0 setsockopt(3, IPPROTO_SCTP, SCTP_RECVRCVINFO, [0], 4) = 0 @@ -44,8 +44,9 @@ * > sctp: SACK[flgs=0, cum_tsn=5, a_rwnd=..., gaps=[], dups=[]] +0.0 < sctp: DATA[flgs=BE, len=1016, tsn=6, sid=0, ssn=5, ppid=10] * > sctp: SACK[flgs=0, cum_tsn=6, a_rwnd=..., gaps=[], dups=[]] -+0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, ..., 16, {nxt_sid=0, nxt_flags=32, nxt_ppid=htonl(10), nxt_length=1000}, [16], [SCTP_RECVV_NXTINFO], [0]) = 1000 -+0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, ..., 16, NULL, [0], [0], [0]) = 1000 ++0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, ..., 16, {nxt_sid=0, nxt_flags=32, nxt_ppid=htonl(10), nxt_length=1000}, +[16], [SCTP_RECVV_NXTINFO], [MSG_EOR]) = 1000 ++0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, ..., 16, NULL, [0], [0], [MSG_EOR]) = 1000 //base SCTP_RECVV_RN +0.0 setsockopt(3, IPPROTO_SCTP, SCTP_RECVRCVINFO, [1], 4) = 0 @@ -56,18 +57,19 @@ * > sctp: SACK[flgs=0, cum_tsn=8, a_rwnd=..., gaps=[], dups=[]] +0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, ..., 16, { recvv_rcvinfo={rcv_sid=0, rcv_ssn=6, rcv_flags=0, rcv_ppid=htonl(0), rcv_tsn=7, rcv_cumtsn=8, rcv_context=0}, -recvv_nxtinfo={nxt_sid=0, nxt_flags=32, nxt_ppid=htonl(10), nxt_length=1000}}, [44], [SCTP_RECVV_RN], [0]) = 1000 +recvv_nxtinfo={nxt_sid=0, nxt_flags=32, nxt_ppid=htonl(10), nxt_length=1000}}, [44], [SCTP_RECVV_RN], [MSG_EOR]) = 1000 +0.0 < sctp: DATA[flgs=BE, len=1016, tsn=9, sid=0, ssn=8, ppid=11] * > sctp: SACK[flgs=0, cum_tsn=9, a_rwnd=..., gaps=[], dups=[]] +0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, ..., 16, { -recvv_rcvinfo={rcv_sid=0, rcv_ssn=7, rcv_flags=0, rcv_ppid=htonl(10), rcv_tsn=8, rcv_cumtsn=9, rcv_context=0}, recvv_nxtinfo=...}, [44], [SCTP_RECVV_RN], [0]) = 1000 +recvv_rcvinfo={rcv_sid=0, rcv_ssn=7, rcv_flags=0, rcv_ppid=htonl(10), rcv_tsn=8, rcv_cumtsn=9, rcv_context=0}, recvv_nxtinfo=...}, +[44], [SCTP_RECVV_RN], [MSG_EOR]) = 1000 +0.0 < sctp: DATA[flgs=BE, len=1016, tsn=10, sid=0, ssn=9, ppid=10] * > sctp: SACK[flgs=0, cum_tsn=10, a_rwnd=..., gaps=[], dups=[]] +0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, ..., 16, { -recvv_rcvinfo=..., recvv_nxtinfo={nxt_sid=0, nxt_flags=32, nxt_ppid=htonl(10), nxt_length=1000}}, [44], [SCTP_RECVV_RN], [0]) = 1000 -+0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, ..., 16, NULL, [0], [SCTP_RECVV_NOINFO], [0]) = 1000 +recvv_rcvinfo=..., recvv_nxtinfo={nxt_sid=0, nxt_flags=32, nxt_ppid=htonl(10), nxt_length=1000}}, [44], [SCTP_RECVV_RN], [8]) = 1000 ++0.0 sctp_recvv(3, [{iov_base=..., iov_len=1000}], 1, ..., 16, NULL, [0], [SCTP_RECVV_NOINFO], [MSG_EOR]) = 1000 +0.0 close(3) = 0 +0.0 > sctp: SHUTDOWN[flgs=0, cum_tsn=10]