.\" Man page generated from reStructuredText. . .TH VMOD_VTC 3 "" "" "" .SH NAME vmod_vtc \- Utility module for varnishtest . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .\" . .\" NB: This file is machine generated, DO NOT EDIT! . .\" . .\" Edit ./vmod_vtc.vcc and run make instead . .\" . .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C 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) .ft P .fi .UNINDENT .UNINDENT .SH DESCRIPTION .sp The goal for this VMOD is to provide VCL users and VMOD authors means to test corner cases or reach certain conditions with varnishtest. .SS VOID barrier_sync(STRING addr, DURATION timeout=0) .sp When writing test cases, the most common pattern is to start a mock server instance, a Varnish instance, and spin up a mock client. Those entities run asynchronously, and others exist like background processes (\fBprocess\fP) or log readers (\fBlogexpect\fP). 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. .sp Not only is it possible to synchronize between test entities, with the \fBbarrier_sync\fP function you can even synchronize VCL code: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C sub vcl_recv { # wait for some barrier b1 to complete vtc.barrier_sync("${b1_sock}"); } .ft P .fi .UNINDENT .UNINDENT .sp If the function fails to synchronize with the barrier for some reason, or if it reaches the optional timeout, it fails the VCL transaction. .SH MISCELLANEOUS .SS BACKEND no_backend() .sp Fails at backend selection. .SS STEVEDORE no_stevedore() .sp Fails at storage selection. .SS IP no_ip() .sp Returns a null IP address, not even a bogo_ip. .SS VOID panic(STRING) .sp It can be useful to crash the child process in order to test the robustness of a VMOD. .SS VOID sleep(DURATION) .sp Block the current worker thread. .SH WORKSPACES .sp 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 \fBclient\fP, \fBbackend\fP, \fBsession\fP and \fBthread\fP\&. .SS VOID workspace_alloc(ENUM, INT size) .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C VOID workspace_alloc( ENUM {client, backend, session, thread}, INT size ) .ft P .fi .UNINDENT .UNINDENT .sp 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. .SS BYTES workspace_reserve(ENUM, INT size) .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C BYTES workspace_reserve( ENUM {client, backend, session, thread}, INT size ) .ft P .fi .UNINDENT .UNINDENT .sp Attempt to reserve \fIsize\fP bytes and release the reservation right away. Return the size of the reservation. .sp See \fI\%vtc.workspace_alloc()\fP for semantics of the \fIsize\fP argument. .SS INT workspace_free(ENUM {client, backend, session, thread}) .sp Find how much unallocated space there is left in a workspace. .SS VOID workspace_snapshot(ENUM) .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C VOID workspace_snapshot(ENUM {client, backend, session, thread}) .ft P .fi .UNINDENT .UNINDENT .sp 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. .SS VOID workspace_reset(ENUM) .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C VOID workspace_reset(ENUM {client, backend, session, thread}) .ft P .fi .UNINDENT .UNINDENT .sp Reset to the previous snapshot of a workspace, it must be the same workspace too. .SS BOOL workspace_overflowed(ENUM) .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C BOOL workspace_overflowed(ENUM {client, backend, session, thread}) .ft P .fi .UNINDENT .UNINDENT .sp Find whether the workspace overflow mark is set or not. .SS VOID workspace_overflow(ENUM) .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C VOID workspace_overflow(ENUM {client, backend, session, thread}) .ft P .fi .UNINDENT .UNINDENT .sp Mark a workspace as overflowed. .SS BLOB workspace_dump(ENUM, ENUM, BYTES off, BYTES len) .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C BLOB workspace_dump( ENUM {client, backend, session, thread}, ENUM {s, f, r}, BYTES off=0, BYTES len=64 ) .ft P .fi .UNINDENT .UNINDENT .sp Return data from a workspace\(aqs \fBs\fP, \fBf\fP, or \fBr\fP pointer as a blob. Data is copied onto the primary workspace to avoid it being subsequently overwritten. .sp The maximum \fIlen\fP is 1KB. .SS INT typesize(STRING) .sp Returns the size in bytes of a collection of C\-datatypes: .INDENT 0.0 .IP \(bu 2 \fB\(aqp\(aq\fP: pointer .IP \(bu 2 \fB\(aqi\(aq\fP: \fBint\fP .IP \(bu 2 \fB\(aqd\(aq\fP: \fBdouble\fP .IP \(bu 2 \fB\(aqf\(aq\fP: \fBfloat\fP .IP \(bu 2 \fB\(aql\(aq\fP: \fBlong\fP .IP \(bu 2 \fB\(aqs\(aq\fP: \fBshort\fP .IP \(bu 2 \fB\(aqz\(aq\fP: \fBsize_t\fP .IP \(bu 2 \fB\(aqo\(aq\fP: \fBoff_t\fP .IP \(bu 2 \fB\(aqj\(aq\fP: \fBintmax_t\fP .UNINDENT .sp This can be useful for VMOD authors in conjunction with workspace operations. .SS BLOB proxy_header(ENUM version, IP client, IP server, STRING authority) .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C BLOB proxy_header( ENUM {v1, v2} version, IP client, IP server, STRING authority=0 ) .ft P .fi .UNINDENT .UNINDENT .sp Format a proxy header of the given version \fBv1\fP or \fBv2\fP and addresses (The VCL IP type also conatins the port number). .sp Optionally also send an authority TLV with version \fBv2\fP (ignored for version \fBv1\fP). .sp Candidate for moving into vmod_proxy, but there were concerns about the interface design .SH SEE ALSO .INDENT 0.0 .IP \(bu 2 \fIvtc(7)\fP .IP \(bu 2 \fIvcl(7)\fP .UNINDENT .SH COPYRIGHT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C Copyright (c) 2017 Varnish Software AS All rights reserved. Author: Dridi Boukelmoune 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 \(ga\(gaAS IS\(aq\(aq 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. .ft P .fi .UNINDENT .UNINDENT .\" Generated by docutils manpage writer. .