Skip to content

testing/libc/sysconf: Add a test of sysconf() - #4022

Merged
acassis merged 1 commit into
apache:masterfrom
casaroli:apps-sysconf-test-up
Nov 13, 2026
Merged

acassis merged 1 commit into
apache:masterfrom
casaroli:apps-sysconf-test-up

Conversation

@casaroli

@casaroli casaroli commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

depends-on: /pull/4033

Summary

This PR adds testing/libc/sysconf (sysconf_test), a test of sysconf():

  • Each name of <unistd.h> gives a value, or -1 with errno unchanged.
  • -1, INT_MIN and INT_MAX give -1 with EINVAL.
  • Each limit with a constant in <limits.h>, <signal.h> or <time.h> gives the value of the constant (ARG_MAX, HOST_NAME_MAX, IOV_MAX, LINE_MAX, PTHREAD_KEYS_MAX, NSIG, CLK_TCK, ...).
  • Each option with a macro in <unistd.h> gives the value of the macro. A macro of 0 means "ask sysconf()": the test then accepts any value.
  • _SC_OPEN_MAX is the RLIMIT_NOFILE soft limit; _SC_PAGE_SIZE is _SC_PAGESIZE and > 0; _SC_NPROCESSORS_ONLN is from 1 to _SC_NPROCESSORS_CONF; _SC_AVPHYS_PAGES is from 0 to _SC_PHYS_PAGES; at most one C compilation environment gives 1, and _SC_V7_*, _SC_V8_* give the same as _SC_V6_*.

The program prints each error and sysconf test: <names> names, <errors> errors, and returns EXIT_FAILURE if there is an error. The names that only apache/nuttx#21674 defines are under #ifdef, so the test also builds on older nuttx.

Impact

Test only. New option CONFIG_TESTING_SYSCONF, default n like the other tests in testing/libc.

Testing

QEMU with HVF, 1 CPU. knsh: kernel build, the program from /system/bin. nsh: flat build, the program as a builtin.

Configuration nuttx master 03aea786390 nuttx with apache/nuttx#21674
qemu-armv8a:knsh 126 names, 144 errors 139 names, 0 errors
qemu-armv8a:nsh 126 names, 143 errors 139 names, 0 errors
qemu-armv8a:knsh and :nsh with PRIORITY_INHERITANCE, PRIORITY_PROTECT, FS_LARGEFILE, TLS_NELEM=8, LIBC_REGEX 139 names, 0 errors; _SC_THREAD_PRIO_INHERIT, _SC_THREAD_PRIO_PROTECT, both _SC_THREAD_ROBUST_PRIO_* and _SC_REGEXP 201712, _SC_THREAD_KEYS_MAX 8, _SC_V6_LP64_OFF64 1 (knsh)
mps2-an500:knsh (protected, QEMU TCG) 139 names, 0 errors

On master, 106 valid names and the invalid names give -1 with ENOSYS, so the test sees an error for each of them and for each constant that sysconf() does not give.

On Linux (glibc 2.43, Fedora, gcc, the same source with FAR and nitems() defined): 132 names, 4 errors. glibc gives EINVAL for 3 valid names (_SC_SS_REPL_MAX, _SC_THREAD_ROBUST_PRIO_INHERIT, _SC_THREAD_ROBUST_PRIO_PROTECT) and has more than one compilation environment (multilib).

CMake (Ninja) build of qemu-armv8a:nsh with the test: OK, no compiler warning in the test.

tools/checkpatch.sh -c -u -m -g origin/master..HEAD passes.

Check that sysconf() gives a value, or -1 with errno unchanged, for each
name of <unistd.h>, and -1 with EINVAL for a name that is not valid.
Check that the names of a limit or an option give the value of its
constant in <limits.h>, <signal.h>, <time.h> or <unistd.h>, that
_SC_OPEN_MAX is the RLIMIT_NOFILE soft limit, and that the processor,
page and compilation environment names give sane values.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx-apps/actions/runs/43134384184

@casaroli
casaroli marked this pull request as draft November 12, 2026 14:09
@casaroli
casaroli marked this pull request as ready for review November 12, 2026 14:09
@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx-apps/actions/runs/43234323732

@casaroli
casaroli marked this pull request as draft November 13, 2026 09:31
@casaroli
casaroli marked this pull request as ready for review November 13, 2026 09:31
@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx-apps/actions/runs/43402001594

@acassis
acassis merged commit 674510b into apache:master Nov 13, 2026
142 of 283 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants