Skip to content

Tests/posix-sysinfo#1788

Open
Momen-MKadry wants to merge 11 commits intounikraft:stagingfrom
Momen-MKadry:gsoc-poc
Open

Tests/posix-sysinfo#1788
Momen-MKadry wants to merge 11 commits intounikraft:stagingfrom
Momen-MKadry:gsoc-poc

Conversation

@Momen-MKadry
Copy link
Copy Markdown

@Momen-MKadry Momen-MKadry commented Mar 14, 2026

Description of Changes

  • Added unit tests for posix-sysinfo library
  • Following cases were covered:
Function Test Case What It Tests
sysinfo() sysinfo_no_info NULL pointer → returns -1
sysinfo_no_paging Valid call: verifies all fields (uptime, loads, totalram, freeram, procs, etc.)
sysinfo_with_paging Sets total_memory = __UL_MAX, verifies mem_unit, totalram, freeram
fpathconf() fpathconf Returns 0 (stub)
pathconf() pathconf Returns 0 (stub)
sysconf() sc_nprocessors_onln _SC_NPROCESSORS_ONLN → 1
sc_pagesize _SC_PAGESIZE__PAGE_SIZE
sc_phys_pages _SC_PHYS_PAGEStotal_memory / PAGE_SIZE
sc_avphys_pages _SC_AVPHYS_PAGESfree_memory / PAGE_SIZE
sc_open_max _SC_OPEN_MAXMAXFDS or 0
sc_getpw_r_size_max _SC_GETPW_R_SIZE_MAX → -1 or 0
sc_unkown_name Unknown name → 0 (fallthrough)
confstr() confstr Returns 0 (stub)
getpagesize() getpagesize Returns __PAGE_SIZE
uname() uname_null_buf NULL buffer → returns -1
uname_valid_buf Verifies all fields: sysname, nodename, release, version, machine
sethostname() sethostname_null_name NULL name → returns -1
sethostname_too_long_name Name exceeding nodename size → returns -1
sethostname_valid_name Sets "valid-name", verifies via uname(), restores
gethostname() gethostname_valid_case Valid buffer → returns 0, matches nodename
gethostname_buf_too_long Buffer too small → returns -1, errno == ENAMETOOLONG
getcpu() getcpu_valid Both cpu & node non-NULL → set to 0
getcpu_null_args Both NULL → returns 0, no crash
getcpu_partial Only cpu non-NULL → set to 0

AI usage note: I used AI mainly to understand existing code and navigate the codebase, and when I finished writing and reviewing the tests I asked for a coverage analysis to make sure nothing was missed and discussed findings with it but nothing was written without understanding it first.

Related Work

N/A

PR Checklist

  • Read the contribution guidelines regarding submitting new changes to the project;
  • Tested your changes against relevant architectures and platforms;
  • Ran the checkpatch.uk on your commit series before opening this PR;
  • Updated relevant documentation.

Fixed line spacing and long lines
1. Fixed trailing whitespace.
2. Added sign off.

Signed-off-by: Momen Kadry <kadry.momen6@proton.me>
I switched to CONFIG_HAVE_PAGING when testing and forgot reverting

Signed-off-by: Momen Kadry <kadry.momen6@proton.me>
Other changes I forgot to revert in sysinfo.c

Signed-off-by: Momen Kadry <kadry.momen6@proton.me>
@github-actions github-actions bot added area/lib Internal Unikraft Microlibrary lang/c Issues or PRs to do with C/C++ lib/posix-sysinfo labels Mar 14, 2026
Used sizeof instead of strlen to avoid possibility of overflow

Signed-off-by: Momen Kadry <kadry.momen6@proton.me>
Replaced pointer name with char array so we can use sizeof

Signed-off-by: Momen Kadry <kadry.momen6@proton.me>
Replaced pointer name with char array so we can use sizeof

Signed-off-by: Momen Kadry <kadry.momen6@proton.me>
…-poc

Merged

Signed-off-by: Momen Kadry <kadry.momen6@proton.me>
Added unlikely() attribute to rare cases in checks in sysinfo.c

Signed-off-by: Momen Kadry <kadry.momen6@proton.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/lib Internal Unikraft Microlibrary lang/c Issues or PRs to do with C/C++ lib/posix-sysinfo

Projects

Status: 🧊 Icebox

Development

Successfully merging this pull request may close these issues.

1 participant