Skip to content

Commit 65853c1

Browse files
author
bneradt
committed
Build test C/C++ files with Automake.
Many AuTests have test plugins or test executables that are used as a part of the test. Before this change these were built by ad hoc calls to g++ or gcc via shell executions from within the test or one of a couple AuTest extensions. This patch removes the building of these files from AuTest and instead uses the Automake build system to build these. This will build these utilities in a way that is consistent with the rest of the system, using the same warning and error flags, the same clang tool configurations, etc.
1 parent 93a72ec commit 65853c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+358
-198
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ RELEASE
193193
# autest
194194
tests/env-test/
195195
tests/Pipfile.lock
196+
tests/gold_tests/chunked_encoding/smuggle-client
197+
tests/gold_tests/tls/ssl-post
196198

197199
iocore/cache/test_*
198200
iocore/cache/test/var/trafficserver/cache.db

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export CCACHE_BASEDIR
2727
# and mgmt, hence we have to build proxy/hdrs first.
2828

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

3232
if BUILD_DOCS
3333
SUBDIRS += doc include

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,6 +2216,7 @@ AC_CONFIG_FILES([
22162216
tools/trafficserver.pc
22172217
tools/tsxs
22182218
tests/unit_tests/Makefile
2219+
tests/Makefile
22192220
])
22202221

22212222
# -----------------------------------------------------------------------------

tests/Makefile.am

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
include $(top_srcdir)/build/plugins.mk
18+
include $(top_srcdir)/build/tidy.mk
19+
20+
noinst_LTLIBRARIES =
21+
noinst_PROGRAMS =
22+
23+
SUBDIRS =
24+
25+
AM_LDFLAGS += $(TS_PLUGIN_LD_FLAGS)
26+
27+
# Automake is pretty draconian about not creating shared object (.so) files for
28+
# non-installed files. However we do not want to install our test plugins so
29+
# we prefix them with noinst_. The following -rpath argument coerces the
30+
# generation of so objects for these test files.
31+
AM_LDFLAGS += -rpath $(abs_builddir)
32+
33+
include gold_tests/continuations/plugins/Makefile.inc
34+
include gold_tests/chunked_encoding/Makefile.inc
35+
include gold_tests/tls/Makefile.inc
36+
include tools/plugins/Makefile.inc
37+
38+
TESTS = $(check_PROGRAMS)
39+
40+
clang-tidy-local: $(DIST_SOURCES)
41+
$(CXX_Clang_Tidy)
42+
$(CC_Clang_Tidy)

tests/gold_tests/autest-site/build.test.ext

Lines changed: 0 additions & 53 deletions
This file was deleted.

tests/gold_tests/autest-site/setup.cli.ext

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ if ENV['ATS_BIN'] is not None:
8080
Variables.update(out)
8181
Variables.AtsExampleDir = os.path.join(AutestSitePath, '../../../example')
8282
Variables.AtsTestToolsDir = os.path.join(AutestSitePath, '../../tools')
83+
Variables.AtsTestPluginsDir = os.path.join(AutestSitePath, '../../tools/plugins/.libs')
8384

8485
# modify delay times as we always have to kill Trafficserver
8586
# no need to wait

tests/gold_tests/autest-site/trafficserver_plugins.test.ext

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,33 @@ Builds, installs, and enables an ATS plugin in the sandbox environment
1919

2020
import os
2121

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

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

30-
# Copy the source to the sandbox directory.
31-
plugin_dir = tsproc.Env['PROXY_CONFIG_PLUGIN_PLUGIN_DIR']
32-
tsproc.Setup.Copy(path, plugin_dir)
27+
Args:
28+
so_path (str): The path to a built .so file.
29+
30+
tsproc (Process): The Traffic Server process whose plugin.config should
31+
be configured to use the provided plugin.
3332

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

42-
link_gxx="export CC=c++ &&"
43-
# Compile the plugin.
44-
in_basename = os.path.basename(path)
45-
if in_basename.endswith(".c"):
46-
link_gxx = ''
47-
in_path = os.path.join(plugin_dir, in_basename)
48-
out_basename = os.path.splitext(in_basename)[0] + '.so'
49-
out_path = os.path.join(plugin_dir, out_basename)
50-
tsproc.Setup.RunCommand(
51-
"{pre_args} {tsxs} {args} -c {0} -o {1}".format(
52-
in_path,
53-
out_path,
54-
tsxs=tsxs,
55-
args=" -L {0} {1}".format(self.Variables.LIBDIR, extra_build_args),
56-
pre_args=link_gxx)
57-
)
37+
filename, extension = os.path.splitext(so_path)
38+
if extension != ".so":
39+
raise ValueError('so_path argument must have a ".so" extension. '
40+
'Received: {}'.format(so_path))
41+
42+
# Copy the shared object to the sandbox directory.
43+
plugin_dir = tsproc.Env['PROXY_CONFIG_PLUGIN_PLUGIN_DIR']
44+
tsproc.Setup.Copy(so_path, plugin_dir)
5845

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

62-
# remove this later
63-
ExtendTest(prepare_plugin, name="prepare_plugin")
6450

6551
ExtendTest(prepare_plugin, name="PreparePlugin")

tests/gold_tests/body_factory/http204_response_plugin.test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
)
3838
ts.Disk.MakeConfigFile(regex_remap_conf_file).AddLine('//.*/ http://donotcare.test @status=204')
3939

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

4242
Test.Setup.Copy(os.path.join(os.pardir, os.pardir, 'tools', 'tcp_client.py'))
4343
Test.Setup.Copy('data')
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
noinst_PROGRAMS += gold_tests/chunked_encoding/smuggle-client
18+
gold_tests_chunked_encoding_smuggle_client_SOURCES = gold_tests/chunked_encoding/smuggle-client.c
19+
gold_tests_chunked_encoding_smuggle_client_LDADD = -lssl

tests/gold_tests/chunked_encoding/chunked_encoding.test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@
9090
'dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key'
9191
)
9292

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

9897
# HTTP1.1 GET: www.example.com
9998
tr = Test.AddTestRun()

0 commit comments

Comments
 (0)