TS-2436: Add initial tsqa test harness

Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/52ce5d25
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/52ce5d25
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/52ce5d25

Branch: refs/heads/master
Commit: 52ce5d251283178e91d2f0a535b479b797ed0934
Parents: 46b845d
Author: James Peach <[email protected]>
Authored: Fri Dec 13 17:09:51 2013 -0800
Committer: James Peach <[email protected]>
Committed: Mon Dec 16 15:01:02 2013 -0800

----------------------------------------------------------------------
 CHANGES                        |   2 +
 ci/tsqa/functions              | 244 ++++++++++++++++++++++++++++++++++++
 ci/tsqa/test-bootstrap         |  41 ++++++
 ci/tsqa/test-log-configuration |  63 ++++++++++
 4 files changed, 350 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/52ce5d25/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 084d8c2..2bd9fd7 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 4.2.0
 
+  *) [TS-2436] Add a simple integration test harness.
+
   *) [TS-2355] ATS 4.0.x crashes when using OpenSSL 1.0.1e
 
   *) [TS-2432] Fix a race in aio_err_callblk.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/52ce5d25/ci/tsqa/functions
----------------------------------------------------------------------
diff --git a/ci/tsqa/functions b/ci/tsqa/functions
new file mode 100644
index 0000000..8535255
--- /dev/null
+++ b/ci/tsqa/functions
@@ -0,0 +1,244 @@
+#! /usr/bin/env bash
+
+#  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.
+
+NCPU=${NCPU:-$(( $(getconf _NPROCESSORS_ONLN) * 2 ))}
+PORT=${PORT:-9090}
+VALGRIND=${VALGRIND:-N}
+TMPDIR=${TMPDIR:-/tmp}
+
+TSQA_FAIL=0                                         # Test failure count
+TSQA_TESNAME=${TSQA_TESTNAME:-tsqa}                 # Name of current test
+TSQA_ROOT=${TSQA_ROOT:-/tmp/$TSQA_TESTNAME.$RANDOM} # Filesystem root for 
current test
+TSQA_TSXS=${TSQA_TSXS:-tsxs}
+
+# Print a log message/
+msg() {
+  echo "MSG:" "$@"
+}
+
+# Print a failure message and increment the failure count.
+fail() {
+  TSQA_FAIL=$(($TSQA_FAIL + 1))
+  echo "FAIL:" "$@" 1>&2
+}
+
+# Fail and exit.
+fatal() {
+  TSQA_FAIL=$(($TSQA_FAIL + 1))
+  echo "FATAL:" "$@" 1>&2
+  exit $TSQA_FAIL
+}
+
+# Run a command and silence any output on stderr.
+quiet() {
+  "$@" 2>/dev/null
+}
+
+tsxs() {
+  $TSQA_TSXS "$@"
+}
+
+tsexec() {
+  local cmd="$1"
+  local run
+  shift
+
+  case $VALGRIND in
+    y|yes|Y|YES|1) run="valgrind --trace-children=yes 
--trace-children-skip=env env" ;;
+    *) run=env ;;
+  esac
+
+  # MALLOC_CHECK_=2 => enable glibc malloc checking, abort on error
+  # MallocStackLogging=1 => record OS X malloc stacks for leak checking
+  $run \
+  MallocStackLogging=1 \
+  MALLOC_CHECK_=2 \
+  TS_ROOT=$TSQA_ROOT \
+  PROXY_CONFIG_HTTP_SERVER_PORTS=$PORT \
+    $(bindir)/$cmd "$@"
+}
+
+reconfigure() {
+  local srcdir="$1"
+  msg running autoreconf in $srcdir ...
+  (
+    cd "$srcdir"
+    autoreconf -i
+  ) > autoreconf.log 2>&1
+}
+
+install () {
+  [[ -d $BUILD ]] && rm -rf $BUILD
+  [[ -d $PREFIX ]] && rm -rf $PREFIX
+
+  msg installing ...
+  mkdir -p $BUILD && (
+    cd $BUILD
+    $SRC/configure \
+      --prefix=$PREFIX \
+      --with-user=$(id -un) \
+      --enable-debug \
+      CCFLAGS=-O0 CXXFLAGS=-O0
+    make -j $NCPU && make install
+  ) > /dev/null
+
+  msg installed to $PREFIX
+}
+
+logdir() {
+  local prefix=$(tsxs -q PREFIX)
+  tsxs -q LOGDIR | sed -es+$prefix/++
+}
+
+runtimedir() {
+  local prefix=$(tsxs -q PREFIX)
+  tsxs -q RUNTIMEDIR | sed -es+$prefix/++
+}
+
+sysconfdir() {
+  local prefix=$(tsxs -q PREFIX)
+  tsxs -q SYSCONFDIR | sed -es+$prefix/++
+}
+
+bindir() {
+  tsxs -q BINDIR
+}
+
+# pidof(name): echo the pid of the given process name
+pidof() {
+  case "$1" in
+  cop|manager|server);;
+  *) fatal no such process name: $1
+  esac
+  quiet cat $TSQA_ROOT/$(runtimedir)/${1}.lock
+}
+
+# alive(name): Test whether the process "name" is alive.
+alive() {
+  local pid=$(pidof $1)
+  if [[ ! -z "$pid" ]] ; then
+    quiet kill -0 $pid
+    return $?
+  fi
+
+  false
+}
+
+# Start up Traffic Server. Test for all the processes so that we have a better
+# chance of delaying the test until traffic_server is ready.
+startup() {
+  tsexec traffic_cop &
+  for proc in cop manager server; do
+    for i in $(seq 10) ; do
+      alive $proc && msg $proc is alive && break
+      sleep 1
+    done
+  done
+
+  # And a final sleep to let traffic_server come up ...
+  sleep 2
+}
+
+# Shut down Traffic Server.
+shutdown() {
+  local pid=$(pidof cop)
+  if [[ -z "$pid" ]] ; then
+    return
+  fi
+
+  # If we are on Darwin, we can check the traffic_server for leaks before 
shutting down
+  if [ -x /usr/bin/leaks ]; then
+    msg checking for leaks ...
+    /usr/bin/leaks $(pidof server)
+  fi
+
+  msg shutting down ...
+  while quiet kill -0 $pid ; do
+    quiet kill -TERM $pid
+    pid=$(pidof cop)
+    if [[ -z "$pid" ]] ; then
+      return
+    fi
+  done
+
+  exit $TSQA_FAIL
+}
+
+# Test for Traffic Server crash logs.
+crash() {
+  local outfile="$TSQA_ROOT/$(logdir)/traffic.out"
+
+  msg checking for crashes ...
+  for i in $(seq 10); do
+    sleep 1
+    [[ -e $outfile ]] && \
+      grep -a -A 10 "STACK TRACE" $outfile && \
+      fail detected a crash
+  done
+}
+
+# Bootstrap a TSQA test root. The result of this is an independent test root
+# that contains all the variable parts of a traffic server configuration, while
+# referring to the parent installation for the actual test binaries.
+bootstrap() {
+  local prefix=$(tsxs -q PREFIX)
+  local sysconfdir=$(tsxs -q SYSCONFDIR | sed -es+$prefix/++)
+  local dir
+
+  # Create runtime directories in the test root.
+  for dir in SYSCONFDIR LOCALSTATEDIR RUNTIMEDIR LOGDIR ; do
+    local p=$(tsxs -q $dir | sed -es+$prefix/++)
+    mkdir -p $TSQA_ROOT/$p
+  done
+
+  # Copy config across
+  cp -r $(tsxs -q SYSCONFDIR)/*.config $TSQA_ROOT/$sysconfdir
+
+  # Delete any config variables we are about to set.
+  sed -i.orig \
+    -e/proxy.config.body_factory.template_sets_dir/d \
+    -e/proxy.config.plugin.plugin_dir/d \
+    -e/proxy.config.bin_path/d \
+    -e/proxy.config.admin.user_id/d \
+    -e/proxy.config.diags/d \
+    $TSQA_ROOT/$sysconfdir/records.config
+
+  cat >> $TSQA_ROOT/$sysconfdir/records.config <<EOF
+CONFIG proxy.config.bin_path STRING $(tsxs -q BINDIR)
+CONFIG proxy.config.plugin.plugin_dir STRING $(tsxs -q LIBEXECDIR)
+CONFIG proxy.config.body_factory.template_sets_dir STRING $(tsxs -q 
SYSCONFDIR)/body_factory
+
+CONFIG proxy.config.admin.user_id STRING $(whoami)
+
+CONFIG proxy.config.diags.output.diag STRING OL
+CONFIG proxy.config.diags.output.debug STRING OL
+CONFIG proxy.config.diags.output.status STRING OL
+CONFIG proxy.config.diags.output.note STRING OL
+CONFIG proxy.config.diags.output.warning STRING OL
+CONFIG proxy.config.diags.output.error STRING OL
+CONFIG proxy.config.diags.output.fatal STRING OL
+CONFIG proxy.config.diags.output.alert STRING OL
+CONFIG proxy.config.diags.output.emergency STRING OL
+
+CONFIG proxy.config.diags.debug.enabled INT 1
+CONFIG proxy.config.diags.debug.tags STRING NULL
+CONFIG proxy.config.diags.show_location INT 1
+EOF
+}
+
+# vim: set sw=2 ts=2 et :

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/52ce5d25/ci/tsqa/test-bootstrap
----------------------------------------------------------------------
diff --git a/ci/tsqa/test-bootstrap b/ci/tsqa/test-bootstrap
new file mode 100755
index 0000000..4f817b4
--- /dev/null
+++ b/ci/tsqa/test-bootstrap
@@ -0,0 +1,41 @@
+#! /usr/bin/env bash
+
+#  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.
+
+TSQA_TSXS=${TSQA_TSXS:-/opt/ats/bin/tsxs}
+TSQA_TESTNAME=$(basename $0)
+source $(dirname $0)/functions
+
+# This test verifies that we can start Traffic Server in the test root. It is 
primarily
+# intended as a trivial payload to test the TSQA harness.
+check() {
+
+  msg waiting ...
+  sleep 2
+}
+
+bootstrap
+
+# If Traffic Server is not up, bring it up ...
+alive cop || startup || fatal unable to start Traffic Server
+trap shutdown 0 EXIT
+
+check
+
+exit $TSQA_FAIL
+
+# vim: set sw=2 ts=2 et :

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/52ce5d25/ci/tsqa/test-log-configuration
----------------------------------------------------------------------
diff --git a/ci/tsqa/test-log-configuration b/ci/tsqa/test-log-configuration
new file mode 100755
index 0000000..b68cd24
--- /dev/null
+++ b/ci/tsqa/test-log-configuration
@@ -0,0 +1,63 @@
+#! /usr/bin/env bash
+
+#  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.
+
+COUNT=${COUNT:-10}
+TSQA_TSXS=${TSQA_TSXS:-/opt/ats/bin/tsxs}
+TSQA_TESTNAME=$(basename $0)
+source $(dirname $0)/functions
+
+# This test verifies that online reloading of the logging configuration
+# does not crash Traffic Server.
+check() {
+  local logdir=$(logdir)
+
+  for i in $(seq $COUNT) ; do
+    msg check $i ...
+    curl --silent --show-error -o /dev/null -H "Host: not there" 
http://localhost:$PORT
+    tsexec traffic_line -s proxy.config.diags.debug.tags -v 'log-.*'
+    tsexec traffic_line -s proxy.config.diags.debug.enabled -v 1
+    tsexec traffic_line -x
+    sleep 1
+    curl --silent --show-error -o /dev/null -H "Host: not there" 
http://localhost:$PORT
+    # Set a harmless proxy.config.log.hostname to trigger a config reload ...
+    tsexec traffic_line -s proxy.config.log.hostname -v jpeach-test-$$-$i
+    tsexec traffic_line -s proxy.config.log.search_top_sites -v $i
+    tsexec traffic_line -x
+    sleep 1
+    curl --silent --show-error -o /dev/null -H "Host: not there" 
http://localhost:$PORT
+    crash
+
+    # Verify that we have all the error logs that we expect.
+    for logfile in error.log diags.log manager.log traffic.out ; do
+      [[ -e $TSQA_ROOT/$logdir/$logfile ]] || fatal $logfile is missing
+    done
+
+  done
+}
+
+bootstrap
+
+# If Traffic Server is not up, bring it up ...
+alive cop || startup || fatal unable to start Traffic Server
+trap shutdown 0 EXIT
+
+check
+
+exit $TSQA_FAIL
+
+# vim: set sw=2 ts=2 et :

Reply via email to