diff --git a/HISTORY.rst b/HISTORY.rst index b6e92f5..9a1624c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,10 @@ Release History --------------- +0.1.9 (2018-02-22) +++++++++++++++++++ +- Use find_library to load libiperf (Thanks to @Austinpayne). This should allow iperf3 lib to run on Mac OS X. + 0.1.8 (2018-01-24) ++++++++++++++++++ - Fixed segmentation fault on several Linux distro's (Thanks to @illu89) diff --git a/docs/source/conf.py b/docs/source/conf.py index 8024c1f..d9b0550 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -66,9 +66,9 @@ # built documents. # # The short X.Y version. -version = '0.1.8' +version = '0.1.9' # The full version, including alpha/beta/rc tags. -release = '0.1.8' +release = '0.1.9' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/iperf3/iperf3.py b/iperf3/iperf3.py index 0170eb5..518b368 100755 --- a/iperf3/iperf3.py +++ b/iperf3/iperf3.py @@ -18,7 +18,7 @@ class provides common settings for the :class:`Client` and :class:`Server` .. moduleauthor:: Mathijs Mortimer """ -from ctypes import cdll, c_char_p, c_int, c_char, c_void_p, c_uint64 +from ctypes import util, cdll, c_char_p, c_int, c_char, c_void_p, c_uint64 import os import select import json @@ -31,7 +31,7 @@ class provides common settings for the :class:`Client` and :class:`Server` from Queue import Queue # Python2 compatibility -__version__ = '0.1.8' +__version__ = '0.1.9' MAX_UDP_BULKSIZE = (65535 - 8 - 20) @@ -88,15 +88,16 @@ class IPerf3(object): """ def __init__(self, role, - verbose=True, - lib_name='libiperf.so.0'): + verbose=True): """Initialise the iperf shared library :param role: 'c' = client; 's' = server :param verbose: enable verbose output - :param lib_name: The libiperf name providing the API to iperf3 """ - # TODO use find_library to find the best library + lib_name = util.find_library('libiperf') + if lib_name is None: + lib_name = 'libiperf.so.0' + try: self.lib = cdll.LoadLibrary(lib_name) except OSError: @@ -801,24 +802,33 @@ def __init__(self, result): # TCP specific test results if self.protocol == 'TCP': - self.sent_bytes = self.json['end']['sum_sent']['bytes'] - self.sent_bps = self.json['end']['sum_sent']['bits_per_second'] - self.received_bytes = self.json['end']['sum_received']['bytes'] - self.received_bps = self.json['end']['sum_received']['bits_per_second'] - - # Bits are measured in 10**3 terms, Bytes are measured in 2**10 terms - self.sent_kbps = self.sent_bps / 1000 # Kilobits per second - self.sent_Mbps = self.sent_kbps / 1000 # Megabits per second - self.sent_kB_s = self.sent_bps / (8 * 1024) # kiloBytes per second - self.sent_MB_s = self.sent_kB_s / 1024 # MegaBytes per second - - self.received_kbps = self.received_bps / 1000 # Kilobits per second - self.received_Mbps = self.received_kbps / 1000 # Megabits per second - self.received_kB_s = self.received_bps / (8* 1024) # kiloBytes per second - self.received_MB_s = self.received_kB_s / 1024 # MegaBytes per second + sent_json = self.json['end']['sum_sent'] + self.sent_bytes = sent_json['bytes'] + self.sent_bps = sent_json['bits_per_second'] + + recv_json = self.json['end']['sum_received'] + self.received_bytes = recv_json['bytes'] + self.received_bps = recv_json['bits_per_second'] + + # Bits are measured in 10**3 terms + # Bytes are measured in 2**10 terms + # kbps = Kilobits per second + # Mbps = Megabits per second + # kB_s = kiloBytes per second + # MB_s = MegaBytes per second + + self.sent_kbps = self.sent_bps / 1000 + self.sent_Mbps = self.sent_kbps / 1000 + self.sent_kB_s = self.sent_bps / (8 * 1024) + self.sent_MB_s = self.sent_kB_s / 1024 + + self.received_kbps = self.received_bps / 1000 + self.received_Mbps = self.received_kbps / 1000 + self.received_kB_s = self.received_bps / (8 * 1024) + self.received_MB_s = self.received_kB_s / 1024 # retransmits only returned from client - self.retransmits = self.json['end']['sum_sent'].get('retransmits') + self.retransmits = sent_json.get('retransmits') # UDP specific test results elif self.protocol == 'UDP': diff --git a/tests/test_iperf3.py b/tests/test_iperf3.py index cf30aa0..2bd3c89 100644 --- a/tests/test_iperf3.py +++ b/tests/test_iperf3.py @@ -9,10 +9,6 @@ def isclose(a, b, rel_tol=1e-09, abs_tol=0.0): class TestPyPerf: - def test_unavailable_library(self): - with pytest.raises(OSError): - client = iperf3.Client(lib_name='bla') - def test_init_client(self): client = iperf3.Client() assert client._test