-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathet2_tests.py
More file actions
132 lines (126 loc) · 4.67 KB
/
et2_tests.py
File metadata and controls
132 lines (126 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# TODO: Document this pytest functional test
import os
import subprocess
import sys
from shutil import copyfile
# Runs java on the class using the ET2 agent.
def run_java( java_path,
agent_path,
main_java_class,
used_class_list,
tmp_path ):
assert(isinstance(used_class_list, list))
# Copy libet2.so file
et2_filename = "libet2.so"
src_path = os.path.join(agent_path, et2_filename)
tgt_path = tmp_path.joinpath(et2_filename)
copyfile( src_path,
tgt_path.absolute().as_posix() )
# Copy class file
# For now, the classpath is hardcoded:
classpath = "java"
java_class_filename = main_java_class + ".class"
class_src_path = os.path.join(classpath, java_class_filename)
class_tgt_path = tmp_path.joinpath(java_class_filename)
copyfile( class_src_path,
class_tgt_path.absolute().as_posix() )
# Copy the used class list:
for used_class_filename in used_class_list:
class_src_path = os.path.join(classpath, used_class_filename)
class_tgt_path = tmp_path.joinpath(used_class_filename)
copyfile( class_src_path,
class_tgt_path.absolute().as_posix() )
# Setup environment variables
tmp_path_name = tmp_path.absolute().as_posix()
my_env = os.environ.copy()
my_env["LD_LIBRARY_PATH"] = tmp_path_name + my_env["LD_LIBRARY_PATH"]
# Setup working directory
if not os.path.isfile( java_path ):
# Java file not found
raise FileNotFoundError("java %s not found." % java_path)
cmd = [ java_path,
"-cp", tmp_path_name,
"-agentpath:" + os.path.join(tmp_path_name, et2_filename),
main_java_class ]
fp = subprocess.Popen( cmd,
stdout = subprocess.PIPE,
stderr = subprocess.STDOUT,
cwd = tmp_path_name,
env = my_env ).stdout
return fp
# Design questions:
# 1. Do we build the et2 library here?
# 2. Do we compile the target java programs here?
def test_hello_world( capsys,
java_path,
agent_path,
tmp_path ):
# Either check that HelloWorld.class is there.
# Or compile it here.
# Check to see that HelloWorld runs
# HelloWorld.java is in `java/`
found = False
with run_java( java_path = java_path,
agent_path = agent_path,
tmp_path = tmp_path,
main_java_class = "HelloWorld",
used_class_list = [] ) as fp:
for x in fp:
xstr = x.decode('utf-8')
if xstr.find("Hello world.") != -1:
found = True
break
assert found
def test_methods( capsys,
java_path,
agent_path,
tmp_path ):
# Either check that Methods.class is there.
# Or compile it here.
# Methods.java is in `java/`
with run_java( java_path = java_path,
agent_path = agent_path,
tmp_path = tmp_path,
main_java_class = "Methods",
used_class_list = [] ) as fp:
for x in fp:
sys.stdout.write(x.decode('utf-8'))
out, err = capsys.readouterr()
sys.stdout.write(out)
sys.stderr.write(err)
def test_new_call( capsys,
java_path,
agent_path,
tmp_path ):
# Either check that NewCall.class is there.
# Or compile it here.
# NewCall.java is in `java/`
used_class_list = [ "FooClass.class", ]
with run_java( java_path = java_path,
agent_path = agent_path,
tmp_path = tmp_path,
main_java_class = "NewCall",
used_class_list = used_class_list ) as fp:
for x in fp:
sys.stdout.write(x.decode('utf-8'))
out, err = capsys.readouterr()
sys.stdout.write(out)
sys.stderr.write(err)
def test_lots_of_allocs( capsys,
java_path,
agent_path,
tmp_path ):
# Either check that LotsOfAllocs.class is there.
# Or compile it here.
# LotsOfAllocs.java is in `java/`
used_class_list = [ "FooClass.class", ]
with run_java( java_path = java_path,
agent_path = agent_path,
tmp_path = tmp_path,
main_java_class = "LotsOfAllocs",
used_class_list = used_class_list ) as fp:
for x in fp:
sys.stdout.write(x.decode('utf-8'))
out, err = capsys.readouterr()
sys.stdout.write(out)
sys.stderr.write(err)