CheckSteps.py 26.8 KB
Newer Older
1
#
scott snyder's avatar
scott snyder committed
2
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
4
5
6
7
8
9
10
11
12
#

'''
Definitions of post-exec check steps in Trigger ART tests
'''

import sys
import os
import re
import subprocess
13
import json
scott snyder's avatar
scott snyder committed
14
import six
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

from TrigValTools.TrigValSteering.Step import Step
from TrigValTools.TrigValSteering.Common import art_input_eos, art_input_cvmfs


class RefComparisonStep(Step):
    '''Base class for steps comparing a file to a reference'''

    def __init__(self, name):
        super(RefComparisonStep, self).__init__(name)
        self.reference = None
        self.input_file = None

    def configure(self, test):
        if self.reference is not None:
            # Do nothing if the reference exists
            if os.path.isfile(self.reference):
                return
            # Try to find the file in DATAPATH
            full_path = subprocess.check_output('find_data.py {}'.format(self.reference), shell=True).strip()
            if os.path.isfile(full_path):
                self.log.debug('%s using reference %s', self.name, full_path)
                self.reference = full_path
                return
            else:
                self.log.warning(
                    '%s failed to find reference %s - wrong path?',
                    self.name, self.reference)
                return

        if self.input_file is None:
            self.log.error('Cannot configure %s because input_file not specified',
                           self.name)
            self.report_result(1, 'TestConfig')
            sys.exit(1)

        branch = os.environ.get('AtlasBuildBranch')  # Available after asetup
        if branch is None:
            branch = os.environ.get('gitlabTargetBranch')  # Available in CI
        if branch is None:
            self.log.warning('Cannot determine the branch name, both variables '
                             'AtlasBuildBranch and gitlabTargetBranch are empty')
            branch = 'UNKNOWN_BRANCH'

        sub_path = '{}/ref/{}/test_{}/'.format(
            test.package_name, branch, test.name)
        ref_eos = art_input_eos + sub_path + self.input_file
        ref_cvmfs = art_input_cvmfs + sub_path + self.input_file
        if os.path.isfile(ref_eos):
            self.log.debug('%s using reference from EOS: %s',
                           self.name, ref_eos)
            self.reference = ref_eos
        elif os.path.isfile(ref_cvmfs):
            self.log.debug('%s using reference from CVMFS: %s',
                           self.name, ref_cvmfs)
            self.reference = ref_cvmfs
        else:
            self.log.warning('%s failed to find reference %s in %s or %s',
                             self.name, sub_path + self.input_file,
                             art_input_eos, art_input_cvmfs)
            self.reference = None

77
78
        super(RefComparisonStep, self).configure(test)

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

class InputDependentStep(Step):
    '''Base class for steps executed only if the input file exists'''

    def __init__(self, name=None):
        super(InputDependentStep, self).__init__(name)
        self.input_file = None

    def run(self, dry_run=False):
        if self.input_file is None:
            self.log.error('%s misconfiguration - no input file specified',
                           self.name)
            self.result = 1
            if self.auto_report_result:
                self.report_result()
            return self.result, '# (internal) {} -> failed'.format(self.name)

        if not os.path.isfile(self.input_file):
            self.log.debug('Skipping %s because %s does not exist',
                           self.name, self.input_file)
99
100
            self.result = 0
            return self.result, '# (internal) {} -> skipped'.format(self.name)
101
102
103
104
105
106
107

        return super(InputDependentStep, self).run(dry_run)


class LogMergeStep(Step):
    '''Merge several log files into one for post-processing'''

108
    def __init__(self, name='LogMerge'):
109
110
        super(LogMergeStep, self).__init__(name)
        self.log_files = None
111
        self.extra_log_regex = None
112
113
114
115
116
117
118
119
        self.merged_name = 'athena.merged.log'
        self.warn_if_missing = True

    def configure(self, test):
        if self.log_files is None:
            self.log_files = []
            for step in test.exec_steps:
                self.log_files.append(step.name)
120
        super(LogMergeStep, self).configure(test)
121

122
123
124
125
126
127
128
129
    def process_extra_regex(self):
        if self.extra_log_regex:
            files = os.listdir('.')
            r = re.compile(self.extra_log_regex)
            match_files = filter(r.match, files)
            for f in match_files:
                self.log_files.append(f)

130
    def merge_logs(self):
scott snyder's avatar
scott snyder committed
131
        encargs = {} if six.PY2 else {'encoding' : 'utf-8'}
132
        try:
scott snyder's avatar
scott snyder committed
133
            with open(self.merged_name, 'w', **encargs) as merged_file:
134
135
136
137
138
139
140
                for log_name in self.log_files:
                    if not os.path.isfile(log_name):
                        if self.warn_if_missing:
                            self.log.warning('Cannot open %s', log_name)
                            merged_file.write(
                                '### WARNING Missing {} ###\n'.format(log_name))
                        continue
scott snyder's avatar
scott snyder committed
141
                    with open(log_name, **encargs) as log_file:
142
143
144
145
146
147
148
149
150
151
                        merged_file.write('### {} ###\n'.format(log_name))
                        for line in log_file:
                            merged_file.write(line)
            return 0
        except OSError as e:
            self.log.error('%s merging failed due to OSError: %s',
                           self.name, e.strerror)
            return 1

    def run(self, dry_run=False):
152
        self.process_extra_regex()
153
        self.log.info('Running %s merging logs %s into %s',
154
155
156
157
158
159
160
161
                      self.name, self.log_files, self.merged_name)
        if dry_run:
            self.result = 0
        else:
            self.result = self.merge_logs()
        return self.result, '# (internal) {} in={} out={}'.format(self.name, self.log_files, self.merged_name)


Rafal Bielski's avatar
Rafal Bielski committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
class RootMergeStep(Step):
    '''
    Merge root files with hadd. Parameters are:
    input_file - file(s) to be merged
    merged_file - output file name
    rename_suffix - if merged_file exists, it is renamed by adding this suffix
    '''

    def __init__(self, name='RootMerge'):
        super(RootMergeStep, self).__init__(name)
        self.input_file = None
        self.merged_file = None
        self.rename_suffix = None
        self.executable = 'hadd'

    def configure(self, test=None):
        self.args += ' ' + self.merged_file + ' ' + self.input_file
179
        super(RootMergeStep, self).configure(test)
Rafal Bielski's avatar
Rafal Bielski committed
180
181
182
183
184
185
186
187
188

    def run(self, dry_run=False):
        if os.path.isfile(self.merged_file) and self.rename_suffix:
            old_name = os.path.splitext(self.merged_file)
            new_name = old_name[0] + self.rename_suffix + old_name[1]
            self.executable = 'mv {} {}; {}'.format(self.merged_file, new_name, self.executable)
        return super(RootMergeStep, self).run(dry_run)


189
190
191
class ZipStep(Step):
    '''Compress a large log file'''

192
    def __init__(self, name='Zip'):
193
194
195
196
197
198
199
        super(ZipStep, self).__init__(name)
        self.zip_output = None
        self.zip_input = None
        self.executable = 'tar'
        self.args = '-czf'
        self.output_stream = Step.OutputStream.STDOUT_ONLY

200
    def configure(self, test=None):
201
        self.args += ' '+self.zip_output+' '+self.zip_input
Rafal Bielski's avatar
Rafal Bielski committed
202
203
        # Remove the file after zipping
        self.args += ' && rm ' + self.zip_input
204
        super(ZipStep, self).configure(test)
205
206
207
208
209
210
211


class CheckLogStep(Step):
    '''Execute CheckLog looking for errors or warnings in a log file'''

    def __init__(self, name):
        super(CheckLogStep, self).__init__(name)
212
        self.executable = 'check_log.py'
213
214
215
216
217
218
219
220
221
222
223
224
        self.log_file = None
        self.check_errors = True
        self.check_warnings = False
        self.config_file = None
        self.args = '--showexcludestats'

    def configure(self, test):
        if self.config_file is None:
            if test.package_name == 'TrigUpgradeTest':
                self.config_file = 'checklogTrigUpgradeTest.conf'
            elif test.package_name == 'TrigP1Test':
                self.config_file = 'checklogTrigP1Test.conf'
225
226
            elif test.package_name == 'TrigValTools':
                self.config_file = 'checklogTrigValTools.conf'
227
228
229
230
231
232
233
            else:
                self.config_file = 'checklogTriggerTest.conf'
        if self.log_file is None:
            if len(test.exec_steps) == 1:
                self.log_file = test.exec_steps[0].name+'.log'
            else:
                self.log_file = 'athena.log'
234
235
        if self.check_errors:
            self.args += ' --errors'
236
237
238
239
240
241
242
243
244
        if self.check_warnings:
            self.args += ' --warnings'
        if self.check_errors and not self.check_warnings:
            self.output_stream = Step.OutputStream.FILE_AND_STDOUT
            self.auto_report_result = True
            self.required = True

        self.args += ' --config {} {}'.format(self.config_file, self.log_file)

245
246
        super(CheckLogStep, self).configure(test)

247
248
249
250

class RegTestStep(RefComparisonStep):
    '''Execute RegTest comparing a log file against a reference'''

251
    def __init__(self, name='RegTest'):
252
253
        super(RegTestStep, self).__init__(name)
        self.regex = 'REGTEST'
254
        self.executable = 'regtest.py'
255
256
257
258
259
260
261
        self.input_base_name = 'athena'
        self.args += ' --linematch ".*"'
        self.auto_report_result = True
        self.output_stream = Step.OutputStream.FILE_AND_STDOUT

    def configure(self, test):
        self.input_file = self.input_base_name+'.regtest'
262
        RefComparisonStep.configure(self, test)
263
        self.args += ' --inputfile {} --reffile {}'.format(self.input_file, self.reference)
264
        Step.configure(self, test)
265
266
267
268
269
270

    def prepare_inputs(self):
        log_file = self.input_base_name+'.log'
        if not os.path.isfile(log_file):
            self.log.error('%s input file %s is missing', self.name, log_file)
            return False
scott snyder's avatar
scott snyder committed
271
272
        encargs = {} if six.PY2 else {'encoding' : 'utf-8'}
        with open(log_file, **encargs) as f_in:
273
            matches = re.findall('{}.*$'.format(self.regex),
274
                                 f_in.read(), re.MULTILINE)
scott snyder's avatar
scott snyder committed
275
            with open(self.input_file, 'w', **encargs) as f_out:
276
277
278
279
280
281
                for line in matches:
                    f_out.write(line+'\n')
        return True

    def rename_ref(self):
        try:
282
283
284
285
            if self.reference:
                new_name = os.path.basename(self.reference) + '.new'
            else:
                new_name = os.path.basename(self.input_file) + '.new'
286
287
288
289
290
291
292
293
294
295
296
297
298
            os.rename(self.input_file, new_name)
            self.log.debug('Renamed %s to %s', self.input_file, new_name)
        except OSError:
            self.log.warning('Failed to rename %s to %s',
                             self.input_file, new_name)

    def run(self, dry_run=False):
        if not dry_run and not self.prepare_inputs():
            self.log.error('%s failed in prepare_inputs()', self.name)
            self.result = 1
            if self.auto_report_result:
                self.report_result()
            return self.result, '# (internal) {} -> failed'.format(self.name)
299
300
301
302
303
304
305
306
        if self.reference is None:
            self.log.error('Missing reference for %s', self.name)
            if not dry_run:
                self.rename_ref()
            self.result = 999
            if self.auto_report_result:
                self.report_result()
            return self.result, '# (internal) {} -> failed'.format(self.name)
307
308
309
310
311
312
        retcode, cmd = super(RegTestStep, self).run(dry_run)
        if not dry_run:
            self.rename_ref()
        return retcode, cmd


313
314
315
316
317
318
319
320
321
322
class RootCompStep(RefComparisonStep):
    '''Execute RootComp comparing histograms against a reference'''

    def __init__(self, name='RootComp'):
        super(RootCompStep, self).__init__(name)
        self.input_file = 'expert-monitoring.root'
        self.executable = 'rootcomp.py'
        self.auto_report_result = True

    def configure(self, test):
323
        RefComparisonStep.configure(self, test)
324
        self.args += ' {} {}'.format(self.reference, self.input_file)
325
        Step.configure(self, test)
326
327
328
329
330
331
332
333
334
335
336
337
338
339

    def run(self, dry_run=False):
        if self.reference is None:
            if not os.path.isfile(self.input_file):
                self.log.debug(
                    'Skipping %s because both reference and input are missing',
                    self.name)
                return 0, '# (internal) {} -> skipped'.format(self.name)
            else:  # input exists but reference not
                self.log.error('Missing reference for %s', self.name)
                self.result = 999
                if self.auto_report_result:
                    self.report_result()
                return self.result, '# (internal) {} -> failed'.format(self.name)
Rafal Bielski's avatar
Rafal Bielski committed
340
        retcode, cmd = super(RootCompStep, self).run(dry_run)
341
342
343
344
        return retcode, cmd


class PerfMonStep(InputDependentStep):
345
346
    '''Execute the PerfMon ntuple post-processing'''

347
    def __init__(self, name='PerfMon'):
348
        super(PerfMonStep, self).__init__(name)
349
        self.input_file = None
350
351
352
353
        self.executable = 'perfmon.py'
        self.args = '-f 0.90'

    def configure(self, test):
354
355
356
357
358
359
        if not self.input_file:
            num_athenaHLT_steps = sum([1 for step in test.exec_steps if step.type == 'athenaHLT'])
            if num_athenaHLT_steps > 0:
                self.input_file = 'athenaHLT_workers/athenaHLT-01/ntuple.pmon.gz'
            else:
                self.input_file = 'ntuple.pmon.gz'
360
        self.args += ' '+self.input_file
361
        super(PerfMonStep, self).configure(test)
362
363
364
365
366


class TailStep(Step):
    '''Copy the last N lines of a log file into a separate file'''

367
    def __init__(self, name='Tail'):
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
        super(TailStep, self).__init__(name)
        self.log_file = 'athena.log'
        self.output_name = None
        self.executable = 'tail'
        self.num_lines = 5000
        self.output_stream = Step.OutputStream.STDOUT_ONLY

    def configure(self, test):
        if self.output_name is None:
            split = os.path.splitext(self.log_file)
            self.output_name = split[0]+'.tail'
            if len(split) > 1:
                self.output_name += split[1]
        self.args += ' -n {:d}'.format(self.num_lines)
        self.args += ' '+self.log_file
        self.args += ' >'+self.output_name
384
        super(TailStep, self).configure(test)
385
386
387
388
389


class HistCountStep(InputDependentStep):
    '''Execute histSizes.py to count histograms in a ROOT file'''

390
    def __init__(self, name='HistCount'):
391
392
393
394
395
396
397
        super(HistCountStep, self).__init__(name)
        self.input_file = 'expert-monitoring.root'
        self.executable = 'histSizes.py'
        self.args = '-t'

    def configure(self, test):
        self.args += ' '+self.input_file
398
        super(HistCountStep, self).configure(test)
399
400


401
402
403
404
405
406
407
408
409
class ChainDumpStep(InputDependentStep):
    '''
    Execute chainDump.py to print trigger counts from histograms to text files
    '''

    def __init__(self, name='ChainDump'):
        super(ChainDumpStep, self).__init__(name)
        self.input_file = 'expert-monitoring.root'
        self.executable = 'chainDump.py'
Rafal Bielski's avatar
Rafal Bielski committed
410
        self.args = '--json'
411
412

    def configure(self, test):
Rafal Bielski's avatar
Rafal Bielski committed
413
        self.args += ' -f '+self.input_file
414
        super(ChainDumpStep, self).configure(test)
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448


class TrigTestJsonStep(Step):
    '''Execute trig-test-json.py to create extra-results.json file'''

    def __init__(self, name='TrigTestJson'):
        super(TrigTestJsonStep, self).__init__(name)
        self.executable = 'trig-test-json.py'


class CheckFileStep(InputDependentStep):
    '''
    Execute checkFile and checkxAOD for POOL files.
    executable and input_file can have multiple comma-separated values
    '''

    def __init__(self, name='CheckFile'):
        super(CheckFileStep, self).__init__(name)
        self.input_file = 'AOD.pool.root,ESD.pool.root,RDO_TRIG.pool.root'
        self.executable = 'checkFile.py,checkxAOD.py'
        self.__executables__ = None
        self.__input_files__ = None

    def configure(self, test):
        # Skip the check if all test steps are athenaHLT (no POOL files)
        test_types = [step.type for step in test.exec_steps]
        num_athenaHLT = sum(1 for tt in test_types if tt == 'athenaHLT')
        if num_athenaHLT == test_types:
            self.log.debug('%s will be skipped because all exec steps use athenaHLT')
            self.__executables__ = None
            self.__input_files__ = None
            return
        self.__executables__ = self.executable.split(',')
        self.__input_files__ = self.input_file.split(',')
449
        super(CheckFileStep, self).configure(test)
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500

    def run(self, dry_run=False):
        ret_codes = []
        commands = []
        for f in self.__input_files__:
            for ex in self.__executables__:
                self.executable = ex
                self.input_file = f
                self.args = f
                ex_base = ex.split('.')[0:-1]
                self.log_file_name = f + '.' + ''.join(ex_base)
                ret, cmd = super(CheckFileStep, self).run(dry_run)
                ret_codes.append(ret)
                commands.append(cmd)

        # Merge executed commands for logging
        merged_cmd = ''
        if len(commands) == 1:
            merged_cmd = commands[0]
        else:
            for cmd in commands:
                if '(internal)' not in cmd:
                    merged_cmd += cmd+'; '
        if len(merged_cmd) == 0:
            merged_cmd = commands[-1]

        return max(ret_codes), merged_cmd


class ZeroCountsStep(Step):
    '''
    Check if all counts are zero.
    input_file can have multiple comma-separated values
    '''

    def __init__(self, name='ZeroCounts'):
        super(ZeroCountsStep, self).__init__(name)
        self.input_file = 'HLTChain.txt,HLTTE.txt,L1AV.txt'
        self.auto_report_result = True
        self.__input_files__ = None

    def configure(self, test=None):
        self.__input_files__ = self.input_file.split(',')

    def check_zero_counts(self, input_file):
        if not os.path.isfile(input_file):
            self.log.debug(
                'Skipping %s for %s because the file does not exist',
                self.name, input_file)
            return -1
        lines_checked = 0
scott snyder's avatar
scott snyder committed
501
502
        encargs = {} if six.PY2 else {'encoding' : 'utf-8'}
        with open(input_file, **encargs) as f_in:
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
            for line in f_in.readlines():
                split_line = line.split()
                lines_checked += 1
                if int(split_line[-1]) != 0:
                    return 0  # at least one non-zero count
        if lines_checked == 0:
            self.log.error('Failed to read counts from %s', input_file)
        return 1  # all counts are zero

    def run(self, dry_run=False):
        results = []
        for input_file in self.__input_files__:
            results.append(self.check_zero_counts(input_file))

        self.result = max(results)
        cmd = '# (internal) {} for {}'.format(self.name, self.__input_files__)
        if self.result < 0:
            cmd = '# (internal) {} -> skipped'.format(self.name)
            self.result = 0
522
523
            return self.result, cmd
        self.log.info('Running %s step', self.name)
524
525
526
527
528
        if self.auto_report_result:
            self.report_result()
        return self.result, cmd


529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
class MessageCountStep(Step):
    '''Count messages printed inside event loop'''

    def __init__(self, name='MessageCount'):
        super(MessageCountStep, self).__init__(name)
        self.executable = 'messageCounter.py'
        self.log_regex = r'(athena\..*log$|athenaHLT:.*\.out$|^log\..*to.*)'
        self.start_pattern = r'(HltEventLoopMgr|AthenaHiveEventLoopMgr).*INFO Starting loop on events'
        self.end_pattern = r'(HltEventLoopMgr.*INFO All events processed|AthenaHiveEventLoopMgr.*INFO.*Loop Finished)'
        self.info_threshold = None
        self.debug_threshold = None
        self.verbose_threshold = None
        self.other_threshold = None
        self.auto_report_result = True

    def configure(self, test):
        self.args += ' -s "{:s}"'.format(self.start_pattern)
        self.args += ' -e "{:s}"'.format(self.end_pattern)
        if self.info_threshold is None:
            self.info_threshold = test.exec_steps[0].max_events
        if self.debug_threshold is None:
            self.debug_threshold = 0
        if self.verbose_threshold is None:
            self.verbose_threshold = 0
        if self.other_threshold is None:
            self.other_threshold = test.exec_steps[0].max_events
        super(MessageCountStep, self).configure(test)

    def run(self, dry_run=False):
        files = os.listdir('.')
        r = re.compile(self.log_regex)
        log_files = filter(r.match, files)
        self.args += ' ' + ' '.join(log_files)
        auto_report = self.auto_report_result
        self.auto_report_result = False
        ret, cmd = super(MessageCountStep, self).run(dry_run)
        self.auto_report_result = auto_report
        if ret != 0:
            self.log.error('%s failed')
            self.result = 1
            if self.auto_report_result:
                self.report_result()
            return self.result, cmd
        (num_info, num_debug, num_verbose, num_other) = (0, 0, 0, 0)
        for log_file in log_files:
            json_file = 'MessageCount.{:s}.json'.format(log_file)
            if not os.path.isfile(json_file):
                self.log.warning('%s cannot open file %s', self.name, json_file)
            with open(json_file) as f:
                summary = json.load(f)
                num_info += summary['INFO']
                num_debug += summary['DEBUG']
                num_verbose += summary['VERBOSE']
                num_other += summary['other']
        if num_info > self.info_threshold:
            self.log.info(
                '%s Number of INFO messages %s is higher than threshold %s',
                self.name, num_info, self.info_threshold)
            self.result += 1
        if num_debug > self.debug_threshold:
            self.log.info(
                '%s Number of DEBUG messages %s is higher than threshold %s',
                self.name, num_debug, self.debug_threshold)
            self.result += 1
        if num_verbose > self.verbose_threshold:
            self.log.info(
                '%s Number of VERBOSE messages %s is higher than threshold %s',
                self.name, num_verbose, self.verbose_threshold)
            self.result += 1
        if num_other > self.other_threshold:
            self.log.info(
                '%s Number of "other" messages %s is higher than threshold %s',
                self.name, num_other, self.other_threshold)
            self.result += 1
        if self.auto_report_result:
            self.report_result()
        return self.result, cmd


608
609
610
611
612
613
614
615
616
def default_check_steps(test):
    '''
    Create the default list of check steps for a test. The configuration
    depends on the package name and the type of exec steps (athena or
    athenaHLT or transforms).
    '''

    check_steps = []

617
    # Log merging
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
    if len(test.exec_steps) == 1:
        exec_step = test.exec_steps[0]
        if exec_step.type == 'athenaHLT':
            logmerge = LogMergeStep()
            logmerge.merged_name = 'athena.log'
            logmerge.log_files = ['athenaHLT.log']
            nforks = 1 if exec_step.forks is None else exec_step.forks
            for n in range(1, 1+nforks):
                logmerge.log_files.append('athenaHLT:{:02d}.out'.format(n))
                logmerge.log_files.append('athenaHLT:{:02d}.err'.format(n))
            check_steps.append(logmerge)
    else:
        logmerge = LogMergeStep()
        logmerge.merged_name = 'athena.log'
        logmerge.log_files = []
        for exec_step in test.exec_steps:
            logmerge.log_files.append(exec_step.get_log_file_name())
635
636
            if exec_step.type == 'athenaHLT':
                logmerge.extra_log_regex = 'athenaHLT:.*(.out|.err)'
637
638
        check_steps.append(logmerge)
    log_to_check = None
Rafal Bielski's avatar
Rafal Bielski committed
639
    log_to_zip = None
640
641
    if len(check_steps) > 0 and isinstance(check_steps[-1], LogMergeStep):
        log_to_check = check_steps[-1].merged_name
Rafal Bielski's avatar
Rafal Bielski committed
642
        log_to_zip = check_steps[-1].merged_name
643
644
645
646

    # Reco_tf log merging
    step_types = [step.type for step in test.exec_steps]
    if 'Reco_tf' in step_types:
647
        reco_tf_logmerge = LogMergeStep('LogMerge_Reco_tf')
648
649
650
651
652
653
654
655
656
        reco_tf_logmerge.warn_if_missing = False
        tf_names = ['HITtoRDO', 'RDOtoRDOTrigger', 'RAWtoESD', 'ESDtoAOD',
                    'PhysicsValidation', 'RAWtoALL', 'BSFTKCreator']
        reco_tf_logmerge.log_files = ['log.'+tf_name for tf_name in tf_names]
        reco_tf_logmerge.merged_name = 'athena.merged.log'
        log_to_zip = reco_tf_logmerge.merged_name
        if log_to_check is not None:
            reco_tf_logmerge.log_files.append(log_to_check)
            log_to_check = reco_tf_logmerge.merged_name
657
        log_to_check = reco_tf_logmerge.merged_name
658
659
        check_steps.append(reco_tf_logmerge)

Rafal Bielski's avatar
Rafal Bielski committed
660
661
662
663
664
665
666
667
668
    # Histogram merging for athenaHLT forks
    num_athenaHLT_steps = sum([1 for step in test.exec_steps if step.type == 'athenaHLT'])
    if num_athenaHLT_steps > 0:
        histmerge = RootMergeStep('HistMerge')
        histmerge.merged_file = 'expert-monitoring.root'
        histmerge.input_file = 'athenaHLT_workers/*/expert-monitoring.root expert-monitoring-mother.root'
        histmerge.rename_suffix = '-mother'
        check_steps.append(histmerge)

669
    # CheckLog for errors
670
    checklog = CheckLogStep('CheckLog')
671
672
673
674
675
    if log_to_check is not None:
        checklog.log_file = log_to_check
    check_steps.append(checklog)

    # CheckLog for warnings
676
    checkwarn = CheckLogStep('Warnings')
677
678
679
680
681
682
    checkwarn.check_errors = False
    checkwarn.check_warnings = True
    if log_to_check is not None:
        checkwarn.log_file = log_to_check
    check_steps.append(checkwarn)

683
684
685
686
    # MessageCount
    msgcount = MessageCountStep('MessageCount')
    check_steps.append(msgcount)

687
688
689
690
    # RegTest
    regtest = RegTestStep()
    if log_to_check is not None:
        regtest.input_base_name = os.path.splitext(log_to_check)[0]
691
    if 'athenaHLT' in step_types:
692
        regtest.regex = r'(?:HltEventLoopMgr(?!.*athenaHLT-)(?!.*DF_Pid)|REGTEST)'
693
694
695
696
697
698
699
700
701
702
703
    check_steps.append(regtest)

    # Tail (probably not so useful these days)
    tail = TailStep()
    if log_to_check is not None:
        tail.log_file = log_to_check
    check_steps.append(tail)

    # PerfMon
    check_steps.append(PerfMonStep())

704
705
706
    # Histogram-based steps
    check_steps.append(RootCompStep())
    check_steps.append(ChainDumpStep())
707
708
    check_steps.append(HistCountStep())

709
710
711
712
713
714
715
716
717
718
    # ZeroCounts
    check_steps.append(ZeroCountsStep())

    # Extra JSON
    check_steps.append(TrigTestJsonStep())

    # CheckFile
    check_steps.append(CheckFileStep())

    # Zip the merged log (can be large and duplicates information)
719
720
721
722
723
724
725
726
    if log_to_zip is not None:
        zip_step = ZipStep()
        zip_step.zip_input = log_to_zip
        zip_step.zip_output = log_to_zip+'.tar.gz'
        check_steps.append(zip_step)

    # return the steps
    return check_steps