-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathfixtures.py
164 lines (109 loc) · 3.26 KB
/
fixtures.py
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import os
# import subprocess
import pytest
# MAKEFILE_CONTENTS = """
# CC=x86_64-linux-gnu-gcc
# default: program
# program.o: program.c $(HEADERS)
# $(CC) -c program.c -fno-asynchronous-unwind-tables -o program.o
# program: program.o
# $(CC) program.o -o program
# program_no_reloc: program.o
# $(CC) program.o -no-pie -o program_no_reloc
# program_relocated: program_relocated.o
# $(CC) program_relocated.o -o program_relocated
# large_elf.o: large_elf.c $(HEADERS)
# $(CC) -c large_elf.c -o large_elf.o
# large_elf: large_elf.o
# $(CC) large_elf.o -no-pie -o large_elf
# """
# C_SOURCE_CONTENTS = """
# #include <stdio.h>
# int foo();
# int bar();
# int main() {
# printf("Hello, World!\\n");
# return foo();
# }
# int foo() {
# return 12;
# }
# int bar() {
# return 24;
# }
# """
# LARGE_SOURCE_CONTENTS_HEADER = """
# int foo();
# int bar();
# int main() {
# return bar();
# }
# """
# LARGE_SOURCE_CONTENTS_FOOTER = """
# int foo() {
# return 12;
# }
# int bar() {
# return 24;
# }
# """
# PATCH_CONTENTS = """
# int noop0();
# int baz()
# {
# noop0();
# return 36;
# }
# """
# def create_noops():
# noops = []
# i = 0
# for i in range(8000):
# instruction = f"int noop{i}(){{}}"
# noops.append(instruction)
# return noops
@pytest.fixture(scope="session")
def elf_test_directory():
return os.path.join(os.path.dirname(__file__), "assets")
# makefile_path = os.path.join(tmpdir, "Makefile")
# c_source_path = os.path.join(tmpdir, "program.c")
# large_source_path = os.path.join(tmpdir, "large_elf.c")
# patch_dir = os.path.join(tmpdir, "source_dir")
# if not os.path.exists(patch_dir):
# os.mkdir(patch_dir)
# patch_path = os.path.join(patch_dir, "patch.c")
# noops = create_noops()
# LARGE_SOURCE_CONTENTS = LARGE_SOURCE_CONTENTS_HEADER
# for noop in noops:
# LARGE_SOURCE_CONTENTS += noop
# LARGE_SOURCE_CONTENTS += LARGE_SOURCE_CONTENTS_FOOTER
# with open(makefile_path, "w") as f:
# f.write(MAKEFILE_CONTENTS)
# with open(c_source_path, "w") as f:
# f.write(C_SOURCE_CONTENTS)
# with open(large_source_path, "w") as f:
# f.write(LARGE_SOURCE_CONTENTS)
# with open(patch_path, "w") as f:
# f.write(PATCH_CONTENTS)
# return tmpdir
@pytest.fixture(scope="session")
def elf_object_file(elf_test_directory):
return os.path.join(elf_test_directory, "program.o")
@pytest.fixture(scope="session")
def elf_executable_file(elf_test_directory):
return os.path.join(elf_test_directory, "program")
@pytest.fixture(scope="session")
def elf_no_pie_executable_file(elf_test_directory):
return os.path.join(elf_test_directory, "program_no_reloc")
@pytest.fixture(scope="session")
def large_elf_source_file(elf_test_directory):
return os.path.join(elf_test_directory, "large_elf.c")
@pytest.fixture(scope="session")
def large_elf_object_file(elf_test_directory):
return os.path.join(elf_test_directory, "large_elf.o")
@pytest.fixture(scope="session")
def large_elf_file(elf_test_directory):
return os.path.join(elf_test_directory, "large_elf")
@pytest.fixture(scope="session")
def patch_file(elf_test_directory):
return os.path.join(elf_test_directory, "source_dir", "patch.c")