1 #!/usr/bin/env python 2 # 3 # Copyright (C) 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 18 import logging 19 20 from vts.runners.host import asserts 21 from vts.runners.host import base_test 22 from vts.runners.host import test_runner 23 from vts.utils.python.controllers import android_device 24 from vts.runners.host import const 25 26 27 class LibcTest(base_test.BaseTestClass): 28 """A basic test of the libc API.""" 29 30 def setUpClass(self): 31 self.dut = self.registerController(android_device)[0] 32 self.dut.lib.InitSharedLib(target_type="bionic_libc", 33 target_basepaths=["/system/lib64"], 34 target_version=1.0, 35 target_filename="libc.so", 36 bits=64, 37 handler_name="libc", 38 target_package="lib.ndk.bionic") 39 40 def testOpenCloseLocalSocketStream(self): 41 """Tests open and close socket operations for local communication. 42 43 Uses local addresses and a streaming socket. 44 """ 45 result = self.dut.lib.libc.socket(self.dut.lib.libc.PF_UNIX, 46 self.dut.lib.libc.SOCK_STREAM, 0) 47 asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1, 48 "libc.socket: could not create socket.") 49 50 result = self.dut.lib.libc.close( 51 result.return_type.scalar_value.int32_t) 52 asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1, 53 "libc.close: unable to close socket.") 54 55 def testOpenCloseLocalSocketDatagram(self): 56 """Tests open and close socket operations for local communication. 57 58 Uses local addresses and a datagram socket. 59 """ 60 result = self.dut.lib.libc.socket(self.dut.lib.libc.PF_UNIX, 61 self.dut.lib.libc.SOCK_DGRAM, 0) 62 asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1, 63 "libc.socket: could not create socket.") 64 65 result = self.dut.lib.libc.close( 66 result.return_type.scalar_value.int32_t) 67 asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1, 68 "libc.close: unable to close socket.") 69 70 def testOpenCloseLocalSocketRaw(self): 71 """Tests open and close socket operations for local communication. 72 73 Uses local addresses and a raw socket. 74 """ 75 result = self.dut.lib.libc.socket(self.dut.lib.libc.PF_UNIX, 76 self.dut.lib.libc.SOCK_RAW, 0) 77 asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1, 78 "libc.socket: could not create socket.") 79 80 result = self.dut.lib.libc.close( 81 result.return_type.scalar_value.int32_t) 82 asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1, 83 "libc.close: unable to close socket.") 84 85 def testOpenCloseLocalSocketSequential(self): 86 """Tests open and close socket operations for local communication. 87 88 Uses local addresses and a sequential socket. 89 """ 90 result = self.dut.lib.libc.socket(self.dut.lib.libc.PF_UNIX, 91 self.dut.lib.libc.SOCK_SEQPACKET, 0) 92 asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1, 93 "libc.socket: could not create socket.") 94 95 result = self.dut.lib.libc.close( 96 result.return_type.scalar_value.int32_t) 97 asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1, 98 "libc.close: unable to close socket.") 99 100 def testOpenCloseINETSocketStream(self): 101 """Tests open and close socket operations for INET communication. 102 103 Uses IP addresses and a streaming socket. 104 """ 105 result = self.dut.lib.libc.socket(self.dut.lib.libc.PF_INET, 106 self.dut.lib.libc.SOCK_STREAM, 0) 107 asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1, 108 "libc.socket: could not create socket.") 109 110 result = self.dut.lib.libc.close( 111 result.return_type.scalar_value.int32_t) 112 asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1, 113 "libc.close: unable to close socket.") 114 115 def testOpenCloseINETSocketDatagram(self): 116 """Tests open and close socket operations for INET communication. 117 118 Uses IP addresses and a datagram socket. 119 """ 120 result = self.dut.lib.libc.socket(self.dut.lib.libc.PF_INET, 121 self.dut.lib.libc.SOCK_DGRAM, 0) 122 asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1, 123 "libc.socket: could not create socket.") 124 125 result = self.dut.lib.libc.close( 126 result.return_type.scalar_value.int32_t) 127 asserts.assertNotEqual(result.return_type.scalar_value.int32_t, -1, 128 "libc.close: unable to close socket.") 129 130 if __name__ == "__main__": 131 test_runner.main() 132