mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
PRELOAD = Path(__file__).resolve().parents[1] / "linuxfs/preload"
|
|
LIMIT = 1024
|
|
WRAPPERS = {
|
|
"descriptor.c": ("dd_descriptor_unlink", "dd_descriptor_rmdir", "dd_descriptor_remove", "dd_descriptor_rename"),
|
|
}
|
|
|
|
|
|
def frames(source, build):
|
|
obj = build / (source + ".o")
|
|
subprocess.run(["cc", "-c", "-fPIC", "-O2", "-Wall", "-fstack-usage", "-o", str(obj), str(PRELOAD / source)],
|
|
check=True)
|
|
sizes = {}
|
|
for line in obj.with_suffix(".su").read_text().splitlines():
|
|
place, size, _ = line.split("\t")
|
|
sizes[place.rsplit(":", 1)[-1]] = int(size)
|
|
return sizes
|
|
|
|
|
|
@unittest.skipUnless(shutil.which("cc"), "needs a C compiler")
|
|
class PreloadWrapperStackTest(unittest.TestCase):
|
|
def test_wrappers_keep_path_buffers_off_their_frames(self):
|
|
with tempfile.TemporaryDirectory() as build:
|
|
for source, names in WRAPPERS.items():
|
|
sizes = frames(source, Path(build))
|
|
for name in names:
|
|
with self.subTest(function=name):
|
|
self.assertIn(name, sizes)
|
|
self.assertLess(sizes[name], LIMIT)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|