Skip to content

Commit ffcc0f6

Browse files
committed
unix/main: Add coverage test for mounting ROMFS filesystem at startup.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 10714de commit ffcc0f6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

ports/unix/main.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,14 @@ MP_NOINLINE int main_(int argc, char **argv) {
549549
MP_OBJ_NEW_QSTR(MP_QSTR__slash_),
550550
};
551551
mp_vfs_mount(2, args, (mp_map_t *)&mp_const_empty_map);
552+
553+
// Make sure the root that was just mounted is the current VFS (it's always at
554+
// the end of the linked list). Can't use chdir('/') because that will change
555+
// the current path within the VfsPosix object.
552556
MP_STATE_VM(vfs_cur) = MP_STATE_VM(vfs_mount_table);
557+
while (MP_STATE_VM(vfs_cur)->next != NULL) {
558+
MP_STATE_VM(vfs_cur) = MP_STATE_VM(vfs_cur)->next;
559+
}
553560
}
554561
#endif
555562

@@ -805,6 +812,21 @@ void nlr_jump_fail(void *val) {
805812
exit(1);
806813
}
807814

815+
#if defined(MICROPY_UNIX_COVERAGE)
816+
static uint8_t romfs_buf[4] = { 0xd2, 0xcd, 0x31, 0x00 }; // empty ROMFS
817+
static const MP_DEFINE_MEMORYVIEW_OBJ(romfs_obj, 'B', 0, sizeof(romfs_buf), romfs_buf);
818+
#endif
819+
808820
mp_obj_t mp_vfs_rom_ioctl(size_t n_args, const mp_obj_t *args) {
821+
#if defined(MICROPY_UNIX_COVERAGE)
822+
switch (mp_obj_get_int(args[0])) {
823+
case MP_VFS_ROM_IOCTL_GET_NUMBER_OF_SEGMENTS:
824+
return MP_OBJ_NEW_SMALL_INT(1);
825+
826+
case MP_VFS_ROM_IOCTL_GET_SEGMENT:
827+
return MP_OBJ_FROM_PTR(&romfs_obj);
828+
}
829+
#endif
830+
809831
return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL);
810832
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy