]> git.proxmox.com Git - mirror_ovs.git/blame - tests/test-unix-socket.py
ofp-print: Abbreviate lists of fields in table features output.
[mirror_ovs.git] / tests / test-unix-socket.py
CommitLineData
cd57233c
BP
1#
2# Copyright (c) 2010, 2012, 2013 Nicira, Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at:
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17import signal
18import socket
19import sys
20
21import ovs.socket_util
36d51634 22from ovs.fatal_signal import signal_alarm
cd57233c 23
bdca6c4b 24
cd57233c
BP
25def main(argv):
26 if len(argv) not in (2, 3):
27 sys.stderr.write("usage: %s SOCKETNAME1 [SOCKETNAME2]", argv[0])
28 sys.exit(1)
29
30 sockname1 = argv[1]
31 if len(argv) > 2:
32 sockname2 = argv[2]
33 else:
34 sockname2 = sockname1
35
36 signal.signal(signal.SIGALRM, signal.SIG_DFL)
36d51634 37 signal_alarm(5)
cd57233c
BP
38
39 # Create a listening socket under name 'sockname1'.
40 error, sock1 = ovs.socket_util.make_unix_socket(socket.SOCK_STREAM, False,
41 sockname1, None)
42 if error:
43 sys.stderr.write("%s: bind failed (%s)" % (sockname1,
44 os.strerror(error)))
a8453a38 45 sys.exit(1)
cd57233c
BP
46 sock1.listen(1)
47
48 # Connect to 'sockname2' (which should be the same file, perhaps under a
49 # different name).
50 error, sock2 = ovs.socket_util.make_unix_socket(socket.SOCK_STREAM, False,
51 None, sockname2)
52 if error:
53 sys.stderr.write("%s: connect failed (%s)" % (sockname2,
54 os.strerror(error)))
a8453a38 55 sys.exit(1)
cd57233c 56
bdca6c4b 57
cd57233c
BP
58if __name__ == '__main__':
59 main(sys.argv)