Browse Source

RD-214 save all.log

- change name Log -> Logcat
develop
bean 2 years ago
parent
commit
9cfd685614
  1. 15
      src/main/kotlin/tv/anypoint/dsl/Dsl.kt
  2. 2
      src/main/kotlin/tv/anypoint/dsl/model/Logcat.kt
  3. 2
      src/main/kotlin/tv/anypoint/dsl/model/Tc.kt
  4. 4
      src/main/kotlin/tv/anypoint/dsl/service/TestCase.kt
  5. 2
      src/main/kotlin/tv/anypoint/tc/Base1.kt
  6. 2
      src/main/kotlin/tv/anypoint/tc/TestCaseStarter.kt
  7. 11
      src/test/kotlin/tv/anypoint/dsl/DslKtTest.kt

15
src/main/kotlin/tv/anypoint/dsl/Dsl.kt

@ -1,13 +1,10 @@
package tv.anypoint.dsl package tv.anypoint.dsl
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import tv.anypoint.proxy.model.adb.ExtraKey import tv.anypoint.proxy.model.adb.ExtraKey
import tv.anypoint.proxy.model.adb.IntentAction import tv.anypoint.proxy.model.adb.IntentAction
import tv.anypoint.dsl.handler.HttpHandler import tv.anypoint.dsl.handler.HttpHandler
import tv.anypoint.dsl.model.Log import tv.anypoint.dsl.model.Logcat
import tv.anypoint.dsl.model.Tc import tv.anypoint.dsl.model.Tc
import tv.anypoint.dsl.service.TestCase
import java.io.BufferedReader import java.io.BufferedReader
import java.io.FileReader import java.io.FileReader
import java.io.LineNumberReader import java.io.LineNumberReader
@ -32,27 +29,27 @@ fun adb(
println("[ADB] adb shell am broadcast $aStr $esStr") println("[ADB] adb shell am broadcast $aStr $esStr")
} }
fun Log.expected( fun Logcat.expected(
expectedLog: String, expectedLog: String,
timeout: Long = 10_000L timeout: Long = 10_000L
) { ) {
val log = this val logcat = this
val startedAt = LocalDateTime.now() val startedAt = LocalDateTime.now()
val reader = LineNumberReader(BufferedReader(FileReader(log.logcatFilePath))) val reader = LineNumberReader(BufferedReader(FileReader(logcat.logcatFilePath)))
while (true) { while (true) {
val now = LocalDateTime.now() val now = LocalDateTime.now()
if (ChronoUnit.MILLIS.between(startedAt, now) > timeout) { if (ChronoUnit.MILLIS.between(startedAt, now) > timeout) {
throw TimeoutException("failed to find log. expectedLog: $expectedLog") throw TimeoutException("failed to find log. expectedLog: $expectedLog")
} }
reader.lineNumber = log.cursor reader.lineNumber = logcat.cursor
var line: String? var line: String?
while ((reader.readLine().also { line = it }) != null) { while ((reader.readLine().also { line = it }) != null) {
if (line!!.contains(expectedLog)) { if (line!!.contains(expectedLog)) {
return return
} }
log.cursor = reader.lineNumber logcat.cursor = reader.lineNumber
} }
Thread.sleep(100) Thread.sleep(100)
} }

2
src/main/kotlin/tv/anypoint/dsl/model/Log.kt → src/main/kotlin/tv/anypoint/dsl/model/Logcat.kt

@ -3,7 +3,7 @@ package tv.anypoint.dsl.model
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable @Serializable
class Log( class Logcat(
val logcatFilePath: String val logcatFilePath: String
) { ) {
var startLine: Int = 0 var startLine: Int = 0

2
src/main/kotlin/tv/anypoint/dsl/model/Tc.kt

@ -26,6 +26,6 @@ class Tc {
lateinit var finishedAt: LocalDateTime lateinit var finishedAt: LocalDateTime
var result: Boolean? = null var result: Boolean? = null
lateinit var log: Log lateinit var logcat: Logcat
var recording: Recording? = null var recording: Recording? = null
} }

4
src/main/kotlin/tv/anypoint/dsl/service/TestCase.kt

@ -5,7 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.event.EventListener import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
import tv.anypoint.ApplicationProperties import tv.anypoint.ApplicationProperties
import tv.anypoint.dsl.model.Log import tv.anypoint.dsl.model.Logcat
import tv.anypoint.dsl.model.Recording import tv.anypoint.dsl.model.Recording
import tv.anypoint.dsl.model.Tc import tv.anypoint.dsl.model.Tc
import java.time.LocalDateTime import java.time.LocalDateTime
@ -56,7 +56,7 @@ abstract class TestCase {
} }
private fun startToDumpLog() { private fun startToDumpLog() {
tc.log = Log("${applicationProperties.fileRoot}/${tc.number}.log") tc.logcat = Logcat("${applicationProperties.fileRoot}/${tc.number}.log")
// TODO 이 함수 호출된 후 main.log 에서 쌓이는 로그를 ${tc.number}.log 파일 새로 만들어서 적재 시작 // TODO 이 함수 호출된 후 main.log 에서 쌓이는 로그를 ${tc.number}.log 파일 새로 만들어서 적재 시작
} }

2
src/main/kotlin/tv/anypoint/tc/Base1.kt

@ -25,7 +25,7 @@ class Base1 : TestCase() {
es = mapOf(tv.anypoint.proxy.model.adb.ExtraKey.TEST_DEVICE to "true") es = mapOf(tv.anypoint.proxy.model.adb.ExtraKey.TEST_DEVICE to "true")
) )
tc.log.expected("changed to test device") tc.logcat.expected("changed to test device")
// AD Agent, AD SDK 통신규격상으로는 a 필수, es 는 선택사항 // AD Agent, AD SDK 통신규격상으로는 a 필수, es 는 선택사항
// https://dev-docs.anypoint.tv/books/ff-settop-ad-agent/page/ad-agent-ad-sdk // https://dev-docs.anypoint.tv/books/ff-settop-ad-agent/page/ad-agent-ad-sdk

2
src/main/kotlin/tv/anypoint/tc/TestCaseStarter.kt

@ -32,7 +32,7 @@ class TestCaseStarter(
if (it.tc.result!!) "PASS" else "FAIL", if (it.tc.result!!) "PASS" else "FAIL",
it.tc.startedAt, it.tc.startedAt,
it.tc.finishedAt, it.tc.finishedAt,
it.tc.log.logcatFilePath, it.tc.logcat.logcatFilePath,
it.tc.recording?.absoluteFilePath ?: "-" it.tc.recording?.absoluteFilePath ?: "-"
) )
) )

11
src/test/kotlin/tv/anypoint/dsl/DslKtTest.kt

@ -1,15 +1,10 @@
package tv.anypoint.dsl package tv.anypoint.dsl
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.core.spec.style.FunSpec import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.longs.shouldBeLessThanOrEqual import io.kotest.matchers.longs.shouldBeLessThanOrEqual
import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldBe
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import mu.KLogging import mu.KLogging
import tv.anypoint.dsl.model.Log import tv.anypoint.dsl.model.Logcat
import java.io.File import java.io.File
import java.time.Duration import java.time.Duration
import java.time.LocalDateTime import java.time.LocalDateTime
@ -21,8 +16,8 @@ class DslKtTest : FunSpec() {
val file = File("./test.log") val file = File("./test.log")
val writer = file.writer() val writer = file.writer()
val startedAt = LocalDateTime.now() val startedAt = LocalDateTime.now()
val test5 = Log("./test.log") val test5 = Logcat("./test.log")
val test7 = Log("./test.log") val test7 = Logcat("./test.log")
object : Thread() { object : Thread() {
override fun run() { override fun run() {

Loading…
Cancel
Save