Home | History | Annotate | Download | only in tests
      1 #!/bin/gawk
      2 #
      3 # Copyright (c) 2014 Masatake YAMATO <yamato (at] redhat.com>
      4 # Copyright (c) 2014-2015 Dmitry V. Levin <ldv (at] 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 
     29 BEGIN {
     30   lines = 5
     31   fail = 0
     32 
     33   r_i = "[1-9][0-9]*"
     34   r_port = "[1-9][0-9][0-9][0-9]+"
     35   r_localhost = "127\\.0\\.0\\.1"
     36   r_socket = "^socket\\(PF_INET, SOCK_STREAM, IPPROTO_IP\\) += 0<TCP:\\[(" r_i ")\\]>$"
     37 }
     38 
     39 NR == 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 }
     46 
     47 NR == 2 {
     48   if (r_connect != "" && match($0, r_connect, a)) {
     49     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$"
     52     next
     53   }
     54 }
     55 
     56 NR == 3 {
     57   if (r_send != "" && (match($0, r_send, a) || match($0, r_sendto, a))) {
     58     port_l = a[1]
     59     r_close = "^close\\(0<TCP:\\[" r_localhost ":" port_l "->" r_localhost ":" port_r "\\]>\\) += 0$"
     60     next
     61   }
     62 }
     63 
     64 NR == 4 {if (r_close != "" && match($0, r_close)) next}
     65 
     66 NR == lines && $0 == "+++ exited with 0 +++" {next}
     67 
     68 {
     69   print "Line " NR " does not match: " $0
     70   fail=1
     71 }
     72 
     73 END {
     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 }
     84