release of integration tests

pull/217/head
Felipe Herranz 2019-03-03 18:01:46 +01:00
rodzic 121598728b
commit bd350b618e
5 zmienionych plików z 44 dodań i 5 usunięć

Wyświetl plik

@ -1,2 +1,24 @@
UsbSerial Integration Tests
===========================
===========================
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)

Wyświetl plik

@ -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)

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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)){