t / t0210 / scrub_normal.perlon commit Merge branch 'sg/fsck-config-in-doc' (14fe4af)
   1#!/usr/bin/perl
   2#
   3# Scrub the variable fields from the normal trace2 output to
   4# make testing easier.
   5
   6use strict;
   7use warnings;
   8
   9my $float = '[0-9]*\.[0-9]+([eE][-+]?[0-9]+)?';
  10
  11# This code assumes that the trace2 data was written with bare
  12# turned on (which omits the "<clock> <file>:<line>" prefix.
  13
  14while (<>) {
  15    # Various messages include an elapsed time in the middle
  16    # of the message.  Replace the time with a placeholder to
  17    # simplify our HEREDOC in the test script.
  18    s/elapsed:$float/elapsed:_TIME_/g;
  19
  20    my $line = $_;
  21
  22    # we expect:
  23    #    start <argv0> [<argv1> [<argv2> [...]]]
  24    #
  25    # where argv0 might be a relative or absolute path, with
  26    # or without quotes, and platform dependent.  Replace argv0
  27    # with a token for HEREDOC matching in the test script.
  28
  29    if ($line =~ m/^start/) {
  30        $line =~ /^start\s+(.*)/;
  31        my $argv = $1;
  32        $argv =~ m/(\'[^\']*\'|[^ ]+)\s+(.*)/;
  33        my $argv_0 = $1;
  34        my $argv_rest = $2;
  35
  36        print "start _EXE_ $argv_rest\n";
  37    }
  38    elsif ($line =~ m/^cmd_path/) {
  39        # Likewise, the 'cmd_path' message breaks out argv[0].
  40        #
  41        # This line is only emitted when RUNTIME_PREFIX is defined,
  42        # so just omit it for testing purposes.
  43        # print "cmd_path _EXE_\n";
  44    }
  45    else {
  46        print "$line";
  47    }
  48}