ofproto: Break out perl code for sorting multiline messages
authorSimon Horman <horms@verge.net.au>
Fri, 13 Jun 2014 02:40:23 +0000 (11:40 +0900)
committerBen Pfaff <blp@nicira.com>
Fri, 13 Jun 2014 23:20:00 +0000 (16:20 -0700)
The flow monitoring tests includes a perl script to sort multiline
messages.  This commit breaks it out of an individual test so that it can
be used elsewhere.

Signed-off-by: Simon Horman <horms@verge.net.au>
[blp@nicira.com changed approach from a separate file to a shell function]
Signed-off-by: Ben Pfaff <blp@nicira.com>
tests/ofproto.at

index bd9c3af..f1c1774 100644 (file)
@@ -2097,6 +2097,28 @@ OFPT_BARRIER_REPLY (OF1.2):
 OVS_VSWITCHD_STOP
 AT_CLEANUP
 
+m4_divert_push([PREPARE_TESTS])
+# Sorts groups of lines that start with a space, without moving them
+# past the nearest line that does not start with a space.
+multiline_sort () {
+    ${PERL} -e '
+        use warnings;
+        use strict;
+        my @buffer = ();
+        while (<STDIN>) {
+            if (/^ /) {
+                push(@buffer, $_);
+            } else {
+                print $_ foreach sort(@buffer);
+                print $_;
+                @buffer = ();
+            }
+        }
+        print $_ foreach sort(@buffer);
+'
+}
+m4_divert_pop([PREPARE_TESTS])
+
 AT_SETUP([ofproto - flow monitoring])
 AT_KEYWORDS([monitor])
 OVS_VSWITCHD_START
@@ -2140,24 +2162,7 @@ ovs-ofctl mod-flows br0 cookie=5,dl_vlan=123,actions=output:3
 ovs-ofctl del-flows br0 dl_vlan=123
 ovs-ofctl del-flows br0
 ovs-appctl -t ovs-ofctl ofctl/barrier
-sort='
-    # Sorts groups of lines that start with a space, without moving them
-    # past the nearest line that does not start with a space.
-    use warnings;
-    use strict;
-    my @buffer = ();
-    while (<STDIN>) {
-        if (/^ /) {
-            push(@buffer, $_);
-        } else {
-            print $_ foreach sort(@buffer);
-            print $_;
-            @buffer = ();
-        }
-    }
-    print $_ foreach sort(@buffer);
-'
-AT_CHECK([sed 's/ (xid=0x[[1-9a-fA-F]][[0-9a-fA-F]]*)//' monitor.log | ${PERL} -e "$sort"], [0],
+AT_CHECK([sed 's/ (xid=0x[[1-9a-fA-F]][[0-9a-fA-F]]*)//' monitor.log | multiline_sort], [0],
 [NXST_FLOW_MONITOR reply (xid=0x0):
  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=124 actions=output:2
 NXST_FLOW_MONITOR reply (xid=0x0):