11cb0ef41Sopenharmony_ci# Copyright 2018 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci# found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciclass ResultBase(object):
71cb0ef41Sopenharmony_ci  @property
81cb0ef41Sopenharmony_ci  def is_skipped(self):
91cb0ef41Sopenharmony_ci    return False
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci  @property
121cb0ef41Sopenharmony_ci  def is_grouped(self):
131cb0ef41Sopenharmony_ci    return False
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  @property
161cb0ef41Sopenharmony_ci  def is_rerun(self):
171cb0ef41Sopenharmony_ci    return False
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciclass Result(ResultBase):
211cb0ef41Sopenharmony_ci  """Result created by the output processor."""
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  def __init__(self, has_unexpected_output, output, cmd=None):
241cb0ef41Sopenharmony_ci    self.has_unexpected_output = has_unexpected_output
251cb0ef41Sopenharmony_ci    self.output = output
261cb0ef41Sopenharmony_ci    self.cmd = cmd
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciclass GroupedResult(ResultBase):
301cb0ef41Sopenharmony_ci  """Result consisting of multiple results. It can be used by processors that
311cb0ef41Sopenharmony_ci  create multiple subtests for each test and want to pass all results back.
321cb0ef41Sopenharmony_ci  """
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  @staticmethod
351cb0ef41Sopenharmony_ci  def create(results):
361cb0ef41Sopenharmony_ci    """Create grouped result from the list of results. It filters out skipped
371cb0ef41Sopenharmony_ci    results. If all results are skipped results it returns skipped result.
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci    Args:
401cb0ef41Sopenharmony_ci      results: list of pairs (test, result)
411cb0ef41Sopenharmony_ci    """
421cb0ef41Sopenharmony_ci    results = [(t, r) for (t, r) in results if not r.is_skipped]
431cb0ef41Sopenharmony_ci    if not results:
441cb0ef41Sopenharmony_ci      return SKIPPED
451cb0ef41Sopenharmony_ci    return GroupedResult(results)
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci  def __init__(self, results):
481cb0ef41Sopenharmony_ci    self.results = results
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci  @property
511cb0ef41Sopenharmony_ci  def is_grouped(self):
521cb0ef41Sopenharmony_ci    return True
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ciclass SkippedResult(ResultBase):
561cb0ef41Sopenharmony_ci  """Result without any meaningful value. Used primarily to inform the test
571cb0ef41Sopenharmony_ci  processor that it's test wasn't executed.
581cb0ef41Sopenharmony_ci  """
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci  @property
611cb0ef41Sopenharmony_ci  def is_skipped(self):
621cb0ef41Sopenharmony_ci    return True
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ciSKIPPED = SkippedResult()
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ciclass RerunResult(Result):
691cb0ef41Sopenharmony_ci  """Result generated from several reruns of the same test. It's a subclass of
701cb0ef41Sopenharmony_ci  Result since the result of rerun is result of the last run. In addition to
711cb0ef41Sopenharmony_ci  normal result it contains results of all reruns.
721cb0ef41Sopenharmony_ci  """
731cb0ef41Sopenharmony_ci  @staticmethod
741cb0ef41Sopenharmony_ci  def create(results):
751cb0ef41Sopenharmony_ci    """Create RerunResult based on list of results. List cannot be empty. If it
761cb0ef41Sopenharmony_ci    has only one element it's returned as a result.
771cb0ef41Sopenharmony_ci    """
781cb0ef41Sopenharmony_ci    assert results
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ci    if len(results) == 1:
811cb0ef41Sopenharmony_ci      return results[0]
821cb0ef41Sopenharmony_ci    return RerunResult(results)
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_ci  def __init__(self, results):
851cb0ef41Sopenharmony_ci    """Has unexpected output and the output itself of the RerunResult equals to
861cb0ef41Sopenharmony_ci    the last result in the passed list.
871cb0ef41Sopenharmony_ci    """
881cb0ef41Sopenharmony_ci    assert results
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_ci    last = results[-1]
911cb0ef41Sopenharmony_ci    super(RerunResult, self).__init__(last.has_unexpected_output, last.output,
921cb0ef41Sopenharmony_ci                                      last.cmd)
931cb0ef41Sopenharmony_ci    self.results = results
941cb0ef41Sopenharmony_ci
951cb0ef41Sopenharmony_ci  @property
961cb0ef41Sopenharmony_ci  def is_rerun(self):
971cb0ef41Sopenharmony_ci    return True
98