Fixes problems spotted by address sanitization testing in recognize_commands
There were two issues. The one that caused the immediate problem was that testing would continue after TF_LITE_MICRO_EXPECT_EQ() failed, since the micro test framework doesn't have the equivalent of ASSERT to abort all testing on a particular failure. That meant we ended up doing a comparison against an uninitialized string, so I added conditional logic to avoid that. There was also a deeper problem though. Running the test under ASAN produced different results, and I determined that this was because a timestamp state variable was being initialized to zero, rather than the expected INT32_MIN value, which led to logic errors further down. I've put in a fix for this too. I also removed two class members that were never used, after I spotted them during my inspection. PiperOrigin-RevId: 234492713
This commit is contained in:
parent
d166674742
commit
6adb75f800
@ -29,7 +29,7 @@ RecognizeCommands::RecognizeCommands(tflite::ErrorReporter* error_reporter,
|
||||
minimum_count_(minimum_count),
|
||||
previous_results_(error_reporter) {
|
||||
previous_top_label_ = "silence";
|
||||
previous_top_label_time_ = 0;
|
||||
previous_top_label_time_ = std::numeric_limits<int32_t>::min();
|
||||
}
|
||||
|
||||
TfLiteStatus RecognizeCommands::ProcessLatestResults(
|
||||
|
||||
@ -149,8 +149,6 @@ class RecognizeCommands {
|
||||
|
||||
// Working variables
|
||||
PreviousResultsQueue previous_results_;
|
||||
int previous_results_head_;
|
||||
int previous_results_tail_;
|
||||
const char* previous_top_label_;
|
||||
int32_t previous_top_label_time_;
|
||||
};
|
||||
|
||||
@ -118,7 +118,9 @@ TF_LITE_MICRO_TEST(RecognizeCommandsTestFindCommands) {
|
||||
}
|
||||
}
|
||||
TF_LITE_MICRO_EXPECT(has_found_new_command);
|
||||
TF_LITE_MICRO_EXPECT_EQ(0, tflite::testing::TestStrcmp("yes", new_command));
|
||||
if (has_found_new_command) {
|
||||
TF_LITE_MICRO_EXPECT_EQ(0, tflite::testing::TestStrcmp("yes", new_command));
|
||||
}
|
||||
|
||||
TfLiteTensor no_results = tflite::testing::CreateQuantizedTensor(
|
||||
{0, 0, 0, 255}, tflite::testing::IntArrayFromInitializer({2, 1, 4}),
|
||||
@ -141,8 +143,10 @@ TF_LITE_MICRO_TEST(RecognizeCommandsTestFindCommands) {
|
||||
}
|
||||
}
|
||||
TF_LITE_MICRO_EXPECT(has_found_new_command);
|
||||
TF_LITE_MICRO_EXPECT_EQ(231, score);
|
||||
TF_LITE_MICRO_EXPECT_EQ(0, tflite::testing::TestStrcmp("no", new_command));
|
||||
if (has_found_new_command) {
|
||||
TF_LITE_MICRO_EXPECT_EQ(231, score);
|
||||
TF_LITE_MICRO_EXPECT_EQ(0, tflite::testing::TestStrcmp("no", new_command));
|
||||
}
|
||||
}
|
||||
|
||||
TF_LITE_MICRO_TEST(RecognizeCommandsTestBadInputLength) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user