diff --git a/integration/README.md b/integration/README.md index 6b17e14..9a18526 100644 --- a/integration/README.md +++ b/integration/README.md @@ -1,2 +1,24 @@ UsbSerial Integration Tests -=========================== \ No newline at end of file +=========================== +For the purpose of helping people contributing to UsbSerial a little set of integration tests have been added. It consists in two parts. +- Python script integration.py that sends a series packets (1kb, 2kb, 8kb, 64kb and 128kb) and validates that those packets are received back correctly. +- Integration Android app that implements UsbSerial and just receives and sends back the packets sent by the python script. + +Requirements +-------------------------------------- +- Windows/OSX/Linux with Python 3 installed +- [PySerial](https://pypi.org/project/pyserial/) +- Android phone with Android 3.1 and with USB OTG capabilities + +Steps +-------------------------------------- +Let's say we want to test UsbSerial transmitting at 115200 bauds and our PC port is /dev/ttyUSB0 +- [Modify UsbService in Integration app to 115200 bauds](https://github.com/felHR85/UsbSerial/blob/integration_tests/integrationapp/src/main/java/com/felhr/integrationapp/UsbService.java#L61). +- Compile and install Integration app on your device. +- Connect your phone to a serial device at one end and your PC at the other end. +- Run python integration.py /dev/ttyUSB0 115200 + +Other Scripts +-------------------------------------- +- send_packet.py (python send_packet.py /dev/ttyUSB0 1024 115200) +- validate_serial_tx.py (python validate_serial_tx.py /dev/ttyUSB0 1024 115200) \ No newline at end of file diff --git a/integration/integration.py b/integration/integration.py index ba6e016..6764c32 100644 --- a/integration/integration.py +++ b/integration/integration.py @@ -1,3 +1,8 @@ +# UsbSerial test: Integration test +# args: +# port (eg /dev/ttyUSB0) +# speed in bauds (eg 115200) + import serial import sys import os @@ -7,9 +12,9 @@ speed = sys.argv[2] test_sizes = [1024, 2048, 16384, 65535, 131072] -for i in range(0,4): +for i in range(0,5): comm = serial.Serial(port, int(speed)) - print("Creating " + str(test_sizes[i] + " bytes buffer")) + print("Creating " + str(test_sizes[i]) + " bytes buffer") data_tx = os.urandom(test_sizes[i]) print("Sending buffer of " + str(test_sizes[i]) + " bytes") comm.write(data_tx) diff --git a/integration/send_packet.py b/integration/send_packet.py index fff49f3..0a6856c 100644 --- a/integration/send_packet.py +++ b/integration/send_packet.py @@ -1,3 +1,9 @@ +# UsbSerial test: Sending single packet +# args: +# port (eg /dev/ttyUSB0) +# size in bytes (eg 1024) +# speed in bauds (eg 115200) + import serial import sys import os diff --git a/integration/validate_serial_tx.py b/integration/validate_serial_tx.py index 4fec419..ce298d1 100644 --- a/integration/validate_serial_tx.py +++ b/integration/validate_serial_tx.py @@ -1,3 +1,9 @@ +# UsbSerial test: Validate single packet +# args: +# port (eg /dev/ttyUSB0) +# size in bytes (eg 1024) +# speed in bauds (eg 115200) + import serial import sys import os diff --git a/integrationapp/src/main/java/com/felhr/integrationapp/UsbService.java b/integrationapp/src/main/java/com/felhr/integrationapp/UsbService.java index c05fd86..54f3813 100644 --- a/integrationapp/src/main/java/com/felhr/integrationapp/UsbService.java +++ b/integrationapp/src/main/java/com/felhr/integrationapp/UsbService.java @@ -58,7 +58,7 @@ public class UsbService extends Service { public static final int CTS_CHANGE = 1; public static final int DSR_CHANGE = 2; private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION"; - private static final int BAUD_RATE = 9600; // BaudRate. Change this value if you need + private static final int BAUD_RATE = 115200; // BaudRate. Change this value if you need public static boolean SERVICE_CONNECTED = false; private IBinder binder = new UsbBinder(); @@ -90,7 +90,7 @@ public class UsbService extends Service { if(buffer.size() == SIZE_TEST_2){ serialPort.write(buffer.readByteArray()); mode = TEST_3; - mHandler.obtainMessage(MESSAGE_TEST_2, "Test 3Kb completed correctly").sendToTarget(); + mHandler.obtainMessage(MESSAGE_TEST_2, "Test 2Kb completed correctly").sendToTarget(); } }else if(mode.equals(TEST_3)){