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

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


The following commit(s) were added to refs/heads/NewAPIMetricsPOC by this push:
     new 342049b15f add cmake support and a unittest. Fix crasher
342049b15f is described below

commit 342049b15f11d6dd762afd82d45e161759e0141f
Author: Chris McFarlen <cmcfar...@apple.com>
AuthorDate: Thu Jul 6 15:44:14 2023 -0500

    add cmake support and a unittest. Fix crasher
---
 CMakeLists.txt                                     |  1 +
 include/api/Metrics.h                              |  3 +-
 .../TSVConnFd => src/api}/CMakeLists.txt           | 13 ++++---
 src/api/Metrics.cc                                 |  2 +-
 src/api/test_Metrics.cc                            | 40 ++++++++++++++++++++++
 src/records/CMakeLists.txt                         |  1 +
 .../gold_tests/pluginTest/TSVConnFd/CMakeLists.txt |  4 ++-
 7 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d17008f78e..fdb08b4bfc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -335,6 +335,7 @@ configure_file(include/ts/apidefs.h.in include/ts/apidefs.h)
 
 enable_testing()
 
+add_subdirectory(src/api)
 add_subdirectory(src/tscpp/util)
 add_subdirectory(src/tscpp/api)
 add_subdirectory(src/tscore)
diff --git a/include/api/Metrics.h b/include/api/Metrics.h
index 0379c7ceb4..f343c0d786 100644
--- a/include/api/Metrics.h
+++ b/include/api/Metrics.h
@@ -32,6 +32,7 @@
 #include <cstdint>
 
 #include "records/P_RecDefs.h"
+#include "ts/apidefs.h"
 
 namespace ts
 {
@@ -63,7 +64,7 @@ public:
 
   virtual ~Metrics() = default;
 
-  Metrics() { _addBlob(); }
+  Metrics() { _blobs[0] = new MetricStorage(); }
 
   // Singleton
   static Metrics &getInstance();
diff --git a/tests/gold_tests/pluginTest/TSVConnFd/CMakeLists.txt 
b/src/api/CMakeLists.txt
similarity index 72%
copy from tests/gold_tests/pluginTest/TSVConnFd/CMakeLists.txt
copy to src/api/CMakeLists.txt
index 6c066fd313..718d9eda5c 100644
--- a/tests/gold_tests/pluginTest/TSVConnFd/CMakeLists.txt
+++ b/src/api/CMakeLists.txt
@@ -15,9 +15,12 @@
 #
 #######################
 
-add_library(TSVConnFd SHARED TSVConnFd.cc)
+add_library(tsapi STATIC Metrics.cc)
 
-set_target_properties(TSVConnFd PROPERTIES
-    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.libs"
-    PREFIX ""
-)
+add_executable(test_Metrics
+        test_Metrics.cc
+        )
+target_link_libraries(test_Metrics PRIVATE tsapi tscore)
+target_include_directories(test_Metrics PRIVATE ${CMAKE_SOURCE_DIR}/include 
${CATCH_INCLUDE_DIR})
+
+add_test(NAME test_Metrics COMMAND $<TARGET_FILE:test_Metrics>)
diff --git a/src/api/Metrics.cc b/src/api/Metrics.cc
index a95588c172..b2d04d31df 100644
--- a/src/api/Metrics.cc
+++ b/src/api/Metrics.cc
@@ -44,7 +44,7 @@ Metrics::_addBlob() // The mutex must be held before calling 
this!
   ink_assert(blob);
   ink_assert(_cur_blob < Metrics::METRICS_MAX_BLOBS);
 
-  _blobs[_cur_blob++] = blob;
+  _blobs[++_cur_blob] = blob;
   _cur_off            = 0;
 }
 
diff --git a/src/api/test_Metrics.cc b/src/api/test_Metrics.cc
new file mode 100644
index 0000000000..83f7d4df80
--- /dev/null
+++ b/src/api/test_Metrics.cc
@@ -0,0 +1,40 @@
+/** @file
+
+    TextView unit tests.
+
+    @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.
+*/
+
+#define CATCH_CONFIG_MAIN
+#include "catch.hpp"
+
+#include "api/Metrics.h"
+
+TEST_CASE("Metrics", "[libtsapi][Metrics]")
+{
+  ts::Metrics m;
+
+  auto fooid = m.newMetric("foo");
+
+  REQUIRE(fooid == 0);
+
+  m.increment(fooid);
+
+  m.recordsDump([](RecT, void *, int, const char *name, int value, RecData *) 
{ printf("Fooo: %s: %d\n", name, value); }, nullptr);
+}
diff --git a/src/records/CMakeLists.txt b/src/records/CMakeLists.txt
index a833909460..c4c01f1a1b 100644
--- a/src/records/CMakeLists.txt
+++ b/src/records/CMakeLists.txt
@@ -48,6 +48,7 @@ target_link_libraries(records_p
         #ts::inkevent cyclic dependency; I_RecProcess.h and P_RecProcess.h
         ts::tscore
         ts::tscpputil
+        tsapi
         yaml-cpp::yaml-cpp
 )
 
diff --git a/tests/gold_tests/pluginTest/TSVConnFd/CMakeLists.txt 
b/tests/gold_tests/pluginTest/TSVConnFd/CMakeLists.txt
index 6c066fd313..13817d9175 100644
--- a/tests/gold_tests/pluginTest/TSVConnFd/CMakeLists.txt
+++ b/tests/gold_tests/pluginTest/TSVConnFd/CMakeLists.txt
@@ -15,9 +15,11 @@
 #
 #######################
 
-add_library(TSVConnFd SHARED TSVConnFd.cc)
+add_library(TSVConnFd MODULE TSVConnFd.cc)
 
 set_target_properties(TSVConnFd PROPERTIES
     LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.libs"
     PREFIX ""
+    SUFFIX ".so"
 )
+target_link_libraries(TSVConnFd PRIVATE tscore traffic_server)

Reply via email to