Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions tensorflow/lite/micro/flatbuffer_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ limitations under the License.

#include "flatbuffers/flexbuffers.h"
#include "tensorflow/lite/micro/test_helpers.h"
#include "tensorflow/lite/micro/testing/micro_test.h"
#include "tensorflow/lite/micro/testing/micro_test_v2.h"

TF_LITE_MICRO_TESTS_BEGIN

TF_LITE_MICRO_TEST(TestFlexbufferWrapper) {
TEST(FlatbufferUtilsTest, TestFlexbufferWrapper) {
struct TestParam {
std::string name;
std::string type;
Expand Down Expand Up @@ -66,16 +64,15 @@ TF_LITE_MICRO_TEST(TestFlexbufferWrapper) {
for (int i = 0; i < param_num; i++) {
std::string& param_value = params[params_sorted[i]].value;
if (params[params_sorted[i]].type == "Int") {
TF_LITE_MICRO_EXPECT(wrapper.ElementAsInt32(i) == std::stoi(param_value));
EXPECT_EQ(wrapper.ElementAsInt32(i), std::stoi(param_value));
} else if (params[params_sorted[i]].type == "Bool") {
TF_LITE_MICRO_EXPECT(wrapper.ElementAsBool(i) == (param_value == "true"));
EXPECT_EQ(wrapper.ElementAsBool(i), (param_value == "true"));
} else if (params[params_sorted[i]].type == "Double") {
TF_LITE_MICRO_EXPECT(wrapper.ElementAsDouble(i) ==
std::stod(param_value));
EXPECT_EQ(wrapper.ElementAsDouble(i), std::stod(param_value));
} else if (params[params_sorted[i]].type == "Float") {
TF_LITE_MICRO_EXPECT(wrapper.ElementAsFloat(i) == std::stof(param_value));
EXPECT_EQ(wrapper.ElementAsFloat(i), std::stof(param_value));
}
}
}

TF_LITE_MICRO_TESTS_END
TF_LITE_MICRO_TESTS_MAIN
12 changes: 5 additions & 7 deletions tensorflow/lite/micro/hexdump_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <cstdint>

#include "tensorflow/lite/micro/span.h"
#include "tensorflow/lite/micro/testing/micro_test.h"
#include "tensorflow/lite/micro/testing/micro_test_v2.h"

constexpr tflite::Span<const char> input{
"This is an input string for testing."};
Expand All @@ -38,22 +38,20 @@ constexpr tflite::Span<const char> expected{
constexpr tflite::Span<const char> expected_no_null{expected.data(),
expected.size() - 1};

TF_LITE_MICRO_TESTS_BEGIN

TF_LITE_MICRO_TEST(TestOutputToBuffer) {
TEST(HexdumpTest, TestOutputToBuffer) {
// Allocate a buffer with an arbitrary amount of extra room so the test has
// the possibility of failing if hexdump mishandles the extra space.
std::array<char, expected.size() + 10> buffer;

tflite::Span<char> output = tflite::hexdump(region, buffer);
TF_LITE_MICRO_EXPECT(output == expected_no_null);
EXPECT_EQ(output, expected_no_null);
}

TF_LITE_MICRO_TEST(TestOutputToDebugLog) {
TEST(HexdumpTest, TestOutputToDebugLog) {
// There's no easy way to verify DebugLog output; however, test it anyhow to
// catch an outright crash, and so the output appears in the log should
// someone wish to examine it.
tflite::hexdump(region);
}

TF_LITE_MICRO_TESTS_END
TF_LITE_MICRO_TESTS_MAIN
42 changes: 19 additions & 23 deletions tensorflow/lite/micro/memory_arena_threshold_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License.
#include "tensorflow/lite/micro/models/keyword_scrambled_model_data.h"
#include "tensorflow/lite/micro/recording_micro_allocator.h"
#include "tensorflow/lite/micro/recording_micro_interpreter.h"
#include "tensorflow/lite/micro/testing/micro_test.h"
#include "tensorflow/lite/micro/testing/micro_test_v2.h"
#include "tensorflow/lite/micro/testing/test_conv_model.h"

/**
Expand Down Expand Up @@ -138,12 +138,11 @@ void EnsureAllocatedSizeThreshold(const char* allocation_type, size_t actual,
// TODO(b/158651472): Better auditing of non-64 bit systems:
if (kIs64BitSystem) {
// 64-bit systems should check floor and ceiling to catch memory savings:
TF_LITE_MICRO_EXPECT_NEAR(actual, expected,
expected * kAllocationThreshold);
EXPECT_NEAR(actual, expected, expected * kAllocationThreshold);
} else {
// Non-64 bit systems should just expect allocation does not exceed the
// ceiling:
TF_LITE_MICRO_EXPECT_LE(actual, expected + expected * kAllocationThreshold);
EXPECT_LE(actual, expected + expected * kAllocationThreshold);
}
}

Expand Down Expand Up @@ -213,24 +212,21 @@ void ValidateModelAllocationThresholds(
sizeof(tflite::NodeAndRegistration) *
thresholds.node_and_registration_count +
thresholds.op_runtime_data_size;
TF_LITE_MICRO_EXPECT_LE(thresholds.tail_alloc_size - tail_est_length,
kAllocationTailMiscCeiling);
EXPECT_LE(thresholds.tail_alloc_size - tail_est_length,
kAllocationTailMiscCeiling);
}

} // namespace

TF_LITE_MICRO_TESTS_BEGIN

TF_LITE_MICRO_TEST(TestKeywordModelMemoryThreshold) {
TEST(MemoryArenaThresholdTest, TestKeywordModelMemoryThreshold) {
tflite::MicroMutableOpResolver<4> op_resolver;
TF_LITE_MICRO_EXPECT_EQ(
EXPECT_EQ(
op_resolver.AddFullyConnected(tflite::Register_FULLY_CONNECTED_INT8()),
kTfLiteOk);
TF_LITE_MICRO_EXPECT_EQ(op_resolver.AddQuantize(), kTfLiteOk);
TF_LITE_MICRO_EXPECT_EQ(
op_resolver.AddSoftmax(tflite::Register_SOFTMAX_INT8_INT16()), kTfLiteOk);
TF_LITE_MICRO_EXPECT_EQ(op_resolver.AddSvdf(tflite::Register_SVDF_INT8()),
kTfLiteOk);
EXPECT_EQ(op_resolver.AddQuantize(), kTfLiteOk);
EXPECT_EQ(op_resolver.AddSoftmax(tflite::Register_SOFTMAX_INT8_INT16()),
kTfLiteOk);
EXPECT_EQ(op_resolver.AddSvdf(tflite::Register_SVDF_INT8()), kTfLiteOk);
tflite::RecordingMicroInterpreter interpreter(
tflite::GetModel(g_keyword_scrambled_model_data), op_resolver,
keyword_model_tensor_arena, kKeywordModelTensorArenaSize);
Expand Down Expand Up @@ -261,14 +257,14 @@ TF_LITE_MICRO_TEST(TestKeywordModelMemoryThreshold) {
thresholds);
}

TF_LITE_MICRO_TEST(TestConvModelMemoryThreshold) {
TEST(MemoryArenaThresholdTest, TestConvModelMemoryThreshold) {
tflite::MicroMutableOpResolver<6> op_resolver;
TF_LITE_MICRO_EXPECT_EQ(op_resolver.AddConv2D(), kTfLiteOk);
TF_LITE_MICRO_EXPECT_EQ(op_resolver.AddQuantize(), kTfLiteOk);
TF_LITE_MICRO_EXPECT_EQ(op_resolver.AddMaxPool2D(), kTfLiteOk);
TF_LITE_MICRO_EXPECT_EQ(op_resolver.AddReshape(), kTfLiteOk);
TF_LITE_MICRO_EXPECT_EQ(op_resolver.AddFullyConnected(), kTfLiteOk);
TF_LITE_MICRO_EXPECT_EQ(op_resolver.AddDequantize(), kTfLiteOk);
EXPECT_EQ(op_resolver.AddConv2D(), kTfLiteOk);
EXPECT_EQ(op_resolver.AddQuantize(), kTfLiteOk);
EXPECT_EQ(op_resolver.AddMaxPool2D(), kTfLiteOk);
EXPECT_EQ(op_resolver.AddReshape(), kTfLiteOk);
EXPECT_EQ(op_resolver.AddFullyConnected(), kTfLiteOk);
EXPECT_EQ(op_resolver.AddDequantize(), kTfLiteOk);

tflite::RecordingMicroInterpreter interpreter(
tflite::GetModel(kTestConvModelData), op_resolver, test_conv_tensor_arena,
Expand Down Expand Up @@ -298,4 +294,4 @@ TF_LITE_MICRO_TEST(TestConvModelMemoryThreshold) {
thresholds);
}

TF_LITE_MICRO_TESTS_END
TF_LITE_MICRO_TESTS_MAIN
Loading
Loading