Add support for writing KMP benchmarks on iOS.
Test: ./gradlew --stop && ANDROIDX_PROJECTS=KMP ./gradlew studio
Change-Id: I95b3408f993ee3082dfa29f666d85aaf9d0ac529
diff --git a/benchmark/benchmark-darwin-core/build.gradle b/benchmark/benchmark-darwin-core/build.gradle
index b322e4b..432c60e 100644
--- a/benchmark/benchmark-darwin-core/build.gradle
+++ b/benchmark/benchmark-darwin-core/build.gradle
@@ -8,7 +8,7 @@
sourceSets {
}
- /// b/243154573
+ // b/243154573
jvm()
ios {
@@ -29,8 +29,8 @@
}
androidx {
- name = "Android Benchmark - Darwin Core"
+ name = "AndroidX Benchmarks - Darwin Core"
mavenGroup = LibraryGroups.BENCHMARK
inceptionYear = "2022"
- description = "Android Benchmark - Darwin Core"
+ description = "AndroidX Benchmarks - Darwin Core"
}
diff --git a/benchmark/benchmark-darwin/build.gradle b/benchmark/benchmark-darwin/build.gradle
new file mode 100644
index 0000000..00812b3
--- /dev/null
+++ b/benchmark/benchmark-darwin/build.gradle
@@ -0,0 +1,48 @@
+import org.jetbrains.kotlin.gradle.plugin.mpp.BitcodeEmbeddingMode
+
+plugins {
+ id("AndroidXPlugin")
+}
+
+androidXMultiplatform {
+ // b/243154573
+ jvm()
+ ios {
+ binaries.framework {
+ baseName = "AndroidXDarwinBenchmarks"
+ embedBitcode = BitcodeEmbeddingMode.DISABLE
+ }
+ }
+ sourceSets {
+ commonMain {
+ dependencies {
+ api(libs.kotlinStdlib)
+ }
+ }
+ commonTest {
+ dependencies {
+ implementation(libs.kotlinTest)
+ implementation(libs.kotlinTestAnnotationsCommon)
+ }
+ }
+ iosArm64Main {
+ dependsOn(commonMain)
+ dependencies {
+ api(project(":benchmark:benchmark-darwin-core"))
+ }
+ }
+ iosSimulatorArm64Main {
+ dependsOn(iosArm64Main)
+ }
+ iosX64Main {
+ dependsOn(iosArm64Main)
+ }
+ }
+}
+
+androidx {
+ name = "AndroidX Benchmarks - Darwin"
+ mavenGroup = LibraryGroups.BENCHMARK
+ inceptionYear = "2022"
+ description = "AndroidX Benchmarks - Darwin"
+}
diff --git a/benchmark/benchmark-darwin/src/commonMain/kotlin/androidx/benchmark/darwin/MeasureOptions.kt b/benchmark/benchmark-darwin/src/commonMain/kotlin/androidx/benchmark/darwin/MeasureOptions.kt
new file mode 100644
index 0000000..5675b04
--- /dev/null
+++ b/benchmark/benchmark-darwin/src/commonMain/kotlin/androidx/benchmark/darwin/MeasureOptions.kt
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package androidx.benchmark.darwin
+
+/**
+ * Test measurement options that control how many iterations to run.
+ */
+expect class MeasureOptions {
+ var iterationCount: ULong
+}
diff --git a/benchmark/benchmark-darwin/src/commonMain/kotlin/androidx/benchmark/darwin/TestCase.kt b/benchmark/benchmark-darwin/src/commonMain/kotlin/androidx/benchmark/darwin/TestCase.kt
new file mode 100644
index 0000000..889b3b9
--- /dev/null
+++ b/benchmark/benchmark-darwin/src/commonMain/kotlin/androidx/benchmark/darwin/TestCase.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package androidx.benchmark.darwin
+
+abstract class TestCase {
+ /**
+ * Provides an opportunity to customize initial state before a test case begins.
+ */
+ abstract fun setUp()
+
+ abstract fun benchmark(context: TestCaseContext)
+
+ abstract fun testDescription(): String
+}
diff --git a/benchmark/benchmark-darwin/src/commonMain/kotlin/androidx/benchmark/darwin/TestCaseContext.kt b/benchmark/benchmark-darwin/src/commonMain/kotlin/androidx/benchmark/darwin/TestCaseContext.kt
new file mode 100644
index 0000000..bca6b09
--- /dev/null
+++ b/benchmark/benchmark-darwin/src/commonMain/kotlin/androidx/benchmark/darwin/TestCaseContext.kt
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package androidx.benchmark.darwin
+
+interface TestCaseContext {
+ /**
+ * Registers a block of teardown code to run after the current test method ends.
+ */
+ fun addTeardownBlock(block: () -> Unit)
+
+ /**
+ * Records the selected metrics for a block of code.
+ */
+ fun measureWithMetrics(metrics: List<*>, options: MeasureOptions, block: () -> Unit)
+}
diff --git a/benchmark/benchmark-darwin/src/commonMain/kotlin/androidx/benchmark/darwin/TestCases.kt b/benchmark/benchmark-darwin/src/commonMain/kotlin/androidx/benchmark/darwin/TestCases.kt
new file mode 100644
index 0000000..b4aebca
--- /dev/null
+++ b/benchmark/benchmark-darwin/src/commonMain/kotlin/androidx/benchmark/darwin/TestCases.kt
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package androidx.benchmark.darwin
+
+/**
+ * Returns a [List] of [TestCase]s to run for benchmarks.
+ */
+expect object TestCases {
+ fun benchmarkTests(): List<TestCase>
+}
diff --git a/benchmark/benchmark-darwin/src/iosArm64Main/kotlin/androidx/benchmark/darwin/MeasureOptions.kt b/benchmark/benchmark-darwin/src/iosArm64Main/kotlin/androidx/benchmark/darwin/MeasureOptions.kt
new file mode 100644
index 0000000..6dbd48a
--- /dev/null
+++ b/benchmark/benchmark-darwin/src/iosArm64Main/kotlin/androidx/benchmark/darwin/MeasureOptions.kt
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package androidx.benchmark.darwin
+
+actual typealias MeasureOptions = platform.XCTest.XCTMeasureOptions
diff --git a/benchmark/benchmark-darwin/src/iosArm64Main/kotlin/androidx/benchmark/darwin/TestCaseContextWrapper.kt b/benchmark/benchmark-darwin/src/iosArm64Main/kotlin/androidx/benchmark/darwin/TestCaseContextWrapper.kt
new file mode 100644
index 0000000..4a569c6
--- /dev/null
+++ b/benchmark/benchmark-darwin/src/iosArm64Main/kotlin/androidx/benchmark/darwin/TestCaseContextWrapper.kt
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package androidx.benchmark.darwin
+
+import platform.XCTest.XCTMeasureOptions
+import platform.XCTest.XCTestCase
+import platform.XCTest.measureWithMetrics
+
+class TestCaseContextWrapper(private val context: XCTestCase) : TestCaseContext {
+ override fun addTeardownBlock(block: () -> Unit) {
+ context.addTeardownBlock(block)
+ }
+
+ override fun measureWithMetrics(
+ metrics: List<*>,
+ options: XCTMeasureOptions,
+ block: () -> Unit
+ ) {
+ context.measureWithMetrics(metrics, options, block)
+ }
+}
diff --git a/benchmark/benchmark-darwin/src/iosArm64Main/kotlin/androidx/benchmark/darwin/TestCases.kt b/benchmark/benchmark-darwin/src/iosArm64Main/kotlin/androidx/benchmark/darwin/TestCases.kt
new file mode 100644
index 0000000..297382d
--- /dev/null
+++ b/benchmark/benchmark-darwin/src/iosArm64Main/kotlin/androidx/benchmark/darwin/TestCases.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package androidx.benchmark.darwin
+
+import androidx.benchmark.darwin.tests.SleepTestCase
+
+actual object TestCases {
+ actual fun benchmarkTests(): List<TestCase> {
+ return listOf(SleepTestCase())
+ }
+}
diff --git a/benchmark/benchmark-darwin/src/iosArm64Main/kotlin/androidx/benchmark/darwin/tests/SleepTestCase.kt b/benchmark/benchmark-darwin/src/iosArm64Main/kotlin/androidx/benchmark/darwin/tests/SleepTestCase.kt
new file mode 100644
index 0000000..25c4a66
--- /dev/null
+++ b/benchmark/benchmark-darwin/src/iosArm64Main/kotlin/androidx/benchmark/darwin/tests/SleepTestCase.kt
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package androidx.benchmark.darwin.tests
+
+import androidx.benchmark.darwin.TestCase
+import androidx.benchmark.darwin.TestCaseContext
+import platform.Foundation.NSLog
+import platform.XCTest.XCTMeasureOptions
+import platform.posix.sleep
+
+class SleepTestCase : TestCase() {
+ override fun setUp() {
+ NSLog("%s", "Hello Benchmarks !")
+ }
+
+ override fun benchmark(context: TestCaseContext) {
+ val options = XCTMeasureOptions.defaultOptions()
+ // A single iteration
+ options.iterationCount = 1.toULong()
+ context.measureWithMetrics(
+ listOf(
+ platform.XCTest.XCTCPUMetric(),
+ platform.XCTest.XCTMemoryMetric(),
+ platform.XCTest.XCTClockMetric()
+ ),
+ options
+ ) {
+ repeat(3) {
+ NSLog("%s", "Sleeping for 1 second")
+ sleep(1)
+ }
+ }
+ }
+
+ override fun testDescription(): String {
+ return "A test that sleeps for 3 seconds"
+ }
+}
diff --git a/benchmark/benchmark-darwin/src/jvmMain/kotlin/androidx/benchmark/darwin/MeasureOptions.kt b/benchmark/benchmark-darwin/src/jvmMain/kotlin/androidx/benchmark/darwin/MeasureOptions.kt
new file mode 100644
index 0000000..bdc7389
--- /dev/null
+++ b/benchmark/benchmark-darwin/src/jvmMain/kotlin/androidx/benchmark/darwin/MeasureOptions.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package androidx.benchmark.darwin
+
+/**
+ * Test measurement options that control how many iterations to run.
+ */
+actual data class MeasureOptions(actual var iterationCount: ULong)
diff --git a/benchmark/benchmark-darwin/src/jvmMain/kotlin/androidx/benchmark/darwin/TestCases.kt b/benchmark/benchmark-darwin/src/jvmMain/kotlin/androidx/benchmark/darwin/TestCases.kt
new file mode 100644
index 0000000..7df615a
--- /dev/null
+++ b/benchmark/benchmark-darwin/src/jvmMain/kotlin/androidx/benchmark/darwin/TestCases.kt
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package androidx.benchmark.darwin
+
+/**
+ * Returns a [List] of [TestCase]s to run for benchmarks.
+ */
+actual object TestCases {
+ actual fun benchmarkTests(): List<TestCase> = listOf()
+}
diff --git a/development/build_log_simplifier/messages.ignore b/development/build_log_simplifier/messages.ignore
index 4ace91a..b06e28e 100644
--- a/development/build_log_simplifier/messages.ignore
+++ b/development/build_log_simplifier/messages.ignore
@@ -131,12 +131,16 @@
Daemon will be stopped at the end of the build
# > Configure project :appsearch:appsearch\-local\-backend
Configuration on demand is an incubating feature\.
+Calculating task graph as configuration cache cannot be reused because the set of Gradle properties has changed\.
You are using legacy USE_ANDROIDX_REMOTE_BUILD_CACHE=true type, this cache has been turned down, so you are \*not\* using a remote cache\. Please move to the new cache using http://go/androidx\-dev\#remote\-build\-cache
Configuration cache is an incubating feature\.
# > Configure project :
updated local\.properties
# > Configure project :compose:test\-utils
The following Kotlin source sets were configured but not added to any Kotlin compilation:
+\* iosArm[0-9]+Main
+\* iosSimulatorArm[0-9]+Main
+\* iosX[0-9]+Main
\* androidAndroidTestRelease
\* androidTestFixtures
\* androidTestFixturesDebug
@@ -478,3 +482,11 @@
WARNING: Please consider reporting this to the maintainers of org\.gradle\.internal\.classloader\.ClassLoaderUtils\$AbstractClassLoaderLookuper
# AGP warning about API usage we have no control over
Values of variant API AnnotationProcessorOptions\.arguments are queried and may return non final values, this is unsupported
+# > Task :help
+Welcome to Gradle [0-9]+\.[0-9]+\.
+To run a build, run gradlew <task> \.\.\.
+To see a list of available tasks, run gradlew tasks
+To see more detail about a task, run gradlew help \-\-task <task>
+To see a list of command\-line options, run gradlew \-\-help
+For more detail on using Gradle, see https://docs\.gradle\.org/[0-9]+\.[0-9]+/userguide/command_line_interface\.html
+For troubleshooting, visit https://help\.gradle\.org
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index 8c59bad..eea363e 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -381,6 +381,7 @@
includeProject(":autofill:autofill", [BuildType.MAIN])
includeProject(":benchmark:benchmark-benchmark", "benchmark/benchmark", [BuildType.MAIN, BuildType.COMPOSE])
includeProject(":benchmark:benchmark-common")
+includeProject(":benchmark:benchmark-darwin", [BuildType.KMP])
includeProject(":benchmark:benchmark-darwin-core", [BuildType.KMP])
includeProject(":benchmark:benchmark-gradle-plugin", "benchmark/gradle-plugin", [BuildType.MAIN])
includeProject(":benchmark:benchmark-junit4")