Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.

Commit b9e9780

Browse files
committed
speed test harness for cached builds of openssl
1 parent e8d7128 commit b9e9780

File tree

4 files changed

+407
-0
lines changed

4 files changed

+407
-0
lines changed

speedtest/fixtures.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Test fixtures
3+
"""
4+
5+
import os
6+
import pytest
7+
from utils import find_visual_studio, get_vc_envs
8+
9+
10+
@pytest.fixture()
11+
def clcache_envs():
12+
"""
13+
return a dict of envs suitable for clcache to work with
14+
:return:
15+
"""
16+
vcdir, _ = find_visual_studio()
17+
envs = get_vc_envs()
18+
cachedir = os.path.join("clcache_cachedir")
19+
envs["CLCACHE_DIR"] = cachedir
20+
envs["CLCACHE_CL"] = os.path.join(vcdir, "cl.exe")
21+
return envs

speedtest/test_performance_curl.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/python
2+
"""
3+
A py.test test that attempts to build libcurl and benchmark the effect of clcache
4+
"""
5+
6+
import sys
7+
import os
8+
import pytest
9+
import urllib
10+
import zipfile
11+
import subprocess
12+
13+
from utils import block_message, retry_delete, common_module_setup, check_program, get_vc_envs, download_file
14+
from utils import DISTDIR, RETAIN_CACHE, EMPTY_CACHE
15+
16+
from fixtures import clcache_envs
17+
18+
CURL_URL = "https://github.com/curl/curl/archive/curl-7_49_0.zip"
19+
CURL_ZIP = "curl-7_49_0.zip"
20+
SOURCES = None
21+
22+
23+
def clean_build():
24+
"""
25+
Unpack the curl source, possibly deleting the previous one
26+
:return:
27+
"""
28+
with zipfile.ZipFile(CURL_ZIP, "r") as unzip:
29+
folder = unzip.namelist()[0]
30+
if os.path.exists(folder):
31+
with block_message("delete old curl folder"):
32+
retry_delete(folder)
33+
34+
with block_message("unzip curl"):
35+
unzip.extractall()
36+
37+
global SOURCES
38+
SOURCES = folder.rstrip("/")
39+
40+
41+
def setup_function(request):
42+
"""
43+
Ensure a clean build tree before each test
44+
:return:
45+
"""
46+
os.chdir(DISTDIR)
47+
clean_build()
48+
49+
50+
def setup_module():
51+
"""
52+
Check that our exe has been built.
53+
:return:
54+
"""
55+
common_module_setup()
56+
download_file(CURL_URL, CURL_ZIP)
57+
58+
59+
def build_curl(addpath=None, envs=get_vc_envs(), pdbs=False):
60+
"""
61+
Build curl with nmake
62+
:return:
63+
"""
64+
check_program(envs, "nmake.exe")
65+
workdir = os.path.join(SOURCES, "winbuild")
66+
67+
if addpath is not None:
68+
envs["PATH"] = addpath + os.pathsep + envs["PATH"]
69+
70+
gen_pdbs = "GEN_PDB=no"
71+
if pdbs:
72+
gen_pdbs = "GEN_PDB=yes"
73+
74+
with block_message("build curl"):
75+
subprocess.check_output(["nmake", "-f", "Makefile.vc", "mode=static",
76+
"ENABLE_SSPI=no",
77+
"ENABLE_IPV6=no",
78+
"ENABLE_IDN=no",
79+
gen_pdbs],
80+
shell=True,
81+
cwd=workdir,
82+
env=envs)
83+
84+
85+
def test_build_nocache():
86+
"""
87+
Build curl with no caching
88+
:return:
89+
"""
90+
build_curl()
91+
92+
93+
@pytest.mark.parametrize("cache_setting", [EMPTY_CACHE, RETAIN_CACHE])
94+
def test_build_withclcache(clcache_envs, cache_setting):
95+
"""
96+
Time a curl build with a cold cache
97+
:param clcache_envs: clcache environment vars fixture
98+
:param cache_setting: if True, delete the cache from disk
99+
:return:
100+
"""
101+
if cache_setting == EMPTY_CACHE:
102+
retry_delete(clcache_envs["CLCACHE_DIR"])
103+
build_curl(DISTDIR, clcache_envs)
104+
105+
106+
if __name__ == "__main__":
107+
pytest.main(sys.argv[1:])
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/usr/bin/python
2+
"""
3+
A py.test test that attempts to build openssl and benchmark the effect of clcache
4+
"""
5+
import sys
6+
import os
7+
import pytest
8+
import zipfile
9+
import subprocess
10+
11+
from utils import block_message, retry_delete, common_module_setup, check_program, get_vc_envs, download_file
12+
from utils import DISTDIR, RETAIN_CACHE, EMPTY_CACHE
13+
14+
from fixtures import clcache_envs
15+
16+
OPENSSL_ZIP = "OpenSSL_1_0_2-stable.zip"
17+
OPENSSL_URL = "https://codeload.github.com/openssl/openssl/zip/OpenSSL_1_0_2-stable"
18+
SOURCES = None
19+
20+
21+
def clean_build():
22+
"""
23+
Unpack the openssl source, possibly deleting the previous one
24+
:return:
25+
"""
26+
with zipfile.ZipFile(OPENSSL_ZIP, "r") as unzip:
27+
folder = unzip.namelist()[0]
28+
if os.path.exists(folder):
29+
with block_message("delete old openssl folder"):
30+
retry_delete(folder)
31+
32+
with block_message("unzip openssl"):
33+
unzip.extractall()
34+
35+
global SOURCES
36+
SOURCES = folder.rstrip("/")
37+
38+
39+
def configure_openssl(envs):
40+
"""
41+
Run the configure steps (requires perl)
42+
:param envs:
43+
:return:
44+
"""
45+
check_program(envs, "nmake.exe")
46+
check_program(envs, "perl.exe")
47+
48+
with block_message("configure openssl"):
49+
subprocess.check_call(["perl",
50+
"Configure", "VC-WIN32", "no-asm", "--prefix=c:\openssl"],
51+
env=envs,
52+
cwd=SOURCES)
53+
54+
with block_message("generate makefiles"):
55+
subprocess.check_call([os.path.join("ms", "do_ms.bat")],
56+
shell=True,
57+
env=envs,
58+
cwd=SOURCES)
59+
60+
61+
def setup_function(request):
62+
"""
63+
Ensure a clean build tree before each test
64+
:return:
65+
"""
66+
os.chdir(DISTDIR)
67+
clean_build()
68+
configure_openssl(get_vc_envs())
69+
70+
71+
def setup_module():
72+
"""
73+
Check that our exe has been built.
74+
:return:
75+
"""
76+
common_module_setup()
77+
download_file(OPENSSL_URL, OPENSSL_ZIP)
78+
79+
80+
def replace_wipe_cflags(filename):
81+
"""
82+
Open the nmake file given and turn off PDB generation for .obj files
83+
:param filename:
84+
:return:
85+
"""
86+
lines = []
87+
with open(filename, "rb") as makefile:
88+
for line in makefile.readlines():
89+
if line.startswith("APP_CFLAG="):
90+
lines.append("APP_CFLAG=")
91+
elif line.startswith("LIB_CFLAG="):
92+
lines.append("LIB_CFLAG=/Zl")
93+
else:
94+
lines.append(line.rstrip())
95+
96+
with open(filename, "wb") as makefile:
97+
for line in lines:
98+
makefile.write(line + "\r\n")
99+
100+
101+
def build_openssl(addpath=None, envs=get_vc_envs(), pdbs=False):
102+
"""
103+
Build openssl, optionally prefixing addpath to $PATH
104+
:param addpath:
105+
:param envs: env var dict to use
106+
:param pdbs: if False, turn off pdb generation in the makefile
107+
:return:
108+
"""
109+
nmakefile = os.path.join("ms", "nt.mak")
110+
if not pdbs:
111+
replace_wipe_cflags(os.path.join(SOURCES, nmakefile))
112+
113+
if addpath is not None:
114+
envs["PATH"] = addpath + os.pathsep + envs["PATH"]
115+
116+
try:
117+
with block_message("running nmake"):
118+
subprocess.check_output(["nmake", "-f", nmakefile],
119+
shell=True,
120+
env=envs,
121+
cwd=SOURCES)
122+
except subprocess.CalledProcessError as cpe:
123+
print cpe.output
124+
raise
125+
126+
127+
def test_build_nocache():
128+
"""
129+
Time an openssl build with no caching involved at all
130+
:return:
131+
"""
132+
build_openssl()
133+
134+
135+
@pytest.mark.parametrize("cache_setting", [EMPTY_CACHE, RETAIN_CACHE])
136+
def test_build_withclcache(clcache_envs, cache_setting):
137+
"""
138+
Time an openssl build with a cold cache
139+
:param clcache_envs: clcache environment vars fixture
140+
:param cache_setting: if True, delete the cache from disk
141+
:return:
142+
"""
143+
if cache_setting == EMPTY_CACHE:
144+
retry_delete(clcache_envs["CLCACHE_DIR"])
145+
build_openssl(DISTDIR, clcache_envs)
146+
147+
148+
if __name__ == "__main__":
149+
pytest.main(sys.argv[1:])

0 commit comments

Comments
 (0)