You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2016/04/23 18:25:26 UTC

[trafficserver] branch master updated (5b64377 -> e5dd21f)

This is an automated email from the ASF dual-hosted git repository.

jpeach pushed a change to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git.

      from  5b64377   Add mkheader convenience script.
       new  f672674   TS-4370: Refactor and rename SrcLoc.
       new  e5dd21f   TS-4370: Add a traffic_server option to list tests.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "adds" were already present in the repository and have only
been added to this reference.


Summary of changes:
 doc/appendices/command-line/traffic_server.en.rst |  7 ++-
 iocore/eventsystem/I_Lock.h                       | 40 +++++++--------
 iocore/eventsystem/Lock.cc                        |  6 +--
 iocore/net/P_SSLUtils.h                           | 10 ++--
 iocore/net/SSLUtils.cc                            |  2 +-
 lib/ts/Diags.cc                                   | 40 ++-------------
 lib/ts/Diags.h                                    | 46 ++---------------
 lib/ts/Makefile.am                                |  2 +
 lib/ts/Regression.cc                              | 31 +++++++++---
 lib/ts/Regression.h                               | 22 ++++++---
 lib/ts/SourceLocation.cc                          | 54 ++++++++++++++++++++
 lib/ts/SourceLocation.h                           | 60 +++++++++++++++++++++++
 proxy/Main.cc                                     | 12 ++++-
 proxy/shared/Error.cc                             |  2 +-
 14 files changed, 208 insertions(+), 126 deletions(-)
 create mode 100644 lib/ts/SourceLocation.cc
 create mode 100644 lib/ts/SourceLocation.h

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].

[trafficserver] 01/02: TS-4370: Refactor and rename SrcLoc.

Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit f6726744568401a766c4748c95f799a071824ae9
Author: James Peach <jp...@apache.org>
AuthorDate: Thu Apr 21 21:02:58 2016 -0700

    TS-4370: Refactor and rename SrcLoc.
    
    In preparation for using SrcLoc outside of diaags, split it into
    its own source file with no dependencies, and rename it to
    SourceLocation.
---
 iocore/eventsystem/I_Lock.h | 40 +++++++++++++++---------------
 iocore/eventsystem/Lock.cc  |  6 ++---
 iocore/net/P_SSLUtils.h     | 10 ++++----
 iocore/net/SSLUtils.cc      |  2 +-
 lib/ts/Diags.cc             | 40 +++---------------------------
 lib/ts/Diags.h              | 46 +++-------------------------------
 lib/ts/Makefile.am          |  2 ++
 lib/ts/SourceLocation.cc    | 54 ++++++++++++++++++++++++++++++++++++++++
 lib/ts/SourceLocation.h     | 60 +++++++++++++++++++++++++++++++++++++++++++++
 proxy/shared/Error.cc       |  2 +-
 10 files changed, 154 insertions(+), 108 deletions(-)

diff --git a/iocore/eventsystem/I_Lock.h b/iocore/eventsystem/I_Lock.h
index e90d1bf..5f4cfc5 100644
--- a/iocore/eventsystem/I_Lock.h
+++ b/iocore/eventsystem/I_Lock.h
@@ -50,7 +50,7 @@
 
 */
 #ifdef DEBUG
-#define SCOPED_MUTEX_LOCK(_l, _m, _t) MutexLock _l(DiagsMakeLocation(), NULL, _m, _t)
+#define SCOPED_MUTEX_LOCK(_l, _m, _t) MutexLock _l(MakeSourceLocation(), NULL, _m, _t)
 #else
 #define SCOPED_MUTEX_LOCK(_l, _m, _t) MutexLock _l(_m, _t)
 #endif // DEBUG
@@ -69,7 +69,7 @@
   @param _t The current EThread executing your code.
 
 */
-#define MUTEX_TRY_LOCK(_l, _m, _t) MutexTryLock _l(DiagsMakeLocation(), (char *)NULL, _m, _t)
+#define MUTEX_TRY_LOCK(_l, _m, _t) MutexTryLock _l(MakeSourceLocation(), (char *)NULL, _m, _t)
 
 /**
   Attempts to acquire the lock to the ProxyMutex.
@@ -85,7 +85,7 @@
   @param _sc The number of attempts or spin count. It must be a positive value.
 
 */
-#define MUTEX_TRY_LOCK_SPIN(_l, _m, _t, _sc) MutexTryLock _l(DiagsMakeLocation(), (char *)NULL, _m, _t, _sc)
+#define MUTEX_TRY_LOCK_SPIN(_l, _m, _t, _sc) MutexTryLock _l(MakeSourceLocation(), (char *)NULL, _m, _t, _sc)
 
 /**
   Attempts to acquire the lock to the ProxyMutex.
@@ -102,7 +102,7 @@
 
 */
 
-#define MUTEX_TRY_LOCK_FOR(_l, _m, _t, _c) MutexTryLock _l(DiagsMakeLocation(), NULL, _m, _t)
+#define MUTEX_TRY_LOCK_FOR(_l, _m, _t, _c) MutexTryLock _l(MakeSourceLocation(), NULL, _m, _t)
 #else // DEBUG
 #define MUTEX_TRY_LOCK(_l, _m, _t) MutexTryLock _l(_m, _t)
 #define MUTEX_TRY_LOCK_SPIN(_l, _m, _t, _sc) MutexTryLock _l(_m, _t, _sc)
@@ -126,9 +126,9 @@
 /////////////////////////////////////
 // DEPRECATED DEPRECATED DEPRECATED
 #ifdef DEBUG
-#define MUTEX_TAKE_TRY_LOCK(_m, _t) Mutex_trylock(DiagsMakeLocation(), (char *)NULL, _m, _t)
-#define MUTEX_TAKE_TRY_LOCK_FOR(_m, _t, _c) Mutex_trylock(DiagsMakeLocation(), (char *)NULL, _m, _t)
-#define MUTEX_TAKE_TRY_LOCK_FOR_SPIN(_m, _t, _c, _sc) Mutex_trylock_spin(DiagsMakeLocation(), NULL, _m, _t, _sc)
+#define MUTEX_TAKE_TRY_LOCK(_m, _t) Mutex_trylock(MakeSourceLocation(), (char *)NULL, _m, _t)
+#define MUTEX_TAKE_TRY_LOCK_FOR(_m, _t, _c) Mutex_trylock(MakeSourceLocation(), (char *)NULL, _m, _t)
+#define MUTEX_TAKE_TRY_LOCK_FOR_SPIN(_m, _t, _c, _sc) Mutex_trylock_spin(MakeSourceLocation(), NULL, _m, _t, _sc)
 #else
 #define MUTEX_TAKE_TRY_LOCK(_m, _t) Mutex_trylock(_m, _t)
 #define MUTEX_TAKE_TRY_LOCK_FOR(_m, _t, _c) Mutex_trylock(_m, _t)
@@ -136,8 +136,8 @@
 #endif
 
 #ifdef DEBUG
-#define MUTEX_TAKE_LOCK(_m, _t) Mutex_lock(DiagsMakeLocation(), (char *)NULL, _m, _t)
-#define MUTEX_TAKE_LOCK_FOR(_m, _t, _c) Mutex_lock(DiagsMakeLocation(), NULL, _m, _t)
+#define MUTEX_TAKE_LOCK(_m, _t) Mutex_lock(MakeSourceLocation(), (char *)NULL, _m, _t)
+#define MUTEX_TAKE_LOCK_FOR(_m, _t, _c) Mutex_lock(MakeSourceLocation(), NULL, _m, _t)
 #else
 #define MUTEX_TAKE_LOCK(_m, _t) Mutex_lock(_m, _t)
 #define MUTEX_TAKE_LOCK_FOR(_m, _t, _c) Mutex_lock(_m, _t)
@@ -152,9 +152,9 @@ typedef EThread *EThreadPtr;
 typedef volatile EThreadPtr VolatileEThreadPtr;
 
 #if DEBUG
-inkcoreapi extern void lock_waiting(const SrcLoc &, const char *handler);
-inkcoreapi extern void lock_holding(const SrcLoc &, const char *handler);
-inkcoreapi extern void lock_taken(const SrcLoc &, const char *handler);
+inkcoreapi extern void lock_waiting(const SourceLocation &, const char *handler);
+inkcoreapi extern void lock_holding(const SourceLocation &, const char *handler);
+inkcoreapi extern void lock_taken(const SourceLocation &, const char *handler);
 #endif
 
 /**
@@ -209,7 +209,7 @@ public:
 
 #ifdef DEBUG
   ink_hrtime hold_time;
-  SrcLoc srcloc;
+  SourceLocation srcloc;
   const char *handler;
 
 #ifdef MAX_LOCK_TAKEN
@@ -280,7 +280,7 @@ extern inkcoreapi ClassAllocator<ProxyMutex> mutexAllocator;
 inline bool
 Mutex_trylock(
 #ifdef DEBUG
-  const SrcLoc &location, const char *ahandler,
+  const SourceLocation &location, const char *ahandler,
 #endif
   ProxyMutex *m, EThread *t)
 {
@@ -324,7 +324,7 @@ Mutex_trylock(
 inline bool
 Mutex_trylock_spin(
 #ifdef DEBUG
-  const SrcLoc &location, const char *ahandler,
+  const SourceLocation &location, const char *ahandler,
 #endif
   ProxyMutex *m, EThread *t, int spincnt = 1)
 {
@@ -373,7 +373,7 @@ Mutex_trylock_spin(
 inline int
 Mutex_lock(
 #ifdef DEBUG
-  const SrcLoc &location, const char *ahandler,
+  const SourceLocation &location, const char *ahandler,
 #endif
   ProxyMutex *m, EThread *t)
 {
@@ -416,7 +416,7 @@ Mutex_unlock(ProxyMutex *m, EThread *t)
       if (m->taken > MAX_LOCK_TAKEN)
         lock_taken(m->srcloc, m->handler);
 #endif // MAX_LOCK_TAKEN
-      m->srcloc = SrcLoc(NULL, NULL, 0);
+      m->srcloc = SourceLocation(NULL, NULL, 0);
       m->handler = NULL;
 #endif // DEBUG
       ink_assert(m->thread_holding);
@@ -436,7 +436,7 @@ private:
 public:
   MutexLock(
 #ifdef DEBUG
-    const SrcLoc &location, const char *ahandler,
+    const SourceLocation &location, const char *ahandler,
 #endif // DEBUG
     ProxyMutex *am, EThread *t)
     : m(am)
@@ -462,7 +462,7 @@ private:
 public:
   MutexTryLock(
 #ifdef DEBUG
-    const SrcLoc &location, const char *ahandler,
+    const SourceLocation &location, const char *ahandler,
 #endif // DEBUG
     ProxyMutex *am, EThread *t)
     : m(am)
@@ -476,7 +476,7 @@ public:
 
   MutexTryLock(
 #ifdef DEBUG
-    const SrcLoc &location, const char *ahandler,
+    const SourceLocation &location, const char *ahandler,
 #endif // DEBUG
     ProxyMutex *am, EThread *t, int sp)
     : m(am)
diff --git a/iocore/eventsystem/Lock.cc b/iocore/eventsystem/Lock.cc
index 098884c..401532a 100644
--- a/iocore/eventsystem/Lock.cc
+++ b/iocore/eventsystem/Lock.cc
@@ -34,7 +34,7 @@
 ClassAllocator<ProxyMutex> mutexAllocator("mutexAllocator");
 
 void
-lock_waiting(const SrcLoc &srcloc, const char *handler)
+lock_waiting(const SourceLocation &srcloc, const char *handler)
 {
   if (is_diags_on("locks")) {
     char buf[128];
@@ -43,7 +43,7 @@ lock_waiting(const SrcLoc &srcloc, const char *handler)
 }
 
 void
-lock_holding(const SrcLoc &srcloc, const char *handler)
+lock_holding(const SourceLocation &srcloc, const char *handler)
 {
   if (is_diags_on("locks")) {
     char buf[128];
@@ -52,7 +52,7 @@ lock_holding(const SrcLoc &srcloc, const char *handler)
 }
 
 void
-lock_taken(const SrcLoc &srcloc, const char *handler)
+lock_taken(const SourceLocation &srcloc, const char *handler)
 {
   if (is_diags_on("locks")) {
     char buf[128];
diff --git a/iocore/net/P_SSLUtils.h b/iocore/net/P_SSLUtils.h
index f890190..9a15426 100644
--- a/iocore/net/P_SSLUtils.h
+++ b/iocore/net/P_SSLUtils.h
@@ -133,11 +133,11 @@ ssl_error_t SSLAccept(SSL *ssl);
 ssl_error_t SSLConnect(SSL *ssl);
 
 // Log an SSL error.
-#define SSLError(fmt, ...) SSLDiagnostic(DiagsMakeLocation(), false, NULL, fmt, ##__VA_ARGS__)
-#define SSLErrorVC(vc, fmt, ...) SSLDiagnostic(DiagsMakeLocation(), false, (vc), fmt, ##__VA_ARGS__)
+#define SSLError(fmt, ...) SSLDiagnostic(MakeSourceLocation(), false, NULL, fmt, ##__VA_ARGS__)
+#define SSLErrorVC(vc, fmt, ...) SSLDiagnostic(MakeSourceLocation(), false, (vc), fmt, ##__VA_ARGS__)
 // Log a SSL diagnostic using the "ssl" diagnostic tag.
-#define SSLDebug(fmt, ...) SSLDiagnostic(DiagsMakeLocation(), true, NULL, fmt, ##__VA_ARGS__)
-#define SSLDebugVC(vc, fmt, ...) SSLDiagnostic(DiagsMakeLocation(), true, (vc), fmt, ##__VA_ARGS__)
+#define SSLDebug(fmt, ...) SSLDiagnostic(MakeSourceLocation(), true, NULL, fmt, ##__VA_ARGS__)
+#define SSLDebugVC(vc, fmt, ...) SSLDiagnostic(MakeSourceLocation(), true, (vc), fmt, ##__VA_ARGS__)
 
 #define SSL_CLR_ERR_INCR_DYN_STAT(vc, x, fmt, ...) \
   do {                                             \
@@ -145,7 +145,7 @@ ssl_error_t SSLConnect(SSL *ssl);
     RecIncrRawStat(ssl_rsb, NULL, (int)x, 1);      \
   } while (0)
 
-void SSLDiagnostic(const SrcLoc &loc, bool debug, SSLNetVConnection *vc, const char *fmt, ...) TS_PRINTFLIKE(4, 5);
+void SSLDiagnostic(const SourceLocation &loc, bool debug, SSLNetVConnection *vc, const char *fmt, ...) TS_PRINTFLIKE(4, 5);
 
 // Return a static string name for a SSL_ERROR constant.
 const char *SSLErrorName(int ssl_error);
diff --git a/iocore/net/SSLUtils.cc b/iocore/net/SSLUtils.cc
index 0c419b9..96af263 100644
--- a/iocore/net/SSLUtils.cc
+++ b/iocore/net/SSLUtils.cc
@@ -1116,7 +1116,7 @@ increment_ssl_server_error(unsigned long err)
 }
 
 void
-SSLDiagnostic(const SrcLoc &loc, bool debug, SSLNetVConnection *vc, const char *fmt, ...)
+SSLDiagnostic(const SourceLocation &loc, bool debug, SSLNetVConnection *vc, const char *fmt, ...)
 {
   unsigned long l;
   char buf[256];
diff --git a/lib/ts/Diags.cc b/lib/ts/Diags.cc
index f5543bb..3c6accd 100644
--- a/lib/ts/Diags.cc
+++ b/lib/ts/Diags.cc
@@ -67,39 +67,6 @@ vprintline(FILE *fp, char (&buffer)[Size], va_list ap)
 
 //////////////////////////////////////////////////////////////////////////////
 //
-//      char *SrcLoc::str(char *buf, int buflen)
-//
-//      This method takes a SrcLoc source location data structure and
-//      converts it to a human-readable representation, in the buffer <buf>
-//      with length <buflen>.  The buffer will always be NUL-terminated, and
-//      must always have a length of at least 1.  The buffer address is
-//      returned on success.  The routine will only fail if the SrcLoc is
-//      not valid, or the buflen is less than 1.
-//
-//////////////////////////////////////////////////////////////////////////////
-
-char *
-SrcLoc::str(char *buf, int buflen) const
-{
-  const char *shortname;
-
-  if (!this->valid() || buflen < 1)
-    return (NULL);
-
-  shortname = strrchr(file, '/');
-  shortname = shortname ? (shortname + 1) : file;
-
-  if (func != NULL) {
-    snprintf(buf, buflen, "%s:%d (%s)", shortname, line, func);
-  } else {
-    snprintf(buf, buflen, "%s:%d", shortname, line);
-  }
-  buf[buflen - 1] = NUL;
-  return (buf);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-//
 //      Diags::Diags(char *bdt, char *bat)
 //
 //      This is the constructor for the Diags class.  The constructor takes
@@ -229,7 +196,8 @@ Diags::~Diags()
 //////////////////////////////////////////////////////////////////////////////
 
 void
-Diags::print_va(const char *debug_tag, DiagsLevel diags_level, const SrcLoc *loc, const char *format_string, va_list ap) const
+Diags::print_va(const char *debug_tag, DiagsLevel diags_level, const SourceLocation *loc, const char *format_string,
+                va_list ap) const
 {
   struct timeval tp;
   const char *s;
@@ -545,7 +513,7 @@ Diags::log(const char *tag, DiagsLevel level, const char *file, const char *func
   va_list ap;
   va_start(ap, format_string);
   if (show_location) {
-    SrcLoc lp(file, func, line);
+    SourceLocation lp(file, func, line);
     print_va(tag, level, &lp, format_string, ap);
   } else {
     print_va(tag, level, NULL, format_string, ap);
@@ -563,7 +531,7 @@ Diags::error_va(DiagsLevel level, const char *file, const char *func, const int
   }
 
   if (show_location) {
-    SrcLoc lp(file, func, line);
+    SourceLocation lp(file, func, line);
     print_va(NULL, level, &lp, format_string, ap);
   } else {
     print_va(NULL, level, NULL, format_string, ap);
diff --git a/lib/ts/Diags.h b/lib/ts/Diags.h
index fc01fc7..0d55e19 100644
--- a/lib/ts/Diags.h
+++ b/lib/ts/Diags.h
@@ -42,6 +42,7 @@
 #include "ContFlags.h"
 #include "ink_inet.h"
 #include "BaseLogFile.h"
+#include "SourceLocation.h"
 
 #define DIAGS_MAGIC 0x12345678
 #define BYTES_IN_MB 1000000
@@ -92,45 +93,6 @@ struct DiagsConfigState {
 
 //////////////////////////////////////////////////////////////////////////////
 //
-//      class SrcLoc
-//
-//      The SrcLoc class wraps up a source code location, including file
-//      name, function name, and line number, and contains a method to
-//      format the result into a string buffer.
-//
-//////////////////////////////////////////////////////////////////////////////
-
-#define DiagsMakeLocation() SrcLoc(__FILE__, __FUNCTION__, __LINE__)
-
-class SrcLoc
-{
-public:
-  const char *file;
-  const char *func;
-  int line;
-
-  bool
-  valid() const
-  {
-    return file && line;
-  }
-
-  SrcLoc(const SrcLoc &rhs) : file(rhs.file), func(rhs.func), line(rhs.line) {}
-  SrcLoc(const char *_file, const char *_func, int _line) : file(_file), func(_func), line(_line) {}
-  SrcLoc &
-  operator=(const SrcLoc &rhs)
-  {
-    this->file = rhs.file;
-    this->func = rhs.func;
-    this->line = rhs.line;
-    return *this;
-  }
-
-  char *str(char *buf, int buflen) const;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-//
 //      class Diags
 //
 //      The Diags class is used for global configuration of the run-time
@@ -194,7 +156,7 @@ public:
 
   const char *level_name(DiagsLevel dl) const;
 
-  inkcoreapi void print_va(const char *tag, DiagsLevel dl, const SrcLoc *loc, const char *format_string, va_list ap) const;
+  inkcoreapi void print_va(const char *tag, DiagsLevel dl, const SourceLocation *loc, const char *format_string, va_list ap) const;
 
   //////////////////////////////
   // user printing interfaces //
@@ -207,7 +169,7 @@ public:
     va_list ap;
     va_start(ap, format_string);
     if (show_location) {
-      SrcLoc lp(file, func, line);
+      SourceLocation lp(file, func, line);
       print_va(tag, dl, &lp, format_string, ap);
     } else {
       print_va(tag, dl, NULL, format_string, ap);
@@ -221,7 +183,7 @@ public:
   ///////////////////////////////////////////////////////////////////////
 
   void
-  log_va(const char *tag, DiagsLevel dl, const SrcLoc *loc, const char *format_string, va_list ap)
+  log_va(const char *tag, DiagsLevel dl, const SourceLocation *loc, const char *format_string, va_list ap)
   {
     if (!on(tag))
       return;
diff --git a/lib/ts/Makefile.am b/lib/ts/Makefile.am
index 71ae96e..cb0e076 100644
--- a/lib/ts/Makefile.am
+++ b/lib/ts/Makefile.am
@@ -53,6 +53,8 @@ libtsutil_la_SOURCES = \
   ContFlags.h \
   Diags.cc \
   Diags.h \
+  SourceLocation.h \
+  SourceLocation.cc \
   DynArray.h \
   EventNotify.cc \
   EventNotify.h \
diff --git a/lib/ts/SourceLocation.cc b/lib/ts/SourceLocation.cc
new file mode 100644
index 0000000..7e7ee0f
--- /dev/null
+++ b/lib/ts/SourceLocation.cc
@@ -0,0 +1,54 @@
+/** @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 "SourceLocation.h"
+#include "ink_defs.h"
+#include <stdio.h>
+#include <string.h>
+
+// This method takes a SourceLocation source location data structure and
+// converts it to a human-readable representation, in the buffer <buf>
+// with length <buflen>.  The buffer will always be NUL-terminated, and
+// must always have a length of at least 1.  The buffer address is
+// returned on success.  The routine will only fail if the SourceLocation is
+// not valid, or the buflen is less than 1.
+
+char *
+SourceLocation::str(char *buf, int buflen) const
+{
+  const char *shortname;
+
+  if (!this->valid() || buflen < 1)
+    return (NULL);
+
+  shortname = strrchr(file, '/');
+  shortname = shortname ? (shortname + 1) : file;
+
+  if (func != NULL) {
+    snprintf(buf, buflen, "%s:%d (%s)", shortname, line, func);
+  } else {
+    snprintf(buf, buflen, "%s:%d", shortname, line);
+  }
+  buf[buflen - 1] = NUL;
+  return (buf);
+}
diff --git a/lib/ts/SourceLocation.h b/lib/ts/SourceLocation.h
new file mode 100644
index 0000000..cda2eeb
--- /dev/null
+++ b/lib/ts/SourceLocation.h
@@ -0,0 +1,60 @@
+/** @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.
+ */
+
+#ifndef SOURCELOCATION_H_88F6E38C_ACBB_4EFE_8819_71FCB162AE9B
+#define SOURCELOCATION_H_88F6E38C_ACBB_4EFE_8819_71FCB162AE9B
+
+// The SourceLocation class wraps up a source code location, including
+// file name, function name, and line number, and contains a method to
+// format the result into a string buffer.
+
+#define MakeSourceLocation() SourceLocation(__FILE__, __FUNCTION__, __LINE__)
+
+class SourceLocation
+{
+public:
+  const char *file;
+  const char *func;
+  int line;
+
+  bool
+  valid() const
+  {
+    return file && line;
+  }
+
+  SourceLocation(const SourceLocation &rhs) : file(rhs.file), func(rhs.func), line(rhs.line) {}
+  SourceLocation(const char *_file, const char *_func, int _line) : file(_file), func(_func), line(_line) {}
+  SourceLocation &
+  operator=(const SourceLocation &rhs)
+  {
+    this->file = rhs.file;
+    this->func = rhs.func;
+    this->line = rhs.line;
+    return *this;
+  }
+
+  char *str(char *buf, int buflen) const;
+};
+
+#endif /* SOURCELOCATION_H_88F6E38C_ACBB_4EFE_8819_71FCB162AE9B */
diff --git a/proxy/shared/Error.cc b/proxy/shared/Error.cc
index cb44d12..265b7c9 100644
--- a/proxy/shared/Error.cc
+++ b/proxy/shared/Error.cc
@@ -54,7 +54,7 @@ ErrorClass::operator()(const char *aformat_string, ...)
 void
 ErrorClass::raise(va_list ap, const char * /* prefix ATS_UNUSED */)
 {
-  SrcLoc loc(filename, function_name, line_number);
+  SourceLocation loc(filename, function_name, line_number);
   diags->print_va(NULL, DL_Fatal, &loc, format_string, ap);
 }
 

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.

[trafficserver] 02/02: TS-4370: Add a traffic_server option to list tests.

Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit e5dd21f26b653d1fc9cebadb224587c8d88e4f92
Author: James Peach <jp...@apache.org>
AuthorDate: Wed Apr 20 22:28:43 2016 -0700

    TS-4370: Add a traffic_server option to list tests.
    
    Add the -l option to traffic_server option to list the available
    tests. This is helpful when you want to run specific tests but need
    to know what they are.
    
    This closes #597.
---
 doc/appendices/command-line/traffic_server.en.rst |  7 ++++-
 lib/ts/Regression.cc                              | 31 +++++++++++++++++------
 lib/ts/Regression.h                               | 22 ++++++++++------
 proxy/Main.cc                                     | 12 ++++++++-
 4 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/doc/appendices/command-line/traffic_server.en.rst b/doc/appendices/command-line/traffic_server.en.rst
index 4c0c905..43c0c3c 100644
--- a/doc/appendices/command-line/traffic_server.en.rst
+++ b/doc/appendices/command-line/traffic_server.en.rst
@@ -57,7 +57,12 @@ environments or where the working set is highly variable.
 
 .. option:: -R LEVEL, --regression LEVEL
 
-.. option:: -r TEST, --regression_rest TEST
+.. option:: -r TEST, --regression_test TEST
+
+.. option:: -l, --regression_list
+
+If Traffic Server was built with tests enabled, this option lists
+the available tests.
 
 .. option:: -T TAGS, --debug_tags TAGS
 
diff --git a/lib/ts/Regression.cc b/lib/ts/Regression.cc
index 878197c..4639285 100644
--- a/lib/ts/Regression.cc
+++ b/lib/ts/Regression.cc
@@ -50,14 +50,9 @@ regression_status_string(int status)
               (status == REGRESSION_TEST_PASSED ? "PASSED" : (status == REGRESSION_TEST_INPROGRESS ? "INPROGRESS" : "FAILED")));
 }
 
-RegressionTest::RegressionTest(const char *name_arg, TestFunction *function_arg, int aopt)
+RegressionTest::RegressionTest(const char *_n, const SourceLocation &_l, TestFunction *_f, int _o)
+  : name(_n), location(_l), function(_f), next(0), status(REGRESSION_TEST_NOT_RUN), printed(false), opt(_o)
 {
-  name = name_arg;
-  function = function_arg;
-  status = REGRESSION_TEST_NOT_RUN;
-  printed = 0;
-  opt = aopt;
-
   if (opt == REGRESSION_OPT_EXCLUSIVE) {
     if (exclusive_test)
       this->next = exclusive_test;
@@ -80,7 +75,7 @@ start_test(RegressionTest *t)
   if (tresult != REGRESSION_TEST_INPROGRESS) {
     fprintf(stderr, "    REGRESSION_RESULT %s:%*s %s\n", t->name, 40 - (int)strlen(t->name), " ",
             regression_status_string(tresult));
-    t->printed = 1;
+    t->printed = true;
   }
   return tresult;
 }
@@ -105,6 +100,26 @@ RegressionTest::run(const char *atest)
   return run_some();
 }
 
+void
+RegressionTest::list()
+{
+  char buf[128];
+  const char *bold = "\x1b[1m";
+  const char *unbold = "\x1b[0m";
+
+  if (!isatty(fileno(stdout))) {
+    bold = unbold = "";
+  }
+
+  for (RegressionTest *t = test; t; t = t->next) {
+    fprintf(stdout, "%s%s%s %s\n", bold, t->name, unbold, t->location.str(buf, sizeof(buf)));
+  }
+
+  for (RegressionTest *t = exclusive_test; t; t = t->next) {
+    fprintf(stdout, "%s%s%s %s\n", bold, t->name, unbold, t->location.str(buf, sizeof(buf)));
+  }
+}
+
 int
 RegressionTest::run_some()
 {
diff --git a/lib/ts/Regression.h b/lib/ts/Regression.h
index cec9255..d22d9c4 100644
--- a/lib/ts/Regression.h
+++ b/lib/ts/Regression.h
@@ -26,6 +26,7 @@
 
 #include "ts/ink_platform.h"
 #include "ts/Regex.h"
+#include "ts/Diags.h"
 
 //   Each module should provide one or more regression tests
 //
@@ -60,37 +61,42 @@
 // regression options
 #define REGRESSION_OPT_EXCLUSIVE (1 << 0)
 
+#define RegressionMakeLocation(f) SourceLocation(__FILE__, f, __LINE__)
+
 struct RegressionTest;
 
 typedef void TestFunction(RegressionTest *t, int type, int *status);
 
 struct RegressionTest {
   const char *name;
+  const SourceLocation location;
   TestFunction *function;
   RegressionTest *next;
   int status;
-  int printed;
+  bool printed;
   int opt;
 
-  RegressionTest(const char *name_arg, TestFunction *function_arg, int aopt);
+  RegressionTest(const char *name_arg, const SourceLocation &loc, TestFunction *function_arg, int aopt);
 
   static int final_status;
   static int ran_tests;
   static DFA dfa;
   static RegressionTest *current;
   static int run(const char *name = NULL);
+  static void list();
   static int run_some();
   static int check_status();
 };
 
-#define REGRESSION_TEST(_f)                                             \
-  void RegressionTest_##_f(RegressionTest *t, int atype, int *pstatus); \
-  RegressionTest regressionTest_##_f(#_f, &RegressionTest_##_f, 0);     \
+#define REGRESSION_TEST(_f)                                                                                        \
+  void RegressionTest_##_f(RegressionTest *t, int atype, int *pstatus);                                            \
+  RegressionTest regressionTest_##_f(#_f, RegressionMakeLocation("RegressionTest_" #_f), &RegressionTest_##_f, 0); \
   void RegressionTest_##_f
 
-#define EXCLUSIVE_REGRESSION_TEST(_f)                                                      \
-  void RegressionTest_##_f(RegressionTest *t, int atype, int *pstatus);                    \
-  RegressionTest regressionTest_##_f(#_f, &RegressionTest_##_f, REGRESSION_OPT_EXCLUSIVE); \
+#define EXCLUSIVE_REGRESSION_TEST(_f)                                                                          \
+  void RegressionTest_##_f(RegressionTest *t, int atype, int *pstatus);                                        \
+  RegressionTest regressionTest_##_f(#_f, RegressionMakeLocation("RegressionTest_" #_f), &RegressionTest_##_f, \
+                                     REGRESSION_OPT_EXCLUSIVE);                                                \
   void RegressionTest_##_f
 
 int rprintf(RegressionTest *t, const char *format, ...);
diff --git a/proxy/Main.cc b/proxy/Main.cc
index 089e06a..eec06d9 100644
--- a/proxy/Main.cc
+++ b/proxy/Main.cc
@@ -143,6 +143,7 @@ bool command_valid = false;
 static char const *CMD_VERIFY_CONFIG = "verify_config";
 #if TS_HAS_TESTS
 static char regression_test[1024] = "";
+static int regression_list = 0;
 #endif
 int auto_clear_hostdb_flag = 0;
 extern int fds_limit;
@@ -192,6 +193,7 @@ static const ArgumentDescription argument_descriptions[] = {
 #if TS_HAS_TESTS
   {"regression", 'R', "Regression Level (quick:1..long:3)", "I", &regression_level, "PROXY_REGRESSION", NULL},
   {"regression_test", 'r', "Run Specific Regression Test", "S512", regression_test, "PROXY_REGRESSION_TEST", NULL},
+  {"regression_list", 'l', "List Regression Tests", "T", &regression_list, "PROXY_REGRESSION_LIST", NULL},
 #endif // TS_HAS_TESTS
 
 #if TS_USE_DIAGS
@@ -211,7 +213,7 @@ static const ArgumentDescription argument_descriptions[] = {
   {"read_core", 'c', "Read Core file", "S255", &core_file, NULL, NULL},
 #endif
 
-  {"accept_mss", ' ', "MSS for client connections", "I", &accept_mss, NULL, NULL},
+  {"accept_mss", '-', "MSS for client connections", "I", &accept_mss, NULL, NULL},
   {"poll_timeout", 't', "poll timeout in milliseconds", "I", &poll_timeout, NULL, NULL},
   HELP_ARGUMENT_DESCRIPTION(),
   VERSION_ARGUMENT_DESCRIPTION()};
@@ -1495,6 +1497,14 @@ main(int /* argc ATS_UNUSED */, const char **argv)
   if (cmd_disable_freelist) {
     ink_freelist_init_ops(ink_freelist_malloc_ops());
   }
+
+#if TS_HAS_TESTS
+  if (regression_list) {
+    RegressionTest::list();
+    ::exit(0);
+  }
+#endif
+
   // Specific validity checks.
   if (*conf_dir && command_index != find_cmd_index(CMD_VERIFY_CONFIG)) {
     fprintf(stderr, "-D option can only be used with the %s command\n", CMD_VERIFY_CONFIG);

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.