| 1 |
import pytest |
| 2 |
import sys |
| 3 |
import os |
| 4 |
from commands import getoutput |
| 5 |
from pypy.tool.release.smartstrip import smartstrip |
| 6 |
|
| 7 |
@pytest.fixture |
| 8 |
def exe(tmpdir): |
| 9 |
src = tmpdir.join("myprog.c") |
| 10 |
src.write(""" |
| 11 |
int foo(int a, int b) { |
| 12 |
return a+b; |
| 13 |
} |
| 14 |
int main(void) { } |
| 15 |
""") |
| 16 |
exe = tmpdir.join("myprog") |
| 17 |
ret = os.system("gcc -o %s %s" % (exe, src)) |
| 18 |
assert ret == 0 |
| 19 |
return exe |
| 20 |
|
| 21 |
def info_symbol(exe, symbol): |
| 22 |
out = getoutput("gdb %s -ex 'info symbol %s' -ex 'quit'" % (exe, symbol)) |
| 23 |
lines = out.splitlines() |
| 24 |
return lines[-1] |
| 25 |
|
| 26 |
@pytest.mark.skipif(sys.platform == 'win32', |
| 27 |
reason='strip not supported on windows') |
| 28 |
class TestSmarStrip(object): |
| 29 |
|
| 30 |
def test_info_symbol(self, exe): |
| 31 |
info = info_symbol(exe, "foo") |
| 32 |
assert info == "foo in section .text" |
| 33 |
|
| 34 |
def test_strip(self, exe): |
| 35 |
smartstrip(exe, keep_debug=False) |
| 36 |
info = info_symbol(exe, "foo") |
| 37 |
assert info.startswith("No symbol table is loaded") |
| 38 |
|
| 39 |
@pytest.mark.skipif(sys.platform != 'linux2', |
| 40 |
reason='keep_debug not supported') |
| 41 |
def test_keep_debug(self, exe, tmpdir): |
| 42 |
smartstrip(exe, keep_debug=True) |
| 43 |
debug = tmpdir.join("myprog.debug") |
| 44 |
assert debug.check(file=True) |
| 45 |
perm = debug.stat().mode & 0777 |
| 46 |
assert perm & 0111 == 0 |
| 47 |
|
| 48 |
info = info_symbol(exe, "foo") |
| 49 |
assert info == "foo in section .text of %s" % exe |
| 50 |
|
| 51 |
debug.remove() |
| 52 |
info = info_symbol(exe, "foo") |
| 53 |
assert info.startswith("No symbol table is loaded") |