---
name: "vmod_vtc"
section: "3"
platform: "linux"
package: "vinyl-cache"
version: "9.1.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/vmod_vtc"
---

# vmod\_vtc(3)

Utility module for vinyltest

## Name

vmod\_vtc - Utility module for vinyltest

## SYNOPSIS

```
import vtc [as name] [from "path"]
VOID barrier_sync(STRING addr, DURATION timeout)
BACKEND no_backend()
STEVEDORE no_stevedore()
IP no_ip()
VOID panic(STRING)
VOID sleep(DURATION)
VOID workspace_alloc(ENUM, INT size)
BYTES workspace_reserve(ENUM, INT size)
INT workspace_free(ENUM)
VOID workspace_snapshot(ENUM)
VOID workspace_reset(ENUM)
BOOL workspace_overflowed(ENUM)
VOID workspace_overflow(ENUM)
BLOB workspace_dump(ENUM, ENUM, BYTES off, BYTES len)
INT typesize(STRING)
BLOB proxy_header(ENUM version, IP client, IP server, STRING authority)
VOID vsl(INT vxid, STRING tag, ENUM side, STRING s)
VOID vsl_replay(STRING s)
VOID storage_revert(STEVEDORE)
VOID storage_full(STEVEDORE)
VOID storage_lessspace(STEVEDORE)
VOID storage_maxspace(STEVEDORE, BYTES)
VOID storage_frag(STEVEDORE, BYTES)
```

## DESCRIPTION

The goal for this VMOD is to provide VCL users and VMOD authors means to test corner cases or reach certain conditions with **vinyltest**.

### VOID barrier\_sync(STRING addr, DURATION timeout=0)

When writing test cases, the most common pattern is to start a mock server instance, a Vinyl Cache instance, and spin up a mock client. Those entities run asynchronously, and others exist like background processes (**process**) or log readers (**logexpect**). While you can synchronize with individual entities and wait for their completion, you must use a barrier if you need to synchronize two or more entities, or wait until a certain point instead of completion.

Not only is it possible to synchronize between test entities, with the **barrier\_sync** function you can even synchronize VCL code:

```
sub vcl_recv {
    # wait for some barrier b1 to complete
    vtc.barrier_sync("${b1_sock}");
}
```

If the function fails to synchronize with the barrier for some reason, or if it reaches the optional timeout, it fails the VCL transaction.

## MISCELLANEOUS

### BACKEND no\_backend()

Fails at backend selection.

### STEVEDORE no\_stevedore()

Fails at storage selection.

### IP no\_ip()

Returns a null IP address, not even a bogo\_ip.

### VOID panic(STRING)

It can be useful to crash the child process in order to test the robustness of a VMOD.

### VOID sleep(DURATION)

Block the current worker thread.

## WORKSPACES

It can be useful to put a workspace in a given state when testing corner cases like resource exhaustion for a transaction, especially for VMOD development. All functions available allow to pick which workspace you need to tamper with, available values are **client**, **backend**, **session** and **thread**.

### VOID workspace\_alloc(ENUM, INT size)

```
VOID workspace_alloc(
   ENUM {client, backend, session, thread},
   INT size
)
```

Allocate and zero out memory from a workspace. A negative size will allocate as much as needed to leave that many bytes free. The actual allocation size may be higher to comply with memory alignment requirements of the CPU architecture. A failed allocation fails the transaction.

### BYTES workspace\_reserve(ENUM, INT size)

```
BYTES workspace_reserve(
   ENUM {client, backend, session, thread},
   INT size
)
```

Attempt to reserve *size* bytes, zero out that memory and release the reservation right away. Return the size of the reservation.

See vtc.workspace\_alloc() for semantics of the *size* argument.

### INT workspace\_free(ENUM {client, backend, session, thread})

Find how much unallocated space there is left in a workspace.

### VOID workspace\_snapshot(ENUM)

```
VOID workspace_snapshot(ENUM {client, backend, session, thread})
```

Snapshot a workspace. Only one snapshot may be active at a time and each VCL can save only one snapshot, so concurrent tasks requiring snapshots are not supported.

### VOID workspace\_reset(ENUM)

```
VOID workspace_reset(ENUM {client, backend, session, thread})
```

Reset to the previous snapshot of a workspace, it must be the same workspace too.

### BOOL workspace\_overflowed(ENUM)

```
BOOL workspace_overflowed(ENUM {client, backend, session, thread})
```

Find whether the workspace overflow mark is set or not.

### VOID workspace\_overflow(ENUM)

```
VOID workspace_overflow(ENUM {client, backend, session, thread})
```

Mark a workspace as overflowed.

### BLOB workspace\_dump(ENUM, ENUM, BYTES off, BYTES len)

```
BLOB workspace_dump(
   ENUM {client, backend, session, thread},
   ENUM {s, f, r},
   BYTES off=0,
   BYTES len=64
)
```

Return data from a workspace's **s**, **f**, or **r** pointer as a blob. Data is copied onto the primary workspace to avoid it being subsequently overwritten.

The maximum *len* is 1KB.

### INT typesize(STRING)

Returns the size in bytes of a collection of C-datatypes:

- •

  **'p'**: pointer

- •

  **'i'**: **int**

- •

  **'d'**: **double**

- •

  **'f'**: **float**

- •

  **'l'**: **long**

- •

  **'s'**: **short**

- •

  **'z'**: **size\_t**

- •

  **'o'**: **off\_t**

- •

  **'j'**: **intmax\_t**

This can be useful for VMOD authors in conjunction with workspace operations.

### BLOB proxy\_header(ENUM version, IP client, IP server, STRING authority)

```
BLOB proxy_header(
   ENUM {v1, v2} version,
   IP client,
   IP server,
   STRING authority=0
)
```

Format a proxy header of the given version **v1** or **v2** and addresses (The VCL IP type also contains the port number).

Optionally also send an authority TLV with version **v2** (ignored for version **v1**).

Candidate for moving into vmod\_proxy, but there were concerns about the interface design

## VSL

These functions allow to generate arbitrary log entries to test the Vinyl Cache Shared Log (VSL) implementation and readers like vinyllog.

### VOID vsl(INT vxid, STRING tag, ENUM {c, b} side, STRING s)

Call **VSLs()** with the given parameters.

The argument order is chosen to match VSL output.

A VCL error is triggered if *tag* cannot be resolved at runtime or if vxid is out of bounds.

### VOID vsl\_replay(STRING s)

Replay literal log lines.

The parser accepts the output generated by **vinyllog -g raw** and **vinyltest log** **vsl\|** lines.

Unparseable lines are silently ignored.

## STORAGE

These functions modify the **STEVEDORE** argument and inject interposer functions, which change behavior of the storage accordingly. Because storages are global, the last invocation always wins, no matter the call site or VCL. All functions undo any other, previous modification.

Note that due to the nature of the technique used, interposer changes may not become visible across all threads.

### VOID storage\_revert(STEVEDORE)

Remove all interposers

### VOID storage\_full(STEVEDORE)

Interpose the storage to fail requests for new objects, new buffers and object bodies.

Interposes: - stevedore: allocobj, allocbuf, - obj\_methods: objgetspace

### VOID storage\_lessspace(STEVEDORE)

Interpose object body allocation to request always one byte less than actually requested.

- •

  obj\_methods: objgetspace

### VOID storage\_maxspace(STEVEDORE, BYTES)

Interpose the storage to fail object body allocations after **BYTES**.

- •

  obj\_methods: objgetspace, objextend, objfree

### VOID storage\_frag(STEVEDORE, BYTES)

Interpose the storage to always request **BYTES**.

- •

  obj\_methods: objgetspace

## SEE ALSO

- •

  *[vtc(7)](/vtc/7.md)*

- •

  *[vcl(7)](/vcl/7.md)*

## COPYRIGHT

```
Copyright (c) 2017 Varnish Software AS
All rights reserved.
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
SPDX-License-Identifier: BSD-2-Clause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
NB: Default to strict $ABI handling, so that path is tested in vmodtool.py
```
