From ba939cf725052fe563046fbee58ed576b1414b4c Mon Sep 17 00:00:00 2001 From: IFX-Anusha Date: Wed, 20 Mar 2024 18:41:59 +0530 Subject: [PATCH] ports/psoc6: Bitstream Tests. Signed-off-by: IFX-Anusha --- tests/psoc6/bitstream_listen.py | 39 +++++++++++++++++++++++++++++ tests/psoc6/bitstream_listen.py.exp | 17 +++++++++++++ tests/psoc6/run_psoc6_tests.sh | 28 ++++++++++++++++++++- tests/psoc6/test_inputs/main.py | 27 ++++++++++++++++++++ tests/psoc6/test_scripts/bit.py | 36 ++++++++++++++++++++++++++ 5 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 tests/psoc6/bitstream_listen.py create mode 100644 tests/psoc6/bitstream_listen.py.exp create mode 100755 tests/psoc6/test_inputs/main.py create mode 100755 tests/psoc6/test_scripts/bit.py diff --git a/tests/psoc6/bitstream_listen.py b/tests/psoc6/bitstream_listen.py new file mode 100644 index 0000000000000..60686a0c7baff --- /dev/null +++ b/tests/psoc6/bitstream_listen.py @@ -0,0 +1,39 @@ +import os +import time +from machine import Pin +from machine import bitstream + +# Allocate pin based on board +machine = os.uname().machine +if "CY8CPROTO-062-4343W" in machine: + pin_in = 'P12_0' + pin_out = 'P13_7' + +elif "CY8CPROTO-063-BLE" in machine: + pin_in = 'P5_3' + pin_out = 'P12_6' + +expected_values = [8000, 5000, 8000, 5000, 8000, 50000, 8000, 5000, 3000, 1000, 3000, 10000, 3000, 1000, 3000, 1000] +tolerance = 100 + +print("bitstream capture") +input_pin = Pin(pin_in, Pin.IN) +periods = [] +last_value = 0 +p0 = Pin(pin_out, Pin.OUT, value=0) +start_time = time.ticks_us() +current_value =0 +for i in range(17): + while (current_value == last_value): + current_value=input_pin.value() + current_time = time.ticks_us() + time_period = time.ticks_diff(current_time, start_time) + last_value=current_value + start_time=current_time + periods.append(time_period) + +for i in range(len(periods)-1): + if abs((periods[i+1] - expected_values[i]) <= tolerance): + print("true") + else: + print("false") \ No newline at end of file diff --git a/tests/psoc6/bitstream_listen.py.exp b/tests/psoc6/bitstream_listen.py.exp new file mode 100644 index 0000000000000..459ca4bca8c00 --- /dev/null +++ b/tests/psoc6/bitstream_listen.py.exp @@ -0,0 +1,17 @@ +bitstream capture +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true diff --git a/tests/psoc6/run_psoc6_tests.sh b/tests/psoc6/run_psoc6_tests.sh index 4a9a6e9100bc7..4aa5da63e2e2e 100755 --- a/tests/psoc6/run_psoc6_tests.sh +++ b/tests/psoc6/run_psoc6_tests.sh @@ -18,6 +18,7 @@ usage() { echo " -n run not yet implemented tests only" echo " -w run wifi tests => needs secrets.py key file>" echo " -v run virtual filesystem related tests. If followed by -x, runs advance tests too." + echo " -b run bitsream script." echo " --dev0 device to be used" echo " --dev1 second device to be used (for multi test)" echo " --psoc6 run only psoc6 port related tests" @@ -39,11 +40,14 @@ for arg in "$@"; do esac done -while getopts "acd:e:fhimnptwvx" o; do +while getopts "abcd:e:fhimnptwvx" o; do case "${o}" in a) all=1 ;; + b) + bitstream=1 + ;; c) cleanResultsDirectoryFirst=1 ;; @@ -135,6 +139,10 @@ if [ -z "${afs}" ]; then afs=0 fi +if [ -z "${bitstream}" ]; then + bitstream=0 +fi + if [ -z "${psoc6OnlyMulti}" ]; then psoc6OnlyMulti=0 fi @@ -431,6 +439,24 @@ if [ ${hwext} -eq 1 ]; then fi +if [ ${bitstream} -eq 1 ]; then + + echo " running bitstream tests ... " + echo + + chmod 777 ./psoc6/test_scripts/bit.py + + python3 ./psoc6/test_scripts/bit.py ${device0} 0 + + echo " running bitstream listen.." + + ./run-tests.py --target psoc6 --device ${device1} \ + \ + psoc6/bitstream_listen.py \ + |tee -a ${resultsFile} + +fi + ### not yet enabled/implemented, therefore failing if [ ${notYetImplemented} -eq 1 ]; then diff --git a/tests/psoc6/test_inputs/main.py b/tests/psoc6/test_inputs/main.py new file mode 100755 index 0000000000000..788922d7ae503 --- /dev/null +++ b/tests/psoc6/test_inputs/main.py @@ -0,0 +1,27 @@ +import sys +import time +import os +from machine import Pin +from machine import bitstream + + +# Allocate pin based on board +machine = os.uname().machine +if "CY8CPROTO-062-4343W" in machine: + gpio_pin = 'P12_1' + input_pin = 'P13_6' +elif "CY8CPROTO-063-BLE" in machine: + gpio_pin = 'P5_2' + input_pin = 'P12_7' + +print("bitstream execution") +timing = [3000000, 1000000, 8000000, 5000000] +buf = bytearray([0xF0]) +p0 = Pin(gpio_pin, Pin.OUT, value=0) +input_pin = Pin(input_pin, Pin.IN) +while(input_pin.value()==1): + pass +for i in range(2): + bitstream(p0, 0, timing, buf) + + diff --git a/tests/psoc6/test_scripts/bit.py b/tests/psoc6/test_scripts/bit.py new file mode 100755 index 0000000000000..982d0d36000b1 --- /dev/null +++ b/tests/psoc6/test_scripts/bit.py @@ -0,0 +1,36 @@ +import sys +import time +import os +import subprocess + +device = sys.argv[1] +file_location = "./psoc6/test_inputs/main.py" +remote_directory_path = "/" +mpr_connect = f"../tools/mpremote/mpremote.py connect {device}" +mpr_file_cp = f"{mpr_connect} cp {file_location} :{remote_directory_path}" +mpr_ls = f"{mpr_connect} fs ls /" +mpr_rm = f"{mpr_connect} fs rm " +mpr_reset =f"../tools/mpremote/mpremote.py reset" + +def exec(cmd, op_file_path="null"): + if cmd == mpr_rm: + # Check if file is present already + output = subprocess.run(f"{mpr_ls} | grep {op_file_path}", shell=True, capture_output=True) + # If the file is present, remove it + if output.returncode == 0: + subprocess.run(f"{cmd} {op_file_path}", shell=True, capture_output=False) + else: + with open(op_file_path, "a") as file: + subprocess.check_call(cmd, shell=True, stdout=file) + +#bistream generation + +print("copying file to remote device") +exec(mpr_rm, "main.py") +exec(mpr_file_cp) +print("Resest board") +subprocess.run(mpr_reset, shell=True) + + + +