Skip to content

Commit a55d48a

Browse files
split perf tests
1 parent ce64e23 commit a55d48a

File tree

3 files changed

+319
-3
lines changed

3 files changed

+319
-3
lines changed

tests/perf/tooling/build_perf_tests.py renamed to tests/perf/tooling/build_perf_hello_world_js.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
# noinspection PyMethodMayBeStatic,PyUnusedLocal
3131
class PrepareAndBuildPerfTests(TnsTest):
3232
TEST_DATA = [
33-
('hello-world-js', Template.HELLO_WORLD_JS.local_package, Changes.JSHelloWord.JS),
34-
('hello-world-ng', Template.HELLO_WORLD_NG.local_package, Changes.NGHelloWorld.TS),
35-
('master-detail-ng', Template.MASTER_DETAIL_NG.local_package, Changes.MasterDetailNG.TS),
33+
('hello-world-js', Template.HELLO_WORLD_JS.local_package, Changes.JSHelloWord.JS)
3634
]
3735

3836
@classmethod
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# pylint: disable=unused-argument
2+
# pylint: disable=undefined-variable
3+
4+
import json
5+
import os
6+
import unittest
7+
8+
from parameterized import parameterized
9+
10+
from core.base_test.tns_test import TnsTest
11+
from core.enums.os_type import OSType
12+
from core.enums.platform_type import Platform
13+
from core.settings import Settings
14+
from core.utils.file_utils import Folder, File
15+
from core.utils.gradle import Gradle
16+
from core.utils.json_utils import JsonUtils
17+
from core.utils.npm import Npm
18+
from core.utils.perf_utils import PerfUtils
19+
from core.utils.xcode import Xcode
20+
from data.changes import Changes, Sync
21+
from data.templates import Template
22+
from products.nativescript.tns import Tns
23+
24+
RETRY_COUNT = 3
25+
TOLERANCE = 0.20
26+
APP_NAME = Settings.AppName.DEFAULT
27+
EXPECTED_RESULTS = JsonUtils.read(os.path.join(Settings.TEST_RUN_HOME, 'tests', 'perf', 'data.json'))
28+
29+
30+
# noinspection PyMethodMayBeStatic,PyUnusedLocal
31+
class PrepareAndBuildPerfTests(TnsTest):
32+
TEST_DATA = [
33+
('hello-world-ng', Template.HELLO_WORLD_NG.local_package, Changes.NGHelloWorld.TS)
34+
]
35+
36+
@classmethod
37+
def setUpClass(cls):
38+
TnsTest.setUpClass()
39+
40+
def setUp(self):
41+
TnsTest.setUp(self)
42+
43+
@classmethod
44+
def tearDownClass(cls):
45+
TnsTest.tearDownClass()
46+
47+
@parameterized.expand(TEST_DATA)
48+
def test_001_prepare_data(self, template, template_package, change_set):
49+
android_result_file = Helpers.get_result_file_name(template, Platform.ANDROID)
50+
ios_result_file = Helpers.get_result_file_name(template, Platform.IOS)
51+
Helpers.prepare_and_build(template=template_package, platform=Platform.ANDROID,
52+
change_set=change_set, result_file=android_result_file)
53+
Helpers.prepare_and_build(template=template_package, platform=Platform.IOS,
54+
change_set=change_set, result_file=ios_result_file)
55+
56+
@parameterized.expand(TEST_DATA)
57+
def test_200_prepare_android_initial(self, template, template_package, change_set):
58+
actual = Helpers.get_actual_result(template, Platform.ANDROID, 'prepare_initial')
59+
expected = Helpers.get_expected_result(template, Platform.ANDROID, 'prepare_initial')
60+
assert PerfUtils.is_value_in_range(actual, expected, TOLERANCE), 'Initial android prepare time is not OK.'
61+
62+
@parameterized.expand(TEST_DATA)
63+
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.')
64+
def test_201_prepare_ios_initial(self, template, template_package, change_set):
65+
actual = Helpers.get_actual_result(template, Platform.IOS, 'prepare_initial')
66+
expected = Helpers.get_expected_result(template, Platform.IOS, 'prepare_initial')
67+
assert PerfUtils.is_value_in_range(actual, expected, TOLERANCE), 'Initial ios prepare time is not OK.'
68+
69+
@parameterized.expand(TEST_DATA)
70+
def test_300_build_android_initial(self, template, template_package, change_set):
71+
actual = Helpers.get_actual_result(template, Platform.ANDROID, 'build_initial')
72+
expected = Helpers.get_expected_result(template, Platform.ANDROID, 'build_initial')
73+
assert PerfUtils.is_value_in_range(actual, expected, TOLERANCE), 'Initial android build time is not OK.'
74+
75+
@parameterized.expand(TEST_DATA)
76+
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.')
77+
def test_301_build_ios_initial(self, template, template_package, change_set):
78+
actual = Helpers.get_actual_result(template, Platform.IOS, 'build_initial')
79+
expected = Helpers.get_expected_result(template, Platform.IOS, 'build_initial')
80+
assert PerfUtils.is_value_in_range(actual, expected, TOLERANCE), 'Initial ios build time is not OK.'
81+
82+
@parameterized.expand(TEST_DATA)
83+
def test_310_build_android_incremental(self, template, template_package, change_set):
84+
actual = Helpers.get_actual_result(template, Platform.ANDROID, 'build_incremental')
85+
expected = Helpers.get_expected_result(template, Platform.ANDROID, 'build_incremental')
86+
assert PerfUtils.is_value_in_range(actual, expected, TOLERANCE), 'Incremental android build time is not OK.'
87+
88+
@parameterized.expand(TEST_DATA)
89+
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.')
90+
def test_311_build_ios_incremental(self, template, template_package, change_set):
91+
actual = Helpers.get_actual_result(template, Platform.IOS, 'build_incremental')
92+
expected = Helpers.get_expected_result(template, Platform.IOS, 'build_incremental')
93+
assert PerfUtils.is_value_in_range(actual, expected, TOLERANCE), 'Incremental ios build time is not OK.'
94+
95+
96+
class PrepareBuildInfo(object):
97+
prepare_initial = 0
98+
prepare_skip = 0
99+
prepare_incremental = 0
100+
build_initial = 0
101+
build_incremental = 0
102+
103+
104+
class Helpers(object):
105+
@staticmethod
106+
def prepare_and_build(template, platform, change_set, result_file):
107+
prepare_initial = 0
108+
build_initial = 0
109+
build_incremental = 0
110+
for _ in range(RETRY_COUNT):
111+
Tns.kill()
112+
Gradle.kill()
113+
Npm.cache_clean()
114+
Xcode.cache_clean()
115+
Folder.clean(folder=os.path.join(Settings.TEST_RUN_HOME, APP_NAME))
116+
Tns.create(app_name=APP_NAME, template=template, update=True)
117+
if platform == Platform.ANDROID:
118+
Tns.platform_add_android(app_name=APP_NAME, framework_path=Settings.Android.FRAMEWORK_PATH)
119+
elif platform == Platform.IOS:
120+
Tns.platform_add_ios(app_name=APP_NAME, framework_path=Settings.IOS.FRAMEWORK_PATH)
121+
else:
122+
raise Exception('Unknown platform: ' + str(platform))
123+
124+
# Prepare
125+
time = Tns.prepare(app_name=APP_NAME, platform=platform, bundle=True).duration
126+
prepare_initial = prepare_initial + time
127+
128+
# Build
129+
time = Tns.build(app_name=APP_NAME, platform=platform, bundle=True).duration
130+
build_initial = build_initial + time
131+
Sync.replace(app_name=APP_NAME, change_set=change_set)
132+
time = Tns.build(app_name=APP_NAME, platform=platform, bundle=True).duration
133+
build_incremental = build_incremental + time
134+
135+
# Calculate averages
136+
result = PrepareBuildInfo()
137+
result.prepare_initial = prepare_initial / RETRY_COUNT
138+
result.build_initial = build_initial / RETRY_COUNT
139+
result.build_incremental = build_incremental / RETRY_COUNT
140+
141+
# Save to results file
142+
File.delete(path=result_file)
143+
result_json = json.dumps(result, default=lambda o: o.__dict__, sort_keys=True, indent=4)
144+
File.write(path=result_file, text=str(result_json))
145+
146+
@staticmethod
147+
def get_result_file_name(template, platform):
148+
result_file = os.path.join(Settings.TEST_OUT_HOME, '{0}_{1}.json'.format(template, str(platform)))
149+
return result_file
150+
151+
@staticmethod
152+
def get_actual_result(template, platform, entry):
153+
result_file = Helpers.get_result_file_name(template, platform)
154+
return JsonUtils.read(result_file)[entry]
155+
156+
@staticmethod
157+
def get_expected_result(template, platform, entry):
158+
platform = str(platform)
159+
return EXPECTED_RESULTS[template][platform][entry]
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# pylint: disable=unused-argument
2+
# pylint: disable=undefined-variable
3+
4+
import json
5+
import os
6+
import unittest
7+
8+
from parameterized import parameterized
9+
10+
from core.base_test.tns_test import TnsTest
11+
from core.enums.os_type import OSType
12+
from core.enums.platform_type import Platform
13+
from core.settings import Settings
14+
from core.utils.file_utils import Folder, File
15+
from core.utils.gradle import Gradle
16+
from core.utils.json_utils import JsonUtils
17+
from core.utils.npm import Npm
18+
from core.utils.perf_utils import PerfUtils
19+
from core.utils.xcode import Xcode
20+
from data.changes import Changes, Sync
21+
from data.templates import Template
22+
from products.nativescript.tns import Tns
23+
24+
RETRY_COUNT = 3
25+
TOLERANCE = 0.20
26+
APP_NAME = Settings.AppName.DEFAULT
27+
EXPECTED_RESULTS = JsonUtils.read(os.path.join(Settings.TEST_RUN_HOME, 'tests', 'perf', 'data.json'))
28+
29+
30+
# noinspection PyMethodMayBeStatic,PyUnusedLocal
31+
class PrepareAndBuildPerfTests(TnsTest):
32+
TEST_DATA = [
33+
('master-detail-ng', Template.MASTER_DETAIL_NG.local_package, Changes.MasterDetailNG.TS)
34+
]
35+
36+
@classmethod
37+
def setUpClass(cls):
38+
TnsTest.setUpClass()
39+
40+
def setUp(self):
41+
TnsTest.setUp(self)
42+
43+
@classmethod
44+
def tearDownClass(cls):
45+
TnsTest.tearDownClass()
46+
47+
@parameterized.expand(TEST_DATA)
48+
def test_001_prepare_data(self, template, template_package, change_set):
49+
android_result_file = Helpers.get_result_file_name(template, Platform.ANDROID)
50+
ios_result_file = Helpers.get_result_file_name(template, Platform.IOS)
51+
Helpers.prepare_and_build(template=template_package, platform=Platform.ANDROID,
52+
change_set=change_set, result_file=android_result_file)
53+
Helpers.prepare_and_build(template=template_package, platform=Platform.IOS,
54+
change_set=change_set, result_file=ios_result_file)
55+
56+
@parameterized.expand(TEST_DATA)
57+
def test_200_prepare_android_initial(self, template, template_package, change_set):
58+
actual = Helpers.get_actual_result(template, Platform.ANDROID, 'prepare_initial')
59+
expected = Helpers.get_expected_result(template, Platform.ANDROID, 'prepare_initial')
60+
assert PerfUtils.is_value_in_range(actual, expected, TOLERANCE), 'Initial android prepare time is not OK.'
61+
62+
@parameterized.expand(TEST_DATA)
63+
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.')
64+
def test_201_prepare_ios_initial(self, template, template_package, change_set):
65+
actual = Helpers.get_actual_result(template, Platform.IOS, 'prepare_initial')
66+
expected = Helpers.get_expected_result(template, Platform.IOS, 'prepare_initial')
67+
assert PerfUtils.is_value_in_range(actual, expected, TOLERANCE), 'Initial ios prepare time is not OK.'
68+
69+
@parameterized.expand(TEST_DATA)
70+
def test_300_build_android_initial(self, template, template_package, change_set):
71+
actual = Helpers.get_actual_result(template, Platform.ANDROID, 'build_initial')
72+
expected = Helpers.get_expected_result(template, Platform.ANDROID, 'build_initial')
73+
assert PerfUtils.is_value_in_range(actual, expected, TOLERANCE), 'Initial android build time is not OK.'
74+
75+
@parameterized.expand(TEST_DATA)
76+
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.')
77+
def test_301_build_ios_initial(self, template, template_package, change_set):
78+
actual = Helpers.get_actual_result(template, Platform.IOS, 'build_initial')
79+
expected = Helpers.get_expected_result(template, Platform.IOS, 'build_initial')
80+
assert PerfUtils.is_value_in_range(actual, expected, TOLERANCE), 'Initial ios build time is not OK.'
81+
82+
@parameterized.expand(TEST_DATA)
83+
def test_310_build_android_incremental(self, template, template_package, change_set):
84+
actual = Helpers.get_actual_result(template, Platform.ANDROID, 'build_incremental')
85+
expected = Helpers.get_expected_result(template, Platform.ANDROID, 'build_incremental')
86+
assert PerfUtils.is_value_in_range(actual, expected, TOLERANCE), 'Incremental android build time is not OK.'
87+
88+
@parameterized.expand(TEST_DATA)
89+
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.')
90+
def test_311_build_ios_incremental(self, template, template_package, change_set):
91+
actual = Helpers.get_actual_result(template, Platform.IOS, 'build_incremental')
92+
expected = Helpers.get_expected_result(template, Platform.IOS, 'build_incremental')
93+
assert PerfUtils.is_value_in_range(actual, expected, TOLERANCE), 'Incremental ios build time is not OK.'
94+
95+
96+
class PrepareBuildInfo(object):
97+
prepare_initial = 0
98+
prepare_skip = 0
99+
prepare_incremental = 0
100+
build_initial = 0
101+
build_incremental = 0
102+
103+
104+
class Helpers(object):
105+
@staticmethod
106+
def prepare_and_build(template, platform, change_set, result_file):
107+
prepare_initial = 0
108+
build_initial = 0
109+
build_incremental = 0
110+
for _ in range(RETRY_COUNT):
111+
Tns.kill()
112+
Gradle.kill()
113+
Npm.cache_clean()
114+
Xcode.cache_clean()
115+
Folder.clean(folder=os.path.join(Settings.TEST_RUN_HOME, APP_NAME))
116+
Tns.create(app_name=APP_NAME, template=template, update=True)
117+
if platform == Platform.ANDROID:
118+
Tns.platform_add_android(app_name=APP_NAME, framework_path=Settings.Android.FRAMEWORK_PATH)
119+
elif platform == Platform.IOS:
120+
Tns.platform_add_ios(app_name=APP_NAME, framework_path=Settings.IOS.FRAMEWORK_PATH)
121+
else:
122+
raise Exception('Unknown platform: ' + str(platform))
123+
124+
# Prepare
125+
time = Tns.prepare(app_name=APP_NAME, platform=platform, bundle=True).duration
126+
prepare_initial = prepare_initial + time
127+
128+
# Build
129+
time = Tns.build(app_name=APP_NAME, platform=platform, bundle=True).duration
130+
build_initial = build_initial + time
131+
Sync.replace(app_name=APP_NAME, change_set=change_set)
132+
time = Tns.build(app_name=APP_NAME, platform=platform, bundle=True).duration
133+
build_incremental = build_incremental + time
134+
135+
# Calculate averages
136+
result = PrepareBuildInfo()
137+
result.prepare_initial = prepare_initial / RETRY_COUNT
138+
result.build_initial = build_initial / RETRY_COUNT
139+
result.build_incremental = build_incremental / RETRY_COUNT
140+
141+
# Save to results file
142+
File.delete(path=result_file)
143+
result_json = json.dumps(result, default=lambda o: o.__dict__, sort_keys=True, indent=4)
144+
File.write(path=result_file, text=str(result_json))
145+
146+
@staticmethod
147+
def get_result_file_name(template, platform):
148+
result_file = os.path.join(Settings.TEST_OUT_HOME, '{0}_{1}.json'.format(template, str(platform)))
149+
return result_file
150+
151+
@staticmethod
152+
def get_actual_result(template, platform, entry):
153+
result_file = Helpers.get_result_file_name(template, platform)
154+
return JsonUtils.read(result_file)[entry]
155+
156+
@staticmethod
157+
def get_expected_result(template, platform, entry):
158+
platform = str(platform)
159+
return EXPECTED_RESULTS[template][platform][entry]

0 commit comments

Comments
 (0)