NPU plugin test /dev - #1
Draft
wangixt wants to merge 5 commits into
Draft
Conversation
wangixt
commented
Mar 11, 2026
Owner


Mount namespaces alone do NOT isolate filesystem data operations on the
underlying storage -- they only isolate mount/unmount event propagation.
When the unit test unmounted the tmpfs overlay on /dev and then continued
to create/delete files, those operations hit the real host /dev directory,
corrupting it (leaving only a regular file 'null' instead of the expected
device nodes).
Replace the mount-namespace-only approach with a chroot-based isolated
test environment:
1. Create a new mount namespace with private propagation.
2. Mount a tmpfs as the new root directory.
3. Mount a separate tmpfs on /dev within the new root (so tests can
safely umount+rmdir /dev without exposing the host filesystem).
4. Create basic device nodes (null, zero, full).
5. Mount procfs for /proc/self/fd/ resolution.
6. Bind-mount the build directory for gcov data persistence.
7. chroot() into the new root.
After chroot, ALL path-based operations resolve within the tmpfs tree,
making it impossible to corrupt the host /dev regardless of what the
tests do with mount/umount/rmdir/mknod inside the chroot.
Also add comprehensive stubs (print_on_level, log_get_loglevel,
criu_get_image_dir, cr_system, npu_ut_set_img_dirfd) to the stubs
file so the test binary can link standalone without the full CRIU
library.
Co-authored-by: wangixt <wangixt@users.noreply.github.com>
|
Cursor Agent can help with this pull request. Just |
npu_ut_set_img_dirfd(), criu_get_image_dir(), cr_system(), print_on_level(), and log_get_loglevel() are already provided by npu_plugin.c under #ifdef NPU_PLUGIN_UT. Having them in the stubs file as well causes 'multiple definition' linker errors. Revert the stubs file to only contain the symbols that are NOT provided by npu_plugin.c: xmalloc/xfree family, strdup/getpwnam_r wrappers, and img_streamer_open. Co-authored-by: wangixt <wangixt@users.noreply.github.com>
Remove the #ifdef NPU_PLUGIN_UT block from npu_plugin.c entirely. The standard pr_* macros from log.h (which call print_on_level()) are now used in UT mode as well. All UT-specific symbols are provided by npu_plugin_ut_stubs.c: - print_on_level() / log_get_loglevel(): logging backend - criu_get_image_dir() / npu_ut_set_img_dirfd(): image dir control - cr_system(): command execution stub - xmalloc/xfree family, strdup/getpwnam_r wrappers, img_streamer_open Also update npu_plugin.c to the latest version with: - cached_npu_memfd / init_cached_memfd / close_cached_memfd - npu_plugin_update_inetsk with id parameter - #ifndef NPU_DEVICE guard Co-authored-by: wangixt <wangixt@users.noreply.github.com>
Move the chroot environment setup from C (setup_chroot_env()) to a
shell script (unit/run_ut_chroot.sh). This is simpler and cleaner:
run_ut_chroot.sh:
1. Re-execs inside unshare --mount --propagation private
2. Creates tmpfs root + /dev (separate tmpfs) + /tmp + /run + /proc
3. Creates device nodes: null, zero, full
4. Bind-mounts shared library dirs (auto-detected via ldd)
5. Bind-mounts build directory for gcov .gcda persistence
6. chroot + exec test binary
npu_plugin_ut.c:
- Removed ~120 lines of setup_chroot_env() / mkdirs_for_path()
- main() just sets devns_entered=1 (already inside chroot)
- enter_private_dev_namespace() is a no-op when devns_entered=1
Makefile:
- unit-run calls: bash unit/run_ut_chroot.sh ./unit/npu_plugin_ut
Co-authored-by: wangixt <wangixt@users.noreply.github.com>
The plugin's npu_plugin_update_vmamap() calls memfd_create() on every invocation (no caching). Under FD pressure memfd_create() fails and returns -ENOTSUP, not -1 (which would come from fcntl F_DUPFD_CLOEXEC in a cached-memfd design). Update the assertion accordingly. Co-authored-by: wangixt <wangixt@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.