fakeexe

package
v0.209.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fakeexe is test support for tests that need an executable named like a tool (ffmpeg, ffprobe) which is the running test binary itself, re-executed as the stand-in (the helper-process trick: the package's init or TestMain sees the tool's name in os.Args[0] and answers as the tool).

It exists because four packages each carried the same helper, and it hard-linked the test binary to the tool's name. On Windows that cannot be cleaned up: a link names the same file as the running test binary, and Windows refuses to unlink any name of a file a live process has mapped as its image, so testing's TempDir cleanup failed with "unlinkat ...\ffmpeg.exe: Access is denied" on a host where the refusal applies (measured there: a link that nothing had ever run was still locked after 20 s, a byte copy was removed at once; on another Windows host both removed fine). A retry cannot help, because the lock lasts as long as the test process does. So on Windows the stand-in is always a copy, and elsewhere a hard link (free, and unlinking one is fine), falling back to a copy.

Where the stand-ins live. Dir is the calling test's own t.TempDir, so a test run that is killed before its cleanups run leaves them inside the run's temp root (which a harness deletes), never as a folder of their own in the shared temp directory. Dir also registers its own removal, with a bounded retry on Windows (a just-run executable can stay held for a moment by a scanner). Cleanups run last-in first-out and Dir registers its after t.TempDir's, so the retry runs before testing's own TempDir removal, which then finds nothing to refuse.

A copy has a price the link did not: the first start of a newly written executable is slow where a scanner inspects it (measured on a development host: 1.7 to 2 s for the first start, 30 ms for the second), and a test that gives the whole call a short deadline would pay it inside its budget. So Install on Windows starts the stand-in once before it returns. That start is a leaf by construction: it carries warmEnv, and this package's init exits the process the moment it sees it, before any package's own init or any test can run. It therefore asks nothing of a package's stand-in dispatcher.

The recursion guard. A stand-in is the test binary, so a stand-in started under a name the package's dispatcher does not recognise runs the whole test suite instead of answering as the tool, and every test that installs a stand-in would start another one: a fork bomb, one directory and one process per level (a runaway of this kind has happened: thousands of copies in minutes). Install records every directory it puts a stand-in in, in dirsEnv, which child processes inherit. A process that finds itself running from one of those directories is a stand-in; if it reaches Dir or Install it is running tests, and it exits with nestedExit at once, so the depth of any such chain is two.

It is a separate package so a production package never imports "testing" (the shape internal/gpuprobe/smitest has).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir(t testing.TB) string

Dir returns a new empty directory for stand-in executables. It is inside the calling test's own temp directory (t.TempDir) and is removed, with a bounded retry on Windows, when the test ends.

func Install

func Install(t testing.TB, dir, name string) string

Install puts a stand-in for the tool called name in dir and returns its path. The name is the tool's name without a suffix ("ffmpeg"); ".exe" is added on Windows, where a file must have it to be run.

func Place

func Place(t testing.TB, name string) string

Place is Install into a directory of its own (see Dir).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL