Home | History | Annotate | Download | only in tests
      1 #!/usr/bin/env python3
      2 #
      3 #   Copyright 2016 - The Android Open Source Project
      4 #
      5 #   Licensed under the Apache License, Version 2.0 (the "License");
      6 #   you may not use this file except in compliance with the License.
      7 #   You may obtain a copy of the License at
      8 #
      9 #       http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 #   Unless required by applicable law or agreed to in writing, software
     12 #   distributed under the License is distributed on an "AS IS" BASIS,
     13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 #   See the License for the specific language governing permissions and
     15 #   limitations under the License.
     16 
     17 import socket
     18 import unittest
     19 
     20 from acts.controllers.utils_lib import host_utils
     21 
     22 
     23 class ActsHostUtilsTest(unittest.TestCase):
     24     """This test class has unit tests for the implementation of everything
     25     under acts.controllers.adb.
     26     """
     27 
     28     def test_detects_udp_port_in_use(self):
     29         test_s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     30         test_s.bind(('localhost', 0))
     31         port = test_s.getsockname()[1]
     32         try:
     33             self.assertFalse(host_utils.is_port_available(port))
     34         finally:
     35             test_s.close()
     36 
     37     def test_detects_tcp_port_in_use(self):
     38         test_s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     39         test_s.bind(('localhost', 0))
     40         port = test_s.getsockname()[1]
     41         try:
     42             self.assertFalse(host_utils.is_port_available(port))
     43         finally:
     44             test_s.close()
     45 
     46 
     47 if __name__ == "__main__":
     48     unittest.main()
     49