You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ma...@apache.org on 2018/03/20 06:23:44 UTC
[trafficserver] branch quic-latest updated: Add tests for HQ
This is an automated email from the ASF dual-hosted git repository.
maskit pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/quic-latest by this push:
new ef7df31 Add tests for HQ
ef7df31 is described below
commit ef7df31604ac843e736dd758c7debdafe68fc595
Author: Masakazu Kitajo <ma...@apache.org>
AuthorDate: Tue Mar 20 15:23:26 2018 +0900
Add tests for HQ
---
.gitignore | 2 +
proxy/hq/test/Makefile.am | 81 +++++++++++++++++
proxy/hq/test/Mock.h | 47 ++++++++++
proxy/hq/test/main.cc | 44 +++++++++
proxy/hq/test/test_HQFrame.cc | 155 ++++++++++++++++++++++++++++++++
proxy/hq/test/test_HQFrameDispatcher.cc | 50 +++++++++++
6 files changed, 379 insertions(+)
diff --git a/.gitignore b/.gitignore
index e79029f..dd7c8ad 100644
--- a/.gitignore
+++ b/.gitignore
@@ -122,6 +122,8 @@ proxy/http2/test_Huffmancode
proxy/http2/test_Http2DependencyTree
proxy/http2/test_HPACK
proxy/http2/hpack-tests/results
+proxy/hq/test/test_HQFrame
+proxy/hq/test/test_HQFrameDispatcher
proxy/logging/test_LogUtils
plugins/header_rewrite/header_rewrite_test
diff --git a/proxy/hq/test/Makefile.am b/proxy/hq/test/Makefile.am
new file mode 100644
index 0000000..10536c9
--- /dev/null
+++ b/proxy/hq/test/Makefile.am
@@ -0,0 +1,81 @@
+# Makefile.am for the traffic/iocore/net hierarchy
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+
+TESTS = $(check_PROGRAMS)
+check_PROGRAMS = \
+ test_HQFrame \
+ test_HQFrameDispatcher
+
+
+AM_CPPFLAGS += \
+ $(iocore_include_dirs) \
+ -I$(abs_top_srcdir)/lib \
+ -I$(abs_top_srcdir)/lib/records \
+ -I$(abs_top_srcdir)/mgmt \
+ -I$(abs_top_srcdir)/mgmt/utils \
+ -I$(abs_top_srcdir)/proxy \
+ -I$(abs_top_srcdir)/proxy/hdrs \
+ -I$(abs_top_srcdir)/proxy/http \
+ -I$(abs_top_srcdir)/proxy/hq \
+ -I$(abs_top_srcdir)/proxy/logging \
+ -I$(abs_top_srcdir)/proxy/shared \
+ -I$(abs_top_srcdir)/tests/include \
+ @OPENSSL_INCLUDES@
+
+#
+# test_HQFrame
+#
+test_HQFrame_CPPFLAGS = \
+ $(AM_CPPFLAGS)
+
+test_HQFrame_LDFLAGS = \
+ @AM_LDFLAGS@
+
+test_HQFrame_SOURCES = \
+ main.cc \
+ test_HQFrame.cc \
+ ../HQFrame.cc
+
+test_HQFrame_LDADD = \
+ $(top_builddir)/iocore/net/quic/libquic.a \
+ $(top_builddir)/lib/ts/libtsutil.la
+
+#
+# test_HQFrameDispatcher
+#
+test_HQFrameDispatcher_CPPFLAGS = \
+ $(AM_CPPFLAGS)
+
+test_HQFrameDispatcher_LDFLAGS = \
+ @AM_LDFLAGS@
+
+test_HQFrameDispatcher_SOURCES = \
+ main.cc \
+ test_HQFrameDispatcher.cc \
+ ../HQFrameDispatcher.cc \
+ ../HQFrame.cc
+
+test_HQFrameDispatcher_LDADD = \
+ $(top_builddir)/iocore/net/quic/libquic.a \
+ $(top_builddir)/lib/ts/libtsutil.la
+
+
+include $(top_srcdir)/build/tidy.mk
+
+tidy-local: $(DIST_SOURCES)
+ $(CXX_Clang_Tidy)
diff --git a/proxy/hq/test/Mock.h b/proxy/hq/test/Mock.h
new file mode 100644
index 0000000..3e7090e
--- /dev/null
+++ b/proxy/hq/test/Mock.h
@@ -0,0 +1,47 @@
+/** @file
+ *
+ * A brief file description
+ *
+ * @section license License
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+#include "catch.hpp"
+
+#include "HQFrameHandler.h"
+
+class HQMockFrameHandler : public HQFrameHandler
+{
+public:
+ int total_frame_received = 0;
+
+ // HQFrameHandler
+
+ std::vector<HQFrameType>
+ interests() override
+ {
+ return {HQFrameType::DATA};
+ }
+
+ HQErrorUPtr
+ handle_frame(std::shared_ptr<const HQFrame> frame) override
+ {
+ this->total_frame_received++;
+ return HQErrorUPtr(new HQNoError());
+ }
+};
diff --git a/proxy/hq/test/main.cc b/proxy/hq/test/main.cc
new file mode 100644
index 0000000..f611f5e
--- /dev/null
+++ b/proxy/hq/test/main.cc
@@ -0,0 +1,44 @@
+/** @file
+ *
+ * A brief file description
+ *
+ * @section license License
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+// To make compile faster
+// https://github.com/philsquared/Catch/blob/master/docs/slow-compiles.md
+#define CATCH_CONFIG_MAIN
+#include "catch.hpp"
+
+#include "ts/Diags.h"
+
+struct EventProcessorListener : Catch::TestEventListenerBase {
+ using TestEventListenerBase::TestEventListenerBase; // inherit constructor
+
+ virtual void
+ testRunStarting(Catch::TestRunInfo const &testRunInfo) override
+ {
+ BaseLogFile *base_log_file = new BaseLogFile("stderr");
+ diags = new Diags(testRunInfo.name.c_str(), "" /* tags */, "" /* actions */, base_log_file);
+ diags->activate_taglist("vv_quic|quic", DiagsTagType_Debug);
+ diags->config.enabled[DiagsTagType_Debug] = true;
+ diags->show_location = SHOW_LOCATION_DEBUG;
+ }
+};
+CATCH_REGISTER_LISTENER(EventProcessorListener);
diff --git a/proxy/hq/test/test_HQFrame.cc b/proxy/hq/test/test_HQFrame.cc
new file mode 100644
index 0000000..061061b
--- /dev/null
+++ b/proxy/hq/test/test_HQFrame.cc
@@ -0,0 +1,155 @@
+/** @file
+ *
+ * A brief file description
+ *
+ * @section license License
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+#include "catch.hpp"
+#include <cstdio>
+#include "HQFrame.h"
+#include "HQFrameDispatcher.h"
+
+TEST_CASE("HQFrame Type", "[hq]")
+{
+ CHECK(HQFrame::type(reinterpret_cast<const uint8_t *>("\x00\x00"), 2) == HQFrameType::DATA);
+ // Undefined ragne
+ CHECK(HQFrame::type(reinterpret_cast<const uint8_t *>("\x00\x0e"), 2) == HQFrameType::UNKNOWN);
+ CHECK(HQFrame::type(reinterpret_cast<const uint8_t *>("\x00\xff"), 2) == HQFrameType::UNKNOWN);
+}
+
+TEST_CASE("Load DATA Frame", "[hq]")
+{
+ SECTION("No flags")
+ {
+ uint8_t buf1[] = {
+ 0x04, // Length
+ 0x00, // Type
+ 0x00, // Flags
+ 0x11, 0x22, 0x33, 0x44, // Payload
+ };
+ std::shared_ptr<const HQFrame> frame1 = HQFrameFactory::create(buf1, sizeof(buf1));
+ CHECK(frame1->type() == HQFrameType::DATA);
+ CHECK(frame1->length() == 4);
+ std::shared_ptr<const HQDataFrame> data_frame = std::dynamic_pointer_cast<const HQDataFrame>(frame1);
+ CHECK(data_frame);
+ CHECK(data_frame->payload_length() == 4);
+ CHECK(memcmp(data_frame->payload(), "\x11\x22\x33\x44", 4) == 0);
+ }
+
+ SECTION("Have flags (invalid)")
+ {
+ uint8_t buf1[] = {
+ 0x04, // Length
+ 0x00, // Type
+ 0xff, // Flags
+ 0x11, 0x22, 0x33, 0x44, // Payload
+ };
+ std::shared_ptr<const HQFrame> frame1 = HQFrameFactory::create(buf1, sizeof(buf1));
+ CHECK(frame1->type() == HQFrameType::DATA);
+ CHECK(frame1->length() == 4);
+ std::shared_ptr<const HQDataFrame> data_frame = std::dynamic_pointer_cast<const HQDataFrame>(frame1);
+ CHECK(data_frame);
+ CHECK(data_frame->payload_length() == 4);
+ CHECK(memcmp(data_frame->payload(), "\x11\x22\x33\x44", 4) == 0);
+ }
+}
+
+TEST_CASE("Store DATA Frame", "[hq]")
+{
+ SECTION("Normal")
+ {
+ uint8_t buf[32] = {0};
+ size_t len;
+ uint8_t expected1[] = {
+ 0x04, // Length
+ 0x00, // Type
+ 0x00, // Flags
+ 0x11, 0x22, 0x33, 0x44, // Payload
+ };
+
+ uint8_t raw1[] = "\x11\x22\x33\x44";
+ ats_unique_buf payload1 = ats_unique_malloc(4);
+ memcpy(payload1.get(), raw1, 4);
+
+ HQDataFrame data_frame(std::move(payload1), 4);
+ CHECK(data_frame.length() == 4);
+
+ data_frame.store(buf, &len);
+ CHECK(len == 7);
+ CHECK(memcmp(buf, expected1, len) == 0);
+ }
+}
+
+TEST_CASE("HQFrameFactory Create Unknown Frame", "[hq]")
+{
+ uint8_t buf1[] = {
+ 0x00, // Length
+ 0xff, // Type
+ 0x00, // Flags
+ };
+ std::shared_ptr<const HQFrame> frame1 = HQFrameFactory::create(buf1, sizeof(buf1));
+ CHECK(frame1);
+ CHECK(frame1->type() == HQFrameType::UNKNOWN);
+ CHECK(frame1->length() == 0);
+}
+
+TEST_CASE("HQFrameFactory Fast Create Frame", "[hq]")
+{
+ HQFrameFactory factory;
+
+ uint8_t buf1[] = {
+ 0x04, // Length
+ 0x00, // Type
+ 0x00, // Flags
+ 0x11, 0x22, 0x33, 0x44, // Payload
+ };
+ uint8_t buf2[] = {
+ 0x04, // Length
+ 0x00, // Type
+ 0x00, // Flags
+ 0xaa, 0xbb, 0xcc, 0xdd, // Payload
+ };
+ std::shared_ptr<const HQFrame> frame1 = factory.fast_create(buf1, sizeof(buf1));
+ CHECK(frame1 != nullptr);
+
+ std::shared_ptr<const HQDataFrame> data_frame1 = std::dynamic_pointer_cast<const HQDataFrame>(frame1);
+ CHECK(data_frame1 != nullptr);
+ CHECK(memcmp(data_frame1->payload(), buf1 + 3, 4) == 0);
+
+ std::shared_ptr<const HQFrame> frame2 = factory.fast_create(buf2, sizeof(buf2));
+ CHECK(frame2 != nullptr);
+
+ std::shared_ptr<const HQDataFrame> data_frame2 = std::dynamic_pointer_cast<const HQDataFrame>(frame2);
+ CHECK(data_frame2 != nullptr);
+ CHECK(memcmp(data_frame2->payload(), buf2 + 3, 4) == 0);
+
+ CHECK(frame1 == frame2);
+}
+
+TEST_CASE("HQFrameFactory Fast Create Unknown Frame", "[hq]")
+{
+ HQFrameFactory factory;
+
+ uint8_t buf1[] = {
+ 0x0f, // Type
+ };
+ std::shared_ptr<const HQFrame> frame1 = factory.fast_create(buf1, sizeof(buf1));
+ CHECK(frame1 == nullptr);
+}
diff --git a/proxy/hq/test/test_HQFrameDispatcher.cc b/proxy/hq/test/test_HQFrameDispatcher.cc
new file mode 100644
index 0000000..caf40ee
--- /dev/null
+++ b/proxy/hq/test/test_HQFrameDispatcher.cc
@@ -0,0 +1,50 @@
+/** @file
+ *
+ * A brief file description
+ *
+ * @section license License
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+#include "catch.hpp"
+
+#include "HQFrameDispatcher.h"
+#include "Mock.h"
+
+TEST_CASE("HQFrameHandler dispatch", "[hq]")
+{
+ uint8_t input[] = {// 1st frame (HEADERS)
+ 0x02, 0x01, 0x00, 0x01, 0x23,
+ // 2nd frame (DATA)
+ 0x04, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44,
+ // 3rd frame (incomplete)
+ 0xff};
+
+ HQFrameDispatcher hqFrameDispatcher;
+ HQMockFrameHandler handler;
+ hqFrameDispatcher.add_handler(&handler);
+ uint16_t nread = 0;
+
+ // Initial state
+ CHECK(handler.total_frame_received == 0);
+ CHECK(nread == 0);
+
+ hqFrameDispatcher.on_read_ready(input, sizeof(input), nread);
+ CHECK(handler.total_frame_received == 1);
+ CHECK(nread == 12);
+}
--
To stop receiving notification emails like this one, please contact
maskit@apache.org.