Dmitry V. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 1 | BEGIN { |
| 2 | lines = 5 |
| 3 | fail = 0 |
| 4 | |
Dmitry V. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 5 | 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. Levin | ed7ada2 | 2015-01-13 00:06:09 +0000 | [diff] [blame] | 8 | r_connect = "^connect\\(0<TCP:\\[" r_i "\\]>, \\{sa_family=AF_INET, sin_port=htons\\((" r_port ")\\), sin_addr=inet_addr\\(\"" r_localhost "\"\\)\\}, " r_i ") += 0$" |
Dmitry V. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 9 | } |
| 10 | |
| 11 | NR == 1 && /^socket\(PF_INET, SOCK_STREAM, IPPROTO_IP\) += 0$/ {next} |
| 12 | |
| 13 | NR == 2 { |
| 14 | if (match($0, r_connect, a)) { |
Dmitry V. Levin | 959205c | 2014-12-26 23:29:26 +0000 | [diff] [blame] | 15 | port_r = a[1] |
| 16 | r_send = "^send\\(0<TCP:\\[" r_localhost ":(" r_port ")->" r_localhost ":" port_r "\\]>, \"data\", 4, MSG_DONTROUTE\\) += 4$" |
| 17 | r_sendto = "^sendto\\(0<TCP:\\[" r_localhost ":(" r_port ")->" r_localhost ":" port_r "\\]>, \"data\", 4, MSG_DONTROUTE, NULL, 0\\) += 4$" |
Dmitry V. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 18 | next |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | NR == 3 { |
Dmitry V. Levin | 959205c | 2014-12-26 23:29:26 +0000 | [diff] [blame] | 23 | if (r_send != "" && (match($0, r_send, a) || match($0, r_sendto, a))) { |
Dmitry V. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 24 | port_l = a[1] |
Dmitry V. Levin | 959205c | 2014-12-26 23:29:26 +0000 | [diff] [blame] | 25 | r_close = "^close\\(0<TCP:\\[" r_localhost ":" port_l "->" r_localhost ":" port_r "\\]>\\) += 0$" |
Dmitry V. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 26 | next |
| 27 | } |
| 28 | } |
| 29 | |
Dmitry V. Levin | 959205c | 2014-12-26 23:29:26 +0000 | [diff] [blame] | 30 | NR == 4 {if (r_close != "" && match($0, r_close)) next} |
Dmitry V. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 31 | |
Dmitry V. Levin | 959205c | 2014-12-26 23:29:26 +0000 | [diff] [blame] | 32 | NR == lines && $0 == "+++ exited with 0 +++" {next} |
Dmitry V. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 33 | |
| 34 | { |
| 35 | print "Line " NR " does not match: " $0 |
| 36 | fail=1 |
| 37 | } |
| 38 | |
| 39 | END { |
| 40 | if (NR != lines) { |
| 41 | print "Expected " lines " lines, found " NR " line(s)." |
| 42 | print "" |
| 43 | exit 1 |
| 44 | } |
| 45 | if (fail) { |
| 46 | print "" |
| 47 | exit 1 |
| 48 | } |
| 49 | } |