Skip to content

Commit

Permalink
tests/psoc6: Final changes for fs tests.
Browse files Browse the repository at this point in the history
Signed-off-by: NikhitaR-IFX <Nikhita.Rajasekhar@infineon.com>
  • Loading branch information
NikhitaR-IFX committed Feb 21, 2024
1 parent 302fc27 commit 149934f
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 37 deletions.
28 changes: 24 additions & 4 deletions ports/psoc6/psoc6_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,38 @@ STATIC psoc6_flash_obj_t psoc6_flash_obj = {
cyhal_flash_t cyhal_flash_obj;
cyhal_flash_info_t flash_info;

// Helper function to get external flash configurations
// Helper function to get internal flash configurations
void get_flash_info(void) {
mplogger_print("\nRetrieving internal flash info...\n");
cyhal_flash_get_info(&cyhal_flash_obj, &flash_info);
// mplogger_print("\nTotal flash size (MB): %d\n", cy_serial_flash_qspi_get_size() / (1024 * 1024));
// mplogger_print("\nSize of erase sector (bytes): %d\n", cy_serial_flash_qspi_get_erase_size(0x00) / (1024));
// mplogger_print("\nPage size (bytes): %d\n", cy_serial_flash_qspi_get_prog_size(0x00));
/* Wait for 100ms for the flash write to complete */
uint32_t timeout = 100;
/* Wait for the command to finish execution */
while ((true != cyhal_flash_is_operation_complete(&cyhal_flash_obj)) && (0 < timeout)) {
timeout--;
cyhal_system_delay_ms(1); /* delay one millisecond each iteration */
}
uint32_t total_flash_size = 0;
uint32_t page_size = 0;
if (0 != timeout) {
for (int index = 0; index < flash_info.block_count; index++)
{
const cyhal_flash_block_info_t *block_info = flash_info.blocks;
total_flash_size += block_info->size;
page_size = block_info->page_size;
}
}

mplogger_print("\nTotal flash size (MB): %ld\n", total_flash_size / (1024 * 1024));
mplogger_print("\nTotal no. of blocks: %d\n", flash_info.block_count);
mplogger_print("\nPage size (bytes): %ld\n", page_size);
}

STATIC mp_obj_t psoc6_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
mplogger_print("\nFlash constructor invoked\n");
#if MICROPY_LOGGER_DEBUG
get_flash_info();
#endif

cy_rslt_t result = CY_RSLT_SUCCESS;

Expand Down
2 changes: 2 additions & 0 deletions ports/psoc6/psoc6_qspi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ void get_ext_flash_info(void) {

STATIC mp_obj_t psoc6_qspi_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
mplogger_print("\nQSPI flash constructor invoked\n");
#if MICROPY_LOGGER_DEBUG
get_ext_flash_info();
#endif

cy_rslt_t result = CY_RSLT_SUCCESS;

Expand Down
37 changes: 4 additions & 33 deletions tests/psoc6/run_psoc6_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -259,49 +259,20 @@ if [ ${fs} -eq 1 ]; then
echo
echo " done."
echo

chmod 777 ./psoc6/test_scripts/fs.py

echo " attempting to save different test files in flash "
echo
echo " saving test_fs_small_file.txt to FS - (size : 10KB) "

command_output=$( ../tools/mpremote/mpremote.py connect ${device0} cp ./psoc6/test_inputs/test_fs_small_file.txt :/)
exp_output="cp ./psoc6/test_inputs/test_fs_small_file.txt :/"
if [ "$command_output" != "$exp_output" ]; then
echo "Error: Cannot save small file."
exit 1
fi
python3 ./psoc6/test_scripts/fs.py ${device0} 0

# On device file saving tests for medium and large size takes considerable amount of time. Hence only when needed, this should be triggered.
if [ ${afs} -eq 1 ]; then

echo " saving test_fs_medium_file.txt to FS - (size : 500KB) "
command_output=$(../tools/mpremote/mpremote.py connect ${device0} cp ./psoc6/test_inputs/test_fs_medium_file.txt :/)
exp_output="cp ./psoc6/test_inputs/test_fs_medium_file.txt :/"
if [ "$command_output" != "$exp_output" ]; then
echo "Error: Cannot save medium file."
exit 1
fi

echo " saving test_fs_large_file.txt to FS - (size : 1MB) "
command_output=$(../tools/mpremote/mpremote.py connect ${device0} cp ./psoc6/test_inputs/test_fs_large_file.txt :/)
exp_output="cp ./psoc6/test_inputs/test_fs_large_file.txt :/"
if [ "$command_output" != "$exp_output" ]; then
echo "Error: Cannot save large file."
exit 1
fi

python3 ./psoc6/test_scripts/fs.py ${device0} 1
fi

echo
echo " done."
echo

fi


if [ ${implemented} -eq 1 ]; then


echo " running implemented tests ..."
echo

Expand Down
80 changes: 80 additions & 0 deletions tests/psoc6/test_scripts/fs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import subprocess
import sys

device = sys.argv[1]
test_type = sys.argv[2]

# local and remote(MPY device) paths
local_small_file_path = "./psoc6/test_inputs/test_fs_small_file.txt"
local_medium_file_path = "./psoc6/test_inputs/test_fs_medium_file.txt"
local_large_file_path = "./psoc6/test_inputs/test_fs_large_file.txt"
remote_directory_path = "/"

# out and exp file paths
basic_test_op_fp = "./psoc6/test_scripts/results/fs_basic.py.out"
adv_test_op_fp = "./psoc6/test_scripts/results/fs_adv.py.out"
exp_basic_op_fp = "./psoc6/test_scripts/fs_basic.py.exp"
exp_adv_op_fp = "./psoc6/test_scripts/fs_adv.py.exp"

# List of mpremote commands
mpr_connect = f"../tools/mpremote/mpremote.py connect {device}"
mpr_small_file_cp = f"{mpr_connect} cp {local_small_file_path} :{remote_directory_path}"
mpr_medium_file_cp = f"{mpr_connect} cp {local_medium_file_path} :{remote_directory_path}"
mpr_large_file_cp = f"{mpr_connect} cp {local_large_file_path} :{remote_directory_path}"
mpr_ls = f"{mpr_connect} fs ls /"
mpr_rm = f"{mpr_connect} fs rm "


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:
print(op_file_path)
with open(op_file_path, "a") as file:
subprocess.call(cmd, shell=True, stdout=file)


def validate_test(op, exp_op):
with open(op, "r") as output_file:
output = output_file.read()

with open(exp_op, "r") as exp_output_file:
exp_output = exp_output_file.read()

if output == exp_output:
print("Operation failed!")
sys.exit(1)
else:
print("Operation successful!")


def fs_basic_test():
print("Running basic test")
print("Saving small file - 10KB")
exec(mpr_rm, "test_fs_small_file.txt")
exec(mpr_small_file_cp, basic_test_op_fp)
validate_test(basic_test_op_fp, exp_basic_op_fp)


def fs_adv_test():
print("Running advance test")
print("Saving small files - 10KB")
exec(mpr_rm, "test_fs_small_file.txt")
exec(mpr_small_file_cp, adv_test_op_fp)
print("Saving medium files - 500KB")
exec(mpr_rm, "test_fs_medium_file.txt")
exec(mpr_medium_file_cp, adv_test_op_fp)
print("Saving large files - 1MB")
exec(mpr_rm, "test_fs_large_file.txt")
exec(mpr_large_file_cp, adv_test_op_fp)
validate_test(adv_test_op_fp, exp_adv_op_fp)


if test_type == "0":
fs_basic_test()
if test_type == "1":
fs_adv_test()
3 changes: 3 additions & 0 deletions tests/psoc6/test_scripts/fs_adv.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cp ./psoc6/test_inputs/test_fs_small_file.txt :/
cp ./psoc6/test_inputs/test_fs_medium_file.txt :/
cp ./psoc6/test_inputs/test_fs_large_file.txt :/
1 change: 1 addition & 0 deletions tests/psoc6/test_scripts/fs_basic.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cp ./psoc6/test_inputs/test_fs_small_file.txt :/

0 comments on commit 149934f

Please sign in to comment.