diff --git a/src/main/kotlin/tv/anypoint/dsl/Dsl.kt b/src/main/kotlin/tv/anypoint/dsl/Dsl.kt index aa0cb07..8b4e41d 100644 --- a/src/main/kotlin/tv/anypoint/dsl/Dsl.kt +++ b/src/main/kotlin/tv/anypoint/dsl/Dsl.kt @@ -1,13 +1,10 @@ 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.IntentAction 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.service.TestCase import java.io.BufferedReader import java.io.FileReader import java.io.LineNumberReader @@ -32,27 +29,27 @@ fun adb( println("[ADB] adb shell am broadcast $aStr $esStr") } -fun Log.expected( +fun Logcat.expected( expectedLog: String, timeout: Long = 10_000L ) { - val log = this + val logcat = this val startedAt = LocalDateTime.now() - val reader = LineNumberReader(BufferedReader(FileReader(log.logcatFilePath))) + val reader = LineNumberReader(BufferedReader(FileReader(logcat.logcatFilePath))) while (true) { val now = LocalDateTime.now() if (ChronoUnit.MILLIS.between(startedAt, now) > timeout) { throw TimeoutException("failed to find log. expectedLog: $expectedLog") } - reader.lineNumber = log.cursor + reader.lineNumber = logcat.cursor var line: String? while ((reader.readLine().also { line = it }) != null) { if (line!!.contains(expectedLog)) { return } - log.cursor = reader.lineNumber + logcat.cursor = reader.lineNumber } Thread.sleep(100) } diff --git a/src/main/kotlin/tv/anypoint/dsl/model/Log.kt b/src/main/kotlin/tv/anypoint/dsl/model/Logcat.kt similarity index 93% rename from src/main/kotlin/tv/anypoint/dsl/model/Log.kt rename to src/main/kotlin/tv/anypoint/dsl/model/Logcat.kt index 6f779cc..bb6d4d1 100644 --- a/src/main/kotlin/tv/anypoint/dsl/model/Log.kt +++ b/src/main/kotlin/tv/anypoint/dsl/model/Logcat.kt @@ -3,7 +3,7 @@ package tv.anypoint.dsl.model import kotlinx.serialization.Serializable @Serializable -class Log( +class Logcat( val logcatFilePath: String ) { var startLine: Int = 0 diff --git a/src/main/kotlin/tv/anypoint/dsl/model/Tc.kt b/src/main/kotlin/tv/anypoint/dsl/model/Tc.kt index 50b054b..405ddac 100644 --- a/src/main/kotlin/tv/anypoint/dsl/model/Tc.kt +++ b/src/main/kotlin/tv/anypoint/dsl/model/Tc.kt @@ -26,6 +26,6 @@ class Tc { lateinit var finishedAt: LocalDateTime var result: Boolean? = null - lateinit var log: Log + lateinit var logcat: Logcat var recording: Recording? = null } diff --git a/src/main/kotlin/tv/anypoint/dsl/service/TestCase.kt b/src/main/kotlin/tv/anypoint/dsl/service/TestCase.kt index cc9b499..06530d2 100644 --- a/src/main/kotlin/tv/anypoint/dsl/service/TestCase.kt +++ b/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.stereotype.Component 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.Tc import java.time.LocalDateTime @@ -56,7 +56,7 @@ abstract class TestCase { } 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 파일 새로 만들어서 적재 시작 } diff --git a/src/main/kotlin/tv/anypoint/tc/Base1.kt b/src/main/kotlin/tv/anypoint/tc/Base1.kt index f82466e..35e19bb 100644 --- a/src/main/kotlin/tv/anypoint/tc/Base1.kt +++ b/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") ) - tc.log.expected("changed to test device") + tc.logcat.expected("changed to test device") // AD Agent, AD SDK 통신규격상으로는 a 필수, es 는 선택사항 // https://dev-docs.anypoint.tv/books/ff-settop-ad-agent/page/ad-agent-ad-sdk diff --git a/src/main/kotlin/tv/anypoint/tc/TestCaseStarter.kt b/src/main/kotlin/tv/anypoint/tc/TestCaseStarter.kt index 20e819a..b9917d6 100644 --- a/src/main/kotlin/tv/anypoint/tc/TestCaseStarter.kt +++ b/src/main/kotlin/tv/anypoint/tc/TestCaseStarter.kt @@ -32,7 +32,7 @@ class TestCaseStarter( if (it.tc.result!!) "PASS" else "FAIL", it.tc.startedAt, it.tc.finishedAt, - it.tc.log.logcatFilePath, + it.tc.logcat.logcatFilePath, it.tc.recording?.absoluteFilePath ?: "-" ) ) diff --git a/src/test/kotlin/tv/anypoint/dsl/DslKtTest.kt b/src/test/kotlin/tv/anypoint/dsl/DslKtTest.kt index 34e01e4..71d9651 100644 --- a/src/test/kotlin/tv/anypoint/dsl/DslKtTest.kt +++ b/src/test/kotlin/tv/anypoint/dsl/DslKtTest.kt @@ -1,15 +1,10 @@ package tv.anypoint.dsl -import io.kotest.core.spec.style.BehaviorSpec import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.longs.shouldBeLessThanOrEqual 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 tv.anypoint.dsl.model.Log +import tv.anypoint.dsl.model.Logcat import java.io.File import java.time.Duration import java.time.LocalDateTime @@ -21,8 +16,8 @@ class DslKtTest : FunSpec() { val file = File("./test.log") val writer = file.writer() val startedAt = LocalDateTime.now() - val test5 = Log("./test.log") - val test7 = Log("./test.log") + val test5 = Logcat("./test.log") + val test7 = Logcat("./test.log") object : Thread() { override fun run() {