Skip to content

Commit d32422a

Browse files
committed
fixing runtime_profiler tests
1 parent 39742cf commit d32422a

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

docker/circleci/run_nosetests.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,35 @@ set -e
33
set -x
44
set -u
55

6+
PYTHON_VERSION=$( python -c "import sys; print('{}{}'.format(sys.version_info[0], sys.version_info[1]))" )
7+
68
# Create necessary directories
7-
mkdir -p /scratch/nose /scratch/crashfiles /scratch/logs/$1
9+
mkdir -p /scratch/nose /scratch/crashfiles /scratch/logs/py${PYTHON_VERSION}
810

911
# Create a nipype config file
1012
mkdir -p /root/.nipype
1113
echo '[logging]' > /root/.nipype/nipype.cfg
1214
echo 'log_to_file = true' >> /root/.nipype/nipype.cfg
13-
echo "log_directory = /scratch/logs/$1" >> /root/.nipype/nipype.cfg
14-
echo '[execution]' >> /root/.nipype/nipype.cfg
15-
echo 'profile_runtime = true' >> /root/.nipype/nipype.cfg
15+
echo "log_directory = /scratch/logs/py${PYTHON_VERSION}" >> /root/.nipype/nipype.cfg
16+
17+
# Enable profile_runtime tests only for python 2.7
18+
if [[ "${PYTHON_VERSION}" -lt "30" ]]; then
19+
echo '[execution]' >> /root/.nipype/nipype.cfg
20+
echo 'profile_runtime = true' >> /root/.nipype/nipype.cfg
21+
fi
1622

1723
# Run tests
1824
cd /root/src/nipype/
1925
make clean
20-
nosetests -s nipype -c /root/src/nipype/.noserc --xunit-file="/scratch/nosetests_$1.xml" --cover-xml-file="/scratch/coverage_$1.xml"
26+
nosetests -s nipype -c /root/src/nipype/.noserc --xunit-file="/scratch/nosetests_py${PYTHON_VERSION}.xml" --cover-xml-file="/scratch/coverage_py${PYTHON_VERSION}.xml"
27+
28+
# Workaround: run here the profiler tests in python 3
29+
if [[ "${PYTHON_VERSION}" -ge "30" ]]; then
30+
echo '[execution]' >> /root/.nipype/nipype.cfg
31+
echo 'profile_runtime = true' >> /root/.nipype/nipype.cfg
32+
nosetests nipype/interfaces/tests/test_runtime_profiler.py --xunit-file="/scratch/nosetests_py${PYTHON_VERSION}_profiler.xml" --cover-xml-file="/scratch/coverage_py${PYTHON_VERSION}_profiler.xml"
33+
nosetests nipype/pipeline/plugins/tests/test_multiproc*.py --xunit-file="/scratch/nosetests_py${PYTHON_VERSION}_multiproc.xml" --cover-xml-file="/scratch/coverage_py${PYTHON_VERSION}_multiproc.xml"
34+
fi
2135

2236
# Copy crashfiles to scratch
2337
for i in $(find /root/src/nipype/ -name "crash-*" ); do cp $i /scratch/crashfiles/; done

nipype/interfaces/tests/test_runtime_profiler.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99

1010
from __future__ import print_function, division, unicode_literals, absolute_import
11-
from builtins import open
11+
from builtins import open, str
1212

1313
# Import packages
1414
import unittest
@@ -72,9 +72,17 @@ def _use_gb_ram(num_gb):
7272
'''
7373
Function to consume GB of memory
7474
'''
75+
import sys
7576

76-
# Eat 1 GB of memory for 1 second
77-
gb_str = ' ' * int(num_gb*1024.0**3)
77+
# Getsize of one character string
78+
bsize = sys.getsizeof(' ') - sys.getsizeof(' ')
79+
boffset = sys.getsizeof('')
80+
81+
num_bytes = int(num_gb * (1024**3))
82+
# Eat num_gb GB of memory for 1 second
83+
gb_str = ' ' * ((num_bytes - boffset) // bsize)
84+
85+
assert sys.getsizeof(gb_str) == num_bytes
7886

7987
# Spin CPU
8088
ctr = 0
@@ -143,7 +151,7 @@ def setUp(self):
143151
# Input number of sub-threads (not including parent threads)
144152
self.num_threads = 2
145153
# Acceptable percent error for memory profiled against input
146-
self.mem_err_gb = 0.25
154+
self.mem_err_gb = 0.3 # Increased to 30% for py2.7
147155

148156
# ! Only used for benchmarking the profiler over a range of
149157
# ! RAM usage and number of threads

0 commit comments

Comments
 (0)