mbed-os for GR-LYCHEE
Dependents: mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more
tools/host_tests/tcpecho_client.py@0:f782d9c66c49, 2018-02-02 (annotated)
- Committer:
- dkato
- Date:
- Fri Feb 02 05:42:23 2018 +0000
- Revision:
- 0:f782d9c66c49
mbed-os for GR-LYCHEE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:f782d9c66c49 | 1 | """ |
dkato | 0:f782d9c66c49 | 2 | mbed SDK |
dkato | 0:f782d9c66c49 | 3 | Copyright (c) 2011-2013 ARM Limited |
dkato | 0:f782d9c66c49 | 4 | |
dkato | 0:f782d9c66c49 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
dkato | 0:f782d9c66c49 | 6 | you may not use this file except in compliance with the License. |
dkato | 0:f782d9c66c49 | 7 | You may obtain a copy of the License at |
dkato | 0:f782d9c66c49 | 8 | |
dkato | 0:f782d9c66c49 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
dkato | 0:f782d9c66c49 | 10 | |
dkato | 0:f782d9c66c49 | 11 | Unless required by applicable law or agreed to in writing, software |
dkato | 0:f782d9c66c49 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
dkato | 0:f782d9c66c49 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dkato | 0:f782d9c66c49 | 14 | See the License for the specific language governing permissions and |
dkato | 0:f782d9c66c49 | 15 | limitations under the License. |
dkato | 0:f782d9c66c49 | 16 | """ |
dkato | 0:f782d9c66c49 | 17 | import socket |
dkato | 0:f782d9c66c49 | 18 | import string, random |
dkato | 0:f782d9c66c49 | 19 | from time import time |
dkato | 0:f782d9c66c49 | 20 | |
dkato | 0:f782d9c66c49 | 21 | from mbed_settings import SERVER_ADDRESS |
dkato | 0:f782d9c66c49 | 22 | |
dkato | 0:f782d9c66c49 | 23 | ECHO_PORT = 7 |
dkato | 0:f782d9c66c49 | 24 | |
dkato | 0:f782d9c66c49 | 25 | LEN_PACKET = 127 |
dkato | 0:f782d9c66c49 | 26 | N_PACKETS = 5000 |
dkato | 0:f782d9c66c49 | 27 | TOT_BITS = float(LEN_PACKET * N_PACKETS * 8) * 2 |
dkato | 0:f782d9c66c49 | 28 | MEGA = float(1024 * 1024) |
dkato | 0:f782d9c66c49 | 29 | UPDATE_STEP = (N_PACKETS/10) |
dkato | 0:f782d9c66c49 | 30 | |
dkato | 0:f782d9c66c49 | 31 | class TCP_EchoClient: |
dkato | 0:f782d9c66c49 | 32 | def __init__(self, host): |
dkato | 0:f782d9c66c49 | 33 | self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
dkato | 0:f782d9c66c49 | 34 | self.s.connect((host, ECHO_PORT)) |
dkato | 0:f782d9c66c49 | 35 | self.packet = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(LEN_PACKET)) |
dkato | 0:f782d9c66c49 | 36 | |
dkato | 0:f782d9c66c49 | 37 | def __packet(self): |
dkato | 0:f782d9c66c49 | 38 | # Comment out the checks when measuring the throughput |
dkato | 0:f782d9c66c49 | 39 | # self.packet = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(LEN_PACKET)) |
dkato | 0:f782d9c66c49 | 40 | self.s.send(self.packet) |
dkato | 0:f782d9c66c49 | 41 | data = self.s.recv(LEN_PACKET) |
dkato | 0:f782d9c66c49 | 42 | # assert self.packet == data, "packet error:\n%s\n%s\n" % (self.packet, data) |
dkato | 0:f782d9c66c49 | 43 | |
dkato | 0:f782d9c66c49 | 44 | def test(self): |
dkato | 0:f782d9c66c49 | 45 | start = time() |
dkato | 0:f782d9c66c49 | 46 | for i in range(N_PACKETS): |
dkato | 0:f782d9c66c49 | 47 | if (i % UPDATE_STEP) == 0: print '%.2f%%' % ((float(i)/float(N_PACKETS)) * 100.) |
dkato | 0:f782d9c66c49 | 48 | self.__packet() |
dkato | 0:f782d9c66c49 | 49 | t = time() - start |
dkato | 0:f782d9c66c49 | 50 | print 'Throughput: (%.2f)Mbits/s' % ((TOT_BITS / t)/MEGA) |
dkato | 0:f782d9c66c49 | 51 | |
dkato | 0:f782d9c66c49 | 52 | def __del__(self): |
dkato | 0:f782d9c66c49 | 53 | self.s.close() |
dkato | 0:f782d9c66c49 | 54 | |
dkato | 0:f782d9c66c49 | 55 | while True: |
dkato | 0:f782d9c66c49 | 56 | e = TCP_EchoClient(SERVER_ADDRESS) |
dkato | 0:f782d9c66c49 | 57 | e.test() |