Home | History | Annotate | Download | only in monitoring
      1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #include "tensorflow/core/lib/monitoring/metric_def.h"
     17 
     18 #include "tensorflow/core/platform/test.h"
     19 
     20 namespace tensorflow {
     21 namespace monitoring {
     22 namespace {
     23 
     24 TEST(MetricDefTest, Simple) {
     25   const MetricDef<MetricKind::kCumulative, int64, 0> metric_def0(
     26       "/tensorflow/metric0", "An example metric with no labels.");
     27   const MetricDef<MetricKind::kGauge, HistogramProto, 1> metric_def1(
     28       "/tensorflow/metric1", "An example metric with one label.", "LabelName");
     29 
     30   EXPECT_EQ("/tensorflow/metric0", metric_def0.name());
     31   EXPECT_EQ("/tensorflow/metric1", metric_def1.name());
     32 
     33   EXPECT_EQ(MetricKind::kCumulative, metric_def0.kind());
     34   EXPECT_EQ(MetricKind::kGauge, metric_def1.kind());
     35 
     36   EXPECT_EQ("An example metric with no labels.", metric_def0.description());
     37   EXPECT_EQ("An example metric with one label.", metric_def1.description());
     38 
     39   EXPECT_EQ(0, metric_def0.label_descriptions().size());
     40   ASSERT_EQ(1, metric_def1.label_descriptions().size());
     41   EXPECT_EQ("LabelName", metric_def1.label_descriptions()[0]);
     42 }
     43 
     44 TEST(MetricDefTest, StringsPersist) {
     45   // Ensure string attributes of the metric are copied into the metric
     46   string name = "/tensorflow/metric0";
     47   string description = "test description";
     48   string label_description = "test label description";
     49   const MetricDef<MetricKind::kCumulative, int64, 1> metric_def(
     50       name, description, label_description);
     51 
     52   // Mutate the strings
     53   name[4] = 'A';
     54   description[4] = 'B';
     55   label_description[4] = 'C';
     56 
     57   EXPECT_NE(name, metric_def.name());
     58   EXPECT_NE(description, metric_def.description());
     59   EXPECT_NE(label_description, metric_def.label_descriptions()[0]);
     60 }
     61 
     62 }  // namespace
     63 }  // namespace monitoring
     64 }  // namespace tensorflow
     65