Skip to content

Commit c82fd42

Browse files
committed
tests/ports/psoc6: Debug fs_basic test.
Signed-off-by: NikhitaR-IFX <nikhita.rajasekhar@infineon.com>
1 parent 52edf7a commit c82fd42

2 files changed

Lines changed: 60 additions & 17 deletions

File tree

tests/ports/psoc6/mp_custom/fs.py

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@
77
logger = logging.getLogger("fs")
88
logging.basicConfig(format="%(levelname)s: %(message)s", encoding="utf-8", level=logging.WARNING)
99

10-
device = sys.argv[1]
10+
'''device = sys.argv[1]
1111
test_type = sys.argv[2]
12-
mem_type = sys.argv[3]
12+
mem_type = sys.argv[3]'''
13+
14+
device = "/dev/ttyACM1"
15+
test_type = "basic"
16+
mem_type = "flash"
17+
1318

1419
test_input_dir = "./ports/psoc6/inputs"
1520
test_script_dir = "./ports/psoc6/mp_custom"
1621
curr_dir = os.getcwd()
1722
print(f"Current directory: {curr_dir}")
1823

24+
mpremote = "~/MPY/micropython/tools/mpremote/mpremote.py"
25+
1926

2027
# List of mpremote commands
21-
mpr_connect = f"../tools/mpremote/mpremote.py connect {device}"
28+
# mpr_connect = f"{mpremote} connect {device}"
2229
mpr_run_script = ""
2330

2431
# Remote directory path
@@ -157,14 +164,9 @@ def copy_files(input_cp_files):
157164
cp_sub_cmd += f"cp {test_input_dir}/{file} :{remote_directory_path}{append_cmd_operand}"
158165

159166
cp_cmd = f"{mpr_connect} {mpr_run_script} {cp_sub_cmd}"
160-
cp_cmd = f"{mpr_connect}"
161-
162-
ls_cmd = f"ls -l ./ports/psoc6/inputs"
163167

164168
logger.debug(f"cp_files command: {cp_cmd}")
165169

166-
print("Check if file is available: ", subprocess.run(ls_cmd, shell=True, capture_output=True))
167-
168170
print("Copying files...", subprocess.run(cp_cmd, shell=True, capture_output=True))
169171

170172

@@ -192,7 +194,7 @@ def validate_test(files, file_sizes):
192194
def cp_files_test(input_files, input_files_size):
193195
rm_files_if_exist(input_files)
194196
copy_files(input_files)
195-
validate_test(input_files, input_files_size)
197+
# validate_test(input_files, input_files_size)
196198

197199

198200
def large_file_tests(device, test_type, mem_type):
@@ -204,13 +206,54 @@ def large_file_tests(device, test_type, mem_type):
204206
cp_files_test(input_files, input_files_size)
205207

206208

207-
def connect_to_dev_test():
208-
print("Connecting to device...")
209+
def copy_files_to_dev(cmd, file):
210+
mpr_cp = f"{mpr_connect} fs cp {file} :/"
211+
print("Copying files...", subprocess.run(mpr_cp, shell=True, capture_output=True))
212+
213+
214+
# Function to find the micropython project root directory
215+
def find_micropython_root(start_path="/"):
216+
for root, dirs, files in os.walk(start_path):
217+
if os.path.basename(root) == "micropython":
218+
return root
219+
return None
220+
221+
222+
# Function to search for a file within the micropython project directory
223+
def find_file_in_micropython(root_dir, filename):
224+
for root, dirs, files in os.walk(root_dir):
225+
if filename in files:
226+
return os.path.join(root, filename)
227+
return None
209228

210-
mpr_connect_ls = f"{mpr_connect} fs ls"
211-
print(subprocess.run(f"{mpr_connect_ls}", shell=True, capture_output=True))
212-
# print(subprocess.run(f"{mpr_connect}", shell=True, capture_output=True))
213229

230+
# Main script logic
231+
if __name__ == "__main__":
232+
# Find the micropython project root starting from the root of the filesystem
233+
root_dir = find_micropython_root(start_path="/")
234+
235+
if root_dir is None:
236+
print("micropython directory not found")
237+
else:
238+
print(f"Found micropython project root at: {root_dir}")
239+
240+
filename = "mpremote.py"
241+
mpremote = find_file_in_micropython(root_dir, filename)
242+
243+
if mpremote:
244+
print(f"File found at: {mpremote}")
245+
else:
246+
print(f"File {filename} not found in the micropython project.")
247+
248+
mpr_connect = f"{mpremote} connect {device}"
249+
250+
ip_file = "test_fs_small_file.txt"
251+
test_ip = find_file_in_micropython(root_dir, ip_file)
252+
253+
mpr_cp = f"{mpr_connect} fs cp {test_ip} :/"
254+
print("Copying files...", subprocess.run(mpr_cp, shell=True, capture_output=True))
214255

215256
# connect_to_dev_test()
216-
large_file_tests(device, test_type, mem_type)
257+
# large_file_tests(device, test_type, mem_type)
258+
259+
# copy_files_to_dev()

tests/ports/psoc6/run_psoc6_tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ mpremote_vfs_large_file_tests() {
161161
echo
162162
echo "running tests : vfs large files"
163163
echo
164-
chmod 777 ${tests_psoc6_dir}/mp_custom/fs_test.py
164+
chmod 777 ${tests_psoc6_dir}/mp_custom/fs.py
165165

166166
# On device file saving tests for medium and large size takes considerable
167167
# amount of time. Hence only when needed, this should be triggered.
@@ -170,7 +170,7 @@ mpremote_vfs_large_file_tests() {
170170
enable_adv_tests="adv"
171171
fi
172172

173-
python3 ${tests_psoc6_dir}/mp_custom/fs_test.py --device ${dev_test} --test_type ${enable_adv_tests} --mem_type ${storage_device}
173+
python3 ${tests_psoc6_dir}/mp_custom/fs.py --device ${dev_test} --test_type ${enable_adv_tests} --mem_type ${storage_device}
174174

175175
update_test_result $?
176176
}

0 commit comments

Comments
 (0)