Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 1 | import json |
| 2 | import time |
| 3 | from common import ApkTestRunner |
| 4 | from com.dtmilano.android.viewclient import ViewNotFoundException |
| 5 | |
| 6 | |
| 7 | class ApkRunnerImpl(ApkTestRunner): |
| 8 | def __init__(self, config): |
| 9 | self.config = config |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 10 | self.config["apk_file_name"] = "com.quicinc.vellamo-3.apk" |
| 11 | self.config["apk_package"] = "com.quicinc.vellamo" |
| 12 | self.config["activity"] = "com.quicinc.vellamo/.main.MainActivity" |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 13 | super(ApkRunnerImpl, self).__init__(self.config) |
| 14 | |
| 15 | def choose_chapter(self, chapter_name): |
| 16 | # ToDo: scroll screen if chapter is not found on the first screen |
| 17 | self.dump_always() |
Anders Roxell | 6558d37 | 2022-02-02 13:10:51 +0100 | [diff] [blame] | 18 | scroll = self.vc.findViewWithText("""LET'S ROLL""") |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 19 | if scroll: |
| 20 | print("Click LET'S ROLL") |
| 21 | scroll.touch() |
| 22 | |
| 23 | chapter_tab = None |
| 24 | self.dump_always() |
| 25 | while chapter_tab is None: |
Anders Roxell | 6558d37 | 2022-02-02 13:10:51 +0100 | [diff] [blame] | 26 | gotit_button = self.vc.findViewWithText("GOT IT") |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 27 | if gotit_button: |
| 28 | print("Click GOT IT") |
| 29 | gotit_button.touch() |
| 30 | else: |
| 31 | print("press DPAD_DOWN") |
| 32 | self.device.press("DPAD_DOWN") |
| 33 | self.dump_always() |
| 34 | chapter_tab = self.vc.findViewWithText(chapter_name) |
| 35 | |
| 36 | enclosing_tab = chapter_tab.getParent().getParent() |
| 37 | for child in enclosing_tab.children: |
| 38 | if child.getClass() == "android.widget.FrameLayout": |
| 39 | for subchild in child.children: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 40 | if ( |
| 41 | subchild.getId() |
| 42 | == "com.quicinc.vellamo:id/card_launcher_run_button" |
| 43 | ): |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 44 | subchild.touch() |
| 45 | break |
| 46 | |
| 47 | def execute(self): |
Yongqin Liu | 4ffe3d2 | 2017-11-24 23:07:02 +0800 | [diff] [blame] | 48 | need_continue = True |
| 49 | while need_continue: |
| 50 | self.dump_always() |
| 51 | btn_setup_1 = self.vc.findViewById("android:id/button1") |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 52 | btn_settings = self.vc.findViewById( |
| 53 | "com.quicinc.vellamo:id/main_toolbar_wheel" |
| 54 | ) |
| 55 | btn_animations = self.vc.findViewWithText( |
Anders Roxell | 6558d37 | 2022-02-02 13:10:51 +0100 | [diff] [blame] | 56 | "Make Vellamo even more beautiful" |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 57 | ) |
| 58 | warn_msg = self.vc.findViewWithText( |
Anders Roxell | 6558d37 | 2022-02-02 13:10:51 +0100 | [diff] [blame] | 59 | "This app was built for an older version of Android and may not work properly. Try checking for updates, or contact the developer." |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 60 | ) |
Anders Roxell | 6558d37 | 2022-02-02 13:10:51 +0100 | [diff] [blame] | 61 | continue_btn = self.vc.findViewWithText("CONTINUE") |
Yongqin Liu | 4ffe3d2 | 2017-11-24 23:07:02 +0800 | [diff] [blame] | 62 | if btn_setup_1: |
| 63 | # Accept Vellamo EULA |
| 64 | btn_setup_1.touch() |
Yongqin Liu | db5f7c0 | 2020-07-24 14:59:53 +0800 | [diff] [blame] | 65 | elif warn_msg: |
| 66 | self.logger.info("Older version warning popped up") |
Anders Roxell | 6558d37 | 2022-02-02 13:10:51 +0100 | [diff] [blame] | 67 | warning_ok_btn = self.vc.findViewWithTextOrRaise("OK") |
Yongqin Liu | db5f7c0 | 2020-07-24 14:59:53 +0800 | [diff] [blame] | 68 | warning_ok_btn.touch() |
| 69 | elif continue_btn: |
| 70 | continue_btn.touch() |
Yongqin Liu | 4ffe3d2 | 2017-11-24 23:07:02 +0800 | [diff] [blame] | 71 | elif btn_settings: |
| 72 | # Open settings |
| 73 | btn_settings.touch() |
| 74 | elif btn_animations: |
| 75 | # Disable animations |
| 76 | btn_animations.touch() |
| 77 | need_continue = False |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 78 | |
| 79 | # Back to the home screen |
| 80 | self.device.press("KEYCODE_BACK") |
| 81 | |
Yongqin Liu | 4ffe3d2 | 2017-11-24 23:07:02 +0800 | [diff] [blame] | 82 | self.logger.info("Benchmark started now") |
| 83 | |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 84 | chapters = ["Browser", "Multicore", "Metal"] |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 85 | for chapter in chapters: |
| 86 | self.choose_chapter(chapter) |
| 87 | |
| 88 | # Start benchmark |
| 89 | self.dump_always() |
| 90 | try: |
Anders Roxell | 6558d37 | 2022-02-02 13:10:51 +0100 | [diff] [blame] | 91 | gotit_button = self.vc.findViewWithText("GOT IT") |
Yongqin Liu | 4ffe3d2 | 2017-11-24 23:07:02 +0800 | [diff] [blame] | 92 | if gotit_button: |
| 93 | gotit_button.touch() |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 94 | except ViewNotFoundException: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 95 | self.report_result("vellamo3-%s" % chapter, "fail") |
| 96 | self.logger.error( |
| 97 | "Start button for chapter %s NOT found, moving to the next chapter..." |
| 98 | ) |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 99 | continue |
| 100 | |
| 101 | # Wait while Vellamo is running benchmark |
| 102 | finished = False |
| 103 | while not finished: |
| 104 | time.sleep(1) |
| 105 | try: |
| 106 | self.dump_always() |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 107 | goback_btn = self.vc.findViewById( |
| 108 | "com.quicinc.vellamo:id/main_toolbar_goback_button" |
| 109 | ) |
Yongqin Liu | 4ffe3d2 | 2017-11-24 23:07:02 +0800 | [diff] [blame] | 110 | if goback_btn: |
| 111 | goback_btn.touch() |
| 112 | time.sleep(5) |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 113 | finished = True |
| 114 | except ViewNotFoundException: |
| 115 | pass |
| 116 | except RuntimeError as e: |
| 117 | print(e) |
| 118 | except ValueError as ve: |
| 119 | print(ve) |
| 120 | |
| 121 | self.logger.info("Benchmark finished: %s" % chapter) |
| 122 | self.device.press("KEYCODE_BACK") |
Yongqin Liu | 4ffe3d2 | 2017-11-24 23:07:02 +0800 | [diff] [blame] | 123 | time.sleep(5) |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 124 | self.device.press("KEYCODE_BACK") |
| 125 | |
| 126 | def parseResult(self): |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 127 | raw_result_file = "%s/chapterscores-itr%s.json" % ( |
| 128 | self.config["output"], |
| 129 | self.config["itr"], |
| 130 | ) |
| 131 | self.call_adb( |
| 132 | "pull /data/data/com.quicinc.vellamo/files/chapterscores.json %s" |
| 133 | % raw_result_file |
| 134 | ) |
| 135 | default_unit = "Points" |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 136 | # This is one-line file, read it in a whole |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 137 | fileopen = open(raw_result_file, "r") |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 138 | jsoncontent = json.load(fileopen) |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 139 | result_flag = "benchmark_results" |
| 140 | chapter_flag = "chapter_name" |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 141 | |
| 142 | total_score = 0 |
| 143 | for item in jsoncontent: |
| 144 | if result_flag and chapter_flag in item.keys(): |
| 145 | chapter = item[chapter_flag] |
| 146 | chapter_total = 0 |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 147 | self.logger.info( |
| 148 | "%s test result found in category: %s" |
| 149 | % (str(len(item[result_flag])), chapter) |
| 150 | ) |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 151 | for elem in item[result_flag]: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 152 | if ( |
| 153 | "failed" in elem.keys() |
| 154 | and "id" in elem.keys() |
| 155 | and "score" in elem.keys() |
| 156 | ): |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 157 | # Pick up the result |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 158 | if elem["failed"] is False: |
| 159 | result = "pass" |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 160 | else: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 161 | result = "fail" |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 162 | # Pick up the full test name |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 163 | testcase = chapter + "-" + elem["id"] |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 164 | # Pick up the test score |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 165 | score = elem["score"] |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 166 | # Submit the result to LAVA |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 167 | self.report_result( |
| 168 | "vellamo3-" + testcase, result, str(score), default_unit |
| 169 | ) |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 170 | chapter_total = chapter_total + score |
| 171 | else: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 172 | print("Corrupted test result found, please check it manually.") |
| 173 | print( |
| 174 | "A valid test result must contain id, score and pass/fail status." |
| 175 | ) |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 176 | |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 177 | self.report_result( |
| 178 | "vellamo3-" + chapter + "-total", |
| 179 | "pass", |
| 180 | str(chapter_total), |
| 181 | default_unit, |
| 182 | ) |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 183 | total_score = total_score + chapter_total |
| 184 | else: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 185 | print( |
| 186 | "Cannot find %s or %s in test result dictionary. Please check it manually." |
| 187 | % (result_flag, chapter_flag) |
| 188 | ) |
Milosz Wasilewski | ab48dca | 2017-03-30 18:54:46 +0100 | [diff] [blame] | 189 | |
| 190 | fileopen.close() |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame] | 191 | self.report_result( |
| 192 | "vellamo3-total-score", "pass", str(total_score), default_unit |
| 193 | ) |