Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9fca4740
authored
Apr 01, 2022
by
samrobinson
Committed by
Ian Baker
Apr 07, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add file logging for skipping instrumentation tests.
PiperOrigin-RevId: 438808231
parent
80ff26b6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
29 deletions
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AndroidTestUtil.java
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TransformerAndroidTestRunner.java
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TransformationTest.java
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AndroidTestUtil.java
View file @
9fca4740
...
...
@@ -22,6 +22,7 @@ import android.os.Build;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.util.Log
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.List
;
import
org.json.JSONException
;
...
...
@@ -42,12 +43,22 @@ public final class AndroidTestUtil {
public
static
final
String
MP4_REMOTE_4K60_PORTRAIT_URI_STRING
=
"https://storage.googleapis.com/exoplayer-test-media-1/mp4/portrait_4k60.mp4"
;
/* package */
static
File
createExternalCacheFile
(
Context
context
,
String
fileName
)
throws
IOException
{
File
file
=
new
File
(
context
.
getExternalCacheDir
(),
fileName
);
checkState
(!
file
.
exists
()
||
file
.
delete
(),
"Could not delete file: "
+
file
.
getAbsolutePath
());
checkState
(
file
.
createNewFile
(),
"Could not create file: "
+
file
.
getAbsolutePath
());
return
file
;
/**
* Log in logcat and in an analysis file that this test was skipped.
*
* <p>Analysis file is a JSON summarising the test, saved to the application cache.
*
* <p>The analysis json will contain a {@code skipReason} key, with the reason for skipping the
* test case.
*/
public
static
void
recordTestSkipped
(
Context
context
,
String
testId
,
String
reason
)
throws
JSONException
,
IOException
{
Log
.
i
(
testId
,
reason
);
JSONObject
testJson
=
new
JSONObject
();
testJson
.
put
(
"skipReason"
,
reason
);
writeTestSummaryToFile
(
context
,
testId
,
testJson
);
}
/**
...
...
@@ -106,5 +117,42 @@ public final class AndroidTestUtil {
return
exceptionJson
;
}
/**
* Writes the summary of a test run to the application cache file.
*
* <p>The cache filename follows the pattern {@code <testId>-result.txt}.
*
* @param context The {@link Context}.
* @param testId A unique identifier for the transformer test run.
* @param testJson A {@link JSONObject} containing a summary of the test run.
*/
/* package */
static
void
writeTestSummaryToFile
(
Context
context
,
String
testId
,
JSONObject
testJson
)
throws
IOException
,
JSONException
{
testJson
.
put
(
"testId"
,
testId
).
put
(
"device"
,
getDeviceDetailsAsJsonObject
());
String
analysisContents
=
testJson
.
toString
(
/* indentSpaces= */
2
);
// Log contents as well as writing to file, for easier visibility on individual device testing.
Log
.
i
(
testId
,
analysisContents
);
File
analysisFile
=
createExternalCacheFile
(
context
,
/* fileName= */
testId
+
"-result.txt"
);
try
(
FileWriter
fileWriter
=
new
FileWriter
(
analysisFile
))
{
fileWriter
.
write
(
analysisContents
);
}
}
/**
* Creates a {@link File} of the {@code fileName} in the application cache directory.
*
* <p>If a file of that name already exists, it is overwritten.
*/
/* package */
static
File
createExternalCacheFile
(
Context
context
,
String
fileName
)
throws
IOException
{
File
file
=
new
File
(
context
.
getExternalCacheDir
(),
fileName
);
checkState
(!
file
.
exists
()
||
file
.
delete
(),
"Could not delete file: "
+
file
.
getAbsolutePath
());
checkState
(
file
.
createNewFile
(),
"Could not create file: "
+
file
.
getAbsolutePath
());
return
file
;
}
private
AndroidTestUtil
()
{}
}
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TransformerAndroidTestRunner.java
View file @
9fca4740
...
...
@@ -26,14 +26,12 @@ import com.google.android.exoplayer2.MediaItem;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.SystemClock
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.Map
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeoutException
;
import
java.util.concurrent.atomic.AtomicReference
;
import
org.checkerframework.checker.nullness.compatqual.NullableType
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/** An android instrumentation test runner for {@link Transformer}. */
...
...
@@ -174,7 +172,9 @@ public class TransformerAndroidTestRunner {
*/
public
TransformationTestResult
run
(
String
testId
,
String
uriString
)
throws
Exception
{
JSONObject
resultJson
=
new
JSONObject
();
resultJson
.
put
(
"inputValues"
,
JSONObject
.
wrap
(
inputValues
));
if
(
inputValues
!=
null
)
{
resultJson
.
put
(
"inputValues"
,
JSONObject
.
wrap
(
inputValues
));
}
try
{
TransformationTestResult
transformationTestResult
=
runInternal
(
testId
,
uriString
);
resultJson
.
put
(
"transformationResult"
,
transformationTestResult
.
asJsonObject
());
...
...
@@ -186,7 +186,7 @@ public class TransformerAndroidTestRunner {
resultJson
.
put
(
"exception"
,
AndroidTestUtil
.
exceptionAsJsonObject
(
e
));
throw
e
;
}
finally
{
writeTestSummaryToFile
(
context
,
testId
,
resultJson
);
AndroidTestUtil
.
writeTestSummaryToFile
(
context
,
testId
,
resultJson
);
}
}
...
...
@@ -303,20 +303,4 @@ public class TransformerAndroidTestRunner {
return
resultBuilder
.
build
();
}
private
static
void
writeTestSummaryToFile
(
Context
context
,
String
testId
,
JSONObject
resultJson
)
throws
IOException
,
JSONException
{
resultJson
.
put
(
"testId"
,
testId
).
put
(
"device"
,
AndroidTestUtil
.
getDeviceDetailsAsJsonObject
());
String
analysisContents
=
resultJson
.
toString
(
/* indentSpaces= */
2
);
// Log contents as well as writing to file, for easier visibility on individual device testing.
Log
.
i
(
TAG_PREFIX
+
testId
,
analysisContents
);
File
analysisFile
=
AndroidTestUtil
.
createExternalCacheFile
(
context
,
/* fileName= */
testId
+
"-result.txt"
);
try
(
FileWriter
fileWriter
=
new
FileWriter
(
analysisFile
))
{
fileWriter
.
write
(
analysisContents
);
}
}
}
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TransformationTest.java
View file @
9fca4740
...
...
@@ -19,6 +19,7 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSE
import
static
com
.
google
.
android
.
exoplayer2
.
transformer
.
AndroidTestUtil
.
MP4_ASSET_URI_STRING
;
import
static
com
.
google
.
android
.
exoplayer2
.
transformer
.
AndroidTestUtil
.
MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING
;
import
static
com
.
google
.
android
.
exoplayer2
.
transformer
.
AndroidTestUtil
.
MP4_REMOTE_4K60_PORTRAIT_URI_STRING
;
import
static
com
.
google
.
android
.
exoplayer2
.
transformer
.
AndroidTestUtil
.
recordTestSkipped
;
import
android.content.Context
;
import
androidx.test.core.app.ApplicationProvider
;
...
...
@@ -30,7 +31,6 @@ import com.google.android.exoplayer2.transformer.TransformationRequest;
import
com.google.android.exoplayer2.transformer.Transformer
;
import
com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner
;
import
com.google.android.exoplayer2.transformer.VideoEncoderSettings
;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.Util
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -120,14 +120,17 @@ public class TransformationTest {
@Test
public
void
transformSef
()
throws
Exception
{
String
testId
=
TAG
+
"_transformSef"
;
Context
context
=
ApplicationProvider
.
getApplicationContext
();
if
(
Util
.
SDK_INT
<
25
)
{
// TODO(b/210593256): Remove test skipping after removing the MediaMuxer dependency.
Log
.
i
(
testId
,
"Skipping on this API version due to lack of muxing support"
);
recordTestSkipped
(
context
,
testId
,
/* reason= */
"Skipping on this API version due to lack of muxing support"
);
return
;
}
Context
context
=
ApplicationProvider
.
getApplicationContext
();
Transformer
transformer
=
new
Transformer
.
Builder
(
context
)
.
setTransformationRequest
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment