Loading system/gd/cert/cert_self_test.py +53 −0 Original line number Original line Diff line number Diff line Loading @@ -22,6 +22,7 @@ from datetime import datetime, timedelta from acts.base_test import BaseTestClass from acts.base_test import BaseTestClass from cert.event_callback_stream import EventCallbackStream from cert.event_callback_stream import EventCallbackStream from cert.event_asserts import EventAsserts from cert.event_asserts import EventAsserts from cert.truth import assertThat # Test packet nesting # Test packet nesting from bluetooth_packets_python3 import hci_packets from bluetooth_packets_python3 import hci_packets Loading Loading @@ -231,3 +232,55 @@ class CertSelfTest(BaseTestClass): # Size is ACL (4) + L2CAP (4) + Configure (8) + MTU (4) + FCS (3) # Size is ACL (4) + L2CAP (4) + Configure (8) + MTU (4) + FCS (3) asserts.assert_true( asserts.assert_true( len(wrapped.Serialize()) == 23, "Packet serialized incorrectly") len(wrapped.Serialize()) == 23, "Packet serialized incorrectly") def test_assertThat_boolean_success(self): assertThat(True).isTrue() assertThat(False).isFalse() def test_assertThat_boolean_falseIsTrue(self): try: assertThat(False).isTrue() except Exception as e: return True return False def test_assertThat_boolean_trueIsFalse(self): try: assertThat(True).isFalse() except Exception as e: return True return False def test_assertThat_object_success(self): assertThat("this").isEqualTo("this") assertThat("this").isNotEqualTo("that") assertThat(None).isNone() assertThat("this").isNotNone() def test_assertThat_object_isEqualToFails(self): try: assertThat("this").isEqualTo("that") except Exception as e: return True return False def test_assertThat_object_isNotEqualToFails(self): try: assertThat("this").isNotEqualTo("this") except Exception as e: return True return False def test_assertThat_object_isNoneFails(self): try: assertThat("this").isNone() except Exception as e: return True return False def test_assertThat_object_isNotNoneFails(self): try: assertThat(None).isNotNone() except Exception as e: return True return False system/gd/cert/truth.py 0 → 100644 +72 −0 Original line number Original line Diff line number Diff line #!/usr/bin/env python3 # # Copyright 2020 - 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. import time from mobly.asserts import assert_true from mobly.asserts import assert_false from mobly import signals import sys, traceback class ObjectSubject(object): def __init__(self, value): self._value = value def isEqualTo(self, other): if self._value != other: raise signals.TestFailure( "Expected \"%s\" to be equal to \"%s\"" % (self._value, other), extras=None) def isNotEqualTo(self, other): if self._value == other: raise signals.TestFailure( "Expected \"%s\" to not be equal to \"%s\"" % (self._value, other), extras=None) def isNone(self): if self._value is not None: raise signals.TestFailure( "Expected \"%s\" to be None" % self._value, extras=None) def isNotNone(self): if self._value is None: raise signals.TestFailure( "Expected \"%s\" to not be None" % self._value, extras=None) class BooleanSubject(ObjectSubject): def __init__(self, value): super().__init__(value) def isTrue(self): assert_true(self._value, "") def isFalse(self): assert_false(self._value, "") def assertThat(subject): if type(subject) is bool: return BooleanSubject(subject) else: return ObjectSubject(subject) system/gd/hci/cert/controller_test.py +9 −14 Original line number Original line Diff line number Diff line Loading @@ -16,8 +16,8 @@ import time import time from mobly.asserts import assert_true from cert.gd_base_test_facade_only import GdFacadeOnlyBaseTestClass from cert.gd_base_test_facade_only import GdFacadeOnlyBaseTestClass from cert.truth import assertThat from google.protobuf import empty_pb2 as empty_proto from google.protobuf import empty_pb2 as empty_proto from facade import rootservice_pb2 as facade_rootservice from facade import rootservice_pb2 as facade_rootservice from hci.facade import controller_facade_pb2 as controller_facade from hci.facade import controller_facade_pb2 as controller_facade Loading @@ -32,10 +32,8 @@ class ControllerTest(GdFacadeOnlyBaseTestClass): def test_get_addresses(self): def test_get_addresses(self): cert_address = self.cert.hci_controller.GetMacAddressSimple() cert_address = self.cert.hci_controller.GetMacAddressSimple() dut_address = self.dut.hci_controller.GetMacAddressSimple() dut_address = self.dut.hci_controller.GetMacAddressSimple() assert_true( cert_address != dut_address, assertThat(cert_address).isNotEqualTo(dut_address) msg="Expected cert and dut address to be different %s" % cert_address) time.sleep(1) # This shouldn't be needed b/149120542 time.sleep(1) # This shouldn't be needed b/149120542 def test_get_local_extended_features(self): def test_get_local_extended_features(self): Loading @@ -47,10 +45,9 @@ class ControllerTest(GdFacadeOnlyBaseTestClass): request0.page_number = 0 request0.page_number = 0 dut_feature_response0 = self.dut.hci_controller.GetLocalExtendedFeatures( dut_feature_response0 = self.dut.hci_controller.GetLocalExtendedFeatures( request0) request0) assert_true( dut_feature_response1.page != dut_feature_response0.page, assertThat(dut_feature_response1.page).isNotEqualTo( msg="Expected cert dut feature pages to be different %d" % dut_feature_response0.page) dut_feature_response1.page) def test_write_local_name(self): def test_write_local_name(self): self.dut.hci_controller.WriteLocalName( self.dut.hci_controller.WriteLocalName( Loading @@ -59,8 +56,6 @@ class ControllerTest(GdFacadeOnlyBaseTestClass): controller_facade.NameMsg(name=b'ImTheCert')) controller_facade.NameMsg(name=b'ImTheCert')) cert_name = self.cert.hci_controller.GetLocalNameSimple() cert_name = self.cert.hci_controller.GetLocalNameSimple() dut_name = self.dut.hci_controller.GetLocalNameSimple() dut_name = self.dut.hci_controller.GetLocalNameSimple() assert_true( dut_name == b'ImTheDUT', msg="unexpected dut name %s" % dut_name) assertThat(dut_name).isEqualTo(b'ImTheDUT') assert_true( assertThat(cert_name).isEqualTo(b'ImTheCert') cert_name == b'ImTheCert', msg="unexpected cert name %s" % cert_name) Loading
system/gd/cert/cert_self_test.py +53 −0 Original line number Original line Diff line number Diff line Loading @@ -22,6 +22,7 @@ from datetime import datetime, timedelta from acts.base_test import BaseTestClass from acts.base_test import BaseTestClass from cert.event_callback_stream import EventCallbackStream from cert.event_callback_stream import EventCallbackStream from cert.event_asserts import EventAsserts from cert.event_asserts import EventAsserts from cert.truth import assertThat # Test packet nesting # Test packet nesting from bluetooth_packets_python3 import hci_packets from bluetooth_packets_python3 import hci_packets Loading Loading @@ -231,3 +232,55 @@ class CertSelfTest(BaseTestClass): # Size is ACL (4) + L2CAP (4) + Configure (8) + MTU (4) + FCS (3) # Size is ACL (4) + L2CAP (4) + Configure (8) + MTU (4) + FCS (3) asserts.assert_true( asserts.assert_true( len(wrapped.Serialize()) == 23, "Packet serialized incorrectly") len(wrapped.Serialize()) == 23, "Packet serialized incorrectly") def test_assertThat_boolean_success(self): assertThat(True).isTrue() assertThat(False).isFalse() def test_assertThat_boolean_falseIsTrue(self): try: assertThat(False).isTrue() except Exception as e: return True return False def test_assertThat_boolean_trueIsFalse(self): try: assertThat(True).isFalse() except Exception as e: return True return False def test_assertThat_object_success(self): assertThat("this").isEqualTo("this") assertThat("this").isNotEqualTo("that") assertThat(None).isNone() assertThat("this").isNotNone() def test_assertThat_object_isEqualToFails(self): try: assertThat("this").isEqualTo("that") except Exception as e: return True return False def test_assertThat_object_isNotEqualToFails(self): try: assertThat("this").isNotEqualTo("this") except Exception as e: return True return False def test_assertThat_object_isNoneFails(self): try: assertThat("this").isNone() except Exception as e: return True return False def test_assertThat_object_isNotNoneFails(self): try: assertThat(None).isNotNone() except Exception as e: return True return False
system/gd/cert/truth.py 0 → 100644 +72 −0 Original line number Original line Diff line number Diff line #!/usr/bin/env python3 # # Copyright 2020 - 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. import time from mobly.asserts import assert_true from mobly.asserts import assert_false from mobly import signals import sys, traceback class ObjectSubject(object): def __init__(self, value): self._value = value def isEqualTo(self, other): if self._value != other: raise signals.TestFailure( "Expected \"%s\" to be equal to \"%s\"" % (self._value, other), extras=None) def isNotEqualTo(self, other): if self._value == other: raise signals.TestFailure( "Expected \"%s\" to not be equal to \"%s\"" % (self._value, other), extras=None) def isNone(self): if self._value is not None: raise signals.TestFailure( "Expected \"%s\" to be None" % self._value, extras=None) def isNotNone(self): if self._value is None: raise signals.TestFailure( "Expected \"%s\" to not be None" % self._value, extras=None) class BooleanSubject(ObjectSubject): def __init__(self, value): super().__init__(value) def isTrue(self): assert_true(self._value, "") def isFalse(self): assert_false(self._value, "") def assertThat(subject): if type(subject) is bool: return BooleanSubject(subject) else: return ObjectSubject(subject)
system/gd/hci/cert/controller_test.py +9 −14 Original line number Original line Diff line number Diff line Loading @@ -16,8 +16,8 @@ import time import time from mobly.asserts import assert_true from cert.gd_base_test_facade_only import GdFacadeOnlyBaseTestClass from cert.gd_base_test_facade_only import GdFacadeOnlyBaseTestClass from cert.truth import assertThat from google.protobuf import empty_pb2 as empty_proto from google.protobuf import empty_pb2 as empty_proto from facade import rootservice_pb2 as facade_rootservice from facade import rootservice_pb2 as facade_rootservice from hci.facade import controller_facade_pb2 as controller_facade from hci.facade import controller_facade_pb2 as controller_facade Loading @@ -32,10 +32,8 @@ class ControllerTest(GdFacadeOnlyBaseTestClass): def test_get_addresses(self): def test_get_addresses(self): cert_address = self.cert.hci_controller.GetMacAddressSimple() cert_address = self.cert.hci_controller.GetMacAddressSimple() dut_address = self.dut.hci_controller.GetMacAddressSimple() dut_address = self.dut.hci_controller.GetMacAddressSimple() assert_true( cert_address != dut_address, assertThat(cert_address).isNotEqualTo(dut_address) msg="Expected cert and dut address to be different %s" % cert_address) time.sleep(1) # This shouldn't be needed b/149120542 time.sleep(1) # This shouldn't be needed b/149120542 def test_get_local_extended_features(self): def test_get_local_extended_features(self): Loading @@ -47,10 +45,9 @@ class ControllerTest(GdFacadeOnlyBaseTestClass): request0.page_number = 0 request0.page_number = 0 dut_feature_response0 = self.dut.hci_controller.GetLocalExtendedFeatures( dut_feature_response0 = self.dut.hci_controller.GetLocalExtendedFeatures( request0) request0) assert_true( dut_feature_response1.page != dut_feature_response0.page, assertThat(dut_feature_response1.page).isNotEqualTo( msg="Expected cert dut feature pages to be different %d" % dut_feature_response0.page) dut_feature_response1.page) def test_write_local_name(self): def test_write_local_name(self): self.dut.hci_controller.WriteLocalName( self.dut.hci_controller.WriteLocalName( Loading @@ -59,8 +56,6 @@ class ControllerTest(GdFacadeOnlyBaseTestClass): controller_facade.NameMsg(name=b'ImTheCert')) controller_facade.NameMsg(name=b'ImTheCert')) cert_name = self.cert.hci_controller.GetLocalNameSimple() cert_name = self.cert.hci_controller.GetLocalNameSimple() dut_name = self.dut.hci_controller.GetLocalNameSimple() dut_name = self.dut.hci_controller.GetLocalNameSimple() assert_true( dut_name == b'ImTheDUT', msg="unexpected dut name %s" % dut_name) assertThat(dut_name).isEqualTo(b'ImTheDUT') assert_true( assertThat(cert_name).isEqualTo(b'ImTheCert') cert_name == b'ImTheCert', msg="unexpected cert name %s" % cert_name)