netdev-dpdk: fix mbuf leaks
[cascardo/ovs.git] / tests / ovsdb-monitor-sort.pl
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 # Breaks lines read from <STDIN> into groups using blank lines as
7 # group separators, then sorts lines within the groups for
8 # reproducibility.
9
10 sub compare_lines {
11     my ($a, $b) = @_;
12
13     my $u = '[0-9a-fA-F]';
14     my $uuid_re = "${u}{8}-${u}{4}-${u}{4}-${u}{4}-${u}{12}";
15     if ($a =~ /^$uuid_re/) {
16         if ($b =~ /^$uuid_re/) {
17             return substr($a, 36) cmp substr($b, 36);
18         } else {
19             return 1;
20         }
21     } elsif ($b =~ /^$uuid_re/) {
22         return -1;
23     } else {
24         return $a cmp $b;
25     }
26 }
27
28 sub output_group {
29     my (@group) = @_;
30     print "$_\n" foreach sort { compare_lines($a, $b) } @group;
31 }
32
33 if ("$^O" eq "msys") {
34     $/ = "\r\n";
35 }
36 my @group = ();
37 while (<STDIN>) {
38     chomp;
39     if ($_ eq '') {
40         output_group(@group);
41         @group = ();
42         print "\n";
43     } else {
44         if (/^,/ && @group) {
45             $group[$#group] .= "\n" . $_;
46         } else {
47             push(@group, $_);
48         }
49     }
50 }
51
52 output_group(@group) if @group;