blob: 92e7ded862f71292316f70dc176a2b35a99ffbda [file] [log] [blame]
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +01001import json
2import time
3from common import ApkTestRunner
4from com.dtmilano.android.viewclient import ViewNotFoundException
5
6
7class ApkRunnerImpl(ApkTestRunner):
8 def __init__(self, config):
9 self.config = config
Benjamin Copeland15d743e2021-02-22 08:35:10 +000010 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 Wasilewskiab48dca2017-03-30 18:54:46 +010013 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 Roxell6558d372022-02-02 13:10:51 +010018 scroll = self.vc.findViewWithText("""LET'S ROLL""")
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +010019 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 Roxell6558d372022-02-02 13:10:51 +010026 gotit_button = self.vc.findViewWithText("GOT IT")
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +010027 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 Copeland15d743e2021-02-22 08:35:10 +000040 if (
41 subchild.getId()
42 == "com.quicinc.vellamo:id/card_launcher_run_button"
43 ):
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +010044 subchild.touch()
45 break
46
47 def execute(self):
Yongqin Liu4ffe3d22017-11-24 23:07:02 +080048 need_continue = True
49 while need_continue:
50 self.dump_always()
51 btn_setup_1 = self.vc.findViewById("android:id/button1")
Benjamin Copeland15d743e2021-02-22 08:35:10 +000052 btn_settings = self.vc.findViewById(
53 "com.quicinc.vellamo:id/main_toolbar_wheel"
54 )
55 btn_animations = self.vc.findViewWithText(
Anders Roxell6558d372022-02-02 13:10:51 +010056 "Make Vellamo even more beautiful"
Benjamin Copeland15d743e2021-02-22 08:35:10 +000057 )
58 warn_msg = self.vc.findViewWithText(
Anders Roxell6558d372022-02-02 13:10:51 +010059 "This app was built for an older version of Android and may not work properly. Try checking for updates, or contact the developer."
Benjamin Copeland15d743e2021-02-22 08:35:10 +000060 )
Anders Roxell6558d372022-02-02 13:10:51 +010061 continue_btn = self.vc.findViewWithText("CONTINUE")
Yongqin Liu4ffe3d22017-11-24 23:07:02 +080062 if btn_setup_1:
63 # Accept Vellamo EULA
64 btn_setup_1.touch()
Yongqin Liudb5f7c02020-07-24 14:59:53 +080065 elif warn_msg:
66 self.logger.info("Older version warning popped up")
Anders Roxell6558d372022-02-02 13:10:51 +010067 warning_ok_btn = self.vc.findViewWithTextOrRaise("OK")
Yongqin Liudb5f7c02020-07-24 14:59:53 +080068 warning_ok_btn.touch()
69 elif continue_btn:
70 continue_btn.touch()
Yongqin Liu4ffe3d22017-11-24 23:07:02 +080071 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 Wasilewskiab48dca2017-03-30 18:54:46 +010078
79 # Back to the home screen
80 self.device.press("KEYCODE_BACK")
81
Yongqin Liu4ffe3d22017-11-24 23:07:02 +080082 self.logger.info("Benchmark started now")
83
Benjamin Copeland15d743e2021-02-22 08:35:10 +000084 chapters = ["Browser", "Multicore", "Metal"]
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +010085 for chapter in chapters:
86 self.choose_chapter(chapter)
87
88 # Start benchmark
89 self.dump_always()
90 try:
Anders Roxell6558d372022-02-02 13:10:51 +010091 gotit_button = self.vc.findViewWithText("GOT IT")
Yongqin Liu4ffe3d22017-11-24 23:07:02 +080092 if gotit_button:
93 gotit_button.touch()
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +010094 except ViewNotFoundException:
Benjamin Copeland15d743e2021-02-22 08:35:10 +000095 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 Wasilewskiab48dca2017-03-30 18:54:46 +010099 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 Copeland15d743e2021-02-22 08:35:10 +0000107 goback_btn = self.vc.findViewById(
108 "com.quicinc.vellamo:id/main_toolbar_goback_button"
109 )
Yongqin Liu4ffe3d22017-11-24 23:07:02 +0800110 if goback_btn:
111 goback_btn.touch()
112 time.sleep(5)
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100113 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 Liu4ffe3d22017-11-24 23:07:02 +0800123 time.sleep(5)
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100124 self.device.press("KEYCODE_BACK")
125
126 def parseResult(self):
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000127 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 Wasilewskiab48dca2017-03-30 18:54:46 +0100136 # This is one-line file, read it in a whole
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000137 fileopen = open(raw_result_file, "r")
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100138 jsoncontent = json.load(fileopen)
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000139 result_flag = "benchmark_results"
140 chapter_flag = "chapter_name"
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100141
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 Copeland15d743e2021-02-22 08:35:10 +0000147 self.logger.info(
148 "%s test result found in category: %s"
149 % (str(len(item[result_flag])), chapter)
150 )
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100151 for elem in item[result_flag]:
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000152 if (
153 "failed" in elem.keys()
154 and "id" in elem.keys()
155 and "score" in elem.keys()
156 ):
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100157 # Pick up the result
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000158 if elem["failed"] is False:
159 result = "pass"
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100160 else:
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000161 result = "fail"
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100162 # Pick up the full test name
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000163 testcase = chapter + "-" + elem["id"]
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100164 # Pick up the test score
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000165 score = elem["score"]
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100166 # Submit the result to LAVA
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000167 self.report_result(
168 "vellamo3-" + testcase, result, str(score), default_unit
169 )
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100170 chapter_total = chapter_total + score
171 else:
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000172 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 Wasilewskiab48dca2017-03-30 18:54:46 +0100176
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000177 self.report_result(
178 "vellamo3-" + chapter + "-total",
179 "pass",
180 str(chapter_total),
181 default_unit,
182 )
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100183 total_score = total_score + chapter_total
184 else:
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000185 print(
186 "Cannot find %s or %s in test result dictionary. Please check it manually."
187 % (result_flag, chapter_flag)
188 )
Milosz Wasilewskiab48dca2017-03-30 18:54:46 +0100189
190 fileopen.close()
Benjamin Copeland15d743e2021-02-22 08:35:10 +0000191 self.report_result(
192 "vellamo3-total-score", "pass", str(total_score), default_unit
193 )