aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/tcp_client.py
diff options
context:
space:
mode:
authorLawrence Brakmo <brakmo@fb.com>2018-01-25 19:14:16 -0500
committerAlexei Starovoitov <ast@kernel.org>2018-01-25 19:41:15 -0500
commitd6d4f60c3a0933852dcc40a2142d93027ea1da76 (patch)
treea740942fab1902605fe48ed877d942c6ad02ad58 /tools/testing/selftests/bpf/tcp_client.py
parentd44874910a26f3a8f81edf873a2473363f07f660 (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-xtools/testing/selftests/bpf/tcp_client.py51
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
6import sys, os, os.path, getopt
7import socket, time
8import subprocess
9import select
10
11def 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
20def 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
32serverPort = int(sys.argv[1])
33HostName = socket.gethostname()
34
35# create active socket
36sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
37try:
38 sock.connect((HostName, serverPort))
39except socket.error as e:
40 sys.exit(1)
41
42buf = ''
43n = 0
44while n < 1000:
45 buf += '+'
46 n += 1
47
48sock.settimeout(1);
49n = send(sock, buf)
50n = read(sock, 500)
51sys.exit(0)