mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-30 16:14:30 +08:00
#3633 - Put all dummy test files in test/test-files
This commit is contained in:
42
test/script/dumb_named_pipe_server.py
Normal file
42
test/script/dumb_named_pipe_server.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""
|
||||
This Python script creates a named pipe server that does nothing but send its input
|
||||
back to the client that connects to it. Only one argument must be given, the path
|
||||
of a named pipe to bind to.
|
||||
"""
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit('You must specify a filepath')
|
||||
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
if os.path.exists(sys.argv[1]):
|
||||
os.remove(sys.argv[1])
|
||||
sock.bind(sys.argv[1])
|
||||
sock.listen(0)
|
||||
|
||||
pid = os.fork()
|
||||
|
||||
if pid:
|
||||
print(pid)
|
||||
sys.exit()
|
||||
|
||||
while True:
|
||||
connection = sock.accept()[0]
|
||||
connection.settimeout(5)
|
||||
|
||||
while True:
|
||||
try:
|
||||
connection.send(connection.recv(1024))
|
||||
except socket.timeout:
|
||||
break
|
||||
|
||||
connection.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
33
test/script/dumb_tcp_client.py
Normal file
33
test/script/dumb_tcp_client.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""
|
||||
This is just a script for testing that the dumb TCP server actually works
|
||||
correctly, for verifying that problems with tests are in Vim. Pass the
|
||||
same port number given to the test server to check that it's working.
|
||||
"""
|
||||
import socket
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
result = sock.connect_ex(('127.0.0.1', int(sys.argv[1])))
|
||||
|
||||
if result:
|
||||
sock.close()
|
||||
sys.exit("Couldn't connect to the socket!")
|
||||
|
||||
data_sent = 'x' * 1024
|
||||
|
||||
sock.send(data_sent)
|
||||
data_received = sock.recv(1024)
|
||||
|
||||
if data_sent != data_received:
|
||||
sock.close()
|
||||
sys.exit("Data sent didn't match data received.")
|
||||
|
||||
sock.close()
|
||||
|
||||
print("Everything was just fine.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
40
test/script/dumb_tcp_server.py
Normal file
40
test/script/dumb_tcp_server.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
This Python script creates a TCP server that does nothing but send its input
|
||||
back to the client that connects to it. Only one argument must be given, a port
|
||||
to bind to.
|
||||
"""
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2 or not sys.argv[1].isdigit():
|
||||
sys.exit('You must specify a port number')
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock.bind(('127.0.0.1', int(sys.argv[1])))
|
||||
sock.listen(0)
|
||||
|
||||
pid = os.fork()
|
||||
|
||||
if pid:
|
||||
print(pid)
|
||||
sys.exit()
|
||||
|
||||
while True:
|
||||
connection = sock.accept()[0]
|
||||
connection.settimeout(5)
|
||||
|
||||
while True:
|
||||
try:
|
||||
connection.send(connection.recv(1024))
|
||||
except socket.timeout:
|
||||
break
|
||||
|
||||
connection.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user