zig/test/standalone
Kendall Condon 5d58306162 rework fuzz testing to be smith based
-- On the standard library side:

The `input: []const u8` parameter of functions passed to `testing.fuzz`
has changed to `smith: *testing.Smith`. `Smith` is used to generate
values from libfuzzer or input bytes generated by libfuzzer.

`Smith` contains the following base methods:
* `value` as a generic method for generating any type
* `eos` for generating end-of-stream markers. Provides the additional
  guarantee `true` will eventually by provided.
* `bytes` for filling a byte array.
* `slice` for filling part of a buffer and providing the length.

`Smith.Weight` is used for giving value ranges a higher probability of
being selected. By default, every value has a weight of zero (i.e. they
will not be selected). Weights can only apply to values that fit within
a u64. The above functions have corresponding ones that accept weights.
Additionally, the following functions are provided:
* `baselineWeights` which provides a set of weights containing every
  possible value of a type.
* `eosSimpleWeighted` for unique weights for `true` and `false`
* `valueRangeAtMost` and `valueRangeLessThan` for weighing only a range
  of values.

-- On the libfuzzer and abi side:

--- Uids

These are u32s which are used to classify requested values. This solves
the problem of a mutation causing a new value to be requested and
shifting all future values; for example:

1. An initial input contains the values 1, 2, 3 which are interpreted
as a, b, and c respectively by the test.

2. The 1 is mutated to a 4 which causes the test to request an extra
value interpreted as d. The input is now 4, 2, 3, 5 (new value) which
the test corresponds to a, d, b, c; however, b and c no longer
correspond to their original values.

Uids contain a hash component and type component. The hash component
is currently determined in `Smith` by taking a hash of the calling
`@returnAddress()` or via an argument in the corresponding `WithHash`
functions. The type component is used extensively in libfuzzer with its
hashmaps.

--- Mutations

At the start of a cycle (a run), a random number of values to mutate is
selected with less being exponentially more likely. The indexes of the
values are selected from a selected uid with a logarithmic bias to uids
with more values.

Mutations may change a single values, several consecutive values in a
uid, or several consecutive values in the uid-independent order they
were requested. They may generate random values, mutate from previous
ones, or copy from other values in the same uid from the same input or
spliced from another.

For integers, mutations from previous ones currently only generates
random values. For bytes, mutations from previous mix new random data
and previous bytes with a set number of mutations.

--- Passive Minimization

A different approach has been taken for minimizing inputs: instead of
trying a fixed set of mutations when a fresh input is found, the input
is instead simply added to the corpus and removed when it is no longer
valuable.

The quality of an input is measured based off how many unique pcs it
hit and how many values it needed from the fuzzer. It is tracked which
inputs hold the best qualities for each pc for hitting the minimum and
maximum unique pcs while needing the least values.

Once all an input's qualities have been superseded for the pcs it hit,
it is removed from the corpus.

-- Comparison to byte-based smith

A byte-based smith would be much more inefficient and complex than this
solution. It would be unable to solve the shifting problem that Uids
do. It is unable to provide values from the fuzzer past end-of-stream.
Even with feedback, it would be unable to act on dynamic weights which
have proven essential with the updated tests (e.g. to constrain values
to a range).

-- Test updates

All the standard library tests have been updated to use the new smith
interface. For `Deque`, an ad hoc allocator was written to improve
performance and remove reliance on heap allocation. `TokenSmith` has
been added to aid in testing Ast and help inform decisions on the smith
interface.
2026-02-13 22:12:19 -05:00
..
c_compiler test: remove complex arithmetic testing from c_compiler standalone test 2025-11-19 01:42:45 +01:00
c_embed_path Migrate from deprecated Step.Compile APIs 2025-07-26 12:06:43 +02:00
child_process std.process: currentDir -> currentPath 2026-01-29 18:47:58 -08:00
cmakedefine test-standalone: update more cases to new main API 2026-01-04 00:27:08 -08:00
coff_dwarf std.Threaded: replace more kernel32 functions with ntdll 2026-02-07 00:02:50 -05:00
compile_asm test: rename issue_8550 standalone test to compile_asm 2025-09-16 14:51:29 +02:00
compiler_rt_panic test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
config_header std: Remove a handful of things deprecated during the 0.15 release cycle 2025-11-27 20:17:04 +00:00
dep_diamond test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
dep_duplicate_module std.Build: add addLibrary function (#22554) 2025-01-22 02:29:21 +00:00
dep_lazypath test: remove -Dskip-translate-c from test-standalone 2025-09-26 01:33:26 +02:00
dep_mutually_recursive test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
dep_recursive tests: remove incorrect import 2025-05-18 17:10:04 +01:00
dep_shared_builtin test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
dep_triangle test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
depend_on_main_mod test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
dependency_options build: fix error in standalone test when using --release 2025-07-28 08:10:23 +01:00
dependencyFromBuildZig Update test build.zig.zon files to conform to the new manifest rules 2025-07-20 18:28:36 +02:00
dirname std.Build: adjust temp files API 2026-01-04 17:23:45 -08:00
embed_generated_file test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
emit_asm_and_bin test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
emit_asm_no_bin test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
emit_llvm_no_bin test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
empty_env fix two standalone tests on windows 2026-01-04 00:27:09 -08:00
empty_global_error_set x86_64: fix @errorName data 2025-01-05 17:15:56 -05:00
entry_point test-standalone: update more cases to new main API 2026-01-04 00:27:08 -08:00
env_vars Environ: reinstate null return on = in environment variable keys 2026-02-05 20:24:31 +01:00
extern Migrate from deprecated Step.Compile APIs 2025-07-26 12:06:43 +02:00
glibc_compat tests: close() -> close(io) 2025-12-23 22:15:08 -08:00
global_linkage std.Build: add addLibrary function (#22554) 2025-01-22 02:29:21 +00:00
install_headers zig libc: fix subcommand 2026-01-04 00:27:08 -08:00
install_raw_hex Remove uses of deprecated callconv aliases 2025-03-05 03:01:43 +00:00
ios std: move child process APIs to std.Io 2026-01-04 00:27:08 -08:00
issue_339 test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
issue_794 test: remove -Dskip-translate-c from test-standalone 2025-09-26 01:33:26 +02:00
issue_5825 Move std.Target.SubSystem to std.zig.Subsystem 2025-11-05 01:31:26 +01:00
issue_11595 test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
issue_12706 Remove uses of deprecated callconv aliases 2025-03-05 03:01:43 +00:00
libcxx test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
libfuzzer rework fuzz testing to be smith based 2026-02-13 22:12:19 -05:00
load_dynamic_library std: move GetFinalPathNameByHandle to Io.Threaded 2026-02-04 16:27:13 -08:00
mix_c_files tests: extern threadlocals require LLVM 2025-06-06 23:42:15 -07:00
mix_o_files test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
pkg_import test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
posix std.process: currentDir -> currentPath 2026-01-29 18:47:58 -08:00
run_cwd test-standalone: update cases to new main API 2026-01-04 00:27:08 -08:00
run_output_caching test-standalone: update more cases to new main API 2026-01-04 00:27:08 -08:00
run_output_paths test-standalone: update more cases to new main API 2026-01-04 00:27:08 -08:00
self_exe_symlink std.process: currentDir -> currentPath 2026-01-29 18:47:58 -08:00
shared_library chore(test/standalone): test linking libc in a shared library 2026-02-11 15:48:18 +01:00
simple update API usage of std.crypto.random to io.random 2026-01-07 11:03:36 -08:00
static_c_lib test: remove unnecessary @cImport usage in some standalone tests 2025-09-18 12:42:24 +02:00
strip_empty_loop test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
strip_struct_init test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
test_obj_link_run std: Remove a handful of things deprecated during the 0.15 release cycle 2025-11-27 20:17:04 +00:00
test_runner_module_imports std.Build: extend test_runner option to specify whether runner uses std.zig.Server 2025-01-20 00:14:58 +00:00
test_runner_path std.Build: extend test_runner option to specify whether runner uses std.zig.Server 2025-01-20 00:14:58 +00:00
tsan test: enable tsan standalone test for x86_64-freebsd and aarch64-freebsd 2025-10-26 11:12:46 +01:00
windows_argv std.Threaded: replace more kernel32 functions with ntdll 2026-02-07 00:02:50 -05:00
windows_bat_args test-standalone: update cases from posix.getrandom 2026-01-07 11:03:37 -08:00
windows_entry_points Let CRT take care of the entry point for wWinMain if libc is linked 2025-11-08 17:11:12 -08:00
windows_paths Add process.Child.Cwd, use it for cwd and remove cwd_dir field 2026-02-02 01:41:35 -08:00
windows_resources windows_resources standalone test: Load a resource and check its data 2026-01-27 20:48:59 +01:00
windows_spawn std.Io.Threaded: implement and cleanup windows codepaths 2026-02-04 14:15:41 -05:00
zerolength_check test: add tests for @memmove 2025-04-26 13:34:17 +10:00
build.zig update_openbsd_libc: add tool for updating openbsd libc startup code 2026-01-05 16:50:44 +01:00
build.zig.zon Teach fs.path about the wonderful world of Windows paths 2025-11-21 00:03:44 -08:00