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 | 3d463be | 2015-08-02 01:41:26 +0000 | [diff] [blame] | 8 | r_socket = "^socket\\(PF_INET, SOCK_STREAM, IPPROTO_IP\\) += 0<TCP:\\[(" r_i ")\\]>$" |
Dmitry V. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 9 | } |
| 10 | |
Dmitry V. Levin | 3d463be | 2015-08-02 01:41:26 +0000 | [diff] [blame] | 11 | NR == 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. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 18 | |
| 19 | NR == 2 { |
Dmitry V. Levin | 3d463be | 2015-08-02 01:41:26 +0000 | [diff] [blame] | 20 | if (r_connect != "" && match($0, r_connect, a)) { |
Dmitry V. Levin | 959205c | 2014-12-26 23:29:26 +0000 | [diff] [blame] | 21 | 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. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 24 | next |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | NR == 3 { |
Dmitry V. Levin | 959205c | 2014-12-26 23:29:26 +0000 | [diff] [blame] | 29 | 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] | 30 | port_l = a[1] |
Dmitry V. Levin | 959205c | 2014-12-26 23:29:26 +0000 | [diff] [blame] | 31 | 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] | 32 | next |
| 33 | } |
| 34 | } |
| 35 | |
Dmitry V. Levin | 959205c | 2014-12-26 23:29:26 +0000 | [diff] [blame] | 36 | NR == 4 {if (r_close != "" && match($0, r_close)) next} |
Dmitry V. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 37 | |
Dmitry V. Levin | 959205c | 2014-12-26 23:29:26 +0000 | [diff] [blame] | 38 | NR == lines && $0 == "+++ exited with 0 +++" {next} |
Dmitry V. Levin | fdfa722 | 2014-09-23 00:14:04 +0000 | [diff] [blame] | 39 | |
| 40 | { |
| 41 | print "Line " NR " does not match: " $0 |
| 42 | fail=1 |
| 43 | } |
| 44 | |
| 45 | END { |
| 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 | } |