From a4353075432921dcad6a20c179ac0547acd55a64 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Mon, 2 Nov 2015 23:18:30 +0100 Subject: [PATCH 1/3] Test case for issue #237 (OS X crash when creating 2048:th Uc object) --- tests/regress/osx_qemu_thread_create_crash.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 tests/regress/osx_qemu_thread_create_crash.py diff --git a/tests/regress/osx_qemu_thread_create_crash.py b/tests/regress/osx_qemu_thread_create_crash.py new file mode 100755 index 00000000..b34b319b --- /dev/null +++ b/tests/regress/osx_qemu_thread_create_crash.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +import platform +import resource + +from unicorn import * + +import regress + +# OS X: OK with 2047 iterations. +# OS X: Crashes at 2048:th iteration ("qemu: qemu_thread_create: Resource temporarily unavailable"). +# Linux: No crashes observed. +class ThreadCreateCrash(regress.RegressTest): + def test(self): + for i in xrange(2048): + Uc(UC_ARCH_X86, UC_MODE_64) + self.assertTrue(True, "If not reached, then we have a crashing bug.") + +if __name__ == '__main__': + regress.main() From b91df4af236b6198835c36b4b256183f853e1d26 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Mon, 2 Nov 2015 23:19:38 +0100 Subject: [PATCH 2/3] Test case for issue #236 (potential memory leak) --- tests/regress/potential_memory_leak.py | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 tests/regress/potential_memory_leak.py diff --git a/tests/regress/potential_memory_leak.py b/tests/regress/potential_memory_leak.py new file mode 100755 index 00000000..46caa6d3 --- /dev/null +++ b/tests/regress/potential_memory_leak.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +import platform +import resource + +from unicorn import * + +import regress + +class MemoryLeak(regress.RegressTest): + def test(self): + if platform.system() == "Darwin": + rusage_multiplier = 1 + elif platform.system() == "Linux": + rusage_multiplier = 1024 + else: + # resource.getrusage(...) is platform dependent. Only tested under Mac and Linux. + return + max_rss_before = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss * rusage_multiplier + for i in xrange(10000): + mu = Uc(UC_ARCH_X86, UC_MODE_64) + mu.mem_map(0, 4096) + mu.emu_start(0, 0) + max_rss_after = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss * rusage_multiplier + rss_increase_per_iteration = (max_rss_after - max_rss_before) / i + self.assertLess(rss_increase_per_iteration, 8000) + +if __name__ == '__main__': + regress.main() From 29903c07f924c1cbb4b179a54899a819000f8d3e Mon Sep 17 00:00:00 2001 From: practicalswift Date: Mon, 2 Nov 2015 23:23:02 +0100 Subject: [PATCH 3/3] Fix typo. --- tests/regress/potential_memory_leak.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/regress/potential_memory_leak.py b/tests/regress/potential_memory_leak.py index 46caa6d3..29a29987 100755 --- a/tests/regress/potential_memory_leak.py +++ b/tests/regress/potential_memory_leak.py @@ -14,7 +14,7 @@ class MemoryLeak(regress.RegressTest): elif platform.system() == "Linux": rusage_multiplier = 1024 else: - # resource.getrusage(...) is platform dependent. Only tested under Mac and Linux. + # resource.getrusage(...) is platform dependent. Only tested under OS X and Linux. return max_rss_before = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss * rusage_multiplier for i in xrange(10000):