Skip to content

Commit

Permalink
unix/main: Add coverage test for mounting ROMFS filesystem at startup.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Mar 6, 2025
1 parent 6bec36a commit be0fce9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ports/unix/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "py/gc.h"
#include "py/objstr.h"
#include "py/cstack.h"
#include "py/mperrno.h"
#include "py/mphal.h"
#include "py/mpthread.h"
#include "extmod/misc.h"
Expand Down Expand Up @@ -548,7 +549,14 @@ MP_NOINLINE int main_(int argc, char **argv) {
MP_OBJ_NEW_QSTR(MP_QSTR__slash_),
};
mp_vfs_mount(2, args, (mp_map_t *)&mp_const_empty_map);

// Make sure the root that was just mounted is the current VFS (it's always at
// the end of the linked list). Can't use chdir('/') because that will change
// the current path within the VfsPosix object.
MP_STATE_VM(vfs_cur) = MP_STATE_VM(vfs_mount_table);
while (MP_STATE_VM(vfs_cur)->next != NULL) {
MP_STATE_VM(vfs_cur) = MP_STATE_VM(vfs_cur)->next;
}
}
#endif

Expand Down Expand Up @@ -803,3 +811,22 @@ void nlr_jump_fail(void *val) {
fprintf(stderr, "FATAL: uncaught NLR %p\n", val);
exit(1);
}

#if MICROPY_VFS_ROM_IOCTL

static uint8_t romfs_buf[4] = { 0xd2, 0xcd, 0x31, 0x00 }; // empty ROMFS
static const MP_DEFINE_MEMORYVIEW_OBJ(romfs_obj, 'B', 0, sizeof(romfs_buf), romfs_buf);

mp_obj_t mp_vfs_rom_ioctl(size_t n_args, const mp_obj_t *args) {
switch (mp_obj_get_int(args[0])) {
case MP_VFS_ROM_IOCTL_GET_NUMBER_OF_SEGMENTS:
return MP_OBJ_NEW_SMALL_INT(1);

case MP_VFS_ROM_IOCTL_GET_SEGMENT:
return MP_OBJ_FROM_PTR(&romfs_obj);
}

return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL);
}

#endif
2 changes: 2 additions & 0 deletions ports/unix/variants/coverage/mpconfigvariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@
#define MICROPY_DEBUG_PARSE_RULE_NAME (1)
#define MICROPY_TRACKED_ALLOC (1)
#define MICROPY_WARNINGS_CATEGORY (1)
#undef MICROPY_VFS_ROM_IOCTL
#define MICROPY_VFS_ROM_IOCTL (1)
#define MICROPY_PY_CRYPTOLIB_CTR (1)

0 comments on commit be0fce9

Please sign in to comment.