Skip to content

Commit be0fce9

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

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

ports/unix/main.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "py/gc.h"
4646
#include "py/objstr.h"
4747
#include "py/cstack.h"
48+
#include "py/mperrno.h"
4849
#include "py/mphal.h"
4950
#include "py/mpthread.h"
5051
#include "extmod/misc.h"
@@ -548,7 +549,14 @@ MP_NOINLINE int main_(int argc, char **argv) {
548549
MP_OBJ_NEW_QSTR(MP_QSTR__slash_),
549550
};
550551
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.
551556
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+
}
552560
}
553561
#endif
554562

@@ -803,3 +811,22 @@ void nlr_jump_fail(void *val) {
803811
fprintf(stderr, "FATAL: uncaught NLR %p\n", val);
804812
exit(1);
805813
}
814+
815+
#if MICROPY_VFS_ROM_IOCTL
816+
817+
static uint8_t romfs_buf[4] = { 0xd2, 0xcd, 0x31, 0x00 }; // empty ROMFS
818+
static const MP_DEFINE_MEMORYVIEW_OBJ(romfs_obj, 'B', 0, sizeof(romfs_buf), romfs_buf);
819+
820+
mp_obj_t mp_vfs_rom_ioctl(size_t n_args, const mp_obj_t *args) {
821+
switch (mp_obj_get_int(args[0])) {
822+
case MP_VFS_ROM_IOCTL_GET_NUMBER_OF_SEGMENTS:
823+
return MP_OBJ_NEW_SMALL_INT(1);
824+
825+
case MP_VFS_ROM_IOCTL_GET_SEGMENT:
826+
return MP_OBJ_FROM_PTR(&romfs_obj);
827+
}
828+
829+
return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL);
830+
}
831+
832+
#endif

ports/unix/variants/coverage/mpconfigvariant.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@
4141
#define MICROPY_DEBUG_PARSE_RULE_NAME (1)
4242
#define MICROPY_TRACKED_ALLOC (1)
4343
#define MICROPY_WARNINGS_CATEGORY (1)
44+
#undef MICROPY_VFS_ROM_IOCTL
45+
#define MICROPY_VFS_ROM_IOCTL (1)
4446
#define MICROPY_PY_CRYPTOLIB_CTR (1)

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