iOS Metal delegate: environment test added.

PiperOrigin-RevId: 270144123
This commit is contained in:
A. Unique TensorFlower 2019-09-19 15:54:46 -07:00 committed by TensorFlower Gardener
parent b58f4f1920
commit 297178914f
2 changed files with 90 additions and 0 deletions

View File

@ -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"],

View File

@ -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 <XCTest/XCTest.h>
#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