diff options
author | Lawrence Brakmo <brakmo@fb.com> | 2018-01-25 19:14:16 -0500 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2018-01-25 19:41:15 -0500 |
commit | d6d4f60c3a0933852dcc40a2142d93027ea1da76 (patch) | |
tree | a740942fab1902605fe48ed877d942c6ad02ad58 /tools/testing/selftests/bpf/tcp_client.py | |
parent | d44874910a26f3a8f81edf873a2473363f07f660 (diff) |
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 @@ | |||
1 | #!/usr/bin/env python2 | ||
2 | # | ||
3 | # SPDX-License-Identifier: GPL-2.0 | ||
4 | # | ||
5 | |||
6 | import sys, os, os.path, getopt | ||
7 | import socket, time | ||
8 | import subprocess | ||
9 | import select | ||
10 | |||
11 | def read(sock, n): | ||
12 | buf = '' | ||
13 | while len(buf) < n: | ||
14 | rem = n - len(buf) | ||
15 | try: s = sock.recv(rem) | ||
16 | except (socket.error), e: return '' | ||
17 | buf += s | ||
18 | return buf | ||
19 | |||
20 | def send(sock, s): | ||
21 | total = len(s) | ||
22 | count = 0 | ||
23 | while count < total: | ||
24 | try: n = sock.send(s) | ||
25 | except (socket.error), e: n = 0 | ||
26 | if n == 0: | ||
27 | return count; | ||
28 | count += n | ||
29 | return count | ||
30 | |||
31 | |||
32 | serverPort = int(sys.argv[1]) | ||
33 | HostName = socket.gethostname() | ||
34 | |||
35 | # create active socket | ||
36 | sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) | ||
37 | try: | ||
38 | sock.connect((HostName, serverPort)) | ||
39 | except socket.error as e: | ||
40 | sys.exit(1) | ||
41 | |||
42 | buf = '' | ||
43 | n = 0 | ||
44 | while n < 1000: | ||
45 | buf += '+' | ||
46 | n += 1 | ||
47 | |||
48 | sock.settimeout(1); | ||
49 | n = send(sock, buf) | ||
50 | n = read(sock, 500) | ||
51 | sys.exit(0) | ||