[pypy-commit] stmgc c5: Make a proper test file.
arigo
noreply at buildbot.pypy.org
Fri Dec 20 14:12:56 CET 2013
Author: Armin Rigo <arigo at tunes.org>
Branch: c5
Changeset: r573:cfd6bed8501b
Date: 2013-12-20 13:49 +0100
http://bitbucket.org/pypy/stmgc/changeset/cfd6bed8501b/
Log: Make a proper test file.
diff --git a/c5/largemalloc.c b/c5/largemalloc.c
--- a/c5/largemalloc.c
+++ b/c5/largemalloc.c
@@ -3,10 +3,10 @@
blocks, which in our case means at least 288 bytes.
*/
-#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <assert.h>
+#include "largemalloc.h"
#define MMAP_LIMIT (1280*1024)
diff --git a/c5/largemalloc.h b/c5/largemalloc.h
new file mode 100644
--- /dev/null
+++ b/c5/largemalloc.h
@@ -0,0 +1,4 @@
+#include <stdlib.h>
+
+char *stm_large_malloc(size_t request_size);
+void stm_large_free(char *data);
diff --git a/c5/test/support.py b/c5/test/support.py
--- a/c5/test/support.py
+++ b/c5/test/support.py
@@ -6,9 +6,9 @@
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
header_files = [os.path.join(parent_dir, _n) for _n in
- "core.h pagecopy.h".split()]
+ "core.h pagecopy.h largemalloc.h".split()]
source_files = [os.path.join(parent_dir, _n) for _n in
- "core.c pagecopy.c".split()]
+ "core.c pagecopy.c largemalloc.c".split()]
_pycache_ = os.path.join(parent_dir, 'test', '__pycache__')
if os.path.exists(_pycache_):
@@ -41,15 +41,19 @@
void _stm_restore_local_state(struct local_data_s *p);
void _stm_teardown(void);
void _stm_teardown_process(void);
+
+char *stm_large_malloc(size_t request_size);
+void stm_large_free(char *data);
""")
lib = ffi.verify('''
#include "core.h"
+#include "largemalloc.h"
''', sources=source_files,
define_macros=[('STM_TESTS', '1')],
undef_macros=['NDEBUG'],
include_dirs=[parent_dir],
- extra_compile_args=['-g', '-O0'])
+ extra_compile_args=['-g', '-O0', '-Werror'])
def intptr(p):
return int(ffi.cast("intptr_t", p))
diff --git a/c5/test/test_largemalloc.py b/c5/test/test_largemalloc.py
new file mode 100644
--- /dev/null
+++ b/c5/test/test_largemalloc.py
@@ -0,0 +1,31 @@
+from support import *
+
+
+class TestLargeMalloc(object):
+
+ def test_simple(self):
+ d1 = lib.stm_large_malloc(7000)
+ d2 = lib.stm_large_malloc(8000)
+ assert d2 - d1 == 7016
+ d3 = lib.stm_large_malloc(9000)
+ assert d3 - d2 == 8016
+ #
+ lib.stm_large_free(d1)
+ lib.stm_large_free(d2)
+ #
+ d4 = lib.stm_large_malloc(600)
+ assert d4 == d1
+ d5 = lib.stm_large_malloc(600)
+ assert d5 == d4 + 616
+ #
+ lib.stm_large_free(d5)
+ #
+ d6 = lib.stm_large_malloc(600)
+ assert d6 == d5
+ #
+ lib.stm_large_free(d4)
+ #
+ d7 = lib.stm_large_malloc(608)
+ assert d7 == d6 + 616
+ d8 = lib.stm_large_malloc(600)
+ assert d8 == d4
More information about the pypy-commit
mailing list