Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create separate sandboxes for different graphics modes
Previously, graphics shadow invalidation did not occur. When the graphics mode switched, graphics shadows that had already been picked were reused. This meant that transitions between graphics modes were very likely to cause segfaults, as transitions between modes would result in a mixture of legacy and native graphics shadow classes being used. Add a new sandbox param for graphics mode. This will result in a separate set of sandboxes to be created when the graphics mode switches. RE #8073 PiperOrigin-RevId: 518349097
- Loading branch information
Showing
3 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
robolectric/src/test/java/org/robolectric/plugins/GraphicsModeTransitionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.robolectric.plugins; | ||
|
||
import static android.os.Build.VERSION_CODES.TIRAMISU; | ||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.robolectric.annotation.GraphicsMode.Mode.LEGACY; | ||
import static org.robolectric.annotation.GraphicsMode.Mode.NATIVE; | ||
|
||
import android.graphics.Matrix; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import org.junit.FixMethodOrder; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.MethodSorters; | ||
import org.robolectric.annotation.Config; | ||
import org.robolectric.annotation.GraphicsMode; | ||
import org.robolectric.shadow.api.Shadow; | ||
import org.robolectric.shadows.ShadowLegacyMatrix; | ||
import org.robolectric.shadows.ShadowMatrix; | ||
import org.robolectric.shadows.ShadowNativeMatrix; | ||
|
||
/** | ||
* Tests methods that cause transitions to different graphics modes. This is to verify that shadow | ||
* invalidation of graphics shadows occurs when the graphics mode changes. | ||
* | ||
* <p>Method order is important to ensure consistent transitions between LEGACY -> NATIVE -> LEGACY | ||
* graphics. | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
@FixMethodOrder(MethodSorters.NAME_ASCENDING) | ||
@Config(sdk = TIRAMISU) | ||
public class GraphicsModeTransitionTest { | ||
@GraphicsMode(LEGACY) | ||
@Test | ||
public void test1Legacy() { | ||
ShadowMatrix shadowMatrix = Shadow.extract(new Matrix()); | ||
assertThat(shadowMatrix).isInstanceOf(ShadowLegacyMatrix.class); | ||
} | ||
|
||
@GraphicsMode(NATIVE) | ||
@Test | ||
public void test2NativeAfterLegacy() { | ||
ShadowMatrix shadowMatrix = Shadow.extract(new Matrix()); | ||
assertThat(shadowMatrix).isInstanceOf(ShadowNativeMatrix.class); | ||
} | ||
|
||
@GraphicsMode(LEGACY) | ||
@Test | ||
public void test3LegacyAfterNative() { | ||
ShadowMatrix shadowMatrix = Shadow.extract(new Matrix()); | ||
assertThat(shadowMatrix).isInstanceOf(ShadowLegacyMatrix.class); | ||
} | ||
} |