diff --git a/usb_test/README.md b/usb_test/README.md new file mode 100644 index 00000000..a9e51739 --- /dev/null +++ b/usb_test/README.md @@ -0,0 +1,27 @@ +# USB Device mode Validation + +## Overview + +This folder contains script related to basic USB functionalities. + +1) usb_enum_win.py -> To check the enumeration of DUT in Windows host +2) usb_enum_linux.py -> To check the enumeration of DUT in Linux host + +## Prerequisites + +For Windows +1) Python 3 +2) pip install subprocess +3) Devcon + +For Linux +1) Python3 + +## Usage + +To run the script: python "filename" + +The script will prompt you to enter the PID. Enter the PID according to the variant of the meta. + +PID for ADV variant -> 9135 +PID for STD variant -> D002 diff --git a/usb_test/usb_enum_linux.py b/usb_test/usb_enum_linux.py new file mode 100644 index 00000000..e64663c3 --- /dev/null +++ b/usb_test/usb_enum_linux.py @@ -0,0 +1,14 @@ +import os + +def check_device_status(pid): + command = f'lsusb | grep -i {pid}' + if(os.system(command) == 0): + print("DUT is properly enumerated") + return True + else: + print("DUT is not found") + return False + +if __name__ == "__main__": + pid = input("Enter the PID of the device: ") + check_device_status(pid) \ No newline at end of file diff --git a/usb_test/usb_enum_win.py b/usb_test/usb_enum_win.py new file mode 100644 index 00000000..324b09af --- /dev/null +++ b/usb_test/usb_enum_win.py @@ -0,0 +1,48 @@ +import time +import subprocess + +def check_device_status(pid): + # Run the devcon status command with the given PID + command = f'devcon status *{pid}*' + result = subprocess.run(command, capture_output=True, universal_newlines=True, stdin=subprocess.DEVNULL,shell=True) + out, err = result.stdout, result.stderr + if out.find("The device has the following problem") != -1: + print("DUT Not properly enumerated. Might be some yellow bang on PCs Device Manager or still taking time to enumerate:{}".format(out)) + print('Checking for 2nd time after waiting for 10 sec') + time.sleep(10) + result = subprocess.run(command, capture_output=True, universal_newlines=True, stdin=subprocess.DEVNULL,shell=True) + out, err = result.stdout, result.stderr + if out.find("The device has the following problem") != -1: + print("DUT Not properly enumerated. Surely be some yellow bang on PCs Device Manager:{}".format(out)) + return False + elif out.find("Driver is running") != -1: + print("DUT is properly enumerated") + return True + else: + print("DUT is not found") + print(out) + return False + elif out.find("Driver is running") != -1: + print("DUT is properly enumerated") + return True + else: + print("DUT is not found") + print(out) + print('Checking for 2nd time after waiting for 10 secs') + time.sleep(10) + result = subprocess.run(command, capture_output=True, universal_newlines=True, stdin=subprocess.DEVNULL,shell=True) + out, err = result.stdout, result.stderr + if out.find("The device has the following problem") != -1: + print("DUT Not properly enumerated. Surely be some yellow bang on PCs Device Manager:{}".format(out)) + return False + elif out.find("Driver is running") != -1: + print("DUT is properly enumerated") + return True + else: + print("DUT is not found") + print(out) + return False + +if __name__ == "__main__": + pid = input("Enter the PID of the device: ") + check_device_status(pid)