Skip to content

Commit 17068bd

Browse files
jaenrig-ifxactions-user
authored andcommitted
ports/psoc6/mp_custom/fs.py: Added logger and fixed ls line end split.
Signed-off-by: enriquezgarc <enriquezgarcia.external@infineon.com>
1 parent 3b1b933 commit 17068bd

File tree

1 file changed

+33
-3
lines changed
  • tests/ports/psoc6/mp_custom

1 file changed

+33
-3
lines changed

tests/ports/psoc6/mp_custom/fs.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import subprocess
22
import sys
33
import os
4+
import logging
5+
6+
logger = logging.getLogger("fs")
7+
logging.basicConfig(format="%(levelname)s: %(message)s", encoding="utf-8", level=logging.WARNING)
48

59
device = sys.argv[1]
610
test_type = sys.argv[2]
@@ -24,6 +28,8 @@ def set_mpr_run_script(mem_type):
2428
if mem_type == "sd":
2529
mpr_run_script = f"run {test_script_dir}/fs_mount_sd.py"
2630

31+
logger.debug(f'Set setup script command to: "{mpr_run_script}"')
32+
2733

2834
def set_remote_dir_path(mem_type):
2935
# Set test directory path based on the memory type
@@ -33,6 +39,8 @@ def set_remote_dir_path(mem_type):
3339
else:
3440
remote_directory_path = "/"
3541

42+
logger.debug(f'Set remote path to : "{mpr_run_script}"')
43+
3644

3745
def get_test_input_files(test_type):
3846
# The "basic" test uses only the small file
@@ -57,27 +65,35 @@ def get_test_name(test_type, mem_type):
5765
elif mem_type == "flash":
5866
mem_type_suffix = ""
5967

68+
logger.debug(f"Get tests name : fs_{test_type}{mem_type_suffix}.py")
69+
6070
return f"fs_{test_type}{mem_type_suffix}.py"
6171

6272

6373
def ls_files(files):
74+
logger.debug(f"ls_files input: {files}")
6475
# It will return an array with the file size found in the remote directory
6576
# If -1, the file was not found
6677
mpr_ls = f"{mpr_connect} {mpr_run_script} fs ls {remote_directory_path}"
78+
logger.debug(f"ls_files command: {mpr_ls}")
6779
output = subprocess.run(f"{mpr_ls}", shell=True, capture_output=True)
6880

6981
files_result = []
70-
lines = output.stdout.decode().split("\r\n")
82+
lines = output.stdout.decode().split("\n")
83+
logger.debug(f"ls_files output lines: {lines}")
7184

7285
for file in files:
7386
file_size = -1
7487
for line in lines:
7588
line = line.split()
89+
logger.debug(f"ls_files current processed line: {line}")
7690
if file in line:
7791
file_size = line[0]
92+
logger.debug(f"ls_files found file: {file} with size {file_size}")
7893

7994
files_result.append(file_size)
8095

96+
logger.debug(f"ls_files result: {files_result}")
8197
return files_result
8298

8399

@@ -87,6 +103,8 @@ def rm_files(files):
87103
# ../tools/mpremote/mpremote.py connect /dev/ttyACM0 fs rm /test_fs_medium_file.txt + fs rm /test_fs_medium_file.txt
88104
mpr_rm = f"{mpr_connect} {mpr_run_script} fs rm "
89105

106+
logger.debug(f"rm_files command: {mpr_rm}")
107+
90108
rm_sub_cmd = ""
91109
last_file = files[-1]
92110
for file in files:
@@ -96,23 +114,31 @@ def rm_files(files):
96114

97115
rm_sub_cmd += f"fs rm {remote_directory_path}{file}{append_cmd_operand}"
98116

99-
subprocess.run(f"{mpr_connect} {mpr_run_script} {rm_sub_cmd}", shell=True, capture_output=True)
117+
mpr_rm_cmd = f"{mpr_connect} {mpr_run_script} {rm_sub_cmd}"
118+
119+
logger.debug(f"rm_files command: {mpr_rm_cmd}")
120+
121+
subprocess.run(f"{mpr_rm_cmd}", shell=True, capture_output=True)
100122

101123

102124
def rm_files_if_exist(files):
103125
matches = ls_files(files)
126+
logger.debug(f"Files (to be removed) found: {matches}")
104127

105128
# Take only the files that which sizes are not -1 (the existing files in the remote directory)
106129
existing_files = []
107130
for i in range(len(matches)):
108131
if matches[i] != -1:
109132
existing_files.append(files[i])
110133

134+
logger.debug(f"Existing (to be removed) files: {existing_files}")
135+
111136
# Remove any found input files in the remote directory
112137
if existing_files != []:
113138
print(f"Removing existing files...")
114139
rm_files(existing_files)
115-
if ls_files(files) == [-1 for _ in range(len(files))]:
140+
matches = ls_files(files)
141+
if matches == [-1 for _ in range(len(files))]:
116142
print(f"Existing files removed.")
117143

118144

@@ -129,6 +155,8 @@ def copy_files(input_cp_files):
129155

130156
cp_cmd = f"{mpr_connect} {mpr_run_script} {cp_sub_cmd}"
131157

158+
logger.debug(f"cp_files command: {cp_cmd}")
159+
132160
subprocess.run(cp_cmd, shell=True, capture_output=True)
133161

134162

@@ -137,6 +165,8 @@ def validate_test(files, file_sizes):
137165
# in the remote directory with the expected file sizes
138166
found_sizes = ls_files(files)
139167

168+
logger.debug(f"Found sizes: {found_sizes}")
169+
140170
if found_sizes != file_sizes:
141171
msg = "fail"
142172
exit_code = 1

0 commit comments

Comments
 (0)