diff options
author | Lawrence Brakmo <brakmo@fb.com> | 2018-01-25 16:14:16 -0800 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2018-01-25 16:41:15 -0800 |
commit | d6d4f60c3a0933852dcc40a2142d93027ea1da76 (patch) | |
tree | a740942fab1902605fe48ed877d942c6ad02ad58 /tools/testing/selftests/bpf/tcp_client.py | |
parent | d44874910a26f3a8f81edf873a2473363f07f660 (diff) | |
download | linux-d6d4f60c3a0933852dcc40a2142d93027ea1da76.tar.gz linux-d6d4f60c3a0933852dcc40a2142d93027ea1da76.tar.bz2 linux-d6d4f60c3a0933852dcc40a2142d93027ea1da76.zip |
bpf: add selftest for tcpbpf
Added a selftest for tcpbpf (sock_ops) that checks that the appropriate
callbacks occured and that it can access tcp_sock fields and that their
values are correct.
Run with command: ./test_tcpbpf_user
Adding the flag "-d" will show why it did not pass.
Signed-off-by: Lawrence Brakmo <brakmo@fb.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/tcp_client.py')
-rwxr-xr-x | tools/testing/selftests/bpf/tcp_client.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/tcp_client.py b/tools/testing/selftests/bpf/tcp_client.py new file mode 100755 index 000000000000..481dccdf140c --- /dev/null +++ b/tools/testing/selftests/bpf/tcp_client.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python2 +# +# SPDX-License-Identifier: GPL-2.0 +# + +import sys, os, os.path, getopt +import socket, time +import subprocess +import select + +def read(sock, n): + buf = '' + while len(buf) < n: + rem = n - len(buf) + try: s = sock.recv(rem) + except (socket.error), e: return '' + buf += s + return buf + +def send(sock, s): + total = len(s) + count = 0 + while count < total: + try: n = sock.send(s) + except (socket.error), e: n = 0 + if n == 0: + return count; + count += n + return count + + +serverPort = int(sys.argv[1]) +HostName = socket.gethostname() + +# create active socket +sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) +try: + sock.connect((HostName, serverPort)) +except socket.error as e: + sys.exit(1) + +buf = '' +n = 0 +while n < 1000: + buf += '+' + n += 1 + +sock.settimeout(1); +n = send(sock, buf) +n = read(sock, 500) +sys.exit(0) |