You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2018/09/20 20:46:06 UTC

[trafficserver] branch master updated: Test: Convert test_arena.cc to Catch

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

bcall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 3f5606e  Test: Convert test_arena.cc to Catch
3f5606e is described below

commit 3f5606e6106735b724d39f94a3a7a8050ec813b3
Author: Xavier Chi <ch...@gmail.com>
AuthorDate: Wed Sep 19 15:36:06 2018 -0500

    Test: Convert test_arena.cc to Catch
---
 .gitignore                                |  1 -
 src/tscore/Makefile.am                    |  6 ++--
 src/tscore/{ => unit_tests}/test_arena.cc | 49 +++++--------------------------
 3 files changed, 10 insertions(+), 46 deletions(-)

diff --git a/.gitignore b/.gitignore
index d5b03d4..f114acc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -79,7 +79,6 @@ src/tscore/ParseRulesCType
 src/tscore/ParseRulesCTypeToLower
 src/tscore/ParseRulesCTypeToUpper
 src/tscore/mkdfa
-src/tscore/test_arena
 src/tscore/test_atomic
 src/tscore/test_freelist
 src/tscore/test_Vec
diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am
index aa1724f..5a47d94 100644
--- a/src/tscore/Makefile.am
+++ b/src/tscore/Makefile.am
@@ -19,7 +19,7 @@
 include $(top_srcdir)/build/tidy.mk
 
 noinst_PROGRAMS = mkdfa CompileParseRules
-check_PROGRAMS = test_arena test_atomic test_freelist test_geometry test_Vec test_X509HostnameValidator test_tscore
+check_PROGRAMS = test_atomic test_freelist test_geometry test_Vec test_X509HostnameValidator test_tscore
 
 TESTS_ENVIRONMENT = LSAN_OPTIONS=suppressions=suppression.txt
 
@@ -237,9 +237,6 @@ test_atomic_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la
 test_freelist_SOURCES = test_freelist.cc
 test_freelist_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@
 
-test_arena_SOURCES = test_arena.cc
-test_arena_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@
-
 test_Vec_SOURCES = test_Vec.cc
 test_Vec_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@
 
@@ -258,6 +255,7 @@ test_tscore_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la
 test_tscore_SOURCES = \
 	unit_tests/unit_test_main.cc \
 	unit_tests/test_AcidPtr.cc \
+	unit_tests/test_arena.cc \
 	unit_tests/test_ArgParser.cc \
 	unit_tests/test_BufferWriter.cc \
 	unit_tests/test_BufferWriterFormat.cc \
diff --git a/src/tscore/test_arena.cc b/src/tscore/unit_tests/test_arena.cc
similarity index 77%
rename from src/tscore/test_arena.cc
rename to src/tscore/unit_tests/test_arena.cc
index 17e7c6d..ec3f28c 100644
--- a/src/tscore/test_arena.cc
+++ b/src/tscore/unit_tests/test_arena.cc
@@ -23,7 +23,7 @@
 
 /****************************************************************************
 
-   ArenaTest.cc
+   test_arena.cc
 
    Description:
 
@@ -33,6 +33,8 @@
 
  ****************************************************************************/
 
+#include "catch.hpp"
+
 #include "tscore/Arena.h"
 #include <cstdio>
 
@@ -47,29 +49,11 @@ fill_test_data(char *ptr, int size, int seed)
   }
 }
 
-int
-check_test_data(char *ptr, int size, int seed)
-{
-  int fail = 0;
-  char a   = 'a' + (seed % 52);
-
-  for (int i = 0; i < size; i++) {
-    if (ptr[i] != a) {
-      fail++;
-    }
-    a = (a + 1) % 52;
-  }
-
-  return fail;
-}
-
-int
-test_block_boundries()
+TEST_CASE("test arena", "[libts][arena]")
 {
   const int sizes_to_test   = 12;
   const int regions_to_test = 1024 * 2;
   char **test_regions       = new char *[regions_to_test];
-  int failures              = 0;
   Arena *a                  = new Arena();
 
   for (int i = 0; i < sizes_to_test; i++) {
@@ -89,14 +73,12 @@ test_block_boundries()
 
     // Now check to make sure the data is correct
     for (j = 0; j < regions_to_test; j++) {
-      int f = check_test_data(test_regions[j], test_size, j);
-
-      if (f != 0) {
-        fprintf(stderr, "block_boundries test failed.  size %d region %d\n", test_size, j);
-        failures++;
+      char a = 'a' + (j % 52);
+      for (int k = 0; k < test_size; k++) {
+        REQUIRE(test_regions[j][k] == a);
+        a = (a + 1) % 52;
       }
     }
-
     // Now free the regions
     for (j = 0; j < regions_to_test; j++) {
       a->free(test_regions[j], test_size);
@@ -107,19 +89,4 @@ test_block_boundries()
 
   delete[] test_regions;
   delete a;
-  return failures;
-}
-
-int
-main()
-{
-  int failures = 0;
-
-  failures += test_block_boundries();
-
-  if (failures) {
-    return 1;
-  } else {
-    return 0;
-  }
 }