Converted unit tests in src/tracing/tests from NL to PW. (#33390)
* Updated unit tests in tracing/tests to use PW instead of NL.
* Fixed the condition that enables tracing tests. It was "mutliplexed" but that has since been replaced by a full path.
* Remove TracingTests from test_components.txt
diff --git a/src/BUILD.gn b/src/BUILD.gn
index d1dfcc7..01aae8a 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -106,7 +106,7 @@
]
if (matter_enable_tracing_support &&
- matter_trace_config == "multiplexed") {
+ matter_trace_config == "${chip_root}/src/tracing/multiplexed") {
tests += [ "${chip_root}/src/tracing/tests" ]
}
}
diff --git a/src/tracing/tests/BUILD.gn b/src/tracing/tests/BUILD.gn
index 8f28b56..f6b4f13 100644
--- a/src/tracing/tests/BUILD.gn
+++ b/src/tracing/tests/BUILD.gn
@@ -19,8 +19,9 @@
import("${chip_root}/build/chip/chip_test_suite.gni")
import("${chip_root}/src/tracing/tracing_args.gni")
-if (matter_enable_tracing_support && matter_trace_config == "multiplexed") {
- chip_test_suite_using_nltest("tests") {
+if (matter_enable_tracing_support &&
+ matter_trace_config == "${chip_root}/src/tracing/multiplexed") {
+ chip_test_suite("tests") {
output_name = "libTracingTests"
test_sources = [
diff --git a/src/tracing/tests/TestMetricEvents.cpp b/src/tracing/tests/TestMetricEvents.cpp
index 72e159d..916a002 100644
--- a/src/tracing/tests/TestMetricEvents.cpp
+++ b/src/tracing/tests/TestMetricEvents.cpp
@@ -13,12 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <gtest/gtest.h>
#include <lib/support/UnitTestRegistration.h>
#include <tracing/backend.h>
#include <tracing/metric_event.h>
-#include <nlunit-test.h>
-
#include <algorithm>
#include <string>
#include <vector>
@@ -74,56 +73,56 @@
std::vector<MetricEvent> mMetricEvents;
};
-void TestBasicMetricEvent(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestBasicMetricEvent)
{
{
MetricEvent event(MetricEvent::Type::kInstantEvent, "instant_event");
- NL_TEST_ASSERT(inSuite, event.type() == MetricEvent::Type::kInstantEvent);
- NL_TEST_ASSERT(inSuite, std::string(event.key()) == std::string("instant_event"));
- NL_TEST_ASSERT(inSuite, event.ValueType() == MetricEvent::Value::Type::kUndefined);
+ EXPECT_EQ(event.type(), MetricEvent::Type::kInstantEvent);
+ EXPECT_EQ(std::string(event.key()), std::string("instant_event"));
+ EXPECT_EQ(event.ValueType(), MetricEvent::Value::Type::kUndefined);
}
{
MetricEvent event(MetricEvent::Type::kBeginEvent, "begin_event");
- NL_TEST_ASSERT(inSuite, event.type() == MetricEvent::Type::kBeginEvent);
- NL_TEST_ASSERT(inSuite, std::string(event.key()) == std::string("begin_event"));
- NL_TEST_ASSERT(inSuite, event.ValueType() == MetricEvent::Value::Type::kUndefined);
+ EXPECT_EQ(event.type(), MetricEvent::Type::kBeginEvent);
+ EXPECT_EQ(std::string(event.key()), std::string("begin_event"));
+ EXPECT_EQ(event.ValueType(), MetricEvent::Value::Type::kUndefined);
}
{
MetricEvent event(MetricEvent::Type::kEndEvent, "end_event");
- NL_TEST_ASSERT(inSuite, event.type() == MetricEvent::Type::kEndEvent);
- NL_TEST_ASSERT(inSuite, std::string(event.key()) == std::string("end_event"));
- NL_TEST_ASSERT(inSuite, event.ValueType() == MetricEvent::Value::Type::kUndefined);
+ EXPECT_EQ(event.type(), MetricEvent::Type::kEndEvent);
+ EXPECT_EQ(std::string(event.key()), std::string("end_event"));
+ EXPECT_EQ(event.ValueType(), MetricEvent::Value::Type::kUndefined);
}
{
MetricEvent event(MetricEvent::Type::kEndEvent, "end_event_with_int32_value", int32_t(42));
- NL_TEST_ASSERT(inSuite, event.type() == MetricEvent::Type::kEndEvent);
- NL_TEST_ASSERT(inSuite, std::string(event.key()) == std::string("end_event_with_int32_value"));
- NL_TEST_ASSERT(inSuite, event.ValueType() == MetricEvent::Value::Type::kInt32);
- NL_TEST_ASSERT(inSuite, event.ValueInt32() == 42);
+ EXPECT_EQ(event.type(), MetricEvent::Type::kEndEvent);
+ EXPECT_EQ(std::string(event.key()), std::string("end_event_with_int32_value"));
+ EXPECT_EQ(event.ValueType(), MetricEvent::Value::Type::kInt32);
+ EXPECT_EQ(event.ValueInt32(), 42);
}
{
MetricEvent event(MetricEvent::Type::kEndEvent, "end_event_with_uint32_value", uint32_t(42));
- NL_TEST_ASSERT(inSuite, event.type() == MetricEvent::Type::kEndEvent);
- NL_TEST_ASSERT(inSuite, std::string(event.key()) == std::string("end_event_with_uint32_value"));
- NL_TEST_ASSERT(inSuite, event.ValueType() == MetricEvent::Value::Type::kUInt32);
- NL_TEST_ASSERT(inSuite, event.ValueUInt32() == 42u);
+ EXPECT_EQ(event.type(), MetricEvent::Type::kEndEvent);
+ EXPECT_EQ(std::string(event.key()), std::string("end_event_with_uint32_value"));
+ EXPECT_EQ(event.ValueType(), MetricEvent::Value::Type::kUInt32);
+ EXPECT_EQ(event.ValueUInt32(), 42u);
}
{
MetricEvent event(MetricEvent::Type::kEndEvent, "end_event_with_error_value", CHIP_ERROR_BUSY);
- NL_TEST_ASSERT(inSuite, event.type() == MetricEvent::Type::kEndEvent);
- NL_TEST_ASSERT(inSuite, std::string(event.key()) == std::string("end_event_with_error_value"));
- NL_TEST_ASSERT(inSuite, event.ValueType() == MetricEvent::Value::Type::kChipErrorCode);
- NL_TEST_ASSERT(inSuite, chip::ChipError(event.ValueErrorCode()) == CHIP_ERROR_BUSY);
+ EXPECT_EQ(event.type(), MetricEvent::Type::kEndEvent);
+ EXPECT_EQ(std::string(event.key()), std::string("end_event_with_error_value"));
+ EXPECT_EQ(event.ValueType(), MetricEvent::Value::Type::kChipErrorCode);
+ EXPECT_EQ(chip::ChipError(event.ValueErrorCode()), CHIP_ERROR_BUSY);
}
}
-void TestInstantMetricEvent(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestInstantMetricEvent)
{
MetricEventBackend backend;
@@ -141,12 +140,11 @@
MetricEvent(MetricEvent::Type::kInstantEvent, "event3"),
};
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
-void TestBeginEndMetricEvent(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestBeginEndMetricEvent)
{
MetricEventBackend backend1;
MetricEventBackend backend2;
@@ -168,9 +166,8 @@
MetricEvent(MetricEvent::Type::kEndEvent, "event1"),
};
- NL_TEST_ASSERT(inSuite, backend1.GetMetricEvents().size() == expected1.size());
- NL_TEST_ASSERT(
- inSuite,
+ EXPECT_EQ(backend1.GetMetricEvents().size(), expected1.size());
+ EXPECT_TRUE(
std::equal(backend1.GetMetricEvents().begin(), backend1.GetMetricEvents().end(), expected1.begin(), expected1.end()));
{
@@ -197,14 +194,13 @@
MetricEvent(MetricEvent::Type::kEndEvent, "event4"),
};
- NL_TEST_ASSERT(inSuite, backend2.GetMetricEvents().size() == expected2.size());
- NL_TEST_ASSERT(
- inSuite,
+ EXPECT_EQ(backend2.GetMetricEvents().size(), expected2.size());
+ EXPECT_TRUE(
std::equal(backend2.GetMetricEvents().begin(), backend2.GetMetricEvents().end(), expected2.begin(), expected2.end()));
}
}
-void TestScopedMetricEvent(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestScopedMetricEvent)
{
MetricEventBackend backend1;
MetricEventBackend backend2;
@@ -247,9 +243,8 @@
MetricEvent(MetricEvent::Type::kEndEvent, "event1", CHIP_ERROR_BUSY),
};
- NL_TEST_ASSERT(inSuite, backend1.GetMetricEvents().size() == expected1.size());
- NL_TEST_ASSERT(
- inSuite,
+ EXPECT_EQ(backend1.GetMetricEvents().size(), expected1.size());
+ EXPECT_TRUE(
std::equal(backend1.GetMetricEvents().begin(), backend1.GetMetricEvents().end(), expected1.begin(), expected1.end()));
std::vector<MetricEvent> expected2 = {
@@ -261,9 +256,8 @@
MetricEvent(MetricEvent::Type::kEndEvent, "event2", CHIP_ERROR_BAD_REQUEST),
};
- NL_TEST_ASSERT(inSuite, backend2.GetMetricEvents().size() == expected2.size());
- NL_TEST_ASSERT(
- inSuite,
+ EXPECT_EQ(backend2.GetMetricEvents().size(), expected2.size());
+ EXPECT_TRUE(
std::equal(backend2.GetMetricEvents().begin(), backend2.GetMetricEvents().end(), expected2.begin(), expected2.end()));
std::vector<MetricEvent> expected3 = {
@@ -271,9 +265,8 @@
MetricEvent(MetricEvent::Type::kEndEvent, "event3", CHIP_ERROR_EVENT_ID_FOUND),
};
- NL_TEST_ASSERT(inSuite, backend3.GetMetricEvents().size() == expected3.size());
- NL_TEST_ASSERT(
- inSuite,
+ EXPECT_EQ(backend3.GetMetricEvents().size(), expected3.size());
+ EXPECT_TRUE(
std::equal(backend3.GetMetricEvents().begin(), backend3.GetMetricEvents().end(), expected3.begin(), expected3.end()));
}
}
@@ -283,7 +276,7 @@
return input * 2;
}
-void TestVerifyOrExitWithMetric(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestVerifyOrExitWithMetric)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
@@ -297,13 +290,12 @@
MetricEvent(MetricEvent::Type::kInstantEvent, "event1", CHIP_ERROR_INCORRECT_STATE),
};
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE);
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(err, CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
-void TestSuccessOrExitWithMetric(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestSuccessOrExitWithMetric)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
@@ -318,10 +310,9 @@
MetricEvent(MetricEvent::Type::kInstantEvent, "event2", CHIP_ERROR_BUSY),
};
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUSY);
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(err, CHIP_ERROR_BUSY);
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
static CHIP_ERROR InvokeReturnErrorOnFailureWithMetric(MetricKey key, const CHIP_ERROR & error)
@@ -330,28 +321,27 @@
return CHIP_NO_ERROR;
}
-void TestReturnErrorOnFailureWithMetric(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestReturnErrorOnFailureWithMetric)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
CHIP_ERROR err = InvokeReturnErrorOnFailureWithMetric("event0", CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = InvokeReturnErrorOnFailureWithMetric("event1", CHIP_ERROR_INCORRECT_STATE);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(err, CHIP_ERROR_INCORRECT_STATE);
err = InvokeReturnErrorOnFailureWithMetric("event2", CHIP_ERROR_BAD_REQUEST);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BAD_REQUEST);
+ EXPECT_EQ(err, CHIP_ERROR_BAD_REQUEST);
std::vector<MetricEvent> expected = {
MetricEvent(MetricEvent::Type::kInstantEvent, "event1", CHIP_ERROR_INCORRECT_STATE),
MetricEvent(MetricEvent::Type::kInstantEvent, "event2", CHIP_ERROR_BAD_REQUEST),
};
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
static CHIP_ERROR InvokeReturnLogErrorOnFailureWithMetric(MetricKey key, const CHIP_ERROR & error)
@@ -360,28 +350,27 @@
return CHIP_NO_ERROR;
}
-void TestReturnLogErrorOnFailureWithMetric(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestReturnLogErrorOnFailureWithMetric)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
CHIP_ERROR err = InvokeReturnLogErrorOnFailureWithMetric("event0", CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = InvokeReturnLogErrorOnFailureWithMetric("event1", CHIP_ERROR_INCORRECT_STATE);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(err, CHIP_ERROR_INCORRECT_STATE);
err = InvokeReturnLogErrorOnFailureWithMetric("event2", CHIP_ERROR_BAD_REQUEST);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BAD_REQUEST);
+ EXPECT_EQ(err, CHIP_ERROR_BAD_REQUEST);
std::vector<MetricEvent> expected = {
MetricEvent(MetricEvent::Type::kInstantEvent, "event1", CHIP_ERROR_INCORRECT_STATE),
MetricEvent(MetricEvent::Type::kInstantEvent, "event2", CHIP_ERROR_BAD_REQUEST),
};
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
static void InvokeReturnOnFailureWithMetric(MetricKey key, const CHIP_ERROR & error)
@@ -390,7 +379,7 @@
return;
}
-void TestReturnOnFailureWithMetric(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestReturnOnFailureWithMetric)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
@@ -406,9 +395,8 @@
MetricEvent(MetricEvent::Type::kInstantEvent, "event2", CHIP_ERROR_BAD_REQUEST),
};
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
static void InvokeVerifyOrReturnWithMetric(MetricKey key, bool result)
@@ -417,7 +405,7 @@
return;
}
-void TestInvokeVerifyOrReturnWithMetric(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestInvokeVerifyOrReturnWithMetric)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
@@ -432,9 +420,8 @@
MetricEvent(MetricEvent::Type::kInstantEvent, "event3", false),
};
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
static CHIP_ERROR InvokeVerifyOrReturnErrorWithMetric(MetricKey key, bool expr, const CHIP_ERROR & error)
@@ -443,31 +430,30 @@
return CHIP_NO_ERROR;
}
-void TestVerifyOrReturnErrorWithMetric(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestVerifyOrReturnErrorWithMetric)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
CHIP_ERROR err = InvokeVerifyOrReturnErrorWithMetric("event0", DoubleOf(2) == 4, CHIP_ERROR_BAD_REQUEST);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = InvokeVerifyOrReturnErrorWithMetric("event1", DoubleOf(3) == 9, CHIP_ERROR_ACCESS_DENIED);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_ACCESS_DENIED);
+ EXPECT_EQ(err, CHIP_ERROR_ACCESS_DENIED);
err = InvokeVerifyOrReturnErrorWithMetric("event2", DoubleOf(4) == 8, CHIP_ERROR_BUSY);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = InvokeVerifyOrReturnErrorWithMetric("event3", DoubleOf(5) == 11, CHIP_ERROR_CANCELLED);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_CANCELLED);
+ EXPECT_EQ(err, CHIP_ERROR_CANCELLED);
std::vector<MetricEvent> expected = {
MetricEvent(MetricEvent::Type::kInstantEvent, "event1", CHIP_ERROR_ACCESS_DENIED),
MetricEvent(MetricEvent::Type::kInstantEvent, "event3", CHIP_ERROR_CANCELLED),
};
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
template <typename return_code_type>
@@ -477,31 +463,30 @@
return return_code_type();
}
-void TestVerifyOrReturnValueWithMetric(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestVerifyOrReturnValueWithMetric)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
auto retval = InvokeVerifyOrReturnValueWithMetric("event0", DoubleOf(2) == 4, 0);
- NL_TEST_ASSERT(inSuite, retval == 0);
+ EXPECT_EQ(retval, 0);
auto err = InvokeVerifyOrReturnValueWithMetric("event1", DoubleOf(3) == 9, CHIP_ERROR_ACCESS_DENIED);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_ACCESS_DENIED);
+ EXPECT_EQ(err, CHIP_ERROR_ACCESS_DENIED);
err = InvokeVerifyOrReturnValueWithMetric("event2", DoubleOf(4) == 8, CHIP_ERROR_BAD_REQUEST);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
retval = InvokeVerifyOrReturnValueWithMetric("event3", DoubleOf(5) == 11, 16);
- NL_TEST_ASSERT(inSuite, retval == 16);
+ EXPECT_EQ(retval, 16);
std::vector<MetricEvent> expected = {
MetricEvent(MetricEvent::Type::kInstantEvent, "event1", CHIP_ERROR_ACCESS_DENIED),
MetricEvent(MetricEvent::Type::kInstantEvent, "event3", 16),
};
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
static CHIP_ERROR InvokeVerifyOrReturnLogErrorWithMetric(MetricKey key, bool expr, const CHIP_ERROR & error)
@@ -510,31 +495,30 @@
return CHIP_NO_ERROR;
}
-void TestVerifyOrReturnLogErrorWithMetric(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestVerifyOrReturnLogErrorWithMetric)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
auto err = InvokeVerifyOrReturnLogErrorWithMetric("event0", DoubleOf(2) == 4, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = InvokeVerifyOrReturnLogErrorWithMetric("event1", DoubleOf(3) == 9, CHIP_ERROR_CANCELLED);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_CANCELLED);
+ EXPECT_EQ(err, CHIP_ERROR_CANCELLED);
err = InvokeVerifyOrReturnLogErrorWithMetric("event2", DoubleOf(4) == 8, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = InvokeVerifyOrReturnLogErrorWithMetric("event3", DoubleOf(5) == 11, CHIP_ERROR_BAD_REQUEST);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BAD_REQUEST);
+ EXPECT_EQ(err, CHIP_ERROR_BAD_REQUEST);
std::vector<MetricEvent> expected = {
MetricEvent(MetricEvent::Type::kInstantEvent, "event1", CHIP_ERROR_CANCELLED),
MetricEvent(MetricEvent::Type::kInstantEvent, "event3", CHIP_ERROR_BAD_REQUEST),
};
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
template <typename return_code_type>
@@ -544,34 +528,33 @@
return return_code_type();
}
-void TestReturnErrorCodeWithMetricIf(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestReturnErrorCodeWithMetricIf)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
auto err = InvokeReturnErrorCodeWithMetricIf("event0", DoubleOf(2) == 4, CHIP_ERROR_DUPLICATE_KEY_ID);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_DUPLICATE_KEY_ID);
+ EXPECT_EQ(err, CHIP_ERROR_DUPLICATE_KEY_ID);
auto retval = InvokeReturnErrorCodeWithMetricIf("event1", DoubleOf(3) == 9, 11);
- NL_TEST_ASSERT(inSuite, retval == 0);
+ EXPECT_EQ(retval, 0);
retval = InvokeReturnErrorCodeWithMetricIf("event2", DoubleOf(4) == 8, 22);
- NL_TEST_ASSERT(inSuite, retval == 22);
+ EXPECT_EQ(retval, 22);
err = InvokeReturnErrorCodeWithMetricIf("event3", DoubleOf(5) == 11, CHIP_ERROR_ACCESS_DENIED);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
std::vector<MetricEvent> expected = {
MetricEvent(MetricEvent::Type::kInstantEvent, "event0", CHIP_ERROR_DUPLICATE_KEY_ID),
MetricEvent(MetricEvent::Type::kInstantEvent, "event2", 22),
};
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
-void TestExitNowWithMetric(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestExitNowWithMetric)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
@@ -584,13 +567,12 @@
MetricEvent(MetricEvent::Type::kInstantEvent, "event0"),
};
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUSY);
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(err, CHIP_ERROR_BUSY);
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
-void TestLogErrorOnFailureWithMetric(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestLogErrorOnFailureWithMetric)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
@@ -606,12 +588,11 @@
MetricEvent(MetricEvent::Type::kInstantEvent, "event3", CHIP_ERROR_BUSY),
};
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
-void TestVerifyOrDoWithMetric(nlTestSuite * inSuite, void * inContext)
+TEST(TestMetricEvents, TestVerifyOrDoWithMetric)
{
MetricEventBackend backend;
ScopedRegistration scope(backend);
@@ -629,41 +610,8 @@
MetricEvent(MetricEvent::Type::kInstantEvent, "event3", false),
};
- NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size());
- NL_TEST_ASSERT(
- inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(backend.GetMetricEvents().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end()));
}
-static const nlTest sMetricTests[] = {
- NL_TEST_DEF("BasicMetricEvent", TestBasicMetricEvent), //
- NL_TEST_DEF("InstantMetricEvent", TestInstantMetricEvent), //
- NL_TEST_DEF("BeginEndMetricEvent", TestBeginEndMetricEvent), //
- NL_TEST_DEF("ScopedMetricEvent", TestScopedMetricEvent), //
- NL_TEST_DEF("VerifyOrExitWithMetric", TestVerifyOrExitWithMetric), //
- NL_TEST_DEF("SuccessOrExitWithMetric", TestSuccessOrExitWithMetric), //
- NL_TEST_DEF("ReturnErrorOnFailureWithMetric", TestReturnErrorOnFailureWithMetric), //
- NL_TEST_DEF("ReturnLogErrorOnFailureWithMetric", TestReturnLogErrorOnFailureWithMetric), //
- NL_TEST_DEF("ReturnOnFailureWithMetric", TestReturnOnFailureWithMetric), //
- NL_TEST_DEF("VerifyOrReturnWithMetric", TestInvokeVerifyOrReturnWithMetric), //
- NL_TEST_DEF("VerifyOrReturnErrorWithMetric", TestVerifyOrReturnErrorWithMetric), //
- NL_TEST_DEF("VerifyOrReturnValueWithMetric", TestVerifyOrReturnValueWithMetric), //
- NL_TEST_DEF("VerifyOrReturnLogErrorWithMetric", TestVerifyOrReturnLogErrorWithMetric), //
- NL_TEST_DEF("ReturnErrorCodeWithMetricIf", TestReturnErrorCodeWithMetricIf), //
- NL_TEST_DEF("ExitNowWithMetric", TestExitNowWithMetric), //
- NL_TEST_DEF("LogErrorOnFailureWithMetric", TestLogErrorOnFailureWithMetric), //
- NL_TEST_DEF("VerifyOrDoWithMetric", TestVerifyOrDoWithMetric), //
- NL_TEST_SENTINEL() //
-};
-
} // namespace
-
-int TestMetricEvents()
-{
- nlTestSuite theSuite = { "Metric event tests", &sMetricTests[0], nullptr, nullptr };
-
- // Run test suite against one context.
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestMetricEvents)
diff --git a/src/tracing/tests/TestTracing.cpp b/src/tracing/tests/TestTracing.cpp
index 61cf07d..88d2a10 100644
--- a/src/tracing/tests/TestTracing.cpp
+++ b/src/tracing/tests/TestTracing.cpp
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <gtest/gtest.h>
#include <lib/support/UnitTestRegistration.h>
#include <tracing/backend.h>
#include <tracing/macros.h>
-
-#include <nlunit-test.h>
+#include <tracing/registry.h>
#include <algorithm>
#include <string>
@@ -52,7 +52,7 @@
std::vector<std::string> mTraces;
};
-void TestBasicTracing(nlTestSuite * inSuite, void * inContext)
+TEST(TestTracing, TestBasicTracing)
{
LoggingTraceBackend backend;
@@ -80,11 +80,11 @@
"END:Group:C", "END:Group:B", "BEGIN:Group:E", "END:Group:E", "END:Group:A",
};
- NL_TEST_ASSERT(inSuite, backend.traces().size() == expected.size());
- NL_TEST_ASSERT(inSuite, std::equal(backend.traces().begin(), backend.traces().end(), expected.begin(), expected.end()));
+ EXPECT_EQ(backend.traces().size(), expected.size());
+ EXPECT_TRUE(std::equal(backend.traces().begin(), backend.traces().end(), expected.begin(), expected.end()));
}
-void TestMultipleBackends(nlTestSuite * inSuite, void * inContext)
+TEST(TestTracing, TestMultipleBackends)
{
LoggingTraceBackend b1;
LoggingTraceBackend b2;
@@ -112,40 +112,23 @@
"BEGIN:G:1", "BEGIN:G:2", "BEGIN:G:3", "END:G:3", "BEGIN:G:4", "END:G:4", "END:G:2", "END:G:1",
};
- NL_TEST_ASSERT(inSuite, b1.traces().size() == expected1.size());
- NL_TEST_ASSERT(inSuite, std::equal(b1.traces().begin(), b1.traces().end(), expected1.begin(), expected1.end()));
+ EXPECT_EQ(b1.traces().size(), expected1.size());
+ EXPECT_TRUE(std::equal(b1.traces().begin(), b1.traces().end(), expected1.begin(), expected1.end()));
std::vector<std::string> expected2 = {
"BEGIN:G:2", "BEGIN:G:3", "END:G:3", "BEGIN:G:4", "END:G:4", "END:G:2",
};
- NL_TEST_ASSERT(inSuite, b2.traces().size() == expected2.size());
- NL_TEST_ASSERT(inSuite, std::equal(b2.traces().begin(), b2.traces().end(), expected2.begin(), expected2.end()));
+ EXPECT_EQ(b2.traces().size(), expected2.size());
+ EXPECT_TRUE(std::equal(b2.traces().begin(), b2.traces().end(), expected2.begin(), expected2.end()));
std::vector<std::string> expected3 = {
"BEGIN:G:3",
"END:G:3",
};
- NL_TEST_ASSERT(inSuite, b3.traces().size() == expected3.size());
- NL_TEST_ASSERT(inSuite, std::equal(b3.traces().begin(), b3.traces().end(), expected3.begin(), expected3.end()));
+ EXPECT_EQ(b3.traces().size(), expected3.size());
+ EXPECT_TRUE(std::equal(b3.traces().begin(), b3.traces().end(), expected3.begin(), expected3.end()));
}
-const nlTest sTests[] = {
- NL_TEST_DEF("BasicTracing", TestBasicTracing), //
- NL_TEST_DEF("BasicMultipleBackends", TestMultipleBackends), //
- NL_TEST_SENTINEL() //
-};
-
} // namespace
-
-int TestTracing()
-{
- nlTestSuite theSuite = { "Tracing tests", &sTests[0], nullptr, nullptr };
-
- // Run test suite against one context.
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestTracing)