Hoist the page info logic in test.py into a helper function, check_info(). This is a preparatory refactoring for the rds over ROCE series that helps modularize the send/recv logic. Breaking up the logic now will help avoid large function pylint errors later. No functional changes are introduced in this patch. Signed-off-by: Allison Henderson --- tools/testing/selftests/net/rds/test.py | 53 +++++++++++++++---------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/net/rds/test.py b/tools/testing/selftests/net/rds/test.py index 027131b26287..5d4b039580df 100755 --- a/tools/testing/selftests/net/rds/test.py +++ b/tools/testing/selftests/net/rds/test.py @@ -79,6 +79,36 @@ def netns_socket(netns, *sock_args): u1.close() return socket.fromfd(fds[0], *sock_args) +def check_info(socks): + """ + Check all rds info pages for errors + + :param socks: list of sockets to check + """ + + # the Python socket module doesn't know these + rds_info_first = 10000 + rds_info_last = 10017 + + nr_success = 0 + nr_error = 0 + + for sock in socks: + for optname in range(rds_info_first, rds_info_last + 1): + # Sigh, the Python socket module doesn't allow us to pass + # buffer lengths greater than 1024 for some reason. RDS + # wants multiple pages. + try: + sock.getsockopt(socket.SOL_RDS, optname, 1024) + nr_success = nr_success + 1 + except OSError as e: + nr_error = nr_error + 1 + if e.errno == errno.ENOSPC: + # ignore + pass + + ksft_pr(f"getsockopt(): {nr_success}/{nr_error}") + def stop_pcaps(): """Stop tcpdump processes. @@ -268,28 +298,7 @@ while nr_send < NUM_PACKETS: ksft_pr("done", nr_send, nr_recv) -# the Python socket module doesn't know these -RDS_INFO_FIRST = 10000 -RDS_INFO_LAST = 10017 - -nr_success = 0 -nr_error = 0 - -for s in sockets: - for optname in range(RDS_INFO_FIRST, RDS_INFO_LAST + 1): - # Sigh, the Python socket module doesn't allow us to pass - # buffer lengths greater than 1024 for some reason. RDS - # wants multiple pages. - try: - s.getsockopt(socket.SOL_RDS, optname, 1024) - nr_success = nr_success + 1 - except OSError as e: - nr_error = nr_error + 1 - if e.errno == errno.ENOSPC: - # ignore - pass - -ksft_pr(f"getsockopt(): {nr_success}/{nr_error}") +check_info(sockets) # cancel timeout signal.alarm(0) -- 2.25.1