Make toco_port trivial initialize-able for test cases.

Problem is toco_port indirects a way of initializing google.
One impl has a static way of finding out if it is initialized (internal).
One impl has a non-static way to find out.

In the non-static way, test cases won't work since we initialize the tensorflow
google emulation elsewhere (gtest override)

PiperOrigin-RevId: 228306710
This commit is contained in:
Andrew Selle 2019-01-08 03:57:48 -08:00 committed by TensorFlower Gardener
parent 3436665db2
commit 137c142341
7 changed files with 20 additions and 0 deletions

View File

@ -342,6 +342,7 @@ tf_cc_test(
name = "import_tensorflow_test",
srcs = ["import_tensorflow_test.cc"],
deps = [
":toco_port",
":toco_tooling",
"//tensorflow/core:framework",
"//tensorflow/core:graph",
@ -386,6 +387,7 @@ tf_cc_test(
srcs = ["tooling_util_test.cc"],
deps = [
":model",
":toco_port",
":tooling_util",
"//tensorflow/core:lib",
"//tensorflow/lite/testing:util",

View File

@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/lite/toco/import_tensorflow.h"
#include "tensorflow/lite/toco/toco_port.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@ -569,5 +570,6 @@ TEST(ImportTest, UnsupportedOpWithMultipleOutputs) {
int main(int argc, char** argv) {
::tflite::LogToStderr();
::testing::InitGoogleTest(&argc, argv);
::toco::port::InitGoogleWasDoneElsewhere();
return RUN_ALL_TESTS();
}

View File

@ -16,6 +16,7 @@ limitations under the License.
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/testing/util.h"
#include "tensorflow/lite/toco/toco_port.h"
namespace toco {
namespace {
@ -176,5 +177,6 @@ TEST(TocoTest, TransientStringTensors) {
int main(int argc, char** argv) {
::tflite::LogToStderr();
::testing::InitGoogleTest(&argc, argv);
::toco::port::InitGoogleWasDoneElsewhere();
return RUN_ALL_TESTS();
}

View File

@ -57,6 +57,11 @@ void InitGoogle(const char* usage, int* argc, char*** argv, bool remove_flags) {
::InitGoogle(usage, argc, argv, remove_flags);
}
void InitGoogleWasDoneElsewhere() {
// Nothing need be done since ::CheckInitGoogleIsDone() is aware of other
// possible initialization entry points.
}
void CheckInitGoogleIsDone(const char* message) {
::CheckInitGoogleIsDone(message);
}
@ -152,6 +157,8 @@ constexpr int kFileWriteFlags = O_CREAT | O_WRONLY;
static bool port_initialized = false;
void InitGoogleWasDoneElsewhere() { port_initialized = true; }
void InitGoogle(const char* usage, int* argc, char*** argv, bool remove_flags) {
if (!port_initialized) {
#if defined(PLATFORM_GOOGLE)

View File

@ -55,6 +55,10 @@ double round(double x);
namespace toco {
namespace port {
// Things like tests use other initialization routines that need control
// of flags. However, for testing we still want to use toco_port.h facilities.
// This function sets initialized flag trivially.
void InitGoogleWasDoneElsewhere();
void InitGoogle(const char* usage, int* argc, char*** argv, bool remove_flags);
void CheckInitGoogleIsDone(const char* message);

View File

@ -61,5 +61,6 @@ TEST(TocoPortTest, JoinPath) {
int main(int argc, char** argv) {
::tflite::LogToStderr();
::testing::InitGoogleTest(&argc, argv);
::toco::port::InitGoogleWasDoneElsewhere();
return RUN_ALL_TESTS();
}

View File

@ -19,6 +19,7 @@ limitations under the License.
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/lite/testing/util.h"
#include "tensorflow/lite/toco/model.h"
#include "tensorflow/lite/toco/toco_port.h"
#include "tensorflow/lite/toco/tooling_util.h"
namespace toco {
@ -208,5 +209,6 @@ TEST(FusedActivationTest, DefaultsToUnfused) {
int main(int argc, char** argv) {
::tflite::LogToStderr();
::testing::InitGoogleTest(&argc, argv);
::toco::port::InitGoogleWasDoneElsewhere();
return RUN_ALL_TESTS();
}