772 Commits

Author SHA1 Message Date
Rob Landley
70f64e5a43 Fix missing error check for short patterns, and add tests.
Reported by Anton Kling.
2025-12-04 16:04:21 -06:00
Alex Kapranoff
1520fe6e9b vi: Support ZZ to save and exit 2025-11-19 11:46:03 -06:00
Elliott Hughes
e18fd82784 xargs: add --process-slot-var.
This also requires that we properly track child pids, so we can map
between pids and slots.
2025-11-19 11:45:44 -06:00
Rob Landley
7d779319ab Let taskset.test check more than 32 processors.
They still need to be contiguous starting at zero though: no holes.
2025-10-27 15:35:06 -05:00
Rob Landley
4fc2d9d6c9 Cleanup tests. 2025-10-20 10:32:55 -05:00
Rob Landley
01225a9fdd Cap $CPUS at 63 so mask math doesn't overflow. 2025-10-20 10:16:42 -05:00
Rob Landley
a72476beef Fix test. 2025-10-08 17:14:58 -05:00
Elliott Hughes
7d965b43da xargs: implement -a. 2025-09-17 23:24:31 -05:00
Rob Landley
73bce5b488 Convert testing->testcmd. 2025-09-08 14:10:32 -05:00
Rob Landley
1bab876006 Add test for write falure. 2025-09-08 14:02:15 -05:00
Rob Landley
62284825a7 Jesse Rosenstock wants taskset to work with an arbitrary number of
leading zeroes for some reason, so take the rightmost 8k of mask data
and test with leading zeroes. (It could instead specifically skip
leading zeroes, but would still have to check sizeof(toybuf) anyway.)

Again, the 6.16 kernel can only set NR_CPUS to 8k (1/4 of the bits in
toybuf) for 2 architectures (x86-64 and powerpc64, and ARM64 maxes out
at 4k (1/8 of toybuf). Last I checked nobody's made hardware anywhere
near that: they thought they might 20 years ago but NUMA didn't scale.
Beowulf clusters existed back in the 1990s and if you really want to
have a cluster mmap() shared memory from network storage you can just do
that and address contentional manually (with manual flock and madvise or
your own bespoke mechanism), or create data stores like riak, or...
2025-09-05 16:59:37 -05:00
Rob Landley
6f8ea8aafd Minor cleanup. 2025-07-19 21:03:33 -05:00
Jesse Rosenstock
40a81414b0 taskset: Document and add test for 0 PID
Since util-linux/util-linux@6c87a3ac5e (taskset: Accept 0 pid for current
process), util-linux's taskset has accepted a 0 PID for the taskset
process.

Toybox has always had this behavior, inherited from sched_getaffinity(2)
and sched_setaffinity(2).

https://www.man7.org/linux/man-pages/man2/sched_getaffinity.2.html

Document the zero PID behavior and use it to simplify the tests.

Note that toybox and util-linux show different output.  I'm not sure if
this should be considered a bug or not.

% ./toybox taskset 1 ./toybox taskset -p 0
pid 0's current affinity mask: 1
% ./taskset 1 ./taskset -p 0
pid 2140985's current affinity mask: 1
2025-07-04 15:25:34 -05:00
Rob Landley
07a422c559 Xz cleanup: inline several init functions, use xmalloc() and error_exit()
with toys.rebound to continue and accept additional input after error file,
reduce error message granularity (it worked or it didn't),
mark more functions static, use toybuf for input.

Fix tests to not look for specific error messages (fixes TEST_HOST).
2025-06-28 20:18:06 -05:00
Rob Landley
105a72fd53 Jesse Rosenstock pointed out that long masks would run past toybuf. 2025-06-23 15:16:01 -05:00
Rob Landley
77cb95ab94 Add taskset tests. 2025-06-23 14:59:16 -05:00
Rob Landley
8433c5d9a4 Redo prefix assignment logic so ! and redirects can interleave.
Move sh_process allocation out of expand_redir() and have caller allocate
and supply it, so multiple expand_redir() calls can append to the
same argv[] and filehandle unredirect context.

Move argv[0] out of ff->arg into TT.argv0 (because $0 is special: shift
and $* don't include it, set can't update it, source and function calls
don't change it...)

Rename call_function() to add_fcall(), because sh_function is function()
definitions and sh_fcall is call stack.

Remove pp->envlen, and replace pp->flags/PFLAG_NOT with pp->not.

Make sh_fcall more sparse: instead of copying fields from parent context
search for them with find_fcall() (convenience wrapper: FIND_FF()) and
get_lineno(). Having one copy greatly simplifies updating the values.

Note: run_command() no longer returns NULL: pp->exit will be nonzero if
setup failed.
2025-06-22 18:28:14 -05:00
Elliott Hughes
957903785a dd: implement oflag=append and oflag=direct. 2025-06-05 16:59:37 -05:00
Rob Landley
f43c791542 Alias support. 2025-05-09 00:43:54 -05:00
Rob Landley
df570102af Implement chmod -cv 2025-04-28 17:39:27 -05:00
Rob Landley
84749b1b7f test -nt and -ot treat existing file as always newer than missing. 2025-04-20 13:06:38 -05:00
Rob Landley
66fabe6c31 Allow tar -T /dev/null to create an empty archive. 2025-04-18 11:08:03 -05:00
Rob Landley
1f4ac174cf Silence TEST_HOST complaining about / in member names for "t". 2025-04-18 11:06:42 -05:00
Jeffery Miller
7353a331ff tests/dd: Add conv=nocreat test cases
Check that conv=nocreat errors out and does not
not create a file.

Test: make test_dd
2025-04-17 20:30:45 -05:00
Rob Landley
bb23558abe toysh fix: Move input search after initialing $PATH, and fix reversed test. 2025-02-25 15:10:28 -06:00
Rob Landley
6225bb45dc Preserve original exitval after trap handler. 2025-02-14 14:08:33 -06:00
Brian Norris
ff667cc643 pgrep: Implement -a
pgrep currently implements -l and -f, but not -a. It also inadvertently
treats -f as a combination of -a and -f, where we both filter via the
full command line and display the full command line. This violates
--help, where -f says "Check full command line for PATTERN".

Implement -a, which takes care of displaying the full command line, and
return -f to simply checking (filtering) via command line.
2025-02-06 16:13:42 -06:00
Rob Landley
48aa258f23 Just comment out the new tests until toysh can runs the test suite. 2025-01-10 16:46:10 -06:00
Rob Landley
c914983e3a Workaround mksh expanding ~ even when it's not the first char in a word. 2025-01-10 11:06:25 -06:00
Rob Landley
58500b8029 Adjust various tests to pass on TEST_HOST debian bookworm. 2025-01-06 09:47:13 -06:00
Rob Landley
b099b26fbc Test -nt and -ot should only check nanoseconds when seconds match. 2025-01-05 17:47:03 -06:00
Ray Gardner
1f1641cc4f Add test for setting NF=0 2024-12-03 14:09:20 -06:00
Rob Landley
97b5ea16cf Fix backslash parsing in $'' so \' doesn't end quote context. 2024-11-23 02:53:29 -06:00
Rob Landley
2045c95214 Kana provided the file, and clarified the ==4 check excludes fat16. 2024-11-08 16:12:18 -06:00
Rob Landley
d04c449ebf Comment out test that submitter didn't include test file for,
and move *type=='v' check back under distinguishing between vfat/iso9660
instead of run for all filetypes and potentially triggering if a new
4 letter physical filesystem type starting with v shows up in future.
2024-11-08 15:36:12 -06:00
Kana Steimle
eafb0b6bb5 blkid, mount: fix blkid -L and add support for mount LABEL=...
Fixes `blkid -L`, and uses that to implement `mount LABEL=...`, the same way
`mount UUID=...` was implemented.

Previously blkid would erroneously print SEC_TYPE="msdos" for vfat filesystems
when the -L option was passed. This line is moved to only print it when neither
-U or -L are passed.

Also fixed to match util-linux's blkid behavior better: SEC_TYPE="msdos" is not
added to the list of tags when the vfat filesystem is fat32 (presumably because
fat32 is not compatible with msdos). A test is added to check this behavior.

To create the fat32.bz2 file used by the test, run the following commands:
$ fallocate -l33M fat32
$ mkfs.vfat -n myfat32 -i 0xB25B2ECB -F 32 fat32
$ bzip2 fat32

It's my first time submitting a patch to any project, so if there's anything I
should do differently in the future, please let me know.
2024-11-08 03:09:37 -06:00
Rob Landley
c47184b389 Annotate broken test_sh which bash (TEST_HOST) passes but toysh doesn't.
By default, known broken tests are skipped, use "BROKEN= make test_sh" to
run them. This yanks 65 tests, leaving 289 which currently pass.

(A lot of the toysh test suite was always aspirational, notes-to-self
to handle some corner case. Unfortunately, that made it less useful for
regression testing changes...)
2024-11-03 17:23:20 -06:00
Rob Landley
fa34b1250f TEST_HOST behavior changed between bash 5.0 and 5.2 2024-11-03 16:58:08 -06:00
Karthikeyan Ramasubramanian
b98e7eba91 Support non memory mapped access
Add --no-mmap flag to indicate seek and read/write access. This allows
accessing devices that do not support mapping into memory - eg.
/dev/nvram, /dev/msr0 etc.

Also currently only WIDTH bytes are mapped into memory even when more
data is accessed. Fix this by mapping WIDTH * number of data.

Test: ./post_update.sh && m toybox. Push devmem test into DUT and access
/dev/mem through memory mapped access, /dev/nvram & /dev/msr* through
non memory-mapped access. Also update the toybox test cases to include
the non memory mapped access and confirm that all the tests are passing.

PASS: devmem read --no-mmap default (4)
PASS: devmem read --no-mmap 1
PASS: devmem read --no-mmap 2
PASS: devmem read --no-mmap 4
PASS: devmem read --no-mmap 8
PASS: devmem write 1
PASS: devmem write 2
PASS: devmem write 4
PASS: devmem write 8
PASS: devmem write --no-mmap 1
PASS: devmem write --no-mmap 2
PASS: devmem write --no-mmap 4
PASS: devmem write --no-mmap 8
PASS: devmem write 1 multiple
PASS: devmem write 2 multiple
PASS: devmem write 4 multiple
PASS: devmem write 8 multiple
PASS: devmem write --no-mmap 1 multiple
PASS: devmem write --no-mmap 2 multiple
PASS: devmem write --no-mmap 4 multiple
PASS: devmem write --no-mmap 8 multiple

Changelog since v1:
- Removed android specific files
- Removed xlseek after xwrite since xwrite advances the position
- Added test cases for --no-mmap access
2024-10-25 23:40:19 -05:00
Ray Gardner
4a31815805 Update awk.test
Add tests for split() via an empty regex string and empty regex literal..
2024-10-23 12:00:12 -05:00
Ray Gardner
0631575ba0 Update awk.test
Add tests for last several commits
2024-10-23 11:54:53 -05:00
Rob Landley
4073e77933 Add O_NONBLOCK and O_NOCTTY to grep's open flags, so grep -r doesn't
catch on FIFO and tty dev nodes quite so easily. Add FIFO test.
2024-10-19 18:06:41 -05:00
Daniel Rosenberg
aea95681c2 Fix diff between symlinks and fifos
diff should allow comparison between regular files and fifos
Added a few tests to help catch regressions here, and added
some cleanup for files the test creates.
2024-09-05 10:30:35 -05:00
Ray Gardner
27d18f0068 Fix nextfile; add tests
The nextfile statement was failing because it left unprocessed input in the
record buffer from the current file. Mod to reset the buffer so it will get
data from the next file immediately. Add a test for the nextfile fix and also
for the preceding commit that fixed the 'getline var' bug (not setting it as a
numeric string if needed).
2024-09-04 00:15:53 -05:00
Daniel Rosenberg
8bed55bb67 Support diff --no-dereference 2024-09-03 23:23:14 -05:00
Rob Landley
d50372cad3 Add obsolete sparse format test file, with test.
The trick is legacy tar ignores --sparse-format unless you also say --posix.
2024-08-16 23:51:51 -05:00
Elliott Hughes
d9d0a1c6e6 file: don't print ELF flags unless we've verified the bitness.
This was the file(1) crash mentioned in #503.
2024-08-10 15:31:32 -05:00
Elliott Hughes
f4ab441ca3 devmem.test: ignore whitespace.
Yet again, I am victim of my own bad habit of only testing on my Debian
desktop... It turns out that [current] Debian od uses a single space
between fields, macOS od uses a tab between fields, and toybox od uses 4
spaces between fields. (Given that POSIX just says "one or more <blank>
characters", I assume this isn't a new problem.)

Sidestep this with NOSPACE=1 for all the od-using tests.
2024-08-01 14:06:29 -05:00
Elliott Hughes
686ca43323 devmem: add -f FILE, arbitrary amounts of data.
-f lets people use /dev/port for x86 i/o ports (rather than needing a
separate x86-only command), or /dev/nvram, or /dev/cpu/*/msr, or
/sys/bus/pci/devices/*:*:*.* ... you get the idea.

It also means we can write some tests. (Though of course, the tests
don't tell us whether this actually works with, /dev/foo, or whether
you actually need to lseek()+write() rather than mmap().)

Also support arbitrary numbers of writes (with address auto-increment).
2024-08-01 01:16:30 -05:00
Elliott Hughes
9b28d1ba0b tar.test: don't test non--p behavior as root.
Fixes https://github.com/landley/toybox/issues/512.
2024-07-25 03:01:14 -05:00