diff --git a/tensorflow/lite/delegates/gpu/metal/BUILD b/tensorflow/lite/delegates/gpu/metal/BUILD index 550733feff8..8e300c524a7 100644 --- a/tensorflow/lite/delegates/gpu/metal/BUILD +++ b/tensorflow/lite/delegates/gpu/metal/BUILD @@ -140,6 +140,28 @@ objc_library( ], ) +objc_library( + name = "environment_test_lib", + testonly = 1, + srcs = ["environment_test.mm"], + sdk_frameworks = ["XCTest"], + deps = [ + ":environment", + "//tensorflow/lite/delegates/gpu/metal/kernels:test_util", + ], +) + +ios_unit_test( + name = "environment_test", + testonly = 1, + minimum_os_version = "10.0", + tags = [ + "notap", + "tflite_not_portable_android", + ], + deps = [":environment_test_lib"], +) + objc_library( name = "inference_context", srcs = ["inference_context.mm"], diff --git a/tensorflow/lite/delegates/gpu/metal/environment_test.mm b/tensorflow/lite/delegates/gpu/metal/environment_test.mm new file mode 100644 index 00000000000..20909c63b3d --- /dev/null +++ b/tensorflow/lite/delegates/gpu/metal/environment_test.mm @@ -0,0 +1,68 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/delegates/gpu/metal/environment.h" + +#import + +#include "tensorflow/lite/delegates/gpu/metal/common.h" + +using ::tflite::gpu::metal::GetiOsSystemVersion; +using ::tflite::gpu::metal::GetAppleSocVersion; +using ::tflite::gpu::metal::GetMacOsGpuVersion; + +@interface EnvironmentTest : XCTestCase + +@end + +@implementation EnvironmentTest + +- (void)testCompileTimeOSDetection { +#if IOS_VERSION > 0 + XCTAssertTrue(MACOS_VERSION == 0 && TVOS_VERSION == 0, @"IOS_VERSION: %d", int{IOS_VERSION}); +#endif +#if MACOS_VERSION > 0 + XCTAssertTrue(IOS_VERSION == 0 && TVOS_VERSION == 0, @"MACOS_VERSION: %d", int{MACOS_VERSION}); +#endif +#if TVOS_VERSION > 0 + XCTAssertTrue(IOS_VERSION == 0 && MACOS_VERSION == 0, @"TVOS_VERSION: %d", int{TVOS_VERSION}); +#endif +} + +- (void)testRunTimeOSDetection { + float runtimeOSVersion = GetiOsSystemVersion(); +#if IOS_VERSION > 0 + XCTAssertTrue(runtimeOSVersion >= 8.0f, @"runtimeOSVersion: %f", runtimeOSVersion); + + int gpuVersion = GetAppleSocVersion(); + XCTAssertTrue(gpuVersion >= 7, @"gpu version: %d", gpuVersion); +#endif + +#if TVOS_VERSION > 0 + XCTAssertTrue(runtimeOSVersion >= 9.0f, @"runtimeOSVersion: %f", runtimeOSVersion); + + int gpuVersion = GetAppleSocVersion(); + XCTAssertTrue(gpuVersion >= 8, @"gpu version: %d", gpuVersion); +#endif + +#if MACOS_VERSION > 0 + XCTAssertTrue(runtimeOSVersion >= 10.11f, @"runtimeOSVersion: %f", runtimeOSVersion); + + int gpuVersion = GetMacOsGpuVersion(device); + XCTAssertTrue(gpuVersion >= 1, @"gpu version: %d", gpuVersion); +#endif +} + +@end