[6.0.0][全量日志] 全量日志添加上传逻辑
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
package com.mogo.functions.test
|
||||
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.LargeTest
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager
|
||||
import com.mogo.eagle.core.function.main.MainLauncherActivity
|
||||
import com.mogo.eagle.core.utilcode.kotlin.onClick
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@LargeTest
|
||||
class CrashTest {
|
||||
|
||||
lateinit var launch: ActivityScenario<MainLauncherActivity>
|
||||
|
||||
|
||||
@Before
|
||||
fun before() {
|
||||
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJavaCrash() = runBlocking {
|
||||
val arguments = InstrumentationRegistry.getArguments()
|
||||
val delay = arguments.getString("delay", "0")
|
||||
val newThread = arguments.getString("new_thread", "false")
|
||||
val delayLong = delay.toLong()
|
||||
if (delayLong <= 0) {
|
||||
throw AssertionError("illegal state ..")
|
||||
}
|
||||
delay(delayLong)
|
||||
launch.onActivity {
|
||||
CallerDevaToolsManager.logcat()?.testJavaCrash(newThread.toBoolean())
|
||||
}
|
||||
delay(TimeUnit.MINUTES.toMillis(10))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testANRCrash() = runBlocking {
|
||||
val arguments = InstrumentationRegistry.getArguments()
|
||||
val delay = arguments.getString("delay", "0")
|
||||
val delayLong = delay.toLong()
|
||||
if (delayLong <= 0) {
|
||||
throw AssertionError("illegal state ..")
|
||||
}
|
||||
delay(delayLong)
|
||||
launch.onActivity { itx ->
|
||||
|
||||
val content = (itx.findViewById<View>(android.R.id.content) as ViewGroup)
|
||||
content.postDelayed({
|
||||
content.addView(Button(itx).also {
|
||||
it.background = ColorDrawable(Color.RED)
|
||||
it.setPadding(20, 20, 20, 20)
|
||||
it.textSize = 40.0f
|
||||
it.text = "点我触发ANR"
|
||||
it.setTextColor(Color.WHITE)
|
||||
it.onClick {
|
||||
CallerDevaToolsManager.logcat()?.testAnrCrash()
|
||||
}
|
||||
})
|
||||
}, 1000)
|
||||
|
||||
}
|
||||
delay(TimeUnit.MINUTES.toMillis(10))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNativeCrash() = runBlocking {
|
||||
val arguments = InstrumentationRegistry.getArguments()
|
||||
val delay = arguments.getString("delay", "0")
|
||||
val newThread = arguments.getString("new_thread", "false")
|
||||
val delayLong = delay.toLong()
|
||||
if (delayLong <= 0) {
|
||||
throw AssertionError("illegal state ..")
|
||||
}
|
||||
delay(delayLong)
|
||||
launch.onActivity {
|
||||
CallerDevaToolsManager.logcat()?.testNativeCrash(newThread.toBoolean())
|
||||
}
|
||||
delay(TimeUnit.MINUTES.toMillis(10))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user