Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit abb09279 authored by Jizheng Chu's avatar Jizheng Chu
Browse files

Include Blueberry files in bluetooth_cert_tests.zip and implement Mobly version of CertSelfTest

Bug: 188852669
Test: Build artifact and run CertSelfTest in venv with Mobly, see detail
steps in go/port-gd-cert.

Change-Id: I29e5c0b0d4afd5ebfc80c85106dca6c605e8898b
parent 5ddb93e7
Loading
Loading
Loading
Loading
+280 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
#
#   Copyright 2019 - The Android Open Source Project
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

from mobly import asserts
from mobly import signals
from mobly import test_runner
from mobly import base_test

from cert.metadata import metadata
from cert.cert_self_test_lib import *


class CertSelfTest(base_test.BaseTestClass):

    def setup_test(self):
        return True

    def teardown_test(self):
        return True

    def test_assert_occurs_at_least_passes(self):
        test_assert_occurs_at_least_passes_core()

    def test_assert_occurs_passes(self):
        test_assert_occurs_passes_core()

    def test_assert_occurs_fails(self):
        test_assert_occurs_fails_core()

    def test_assert_occurs_at_most_passes(self):
        test_assert_occurs_at_most_passes_core()

    def test_assert_occurs_at_most_fails(self):
        test_assert_occurs_at_most_fails_core()

    def test_skip_a_test(self):
        test_skip_a_test_core()

    def test_nested_packets(self):
        test_nested_packets_core()

    def test_l2cap_config_options(self):
        test_l2cap_config_options_core()

    def test_assertThat_boolean_success(self):
        test_assertThat_boolean_success_core()

    def test_assertThat_boolean_falseIsTrue(self):
        test_assertThat_boolean_falseIsTrue_core()

    def test_assertThat_boolean_trueIsFalse(self):
        test_assertThat_boolean_trueIsFalse_core()

    def test_assertThat_object_success(self):
        test_assertThat_object_success_core()

    def test_assertThat_object_isEqualToFails(self):
        test_assertThat_object_isEqualToFails_core()

    def test_assertThat_object_isNotEqualToFails(self):
        test_assertThat_object_isNotEqualToFails_core()

    def test_assertThat_object_isNoneFails(self):
        test_assertThat_object_isNoneFails_core()

    def test_assertThat_object_isNotNoneFails(self):
        test_assertThat_object_isNotNoneFails_core()

    def test_assertThat_eventStream_emits_passes(self):
        test_assertThat_eventStream_emits_passes_core()

    def test_assertThat_eventStream_emits_then_passes(self):
        test_assertThat_eventStream_emits_then_passes_core()

    def test_assertThat_eventStream_emits_fails(self):
        test_assertThat_eventStream_emits_fails_core()

    def test_assertThat_eventStream_emits_then_fails(self):
        test_assertThat_eventStream_emits_then_fails_core()

    def test_assertThat_eventStream_emitsInOrder_passes(self):
        test_assertThat_eventStream_emitsInOrder_passes_core()

    def test_assertThat_eventStream_emitsInAnyOrder_passes(self):
        test_assertThat_eventStream_emitsInAnyOrder_passes_core()

    def test_assertThat_eventStream_emitsInOrder_fails(self):
        test_assertThat_eventStream_emitsInOrder_fails_core()

    def test_assertThat_eventStream_emitsInAnyOrder_fails(self):
        test_assertThat_eventStream_emitsInAnyOrder_fails_core()

    def test_assertThat_emitsNone_passes(self):
        test_assertThat_emitsNone_passes_core()

    def test_assertThat_emitsNone_passes_after_1_second(self):
        test_assertThat_emitsNone_passes_after_1_second_core()

    def test_assertThat_emitsNone_fails(self):
        test_assertThat_emitsNone_fails_core()

    def test_assertThat_emitsNone_zero_passes(self):
        test_assertThat_emitsNone_zero_passes_core()

    def test_assertThat_emitsNone_zero_passes_after_one_second(self):
        test_assertThat_emitsNone_zero_passes_after_one_second_core()

    def test_assertThat_emitsNone_zero_fails(self):
        test_assertThat_emitsNone_zero_fails_core()

    def test_filtering_event_stream_none_filter_function(self):
        test_filtering_event_stream_none_filter_function_core()

    def test_metadata_empty(self):

        @metadata()
        def simple_pass_test(arg):
            pass

        try:
            simple_pass_test(1)
        except signals.TestFailure:
            pass
        except Exception as e:
            asserts.fail("@metadata() should only raise signals.TestFailure, "
                         "but raised %s with msg %s instead" % (e.__class__.__name__, str(e)))
        else:
            asserts.fail("@metadata() should not work")

    def test_metadata_empty_no_function_call(self):

        @metadata
        def simple_pass_test(arg):
            pass

        try:
            simple_pass_test(1)
        except signals.TestFailure:
            pass
        except Exception as e:
            asserts.fail("@metadata should only raise signals.TestFailure, "
                         "but raised %s with msg %s instead" % (e.__class__.__name__, str(e)))
        else:
            asserts.fail("@metadata should not work")

    def test_metadata_pts_missing_id(self):

        @metadata(pts_test_name="Hello world")
        def simple_pass_test(arg):
            pass

        try:
            simple_pass_test(1)
        except signals.TestFailure:
            pass
        except Exception as e:
            asserts.fail("should only raise signals.TestFailure, "
                         "but raised %s with msg %s instead" % (e.__class__.__name__, str(e)))
        else:
            asserts.fail("missing pts_test_id should not work")

    def test_metadata_pts_missing_name(self):

        @metadata(pts_test_id="A/B/C")
        def simple_pass_test(arg):
            pass

        try:
            simple_pass_test(1)
        except signals.TestFailure:
            pass
        except Exception as e:
            asserts.fail("should only raise signals.TestFailure, "
                         "but raised %s with msg %s instead" % (e.__class__.__name__, str(e)))
        else:
            asserts.fail("missing pts_test_name should not work")

    def test_metadata_pts_test_id_and_description(self):

        @metadata(pts_test_id="A/B/C", pts_test_name="Hello world")
        def simple_pass_test(arg):
            pass

        try:
            simple_pass_test(1)
        except signals.TestPass as e:
            asserts.assert_true("pts_test_id" in e.extras, msg=("pts_test_id not in extra: %s" % str(e.extras)))
            asserts.assert_equal(e.extras["pts_test_id"], "A/B/C")
            asserts.assert_true("pts_test_name" in e.extras, msg=("pts_test_name not in extra: %s" % str(e.extras)))
            asserts.assert_equal(e.extras["pts_test_name"], "Hello world")
        else:
            asserts.fail("Must throw an exception using @metadata decorator")

    def test_metadata_test_with_exception_stacktrace(self):

        @metadata(pts_test_id="A/B/C", pts_test_name="Hello world")
        def simple_fail_test(failure_argument):
            raise ValueError(failure_argument)

        try:
            simple_fail_test("BEEFBEEF")
        except signals.TestError as e:
            asserts.assert_true("pts_test_id" in e.extras, msg=("pts_test_id not in extra: %s" % str(e.extras)))
            asserts.assert_equal(e.extras["pts_test_id"], "A/B/C")
            asserts.assert_true("pts_test_name" in e.extras, msg=("pts_test_name not in extra: %s" % str(e.extras)))
            asserts.assert_equal(e.extras["pts_test_name"], "Hello world")
            trace_str = traceback.format_exc()
            asserts.assert_true(
                "raise ValueError(failure_argument)" in trace_str,
                msg="Failed test method not in error stack trace: %s" % trace_str)
        else:
            asserts.fail("Must throw an exception using @metadata decorator")

    def test_fluent_behavior_simple(self):
        test_fluent_behavior_simple_core()

    def test_fluent_behavior__then_single__captures_one(self):
        test_fluent_behavior__then_single__captures_one_core()

    def test_fluent_behavior__then_times__captures_all(self):
        test_fluent_behavior__then_times__captures_all_core()

    def test_fluent_behavior__always__captures_all(self):
        test_fluent_behavior__always__captures_all_core()

    def test_fluent_behavior__matcher__captures_relevant(self):
        test_fluent_behavior__matcher__captures_relevant_core()

    def test_fluent_behavior__then_repeated__captures_relevant(self):
        test_fluent_behavior__then_repeated__captures_relevant_core()

    def test_fluent_behavior__fallback__captures_relevant(self):
        test_fluent_behavior__fallback__captures_relevant_core()

    def test_fluent_behavior__default_unhandled_crash(self):
        test_fluent_behavior__default_unhandled_crash_core()

    def test_fluent_behavior__set_default_works(self):
        test_fluent_behavior__set_default_works_core()

    def test_fluent_behavior__wait_until_done(self):
        test_fluent_behavior__wait_until_done_core()

    def test_fluent_behavior__wait_until_done_different_lambda(self):
        test_fluent_behavior__wait_until_done_different_lambda_core()

    def test_fluent_behavior__wait_until_done_anything(self):
        test_fluent_behavior__wait_until_done_anything_core()

    def test_fluent_behavior__wait_until_done_not_happened(self):
        test_fluent_behavior__wait_until_done_not_happened_core()

    def test_fluent_behavior__wait_until_done_with_default(self):
        test_fluent_behavior__wait_until_done_with_default_core()

    def test_fluent_behavior__wait_until_done_two_events_AA(self):
        test_fluent_behavior__wait_until_done_two_events_AA_core()

    def test_fluent_behavior__wait_until_done_two_events_AB(self):
        test_fluent_behavior__wait_until_done_two_events_AB_core()

    def test_fluent_behavior__wait_until_done_only_one_event_is_done(self):
        test_fluent_behavior__wait_until_done_only_one_event_is_done_core()


if __name__ == '__main__':
    test_runner.main()
+32 −0
Original line number Diff line number Diff line
_description: Bluetooth cert testing
TestBeds:
  - _description: Host only cert testbed
    Name: HostOnlyCert
    rootcanal:
      test_port: '6401'
      hci_port: '6402'
      link_layer_port: '6403'
    GdDevice:
      - grpc_port: '8998'
        grpc_root_server_port: '8996'
        signal_port: '8994'
        label: cert
        Name: Cert Device
        cmd:
          - "$GD_ROOT/bluetooth_stack_with_facade"
          - "--grpc-port=$(grpc_port)"
          - "--root-server-port=$(grpc_root_server_port)"
          - "--rootcanal-port=$(rootcanal_port)"
          - "--signal-port=$(signal_port)"
      - grpc_port: '8999'
        grpc_root_server_port: '8997'
        signal_port: '8995'
        label: dut
        Name: DUT Device
        cmd:
          - "$GD_ROOT/bluetooth_stack_with_facade"
          - "--grpc-port=$(grpc_port)"
          - "--root-server-port=$(grpc_root_server_port)"
          - "--rootcanal-port=$(rootcanal_port)"
          - "--signal-port=$(signal_port)"
logpath: "/tmp/logs"
+1 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ $(bluetooth_cert_tests_py_package_zip): $(SOONG_ZIP) $(LOCAL_acts_zip) \
	$(hide) $(SOONG_ZIP) -d -o $@ -C $(dir $@)bluetooth_cert_tests -D $(dir $@)bluetooth_cert_tests \
		-P acts_framework \
		-C $(dir $@)acts/tools/test/connectivity/acts/framework -D $(dir $@)acts/tools/test/connectivity/acts/framework \
		-P blueberry -C packages/modules/Bluetooth/system/blueberry -D packages/modules/Bluetooth/system/blueberry \
		-P llvm_binutils -C $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION) \
		-f $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION)/bin/llvm-cov \
		-f $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION)/bin/llvm-profdata \