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 // To make compile faster
25 // https://github.com/philsquared/Catch/blob/master/docs/slow-compiles.md
26 // #define CATCH_CONFIG_MAIN
27 #define CATCH_CONFIG_RUNNER
28 #include "catch.hpp"
29 
30 #include "tscore/I_Layout.h"
31 #include "tscore/Diags.h"
32 
33 #include "I_EventSystem.h"
34 #include "RecordsConfig.h"
35 
36 #include "QUICConfig.h"
37 #include "HuffmanCodec.h"
38 #include "QPACK.h"
39 #include "HTTP.h"
40 
41 #define TEST_THREADS 1
42 
43 char qifdir[256]  = "./qifs/qifs";
44 char encdir[256]  = "./qifs/encoded";
45 char decdir[256]  = "./qifs/decoded";
46 int tablesize     = 4096;
47 int streams       = 100;
48 int ackmode       = 0;
49 char appname[256] = "ats";
50 char pattern[256] = "";
51 
52 struct EventProcessorListener : Catch::TestEventListenerBase {
53   using TestEventListenerBase::TestEventListenerBase; // inherit constructor
54 
55   virtual void
testRunStartingEventProcessorListener56   testRunStarting(Catch::TestRunInfo const &testRunInfo) override
57   {
58     BaseLogFile *base_log_file = new BaseLogFile("stderr");
59     diags                      = new Diags(testRunInfo.name, "" /* tags */, "" /* actions */, base_log_file);
60     diags->activate_taglist("qpack", DiagsTagType_Debug);
61     diags->config.enabled[DiagsTagType_Debug] = true;
62     diags->show_location                      = SHOW_LOCATION_DEBUG;
63 
64     Layout::create();
65     RecProcessInit(RECM_STAND_ALONE);
66     LibRecordsConfigInit();
67 
68     QUICConfig::startup();
69 
70     ink_event_system_init(EVENT_SYSTEM_MODULE_PUBLIC_VERSION);
71     eventProcessor.start(TEST_THREADS);
72 
73     Thread *main_thread = new EThread;
74     main_thread->set_specific();
75 
76     url_init();
77     mime_init();
78     http_init();
79     hpack_huffman_init();
80   }
81 };
82 CATCH_REGISTER_LISTENER(EventProcessorListener);
83 
84 int
main(int argc,char * argv[])85 main(int argc, char *argv[])
86 {
87   Catch::Session session;
88   using namespace Catch::clara;
89   auto cli =
90     session.cli() | Opt(qifdir, "qifdir")["--q-qif-dir"]("path for a directory that contains QIF files (default:qifs/qifs") |
91     Opt(encdir, "encdir")["--q-encoded-dir"]("path for a directory that encoded files will be stored (default:qifs/encoded)") |
92     Opt(decdir, "decdir")["--q-decoded-dir"]("path for a directory that decoded files will be stored (default:qifs/decoded)") |
93     Opt(tablesize, "size")["--q-dynamic-table-size"]("dynamic table size for encoding: 0-65535 (default:4096)") |
94     Opt(streams, "n")["--q-max-blocked-streams"]("max blocked streams for encoding: 0-65535 (default:100)") |
95     Opt(ackmode, "mode")["--q-ack-mode"]("acknowledgement modes for encoding: none(default:0) or immediate(1)") |
96     Opt(pattern, "pattern")["--q-pattern"]("filename pattern: file name pattern for decoding (default:)") |
97     Opt(appname, "app")["--q-app"]("app name: app name (default:ats)");
98 
99   session.cli(cli);
100 
101   int returnCode = session.applyCommandLine(argc, argv);
102   if (returnCode != 0) {
103     return returnCode;
104   }
105 
106   return session.run();
107 }
108