Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ RELEASE
# autest
tests/env-test/
tests/Pipfile.lock
tests/gold_tests/chunked_encoding/smuggle-client
tests/gold_tests/tls/ssl-post

iocore/cache/test_*
iocore/cache/test/var/trafficserver/cache.db
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export CCACHE_BASEDIR
# and mgmt, hence we have to build proxy/hdrs first.

# depends on the generates ts/ts.h include file.
SUBDIRS = src/tscpp/util lib src/tscore iocore proxy mgmt src plugins tools example rc configs include
SUBDIRS = src/tscpp/util lib src/tscore iocore proxy mgmt src plugins tools example rc configs include tests

if BUILD_DOCS
SUBDIRS += doc include
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,7 @@ AC_CONFIG_FILES([
tools/trafficserver.pc
tools/tsxs
tests/unit_tests/Makefile
tests/Makefile
])

# -----------------------------------------------------------------------------
Expand Down
42 changes: 42 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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 $(top_srcdir)/build/plugins.mk
include $(top_srcdir)/build/tidy.mk

noinst_LTLIBRARIES =
noinst_PROGRAMS =

SUBDIRS =

AM_LDFLAGS += $(TS_PLUGIN_LD_FLAGS)

# Automake is pretty draconian about not creating shared object (.so) files for
# non-installed files. However we do not want to install our test plugins so
# we prefix them with noinst_. The following -rpath argument coerces the
# generation of so objects for these test files.
AM_LDFLAGS += -rpath $(abs_builddir)

include gold_tests/continuations/plugins/Makefile.inc
include gold_tests/chunked_encoding/Makefile.inc
include gold_tests/tls/Makefile.inc
include tools/plugins/Makefile.inc

TESTS = $(check_PROGRAMS)

clang-tidy-local: $(DIST_SOURCES)
$(CXX_Clang_Tidy)
$(CC_Clang_Tidy)
53 changes: 0 additions & 53 deletions tests/gold_tests/autest-site/build.test.ext

This file was deleted.

1 change: 1 addition & 0 deletions tests/gold_tests/autest-site/setup.cli.ext
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ if ENV['ATS_BIN'] is not None:
Variables.update(out)
Variables.AtsExampleDir = os.path.join(AutestSitePath, '../../../example')
Variables.AtsTestToolsDir = os.path.join(AutestSitePath, '../../tools')
Variables.AtsTestPluginsDir = os.path.join(AutestSitePath, '../../tools/plugins/.libs')

# modify delay times as we always have to kill Trafficserver
# no need to wait
Expand Down
56 changes: 21 additions & 35 deletions tests/gold_tests/autest-site/trafficserver_plugins.test.ext
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,33 @@ Builds, installs, and enables an ATS plugin in the sandbox environment

import os

def prepare_plugin(self, path, tsproc, plugin_args = "", extra_build_args=''):
"""Builds, installs, and enables an ATS plugin in the sandbox environment

The source file at the given path is copied to the sandbox directory of the
given traffic server process and compiled into a binary with the file
extensioned replaced with '.so'. An entry for this plugin is added to
the 'plugin.config' file."""
def prepare_plugin(self, so_path, tsproc, plugin_args=""):
"""
Installs and enables an ATS plugin in the sandbox environment.

# Copy the source to the sandbox directory.
plugin_dir = tsproc.Env['PROXY_CONFIG_PLUGIN_PLUGIN_DIR']
tsproc.Setup.Copy(path, plugin_dir)
Args:
so_path (str): The path to a built .so file.

tsproc (Process): The Traffic Server process whose plugin.config should
be configured to use the provided plugin.

tsxs = os.path.join(self.Variables.BINDIR,'tsxs')
# get the top level object ( ie Test) to add a condition
# need to change this API in AuTest to be a better name as it now has value
# to be called by user API - dragon512
self._RootRunable.SkipUnless(
Condition.HasProgram(tsxs, "tsxs needs be installed with trafficserver package for this test to run")
)
plugin_args (str): The arguments to provide the plugin in the
plugin.config.
"""

link_gxx="export CC=c++ &&"
# Compile the plugin.
in_basename = os.path.basename(path)
if in_basename.endswith(".c"):
link_gxx = ''
in_path = os.path.join(plugin_dir, in_basename)
out_basename = os.path.splitext(in_basename)[0] + '.so'
out_path = os.path.join(plugin_dir, out_basename)
tsproc.Setup.RunCommand(
"{pre_args} {tsxs} {args} -c {0} -o {1}".format(
in_path,
out_path,
tsxs=tsxs,
args=" -L {0} {1}".format(self.Variables.LIBDIR, extra_build_args),
pre_args=link_gxx)
)
filename, extension = os.path.splitext(so_path)
if extension != ".so":
raise ValueError('so_path argument must have a ".so" extension. '
'Received: {}'.format(so_path))

# Copy the shared object to the sandbox directory.
plugin_dir = tsproc.Env['PROXY_CONFIG_PLUGIN_PLUGIN_DIR']
tsproc.Setup.Copy(so_path, plugin_dir)

# Add an entry to plugin.config.
tsproc.Disk.plugin_config.AddLine("{0} {1}".format(out_basename,plugin_args))
basename = os.path.basename(so_path)
tsproc.Disk.plugin_config.AddLine("{0} {1}".format(basename, plugin_args))

# remove this later
ExtendTest(prepare_plugin, name="prepare_plugin")

ExtendTest(prepare_plugin, name="PreparePlugin")
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
)
ts.Disk.MakeConfigFile(regex_remap_conf_file).AddLine('//.*/ http://donotcare.test @status=204')

Test.PreparePlugin(os.path.join(Test.Variables.AtsTestToolsDir, 'plugins', 'custom204plugin.cc'), ts)
Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'custom204plugin.so'), ts)

Test.Setup.Copy(os.path.join(os.pardir, os.pardir, 'tools', 'tcp_client.py'))
Test.Setup.Copy('data')
Expand Down
19 changes: 19 additions & 0 deletions tests/gold_tests/chunked_encoding/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.

noinst_PROGRAMS += gold_tests/chunked_encoding/smuggle-client
gold_tests_chunked_encoding_smuggle_client_SOURCES = gold_tests/chunked_encoding/smuggle-client.c
gold_tests_chunked_encoding_smuggle_client_LDADD = -lssl
7 changes: 3 additions & 4 deletions tests/gold_tests/chunked_encoding/chunked_encoding.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@
'dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key'
)

# build test code
tr = Test.Build(target='smuggle-client', sources=['smuggle-client.c'])
tr.TimeOut = 5
tr.Setup.Copy('smuggle-client.c')
# smuggle-client is built via `make`. Here we copy the built binary down to the
# test directory so that the test runs in this file can use it.
Test.Setup.Copy('smuggle-client')

# HTTP1.1 GET: www.example.com
tr = Test.AddTestRun()
Expand Down
61 changes: 18 additions & 43 deletions tests/gold_tests/command_argument/verify_global_plugin.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def create_ts_process():
tr = Test.AddTestRun("Verify the requirement of our Plugin API.")
ts = create_ts_process()
Test.PreparePlugin(
os.path.join(Test.Variables.AtsTestToolsDir,
'plugins', 'missing_ts_plugin_init.cc'),
os.path.join(Test.Variables.AtsTestPluginsDir,
'missing_ts_plugin_init.so'),
ts)
tr.Processes.Default.Env = ts.Env
tr.Processes.Default.Command = \
Expand All @@ -98,7 +98,8 @@ def create_ts_process():
tr.Processes.Default.Streams.stderr = Testers.ContainsExpression(
"ERROR: .*unable to find TSPluginInit function in",
"Should warn about the need for the TSPluginInit symbol")
ts.Disk.diags_log.Content = Testers.ContainsExpression("ERROR",
ts.Disk.diags_log.Content = Testers.ContainsExpression(
"ERROR",
"ERROR: .*unable to find TSPluginInit function in")


Expand All @@ -109,8 +110,8 @@ def create_ts_process():
tr = Test.AddTestRun("Verify a properly formed plugin works as expected.")
ts = create_ts_process()
Test.PreparePlugin(
os.path.join(Test.Variables.AtsTestToolsDir,
'plugins', 'conf_remap_stripped.cc'),
os.path.join(Test.Variables.AtsTestPluginsDir,
'conf_remap_stripped.so'),
ts)
tr.Processes.Default.Env = ts.Env
tr.Processes.Default.Command = \
Expand All @@ -121,7 +122,8 @@ def create_ts_process():
tr.Processes.Default.Streams.stderr = Testers.ContainsExpression(
"ERROR: .*unable to find TSPluginInit function in",
"Should warn about the need for the TSPluginInit symbol")
ts.Disk.diags_log.Content = Testers.ContainsExpression("ERROR",
ts.Disk.diags_log.Content = Testers.ContainsExpression(
"ERROR",
"ERROR: .*unable to find TSPluginInit function in")


Expand All @@ -132,8 +134,8 @@ def create_ts_process():
tr = Test.AddTestRun("Verify a properly formed plugin works as expected.")
ts = create_ts_process()
Test.PreparePlugin(
os.path.join(Test.Variables.AtsTestToolsDir,
'plugins', 'ssl_hook_test.cc'),
os.path.join(Test.Variables.AtsTestPluginsDir,
'ssl_hook_test.so'),
ts)
tr.Processes.Default.Env = ts.Env
tr.Processes.Default.Command = \
Expand All @@ -146,53 +148,26 @@ def create_ts_process():
"Verification should succeed")


def prepare_undefined_symbol_plugin(tsproc, path_c, path_cpp, path_h):
"""
Intentionally create an SO file with an undefined symbol.

We've seen issues where a plugin is created in which a C++ file
includes a function declaration and then expects a definition
of the mangled version of that function. However, the definition
was created with a c-compiler and thus is not mangled. This
builds a plugin with just such an undefined mangled symbol.
"""
plugin_dir = tsproc.Env['PROXY_CONFIG_PLUGIN_PLUGIN_DIR']
tsproc.Setup.Copy(path_c, plugin_dir)
tsproc.Setup.Copy(path_cpp, plugin_dir)
tsproc.Setup.Copy(path_h, plugin_dir)

in_basename = os.path.basename(path_c)
out_basename = os.path.splitext(in_basename)[0] + '.so'
out_path = os.path.join(plugin_dir, out_basename)
tsproc.Setup.RunCommand(
("gcc -c -fPIC {path_c} -o {path_c}_o; "
"g++ -c -fPIC {path_cpp} -o {path_cpp}_o; "
"g++ {path_c}_o {path_cpp}_o -shared -o {out_path}").format(
**locals())
)


"""
TEST: This is a regression test for a shared object file that doesn't have all
of the required symbols defined because of a malformed interaction between C
and C++ files.
"""
tr = Test.AddTestRun("Regression test for an undefined, mangled C++ symbol.")
ts = create_ts_process()
plugins_dir = os.path.join(Test.Variables.AtsTestToolsDir, 'plugins')
prepare_undefined_symbol_plugin(
ts,
os.path.join(plugins_dir, 'missing_mangled_definition.c'),
os.path.join(plugins_dir, 'missing_mangled_definition.cc'),
os.path.join(plugins_dir, 'missing_mangled_definition.h'))
plugin_filename = 'missing_mangled_definition.so'
built_plugin_path = os.path.join(Test.Variables.AtsTestPluginsDir, plugin_filename)
ats_plugin_dir = ts.Env['PROXY_CONFIG_PLUGIN_PLUGIN_DIR']
ts.Setup.Copy(built_plugin_path, ats_plugin_dir)
tr.Processes.Default.Env = ts.Env
tr.Processes.Default.Command = \
"traffic_server -C 'verify_global_plugin {filename}'".format(
filename="${PROXY_CONFIG_PLUGIN_PLUGIN_DIR}/missing_mangled_definition.so")
"traffic_server -C 'verify_global_plugin {plugin_path}'".format(
plugin_path=os.path.join(ats_plugin_dir, plugin_filename))
tr.Processes.Default.ReturnCode = 1
tr.Processes.Default.StartBefore(ts)
tr.Processes.Default.Streams.stderr = Testers.ContainsExpression(
"ERROR: .*: undefined symbol: .*foo.*",
"Should warn about the need for the TSPluginInit symbol")
ts.Disk.diags_log.Content = Testers.ContainsExpression("ERROR",
ts.Disk.diags_log.Content = Testers.ContainsExpression(
"ERROR",
"ERROR: .*: undefined symbol: .*foo.*")
12 changes: 6 additions & 6 deletions tests/gold_tests/command_argument/verify_remap_plugin.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def create_ts_process():
tr = Test.AddTestRun("Verify the requirement of our Plugin API.")
ts = create_ts_process()
Test.PreparePlugin(
os.path.join(Test.Variables.AtsTestToolsDir,
'plugins', 'missing_ts_plugin_init.cc'),
os.path.join(Test.Variables.AtsTestPluginsDir,
'missing_ts_plugin_init.so'),
ts)
tr.Processes.Default.Env = ts.Env
tr.Processes.Default.Command = \
Expand All @@ -109,8 +109,8 @@ def create_ts_process():
tr = Test.AddTestRun("Verify a global plugin argument produces warning.")
ts = create_ts_process()
Test.PreparePlugin(
os.path.join(Test.Variables.AtsTestToolsDir,
'plugins', 'ssl_hook_test.cc'),
os.path.join(Test.Variables.AtsTestPluginsDir,
'ssl_hook_test.so'),
ts)
tr.Processes.Default.Env = ts.Env
tr.Processes.Default.Command = \
Expand All @@ -132,8 +132,8 @@ def create_ts_process():
tr = Test.AddTestRun("Verify a properly formed plugin works as expected.")
ts = create_ts_process()
Test.PreparePlugin(
os.path.join(Test.Variables.AtsTestToolsDir,
'plugins', 'conf_remap_stripped.cc'),
os.path.join(Test.Variables.AtsTestPluginsDir,
'conf_remap_stripped.so'),
ts)
tr.Processes.Default.Env = ts.Env
tr.Processes.Default.Command = \
Expand Down
2 changes: 1 addition & 1 deletion tests/gold_tests/cont_schedule/schedule_on_pool.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
})

# Load plugin
Test.PreparePlugin(os.path.join(Test.Variables.AtsTestToolsDir, 'plugins', 'cont_schedule.cc'), ts, 'pool')
Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'cont_schedule.so'), ts, 'pool')

# www.example.com Host
tr = Test.AddTestRun()
Expand Down
Loading