Merge branch 'master' of https://github.com/kmcdonell/pcp into kenj-merge
[pcp.git] / qa / 527
blob4a32338003b13dba81ced6741f45c69c24da9390
1 #!/bin/sh
2 # PCP QA Test No. 527
3 # Check that timestamps are monotonic increasing for archives
4 # created by libpcp_import. Based on
5 # https://bugzilla.redhat.com/show_bug.cgi?id=958745
7 # Copyright (c) 2013 Red Hat, Inc. and Ken McDonell. All Rights Reserved.
10 seq=`basename $0`
11 echo "QA output created by $seq"
13 # get standard environment, filters and checks
14 . ./common.product
15 . ./common.filter
16 . ./common.check
18 [ -f ${PCP_LIB_DIR}/libpcp_import.${DSO_SUFFIX} ] || \
19 _notrun "No support for libpcp_import"
20 perl -e "use PCP::LogImport" 2>/dev/null || \
21 _notrun "Perl PCP::LogImport module is not installed"
24 _filter()
26 # make deterministic tmp file names
27 # dodge buglet in die() line# handling for some perl versions
28 sed \
29 -e "s;$tmp;TMP;g" \
30 -e "s;line 0\.000.*$;line 2.;g" \
31 -e "s;line NaN\.$;line 2.;g" \
32 #end
35 status=1 # failure is the default!
36 $sudo rm -rf $tmp.* $seq.full
37 trap "cd $here; rm -rf $tmp.*; exit \$status" 0 1 2 3 15
39 # first data file
41 cat <<'End-of-File' >$tmp.gfs_inodes.csv
42 Date,Time,Device,inodes
43 2013-04-18,13:40,/dev/dm-12,102808
44 2013-04-18,13:45,/dev/dm-12,102798
45 2013-04-18,13:50,/dev/dm-12,102799
46 2013-04-18,13:55,/dev/dm-12,102808
47 2013-04-18,14:00,/dev/dm-12,102804
48 2013-04-18,14:05,/dev/dm-12,103182
49 2013-04-18,14:10,/dev/dm-12,102864
50 2013-04-18,14:15,/dev/dm-12,102810
51 2013-04-18,14:20,/dev/dm-12,102805
52 End-of-File
54 # second data file
56 cat <<'End-of-File' >$tmp.gfs_metadata.csv
57 Date,Time,Device,fmb
58 2013-04-18,13:40,/dev/dm-12,3712689
59 2013-04-18,13:45,/dev/dm-12,3712699
60 2013-04-18,13:50,/dev/dm-12,3712698
61 2013-04-18,13:55,/dev/dm-12,3712689
62 2013-04-18,14:00,/dev/dm-12,3712693
63 2013-04-18,14:05,/dev/dm-12,3712273
64 2013-04-18,14:10,/dev/dm-12,3712349
65 2013-04-18,14:15,/dev/dm-12,3711980
66 2013-04-18,14:20,/dev/dm-12,3711842
67 End-of-File
69 # Perl script
71 cat <<'End-of-File' >$tmp.pl
72 #!/usr/bin/env perl
74 use strict;
75 use warnings;
76 use Date::Parse;
77 use Date::Format;
78 use PCP::LogImport;
80 End-of-File
81 echo "pmiStart(\"$tmp.gfs\", 0);" >>$tmp.pl
82 cat <<'End-of-File' >>$tmp.pl
83 $_ = pmiSetTimezone('UTC');
84 $_ == 0 || die "pmiSetTimezone(UTC): " . pmiErrStr($_);
86 $_ = pmiAddMetric("gfs.inodes",
87 PM_ID_NULL, PM_TYPE_DOUBLE, PM_INDOM_NULL,
88 PM_SEM_INSTANT, pmiUnits(0,0,1,0,0,PM_COUNT_ONE));
89 $_ == 0 || die "pmiAddMetric(gfs.inodes): " . pmiErrStr($_);
92 End-of-File
93 echo "open(INFILE, \"<$tmp.gfs_inodes.csv\");" >>$tmp.pl
94 cat <<'End-of-File' >>$tmp.pl
95 while (<INFILE>) {
96 next if $. == 1;
97 chomp;
98 my @part = split(/,/, $_);
100 $_ = pmiPutValue("gfs.inodes", "", $part[3]);
101 $_ == 0 || die "pmiPutValue(gfs.inodes): " . pmiErrStr($_);
103 $_ = pmiWrite(str2time($part[0] . "T" . $part[1] . ":00", 'UTC'), 0);
104 $_ == 0 || die "pmiWrite(gfs.fmb): " . pmiErrStr($_);
106 close(INFILE);
109 $_ = pmiAddMetric("gfs.fmb",
110 PM_ID_NULL, PM_TYPE_DOUBLE, PM_INDOM_NULL,
111 PM_SEM_INSTANT, pmiUnits(0,0,1,0,0,PM_COUNT_ONE));
112 $_ == 0 || die "pmiAddMetric(gfs.fmb): " . pmiErrStr($_);
114 End-of-File
115 echo "open(INFILE, \"<$tmp.gfs_metadata.csv\");" >>$tmp.pl
116 cat <<'End-of-File' >>$tmp.pl
117 while (<INFILE>) {
118 next if $. == 1;
119 chomp;
120 my @part = split(/,/, $_);
122 $_ = pmiPutValue("gfs.fmb", "", $part[3]);
123 $_ == 0 || die "pmiPutValue(gfs.fmb): " . pmiErrStr($_);
125 $_ = pmiWrite(str2time($part[0] . "T" . $part[1] . ":00", 'UTC'), 0);
126 $_ == 0 || die "pmiWrite(gfs.fmb): " . pmiErrStr($_);
128 close(INFILE);
131 pmiEnd();
132 End-of-File
134 # real QA test starts here
135 perl $tmp.pl 2>&1 | _filter
137 for part in 0 meta index
139 [ -f $tmp.$part ] && echo "oops, .$part file created"
140 done
142 # success, all done
143 status=0
145 exit