From 9b77df24d05e855a9093a829258ae12a34e19ed4 Mon Sep 17 00:00:00 2001 From: Bean Date: Thu, 11 Apr 2024 18:32:42 +0900 Subject: [PATCH] RD-205 init project --- src/main/kotlin/tv/anypoint/dsl/Dsl.kt | 29 +++++++++++++++---- .../kotlin/tv/anypoint/dsl/TestCaseStarter.kt | 5 ++-- .../kotlin/tv/anypoint/dsl/model/LogInfo.kt | 8 +++++ src/main/kotlin/tv/anypoint/dsl/model/Tc.kt | 3 +- .../tv/anypoint/dsl/model/adb/ExtraKey.kt | 4 ++- .../tv/anypoint/dsl/service/TestCase.kt | 18 +++++++----- src/main/kotlin/tv/anypoint/tc/Base1.kt | 11 +++++++ 7 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 src/main/kotlin/tv/anypoint/dsl/model/LogInfo.kt diff --git a/src/main/kotlin/tv/anypoint/dsl/Dsl.kt b/src/main/kotlin/tv/anypoint/dsl/Dsl.kt index d9a4b4c..b2e40de 100644 --- a/src/main/kotlin/tv/anypoint/dsl/Dsl.kt +++ b/src/main/kotlin/tv/anypoint/dsl/Dsl.kt @@ -4,6 +4,13 @@ import tv.anypoint.dsl.handler.HttpHandler import tv.anypoint.dsl.model.adb.ExtraKey import tv.anypoint.dsl.model.adb.IntentAction import tv.anypoint.dsl.model.Tc +import tv.anypoint.dsl.service.TestCase +import java.time.Duration +import java.time.LocalDateTime +import java.time.Period +import java.time.temporal.ChronoUnit +import java.util.concurrent.TimeUnit +import java.util.concurrent.TimeoutException inline fun tc( block: Tc.() -> Unit @@ -15,17 +22,29 @@ inline fun http( data class Adb( val a: IntentAction, - val es: Pair + val es: Map ) inline fun adb( a: IntentAction, - es: Pair + es: Map ) { val adb = Adb(a, es) - println("[ADB] adb shell am broadcast -a $a --es ${es.first} ${es.second}") + val aStr = "-a $a" + val esStr: String = es.entries.joinToString(" ") { "--es ${it.key.string} ${it.value}" } + println("[ADB] adb shell am broadcast $aStr $esStr") } -fun expected(expectedLog: String) { - // TODO: logcat 스트림에서 expectedLog 찾기, 제한시간 내에 못찾으면 TimeoutException 뱉기 +fun TestCase.expected( + expectedLog: String, + timeout: Long = 10_000L +) { + val startedAt = LocalDateTime.now() + while (true) { + val now = LocalDateTime.now() + if (ChronoUnit.MILLIS.between(startedAt, now) > timeout) { + throw TimeoutException("failed to find log. expectedLog: $expectedLog, absoluteFilePath: ${this.tc.logInfo.absoluteFilePath}") + } + // TODO: tc 로그에서 expectedLog 찾기 tc.logInfo.cursor ~ 마지막 라인까지의 로그 중에 찾으면 됨 + } } \ No newline at end of file diff --git a/src/main/kotlin/tv/anypoint/dsl/TestCaseStarter.kt b/src/main/kotlin/tv/anypoint/dsl/TestCaseStarter.kt index 5ba0530..2ffafe2 100644 --- a/src/main/kotlin/tv/anypoint/dsl/TestCaseStarter.kt +++ b/src/main/kotlin/tv/anypoint/dsl/TestCaseStarter.kt @@ -12,7 +12,8 @@ class TestCaseStarter( private val testCases: List ) { @EventListener(ApplicationReadyEvent::class) - fun doSomethingAfterStartup() { + fun testAfterStartup() { + // TODO: main.log 덤프 시작 testCases.forEach { it.executeTest() } @@ -27,7 +28,7 @@ class TestCaseStarter( if (it.tc.result!!) "PASS" else "FAIL", it.tc.startedAt, it.tc.finishedAt, - it.tc.logAbsoluteFilePath, + it.tc.logInfo.absoluteFilePath, it.tc.recordingInfo?.absoluteFilePath ?: "-" ) ) diff --git a/src/main/kotlin/tv/anypoint/dsl/model/LogInfo.kt b/src/main/kotlin/tv/anypoint/dsl/model/LogInfo.kt new file mode 100644 index 0000000..4d201f0 --- /dev/null +++ b/src/main/kotlin/tv/anypoint/dsl/model/LogInfo.kt @@ -0,0 +1,8 @@ +package tv.anypoint.dsl.model + +class LogInfo( + val absoluteFilePath: String +) { + var cursor: Long = 0 + var lastLine: Long = 0 +} \ No newline at end of file diff --git a/src/main/kotlin/tv/anypoint/dsl/model/Tc.kt b/src/main/kotlin/tv/anypoint/dsl/model/Tc.kt index 8551ee7..75d316d 100644 --- a/src/main/kotlin/tv/anypoint/dsl/model/Tc.kt +++ b/src/main/kotlin/tv/anypoint/dsl/model/Tc.kt @@ -25,6 +25,7 @@ class Tc { val startedAt: LocalDateTime = LocalDateTime.now() lateinit var finishedAt: LocalDateTime var result: Boolean? = null - lateinit var logAbsoluteFilePath: String + + lateinit var logInfo: LogInfo var recordingInfo: RecordingInfo? = null } \ No newline at end of file diff --git a/src/main/kotlin/tv/anypoint/dsl/model/adb/ExtraKey.kt b/src/main/kotlin/tv/anypoint/dsl/model/adb/ExtraKey.kt index 3b632b6..e504418 100644 --- a/src/main/kotlin/tv/anypoint/dsl/model/adb/ExtraKey.kt +++ b/src/main/kotlin/tv/anypoint/dsl/model/adb/ExtraKey.kt @@ -2,5 +2,7 @@ package tv.anypoint.dsl.model.adb enum class ExtraKey(val string: String) { EXTRA_JSON("EXTRA_JSON"), - + CHANGE_COMMAND("change.command"), + API_ENDPOINT("api.endpoint"), + TEST_DEVICE("test.device") } \ No newline at end of file diff --git a/src/main/kotlin/tv/anypoint/dsl/service/TestCase.kt b/src/main/kotlin/tv/anypoint/dsl/service/TestCase.kt index 9cff342..95f5044 100644 --- a/src/main/kotlin/tv/anypoint/dsl/service/TestCase.kt +++ b/src/main/kotlin/tv/anypoint/dsl/service/TestCase.kt @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component import tv.anypoint.ApplicationProperties import tv.anypoint.dsl.exception.httpValidationError +import tv.anypoint.dsl.model.LogInfo import tv.anypoint.dsl.model.RecordingInfo import tv.anypoint.dsl.model.http.AdsResponse import tv.anypoint.dsl.model.http.AssetConvertResponse @@ -36,12 +37,13 @@ abstract class TestCase { try { if (tc.reboot) { - // TODO logger.info("[TC-${tc.number}] reboot STB") + // TODO } else { logger.info("[TC-${tc.number}] get systemInfo STB") + // TODO } - startToCollectLog() + startToDumpLog() auth() ads() @@ -51,7 +53,7 @@ abstract class TestCase { test() stopRecording(tc) - stopToCollectLog() + stopToDumpLog() } catch (e: Exception) { logger.error("[TC-${tc.number}] FAILED!! ${e.message}", e) tc.result = false @@ -63,13 +65,13 @@ abstract class TestCase { tc.result = true } - private fun startToCollectLog() { - tc.logAbsoluteFilePath = "applicationProperties.filePath/TC-${tc.number}.log" - // TODO + private fun startToDumpLog() { + tc.logInfo = LogInfo("${applicationProperties.filePath}/TC-${tc.number}.log") + // TODO 이 함수 호출된 후 main.log 에서 쌓이는 로그를 TC-${tc.number}.log 파일 새로 만들어서 적재 시작 } - private fun stopToCollectLog() { - // TODO + private fun stopToDumpLog() { + // TODO main.log >> TC-${tc.number}.log 적재 종료 } private fun auth() { diff --git a/src/main/kotlin/tv/anypoint/tc/Base1.kt b/src/main/kotlin/tv/anypoint/tc/Base1.kt index 4142a45..c99f408 100644 --- a/src/main/kotlin/tv/anypoint/tc/Base1.kt +++ b/src/main/kotlin/tv/anypoint/tc/Base1.kt @@ -2,10 +2,13 @@ package tv.anypoint.tc import mu.KLogging import org.springframework.stereotype.Component +import tv.anypoint.dsl.adb import tv.anypoint.dsl.http import tv.anypoint.dsl.service.TestCase import tv.anypoint.dsl.tc import tv.anypoint.dsl.model.Tc +import tv.anypoint.dsl.model.adb.ExtraKey +import tv.anypoint.dsl.model.adb.IntentAction @Component class Base1 : TestCase() { @@ -18,8 +21,16 @@ class Base1 : TestCase() { } override fun test() { + adb( + a = IntentAction.CHANGE_TEST_PROPERTY, + es = mapOf(ExtraKey.TEST_DEVICE to "true") + ) logger.debug("started to base1 test") logger.debug("finished to base1 test") + adb( + a = IntentAction.CHANGE_TEST_PROPERTY, + es = mapOf(ExtraKey.TEST_DEVICE to "false") + ) } companion object : KLogging()