aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/fifo.h
blob: b0b35e25af74cc669200d6d124fd6ef4d77b1e2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
Testing VPP
===========

As of this writing, the vpp source tree includes over 1,000 unit test
vectors. Best practices prior to pushing patches for code review: make
sure that all of the “make test” test vectors pass.

We attempt to maintain the top-level “make test-help” command so that it
accurately describes all of the “make test” options.

Examples
--------

Basic test run, all test vectors, single-vpp instance, optimized image:

::

     $ make test

10-way parallel basic test run:

::

     $ make TEST_JOBS=10 test

Run a specific test suite (mpls, in this case):

::

     $ make TEST=test_mpls test

Run a specific test suite, debug image, pause prior to running the test
suite; attach to the vpp image in gdb:

::

     $ make TEST=xxx DEBUG=gdb test-debug

Detailed Documentation
----------------------

Current “make test-help” output:

::

    $ make test-help
    Running tests:

     test                   - build and run (basic) functional tests
     test-debug             - build and run (basic) functional tests (debug build)
     test-all               - build and run functional and extended tests
     test-all-debug         - build and run functional and extended tests (debug build)
     retest                 - run functional tests
     retest-debug           - run functional tests (debug build)
     retest-all             - run functional and extended tests
     retest-all-debug       - run functional and extended tests (debug build)
     test-cov               - generate code coverage report for test framework
     test-gcov                      - build and run functional tests (gcov build)
     test-wipe              - wipe (temporary) files generated by unit tests
     test-wipe-cov          - wipe code coverage report for test framework
     test-wipe-papi         - rebuild vpp_papi sources
     test-wipe-all          - wipe (temporary) files generated by unit tests, and coverage
     test-shell             - enter shell with test environment
     test-shell-debug       - enter shell with test environment (debug build)
     test-checkstyle        - check PEP8 compliance for test framework
     test-refresh-deps      - refresh the Python dependencies for the tests

    Arguments controlling test runs:

     V=[0|1|2]              - set test verbosity level
                              0=ERROR, 1=INFO, 2=DEBUG
     TEST_JOBS=[<n>|auto]   - use at most <n> parallel python processes for test execution, if auto, set to number of available cpus (default: 1)
     MAX_VPP_CPUS=[<n>|auto]- use at most <n> cpus for running vpp main and worker threads, if auto, set to number of available cpus (default: auto)
     CACHE_OUTPUT=[0|n|no]  - disable cache VPP stdout/stderr and log as one block after test finishes (default: yes)
     FAILFAST=[1|y|yes]     - fail fast if 1, otherwise complete all tests
     TIMEOUT=<timeout>      - fail test suite if any single test takes longer than <timeout> (in seconds) to finish (default: 600)
     RETRIES=<n>            - retry failed tests <n> times
     DEBUG=<type>           - set VPP debugging kind
        DEBUG=core          - detect coredump and load it in gdb on crash
        DEBUG=gdb           - allow easy debugging by printing VPP PID
                              and waiting for user input before running
                              and tearing down a testcase
        DEBUG=gdbserver     - run gdb inside a gdb server, otherwise
                              same as above
        DEBUG=attach        - attach test case to already running vpp in gdb (see test-start-vpp-in-gdb)
     STEP=[1|y|yes]         - enable stepping through a testcase (for testcase debugging)
     SANITY=[0|n|no]        - disable sanity import of vpp-api/sanity vpp run before running tests
     EXTENDED_TESTS=[1|y|yes] - run extended tests
     TEST=<filter>          - filter the set of tests:
        by file-name        - only run tests from specified file, e.g. TEST=test_bfd selects all tests from test_bfd.py
        by file-suffix      - same as file-name, but 'test_' is omitted e.g. TEST=bfd selects all tests from test_bfd.py
        by wildcard         - wildcard filter
}
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
  Copyright (c) 2005 Eliot Dresselhaus

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef included_fifo_h
#define included_fifo_h

#include <vppinfra/cache.h>
#include <vppinfra/error.h>	/* for ASSERT */
#include <vppinfra/vec.h>

typedef struct
{
  /* First index of valid data in fifo. */
  u32 head_index;

 
fine clib_fifo_len(v) vec_len(v) #define _clib_fifo_len(v) _vec_len(v) #define clib_fifo_end(v) vec_end(v) always_inline uword clib_fifo_elts (void *v) { word l, r; clib_fifo_header_t *f = clib_fifo_header (v); if (!v) return 0; l = _clib_fifo_len (v); r = (word) f->tail_index - (word) f->head_index; r = r < 0 ? r + l : r; ASSERT (r >= 0 && r <= l); return r; } always_inline uword clib_fifo_free_elts (void *v) { return clib_fifo_len (v) - clib_fifo_elts (v); } always_inline void clib_fifo_reset (void *v) { clib_fifo_header_t *f = clib_fifo_header (v); if (v) { f->head_index = f->tail_index = 0; _vec_len (v) = 0; } } /* External resize function. */ void *_clib_fifo_resize (void *v, uword n_elts, uword elt_bytes); #define clib_fifo_resize(f,n_elts) \ f = _clib_fifo_resize ((f), (n_elts), sizeof ((f)[0])) always_inline void * _clib_fifo_validate (void *v, uword n_elts, uword elt_bytes) { if (clib_fifo_free_elts (v) < n_elts) v = _clib_fifo_resize (v, n_elts, elt_bytes); return v; } #define clib_fifo_validate(f,n_elts) \ f = _clib_fifo_validate ((f), (n_elts), sizeof (f[0])) /* Advance tail pointer by N_ELTS which can be either positive or negative. */ always_inline void * _clib_fifo_advance_tail (void *v, word n_elts, uword elt_bytes, uword * tail_return) { word i, l, n_free; clib_fifo_header_t *f; n_free = clib_fifo_free_elts (v); if (n_free < n_elts) { v = _clib_fifo_resize (v, n_elts, elt_bytes); n_free = clib_fifo_free_elts (v); } ASSERT (n_free >= n_elts); n_free -= n_elts; f = clib_fifo_header (v); l = _clib_fifo_len (v); i = f->tail_index; if (n_free == 0) { /* Mark fifo full. */ f->tail_index = f->head_index + l; } else { word n = f->tail_index + n_elts; if (n >= l) n -= l; else if (n < 0) n += l; ASSERT (n >= 0 && n < l); f->tail_index = n; } ASSERT (clib_fifo_free_elts (v) == n_free); if (tail_return) *tail_return = n_elts > 0 ? i : f->tail_index; return v; } #define clib_fifo_advance_tail(f,n_elts) \ ({ \ uword _i; \ (f) = _clib_fifo_advance_tail ((f), (n_elts), sizeof ((f)[0]), &_i); \ (f) + _i; \ }) always_inline uword clib_fifo_advance_head (void *v, uword n_elts) { clib_fifo_header_t *f; uword l, i, n; ASSERT (clib_fifo_elts (v) >= n_elts); f = clib_fifo_header (v); l = _clib_fifo_len (v); /* If fifo was full, restore tail pointer. */ if (f->tail_index == f->head_index + l) f->tail_index = f->head_index; n = i = f->head_index; n += n_elts; n = n >= l ? n - l : n; ASSERT (n < l); f->head_index = n; return i; } /* Add given element to fifo. */ #define clib_fifo_add1(f,e) \ do { \ uword _i; \ (f) = _clib_fifo_advance_tail ((f), 1, sizeof ((f)[0]), &_i); \ (f)[_i] = (e); \ } while (0) /* Add element to fifo; return pointer to new element. */ #define clib_fifo_add2(f,p) \ do { \ uword _i; \ (f) = _clib_fifo_advance_tail ((f), 1, sizeof ((f)[0]), &_i); \ (p) = (f) + _i; \ } while (0) /* Add several elements to fifo. */ #define clib_fifo_add(f,e,n) \ do { \ uword _i, _l; word _n0, _n1; \ \ _n0 = (n); \ (f) = _clib_fifo_advance_tail ((f), _n0, sizeof ((f)[0]), &_i); \ _l = clib_fifo_len (f); \ _n1 = _i + _n0 - _l; \ _n1 = _n1 < 0 ? 0 : _n1; \ _n0 -= _n1; \ clib_memcpy ((f) + _i, (e), _n0 * sizeof ((f)[0])); \ if (_n1) \ clib_memcpy ((f) + 0, (e) + _n0, _n1 * sizeof ((f)[0])); \ } while (0) /* Subtract element from fifo. */ #define clib_fifo_sub1(f,e) \ do { \ uword _i; \ ASSERT (clib_fifo_elts (f) >= 1); \ _i = clib_fifo_advance_head ((f), 1); \ (e) = (f)[_i]; \ } while (0) #define clib_fifo_sub2(f,p) \ do { \ uword _i; \ ASSERT (clib_fifo_elts (f) >= 1); \ _i = clib_fifo_advance_head ((f), 1); \ (p) = (f) + _i; \ } while (0) always_inline uword clib_fifo_head_index (void *v) { clib_fifo_header_t *f = clib_fifo_header (v); return v ? f->head_index : 0; } always_inline uword clib_fifo_tail_index (void *v) { clib_fifo_header_t *f = clib_fifo_header (v); return v ? f->tail_index : 0; } #define clib_fifo_head(v) ((v) + clib_fifo_head_index (v)) #define clib_fifo_tail(v) ((v) + clib_fifo_tail_index (v)) #define clib_fifo_free(f) vec_free_h((f),sizeof(clib_fifo_header_t)) always_inline uword clib_fifo_elt_index (void *v, uword i) { clib_fifo_header_t *f = clib_fifo_header (v); uword result = 0; ASSERT (i < clib_fifo_elts (v)); if (v) { result = f->head_index + i; if (result >= _vec_len (v)) result -= _vec_len (v); } return result; } #define clib_fifo_elt_at_index(v,i) ((v) + clib_fifo_elt_index (v, (i))) #define clib_fifo_foreach(v,f,body) \ do { \ uword _i, _l, _n; \ \ _i = clib_fifo_head_index (f); \ _l = clib_fifo_len (f); \ _n = clib_fifo_elts (f); \ while (_n > 0) \ { \ (v) = (f) + _i; \ do { body; } while (0); \ _n--; \ _i++; \ _i = _i >= _l ? 0 : _i; \ } \ } while (0) #endif /* included_fifo_h */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */