blob: f4dcf913ed2dec681c318fda4983621acffb6205 [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001#!/bin/gawk
2#
3# Copyright (c) 2014 Masatake YAMATO <yamato@redhat.com>
4# Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15# 3. The name of the author may not be used to endorse or promote products
16# derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000029BEGIN {
30 lines = 5
31 fail = 0
32
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000033 r_i = "[1-9][0-9]*"
34 r_port = "[1-9][0-9][0-9][0-9]+"
35 r_localhost = "127\\.0\\.0\\.1"
Dmitry V. Levin3d463be2015-08-02 01:41:26 +000036 r_socket = "^socket\\(PF_INET, SOCK_STREAM, IPPROTO_IP\\) += 0<TCP:\\[(" r_i ")\\]>$"
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000037}
38
Dmitry V. Levin3d463be2015-08-02 01:41:26 +000039NR == 1 {
40 if (match($0, r_socket, a)) {
41 inode = a[1]
42 r_connect = "^connect\\(0<TCP:\\[" inode "\\]>, \\{sa_family=AF_INET, sin_port=htons\\((" r_port ")\\), sin_addr=inet_addr\\(\"" r_localhost "\"\\)\\}, " r_i ") += 0$"
43 next
44 }
45}
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000046
47NR == 2 {
Dmitry V. Levin3d463be2015-08-02 01:41:26 +000048 if (r_connect != "" && match($0, r_connect, a)) {
Dmitry V. Levin959205c2014-12-26 23:29:26 +000049 port_r = a[1]
50 r_send = "^send\\(0<TCP:\\[" r_localhost ":(" r_port ")->" r_localhost ":" port_r "\\]>, \"data\", 4, MSG_DONTROUTE\\) += 4$"
51 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 +000052 next
53 }
54}
55
56NR == 3 {
Dmitry V. Levin959205c2014-12-26 23:29:26 +000057 if (r_send != "" && (match($0, r_send, a) || match($0, r_sendto, a))) {
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000058 port_l = a[1]
Dmitry V. Levin959205c2014-12-26 23:29:26 +000059 r_close = "^close\\(0<TCP:\\[" r_localhost ":" port_l "->" r_localhost ":" port_r "\\]>\\) += 0$"
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000060 next
61 }
62}
63
Dmitry V. Levin959205c2014-12-26 23:29:26 +000064NR == 4 {if (r_close != "" && match($0, r_close)) next}
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000065
Dmitry V. Levin959205c2014-12-26 23:29:26 +000066NR == lines && $0 == "+++ exited with 0 +++" {next}
Dmitry V. Levinfdfa7222014-09-23 00:14:04 +000067
68{
69 print "Line " NR " does not match: " $0
70 fail=1
71}
72
73END {
74 if (NR != lines) {
75 print "Expected " lines " lines, found " NR " line(s)."
76 print ""
77 exit 1
78 }
79 if (fail) {
80 print ""
81 exit 1
82 }
83}