Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TestApp #218

Merged
merged 5 commits into from
Mar 12, 2025
Merged
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
9 changes: 6 additions & 3 deletions Sources/OpenSwiftUI/App/LegacyApp.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
//
// LegacyApp.swift
// OpenSwiftUI
// OpenSwiftUICore
//
// Audited for iOS 15.5
// Audited for iOS 18.0
// Status: Complete
// ID: F8F4CFB3FB453F4ECC15C05B76BCD1E4
// ID: F8F4CFB3FB453F4ECC15C05B76BCD1E4 (SwiftUI)

public enum __App {}

@available(*, unavailable)
extension __App: Sendable {}

extension __App {
public static func run(_ rootView: some View) -> Never {
runApp(ShoeboxAdaptor(rootView: rootView))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class _UIGraphicsView: UIView {
}

override func _shouldAnimateProperty(withKey key: String) -> Bool {
if layer.hasBeenCommitted() {
if layer.hasBeenCommitted {
super._shouldAnimateProperty(withKey: key)
} else {
false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
//
// _PerformanceTest.swift
// PerformanceTest.swift
// OpenSwiftUI
//
// Audited for iOS 15.5
// Audited for iOS 18.0
// Status: WIP

#if os(iOS)
import UIKit
#elseif os(macOS)
import AppKit
#endif

import OpenSwiftUI_SPI

public protocol _PerformanceTest: _Test {
var name: String { get }
func runTest(host: _BenchmarkHost, options: [AnyHashable: Any])
func runTest(host: any _BenchmarkHost, options: [AnyHashable: Any])
}

extension __App {
Expand All @@ -24,12 +23,6 @@ extension __App {
}
}

extension _TestApp {
public func runPerformanceTests(_ tests: [_PerformanceTest]) -> Never {
preconditionFailure("TODO")
}
}

extension _BenchmarkHost {
public func _started(test: _PerformanceTest) {
#if os(iOS)
Expand Down
53 changes: 23 additions & 30 deletions Sources/OpenSwiftUI/Test/TestApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,40 @@
// TestApp.swift
// OpenSwiftUI
//
// Audited for iOS 15.5
// Audited for iOS 18.0
// Status: WIP
// ID: A519B5B95CA8FF4E3445832668F0B2D2

@_spi(Testing)
import OpenSwiftUICore
public import OpenSwiftUICore
import Foundation

public struct _TestApp {
public init() {
preconditionFailure("TODO")
}
extension _TestApp {
public func run() -> Never {
let semanticsIndex = CommandLine.arguments.lastIndex(of: "--semantics")
if let semanticsIndex,
semanticsIndex + 1 != CommandLine.arguments.count {
setSemantics(CommandLine.arguments[semanticsIndex + 1])
} else {
setSemantics("lastest")
}
#if canImport(Darwin)
CFPreferencesSetAppValue("AppleLanguages" as NSString, ["en"] as NSArray, kCFPreferencesCurrentApplication)
// CTClearFontFallbacksCache()
#endif
Color.Resolved.legacyInterpolation = true
let rootView = RootView()
preconditionFailure("TODO")
}
}

extension _TestApp {
struct RootView: View {
@State
var state: StateType

init() {
preconditionFailure("TODO")
}

var body: some View {
state.testView
preconditionFailure("TODO")
}
public func runBenchmarks(_ benchmarks: [_Benchmark]) -> Never {
let _ = RootView()
preconditionFailure("TODO")
}

}

extension _TestApp.RootView {
struct StateType {
var id: Int
var testView: AnyView

mutating func setTestView<V: View>(_ view: V) {
id += 1
testView = AnyView(view.testID(id))
}
extension _TestApp {
public func runPerformanceTests(_ tests: [_PerformanceTest]) -> Never {
preconditionFailure("TODO")
}
}
10 changes: 0 additions & 10 deletions Sources/OpenSwiftUI/Test/_Benchmark.swift

This file was deleted.

9 changes: 0 additions & 9 deletions Sources/OpenSwiftUI/Test/_Test.swift

This file was deleted.

3 changes: 3 additions & 0 deletions Sources/OpenSwiftUICore/Semantic/Semantics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ package enum SemanticRequirement {

extension Semantics {
package static var forced: Forced = Forced()

package func test<R>(as keyPath: WritableKeyPath<Forced, Semantics?> = \.sdk, _ body: () throws -> R) rethrows -> R {
let value = Semantics.forced[keyPath: keyPath]
Semantics.forced[keyPath: keyPath] = self
Expand All @@ -57,7 +58,9 @@ extension Semantics {
extension Semantics {
package struct Forced {
package var sdk: Semantics?

package var deploymentTarget: Semantics?

package init() {
if dyld_program_sdk_at_least(dyld_build_version_t(semantics: firstRelease)) {
sdk = nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
//
// _BenchmarkHost.swift
// OpenSwiftUI
// Benchmark.swift
// OpenSwiftUICore
//
// Audited for iOS 15.5
// Status: Complete
// ID: 3E629D505F0A70F29ACFC010AA42C6E0
// Audited for iOS 18.0
// Status: WIP
// ID: 3E629D505F0A70F29ACFC010AA42C6E0 (SwiftUI)
// ID: 5BCCF82F8606CD0B3127FDEEA7C13601 (SwiftUICore)

public import Foundation

#if canImport(QuartzCore)
import QuartzCore
#endif

private let enableProfiler = EnvironmentHelper.bool(for: "OPENSWIFTUI_PROFILE_BENCHMARKS")

public protocol _BenchmarkHost: AnyObject {
func _renderForTest(interval: Double)
func _renderAsyncForTest(interval: Double) -> Bool
func _performScrollTest(startOffset: CGFloat, iterations: Int, delta: CGFloat, length: CGFloat, completion: (() -> Void)?)
}

public protocol _Benchmark: _Test {
func measure(host: _BenchmarkHost) -> [Double]
}

package var enableProfiler = EnvironmentHelper.bool(for: "OPENSWIFTUI_PROFILE_BENCHMARKS")

package var enableTracer = EnvironmentHelper.bool(for: "OPENSWIFTUI_TRACE_BENCHMARKS")

extension _BenchmarkHost {
public func _renderAsyncForTest(interval _: Double) -> Bool {
false
}

public func _performScrollTest(startOffset _: CGFloat, iterations _: Int, delta _: CGFloat, length _: CGFloat, completion _: (() -> Void)?) {}

public func measureAction(action: () -> Void) -> Double {
// WIP: trace support
#if canImport(QuartzCore)
let begin = CACurrentMediaTime()
if enableProfiler,
Expand All @@ -45,17 +52,17 @@ extension _BenchmarkHost {
preconditionFailure("Unsupported Platfrom")
#endif
}

public func measureRender(interval: Double = 1.0 / 60.0) -> Double {
measureAction {
_renderForTest(interval: interval)
}
}

public func measureRenders(seconds: Double) -> [Double] {
measureRenders(duration: seconds)
}

public func measureRenders(duration: Double) -> [Double] {
let minutes = duration / 60.0
let value = Int(minutes.rounded(.towardZero)) + 1
Expand All @@ -67,3 +74,15 @@ extension _BenchmarkHost {
return results
}
}

package func summarize(_ measurements: [(any _Benchmark, [Double])]) -> String {
preconditionFailure("TODO")
}

package func write(_ measurements: [(any _Benchmark, [Double])], to path: String) throws {
preconditionFailure("TODO")
}

package func log(_ measurements: [(any _Benchmark, [Double])]) {
preconditionFailure("TODO")
}
Loading
Loading