コード例 #1
0
ファイル: testcase_test.py プロジェクト: BeauJoh/phd
def test_Generator_GetOrAdd_ToProto_equivalence(session):
    proto_in = deepsmith_pb2.Testcase(
        toolchain='cpp',
        generator=deepsmith_pb2.Generator(name='generator', ),
        harness=deepsmith_pb2.Harness(name='harness', ),
        inputs={
            'src': 'void main() {}',
            'data': '[1,2]'
        },
        invariant_opts={'config': 'opt'},
        profiling_events=[
            deepsmith_pb2.ProfilingEvent(
                client='localhost',
                type='generate',
                duration_ms=100,
                event_start_epoch_ms=101231231,
            ),
        ])
    testcase = deeplearning.deepsmith.testcase.Testcase.GetOrAdd(
        session, proto_in)

    # NOTE: We have to flush so that SQLAlchemy resolves all of the object IDs.
    session.flush()
    proto_out = testcase.ToProto()
    assert proto_in == proto_out
    proto_out.ClearField('toolchain')
    assert proto_in != proto_out  # Sanity check.
コード例 #2
0
def test_Generator_GetOrAdd_ToProto_equivalence(session):
    proto_in = deepsmith_pb2.Testcase(
        toolchain="cpp",
        generator=deepsmith_pb2.Generator(name="generator", ),
        harness=deepsmith_pb2.Harness(name="harness", ),
        inputs={
            "src": "void main() {}",
            "data": "[1,2]"
        },
        invariant_opts={"config": "opt"},
        profiling_events=[
            deepsmith_pb2.ProfilingEvent(
                client="localhost",
                type="generate",
                duration_ms=100,
                event_start_epoch_ms=101231231,
            ),
        ],
    )
    testcase = deeplearning.deepsmith.testcase.Testcase.GetOrAdd(
        session, proto_in)

    # NOTE: We have to flush so that SQLAlchemy resolves all of the object IDs.
    session.flush()
    proto_out = testcase.ToProto()
    assert proto_in == proto_out
    proto_out.ClearField("toolchain")
    assert proto_in != proto_out  # Sanity check.
コード例 #3
0
    def GetTestcases(self, request: datastore_pb2.GetTestcasesRequest,
                     response: datastore_pb2.GetTestcasesResponse) -> None:
        """Request testcases."""
        with self.Session(commit=False) as session:
            # Validate request parameters.
            if request.max_num_testcases < 1:
                raise InvalidRequest(
                    f'max_num_testcases must be >= 1, not {request.max_num_testcases}'
                )

            q = self._BuildTestcaseRequestQuery(session, request)
            q.limit(request.max_num_testcases)

            if request.return_testcases:
                response.testcases = [testcase.ToProto() for testcase in q]

            if request.return_total_matching_count:
                q2 = self._BuildTestcaseRequestQuery(session, request)
                response.total_matching_count = q2.count()
コード例 #4
0
ファイル: testcase_test.py プロジェクト: BeauJoh/phd
def test_Testcase_ToProto():
    now = labdate.GetUtcMillisecondsNow()

    testcase = deeplearning.deepsmith.testcase.Testcase(
        toolchain=deeplearning.deepsmith.toolchain.Toolchain(string='cpp'),
        generator=deeplearning.deepsmith.generator.Generator(name='generator'),
        harness=deeplearning.deepsmith.harness.Harness(name='harness'),
        inputset=[
            deeplearning.deepsmith.testcase.TestcaseInput(
                name=deeplearning.deepsmith.testcase.TestcaseInputName(
                    string='src'),
                value=deeplearning.deepsmith.testcase.TestcaseInputValue(
                    string='void main() {}'),
            ),
            deeplearning.deepsmith.testcase.TestcaseInput(
                name=deeplearning.deepsmith.testcase.TestcaseInputName(
                    string='data'),
                value=deeplearning.deepsmith.testcase.TestcaseInputValue(
                    string='[1,2]'),
            ),
        ],
        invariant_optset=[
            deeplearning.deepsmith.testcase.TestcaseInvariantOpt(
                name=deeplearning.deepsmith.testcase.TestcaseInvariantOptName(
                    string='config'),
                value=deeplearning.deepsmith.testcase.
                TestcaseInvariantOptValue(string='opt'),
            ),
        ],
        profiling_events=[
            deeplearning.deepsmith.profiling_event.TestcaseProfilingEvent(
                client=deeplearning.deepsmith.client.Client(
                    string='localhost'),
                type=deeplearning.deepsmith.profiling_event.ProfilingEventType(
                    string='generate', ),
                duration_ms=100,
                event_start=now,
            ),
            deeplearning.deepsmith.profiling_event.TestcaseProfilingEvent(
                client=deeplearning.deepsmith.client.Client(
                    string='localhost'),
                type=deeplearning.deepsmith.profiling_event.ProfilingEventType(
                    string='foo', ),
                duration_ms=100,
                event_start=now,
            ),
        ])
    proto = testcase.ToProto()
    assert proto.toolchain == 'cpp'
    assert proto.generator.name == 'generator'
    assert proto.harness.name == 'harness'
    assert len(proto.inputs) == 2
    assert proto.inputs['src'] == 'void main() {}'
    assert proto.inputs['data'] == '[1,2]'
    assert len(proto.invariant_opts) == 1
    assert proto.invariant_opts['config'] == 'opt'
    assert len(proto.profiling_events) == 2
    assert (proto.profiling_events[0].event_start_epoch_ms ==
            labdate.MillisecondsTimestamp(now))
    assert proto.profiling_events[0].client == 'localhost'
    assert proto.profiling_events[0].type == 'generate'
    assert proto.profiling_events[0].client == 'localhost'
コード例 #5
0
def test_Testcase_ToProto():
    now = labdate.GetUtcMillisecondsNow()

    testcase = deeplearning.deepsmith.testcase.Testcase(
        toolchain=deeplearning.deepsmith.toolchain.Toolchain(string="cpp"),
        generator=deeplearning.deepsmith.generator.Generator(name="generator"),
        harness=deeplearning.deepsmith.harness.Harness(name="harness"),
        inputset=[
            deeplearning.deepsmith.testcase.TestcaseInput(
                name=deeplearning.deepsmith.testcase.TestcaseInputName(
                    string="src"),
                value=deeplearning.deepsmith.testcase.TestcaseInputValue(
                    string="void main() {}"),
            ),
            deeplearning.deepsmith.testcase.TestcaseInput(
                name=deeplearning.deepsmith.testcase.TestcaseInputName(
                    string="data"),
                value=deeplearning.deepsmith.testcase.TestcaseInputValue(
                    string="[1,2]"),
            ),
        ],
        invariant_optset=[
            deeplearning.deepsmith.testcase.TestcaseInvariantOpt(
                name=deeplearning.deepsmith.testcase.TestcaseInvariantOptName(
                    string="config"),
                value=deeplearning.deepsmith.testcase.
                TestcaseInvariantOptValue(string="opt"),
            ),
        ],
        profiling_events=[
            deeplearning.deepsmith.profiling_event.TestcaseProfilingEvent(
                client=deeplearning.deepsmith.client.Client(
                    string="localhost"),
                type=deeplearning.deepsmith.profiling_event.ProfilingEventType(
                    string="generate", ),
                duration_ms=100,
                event_start=now,
            ),
            deeplearning.deepsmith.profiling_event.TestcaseProfilingEvent(
                client=deeplearning.deepsmith.client.Client(
                    string="localhost"),
                type=deeplearning.deepsmith.profiling_event.ProfilingEventType(
                    string="foo", ),
                duration_ms=100,
                event_start=now,
            ),
        ],
    )
    proto = testcase.ToProto()
    assert proto.toolchain == "cpp"
    assert proto.generator.name == "generator"
    assert proto.harness.name == "harness"
    assert len(proto.inputs) == 2
    assert proto.inputs["src"] == "void main() {}"
    assert proto.inputs["data"] == "[1,2]"
    assert len(proto.invariant_opts) == 1
    assert proto.invariant_opts["config"] == "opt"
    assert len(proto.profiling_events) == 2
    assert proto.profiling_events[
        0].event_start_epoch_ms == labdate.MillisecondsTimestamp(now)
    assert proto.profiling_events[0].client == "localhost"
    assert proto.profiling_events[0].type == "generate"
    assert proto.profiling_events[0].client == "localhost"