blob: 79e9ee085e0a4bca6e260ebf06e8a23e97abff18 [file] [log] [blame]
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +00001BEGIN {
2 lines = 5
3 fail = 0
4
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +00005 r_i = "[1-9][0-9]*"
6 r_port = "[1-9][0-9][0-9][0-9]+"
7 r_localhost = "127\\.0\\.0\\.1"
Dmitry V. Levin3d463be2015-08-02 01:41:26 +00008 r_socket = "^socket\\(PF_INET, SOCK_STREAM, IPPROTO_IP\\) += 0<TCP:\\[(" r_i ")\\]>$"
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +00009}
10
Dmitry V. Levin3d463be2015-08-02 01:41:26 +000011NR == 1 {
12 if (match($0, r_socket, a)) {
13 inode = a[1]
14 r_connect = "^connect\\(0<TCP:\\[" inode "\\]>, \\{sa_family=AF_INET, sin_port=htons\\((" r_port ")\\), sin_addr=inet_addr\\(\"" r_localhost "\"\\)\\}, " r_i ") += 0$"
15 next
16 }
17}
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000018
19NR == 2 {
Dmitry V. Levin3d463be2015-08-02 01:41:26 +000020 if (r_connect != "" && match($0, r_connect, a)) {
Dmitry V. Levin959205c2014-12-26 23:29:26 +000021 port_r = a[1]
22 r_send = "^send\\(0<TCP:\\[" r_localhost ":(" r_port ")->" r_localhost ":" port_r "\\]>, \"data\", 4, MSG_DONTROUTE\\) += 4$"
23 r_sendto = "^sendto\\(0<TCP:\\[" r_localhost ":(" r_port ")->" r_localhost ":" port_r "\\]>, \"data\", 4, MSG_DONTROUTE, NULL, 0\\) += 4$"
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000024 next
25 }
26}
27
28NR == 3 {
Dmitry V. Levin959205c2014-12-26 23:29:26 +000029 if (r_send != "" && (match($0, r_send, a) || match($0, r_sendto, a))) {
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000030 port_l = a[1]
Dmitry V. Levin959205c2014-12-26 23:29:26 +000031 r_close = "^close\\(0<TCP:\\[" r_localhost ":" port_l "->" r_localhost ":" port_r "\\]>\\) += 0$"
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000032 next
33 }
34}
35
Dmitry V. Levin959205c2014-12-26 23:29:26 +000036NR == 4 {if (r_close != "" && match($0, r_close)) next}
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000037
Dmitry V. Levin959205c2014-12-26 23:29:26 +000038NR == lines && $0 == "+++ exited with 0 +++" {next}
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000039
40{
41 print "Line " NR " does not match: " $0
42 fail=1
43}
44
45END {
46 if (NR != lines) {
47 print "Expected " lines " lines, found " NR " line(s)."
48 print ""
49 exit 1
50 }
51 if (fail) {
52 print ""
53 exit 1
54 }
55}