1 /** @file
2 
3   A brief file description
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 /****************************************************************************
25 
26   P_NetVCTest.h
27 
28    Description:
29        Unit test for infrastructure for VConnections implementing the
30          NetVConnection interface
31 
32 
33 
34 
35  ****************************************************************************/
36 
37 #pragma once
38 
39 #include "tscore/ink_platform.h"
40 #include "tscore/Regression.h"
41 
42 class VIO;
43 class MIOBuffer;
44 class IOBufferReader;
45 
46 enum NetVcTestType_t {
47   NET_VC_TEST_ACTIVE,
48   NET_VC_TEST_PASSIVE,
49 };
50 
51 struct NVC_test_def {
52   const char *test_name;
53 
54   int bytes_to_send;
55   int nbytes_write;
56 
57   int bytes_to_read;
58   int nbytes_read;
59 
60   int write_bytes_per;
61   int timeout;
62 
63   int expected_read_term;
64   int expected_write_term;
65 };
66 
67 extern NVC_test_def netvc_tests_def[];
68 extern const unsigned num_netvc_tests;
69 
70 class NetTestDriver : public Continuation
71 {
72 public:
73   NetTestDriver();
74   ~NetTestDriver() override;
75 
76   int errors = 0;
77 
78 protected:
79   RegressionTest *r = nullptr;
80   int *pstatus      = nullptr;
81 };
82 
83 class NetVCTest : public Continuation
84 {
85 public:
86   NetVCTest();
87   ~NetVCTest() override;
88   NetVcTestType_t test_cont_type = NET_VC_TEST_ACTIVE;
89 
90   int main_handler(int event, void *data);
91   void read_handler(int event);
92   void write_handler(int event);
93   void cleanup();
94 
95   void init_test(NetVcTestType_t n_type, NetTestDriver *driver, NetVConnection *nvc, RegressionTest *robj, NVC_test_def *my_def,
96                  const char *module_name_arg, const char *debug_tag_arg);
97   void start_test();
98   int fill_buffer(MIOBuffer *buf, uint8_t *seed, int bytes);
99   int consume_and_check_bytes(IOBufferReader *r, uint8_t *seed);
100 
101   void write_finished();
102   void read_finished();
103   void finished();
104   void record_error(const char *msg);
105 
106   NetVConnection *test_vc = nullptr;
107   RegressionTest *regress = nullptr;
108   NetTestDriver *driver   = nullptr;
109 
110   VIO *read_vio  = nullptr;
111   VIO *write_vio = nullptr;
112 
113   MIOBuffer *read_buffer  = nullptr;
114   MIOBuffer *write_buffer = nullptr;
115 
116   IOBufferReader *reader_for_rbuf = nullptr;
117   IOBufferReader *reader_for_wbuf = nullptr;
118 
119   int write_bytes_to_add_per = 0;
120   int timeout                = 0;
121 
122   int actual_bytes_read = 0;
123   int actual_bytes_sent = 0;
124 
125   bool write_done = false;
126   bool read_done  = false;
127 
128   uint8_t read_seed  = 0;
129   uint8_t write_seed = 0;
130 
131   int bytes_to_send = 0;
132   int bytes_to_read = 0;
133 
134   int nbytes_read  = 0;
135   int nbytes_write = 0;
136 
137   int expected_read_term  = 0;
138   int expected_write_term = 0;
139 
140   const char *test_name   = nullptr;
141   const char *module_name = nullptr;
142   const char *debug_tag   = nullptr;
143 };
144