Пример #1
0
def PrintRandomResult(session: db.session_t) -> None:
    """Pretty print a random result.

  Args:
    session: A database session.
  """
    query = session.query(deeplearning.deepsmith.result.Result)
    result = _SelectRandomRow(query)
    print(pbutil.PrettyPrintJson(result.ToProto()))
Пример #2
0
def DifftestTestcase(s: db.session_t, t: testcase.Testcase,
                     outdir: pathlib.Path) -> None:
    """Difftest a testcase."""
    results = list(s.query(result.Result).filter(result.Result.testcase == t))
    for r in results:
        r.output_class = GetResultOutputClass(r)
    majority = GetMajorityOutput(results)

    def OutputPath(result_class: str) -> pathlib.Path:
        try:
            if r.testbed.opts['opencl_opt'] == 'enabled':
                opt = '+'
            elif r.testbed.opts['opencl_opt'] == 'disabled':
                opt = '-'
            else:
                raise KeyError
        except KeyError:
            raise LookupError(str(r.testbed))
        testbeds = sorted(x[0] for x in s.query(testbed.Testbed.name))
        dir = outdir / result_class / str(testbeds.index(r.testbed.name)) / opt
        dir.mkdir(parents=True, exist_ok=True)
        return dir / (str(r.id) + '.pbtxt')

    for r in results:
        if r.output_class == 'Build crash':
            pbutil.ToFile(r.ToProto(), OutputPath('bc'))
        elif r.output_class == 'Build timeout':
            pbutil.ToFile(r.ToProto(), OutputPath('bto'))
        elif (majority.majority_outcome == 'Pass'
              and r.output_class == 'Build failure'):
            pbutil.ToFile(r.ToProto(), OutputPath('abf'))
        elif (majority.majority_outcome == 'Pass'
              and r.output_class == 'Runtime crash'):
            pbutil.ToFile(r.ToProto(), OutputPath('arc'))
        elif (r.outputs['stdout'] != majority.majority_stdout
              and majority.majority_outcome == 'Pass'
              and majority.stdout_majority_size >= math.ceil(
                  2 * majority.outcome_majority_size / 3)):
            pbutil.ToFile(r.ToProto(), OutputPath('awo'))
        else:
            pbutil.ToFile(r.ToProto(), OutputPath('pass'))
Пример #3
0
def DifftestTestcase(s: db.session_t, t: testcase.Testcase,
                     outdir: pathlib.Path) -> None:
    """Difftest a testcase."""
    results = list(s.query(result.Result).filter(result.Result.testcase == t))
    for r in results:
        r.output_class = GetResultOutputClass(r)
    majority = GetMajorityOutput(results)

    def OutputPath(result_class: str) -> pathlib.Path:
        try:
            if r.testbed.opts["opencl_opt"] == "enabled":
                opt = "+"
            elif r.testbed.opts["opencl_opt"] == "disabled":
                opt = "-"
            else:
                raise KeyError
        except KeyError:
            raise LookupError(str(r.testbed))
        testbeds = sorted(x[0] for x in s.query(testbed.Testbed.name))
        dir = outdir / result_class / str(testbeds.index(r.testbed.name)) / opt
        dir.mkdir(parents=True, exist_ok=True)
        return dir / (str(r.id) + ".pbtxt")

    for r in results:
        if r.output_class == "Build crash":
            pbutil.ToFile(r.ToProto(), OutputPath("bc"))
        elif r.output_class == "Build timeout":
            pbutil.ToFile(r.ToProto(), OutputPath("bto"))
        elif (majority.majority_outcome == "Pass"
              and r.output_class == "Build failure"):
            pbutil.ToFile(r.ToProto(), OutputPath("abf"))
        elif (majority.majority_outcome == "Pass"
              and r.output_class == "Runtime crash"):
            pbutil.ToFile(r.ToProto(), OutputPath("arc"))
        elif (r.outputs["stdout"] != majority.majority_stdout
              and majority.majority_outcome == "Pass"
              and majority.stdout_majority_size >= math.ceil(
                  2 * majority.outcome_majority_size / 3)):
            pbutil.ToFile(r.ToProto(), OutputPath("awo"))
        else:
            pbutil.ToFile(r.ToProto(), OutputPath("pass"))
Пример #4
0
    def GetOrAdd(cls, session: db.session_t,
                 proto: deepsmith_pb2.Result) -> 'Result':
        testcase = deeplearning.deepsmith.testcase.Testcase.GetOrAdd(
            session, proto.testcase)
        testbed = deeplearning.deepsmith.testbed.Testbed.GetOrAdd(
            session, proto.testbed)

        # Only add the result if the the <testcase, testbed> tuple is unique. This
        # is to prevent duplicate results where only the output differs.
        result = session.query(Result).filter(
            Result.testcase == testcase, Result.testbed == testbed).first()
        if result:
            return result

        # Build the list of outputs, and md5sum the key value strings.
        outputs = []
        md5 = hashlib.md5()
        for proto_output_name in sorted(proto.outputs):
            proto_output_value = proto.outputs[proto_output_name]
            md5.update(
                (proto_output_name + proto_output_value).encode('utf-8'))
            output = labm8.sqlutil.GetOrAdd(
                session,
                ResultOutput,
                name=ResultOutputName.GetOrAdd(session,
                                               string=proto_output_name),
                value=ResultOutputValue.GetOrAdd(session,
                                                 string=proto_output_value))
            outputs.append(output)

        # Create output set table entries.
        outputset_id = md5.digest()
        for output in outputs:
            labm8.sqlutil.GetOrAdd(session,
                                   ResultOutputSet,
                                   id=outputset_id,
                                   output=output)

        # Create a new result only if everything *except* the profiling events
        # are unique. This means that if a generator produced the same testcase
        # twice (on separate occasions), only the first is added to the datastore.
        result = labm8.sqlutil.Get(session,
                                   cls,
                                   testcase=testcase,
                                   testbed=testbed,
                                   returncode=proto.returncode,
                                   outputset_id=outputset_id,
                                   outcome_num=proto.outcome)
        if not result:
            result = cls(testcase=testcase,
                         testbed=testbed,
                         returncode=proto.returncode,
                         outputset_id=outputset_id,
                         outcome_num=proto.outcome)
            session.add(result)
            # Add profiling events.
            for event in proto.profiling_events:
                deeplearning.deepsmith.profiling_event.ResultProfilingEvent.GetOrAdd(
                    session, event, result)

        return result