Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyrasite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
pyrasite
Commits
34285a1b
Commit
34285a1b
authored
Mar 26, 2012
by
Luke Macken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix our multi-threaded unit tests
parent
13241381
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
10 deletions
+9
-10
pyrasite/tests/test_code_injection.py
pyrasite/tests/test_code_injection.py
+2
-2
pyrasite/tests/utils.py
pyrasite/tests/utils.py
+7
-8
No files found.
pyrasite/tests/test_code_injection.py
View file @
34285a1b
...
...
@@ -47,8 +47,8 @@ class TestCodeInjection(unittest.TestCase):
os
.
unlink
(
program
)
def
test_many_payloads_into_program_with_many_threads
(
self
):
program
=
generate_program
(
threads
=
50
)
num_payloads
=
50
program
=
generate_program
(
threads
=
25
)
num_payloads
=
25
try
:
for
exe
in
interpreters
():
p
=
run_program
(
program
,
exe
=
exe
)
...
...
pyrasite/tests/utils.py
View file @
34285a1b
...
...
@@ -30,21 +30,20 @@ def generate_program(threads=1):
import os, time, threading
running = True
pidfile = '/tmp/pyrasite_%d' % os.getpid()
open(pidfile, 'w').close()
def cpu_bound():
i = 2
y = 0
def fib(n):
return fib(n - 1) + fib(n - 2)
i = 0
while running:
y += fib(i)
i += 1
while os.path.exists(pidfile):
time.sleep(0.1)
"""
)
# CPU-bound threads
for
t
in
range
(
threads
):
script
+=
"threading.Thread(target=cpu_bound).start()
\
n
"
script
+=
"open(pidfile, 'w').close()
\
n
"
script
+=
textwrap
.
dedent
(
"""
while os.path.exists(pidfile):
time.sleep(0.1)
running = False
"""
)
tmp
.
write
(
script
)
tmp
.
close
()
return
filename
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment