mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-05-24 13:56:23 +03:00
feat: Introduce stable Bazel build
The initial migration to a Bazel based build. All attempts have been made to maintain configuration parity with the upstream build.
This commit is contained in:
parent
54eaed1d8b
commit
7f192e9919
29 changed files with 6564 additions and 1 deletions
95
test/BUILD.bazel
Normal file
95
test/BUILD.bazel
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
load("//:tools/cc.bzl", "COPTS")
|
||||
|
||||
expand_template(
|
||||
name = "jemalloc_test",
|
||||
testonly = True,
|
||||
out = "include/test/jemalloc_test.h",
|
||||
substitutions = {
|
||||
"@install_suffix@": "",
|
||||
"@je_@": "je_",
|
||||
"@private_namespace@": "je_",
|
||||
},
|
||||
template = "include/test/jemalloc_test.h.in",
|
||||
)
|
||||
|
||||
expand_template(
|
||||
name = "jemalloc_test_defs",
|
||||
testonly = True,
|
||||
out = "include/test/jemalloc_test_defs.h",
|
||||
substitutions = {
|
||||
"#undef HAVE_SSE2": "/* #undef HAVE_SSE2 */",
|
||||
"#undef HAVE_ALTIVEC": "/* #undef HAVE_ALTIVEC */",
|
||||
},
|
||||
template = "include/test/jemalloc_test_defs.h.in",
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "testlib",
|
||||
testonly = True,
|
||||
srcs = [
|
||||
"src/SFMT.c",
|
||||
"src/btalloc.c",
|
||||
"src/btalloc_0.c",
|
||||
"src/btalloc_1.c",
|
||||
"src/math.c",
|
||||
"src/mtx.c",
|
||||
"src/sleep.c",
|
||||
"src/test.c",
|
||||
"src/thd.c",
|
||||
"src/timer.c",
|
||||
],
|
||||
hdrs = [
|
||||
"include/test/SFMT.h",
|
||||
"include/test/SFMT-alti.h",
|
||||
"include/test/SFMT-params.h",
|
||||
"include/test/SFMT-params11213.h",
|
||||
"include/test/SFMT-params1279.h",
|
||||
"include/test/SFMT-params132049.h",
|
||||
"include/test/SFMT-params19937.h",
|
||||
"include/test/SFMT-params216091.h",
|
||||
"include/test/SFMT-params2281.h",
|
||||
"include/test/SFMT-params4253.h",
|
||||
"include/test/SFMT-params44497.h",
|
||||
"include/test/SFMT-params607.h",
|
||||
"include/test/SFMT-params86243.h",
|
||||
"include/test/SFMT-sse2.h",
|
||||
"include/test/arena_util.h",
|
||||
"include/test/bench.h",
|
||||
"include/test/bgthd.h",
|
||||
"include/test/btalloc.h",
|
||||
"include/test/extent_hooks.h",
|
||||
"include/test/jemalloc_test.h",
|
||||
"include/test/jemalloc_test_defs.h",
|
||||
"include/test/math.h",
|
||||
"include/test/mq.h",
|
||||
"include/test/mtx.h",
|
||||
"include/test/nbits.h",
|
||||
"include/test/san.h",
|
||||
"include/test/sleep.h",
|
||||
"include/test/test.h",
|
||||
"include/test/thd.h",
|
||||
"include/test/timer.h",
|
||||
],
|
||||
copts = COPTS,
|
||||
includes = ["include"],
|
||||
linkstatic = True,
|
||||
local_defines = select(
|
||||
{
|
||||
"//settings:unit_test": ["JEMALLOC_UNIT_TEST"],
|
||||
"//settings:integration_test": ["JEMALLOC_INTEGRATION_TEST"],
|
||||
"//settings:integration_cpp_test": ["JEMALLOC_INTEGRATION_CPP_TEST"],
|
||||
},
|
||||
no_match_error = "Explicit test setting must be configured //settings:with_test",
|
||||
),
|
||||
tags = ["manual"],
|
||||
visibility = ["//test:__subpackages__"],
|
||||
deps = ["//:jemalloc_core"] + select(
|
||||
{
|
||||
"//settings:integration_test": ["//:utils"],
|
||||
"//settings:integration_cpp_test": ["//:utils"],
|
||||
"//conditions:default": [],
|
||||
},
|
||||
),
|
||||
)
|
||||
118
test/integration/BUILD.bazel
Normal file
118
test/integration/BUILD.bazel
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
load("@rules_cc//cc:defs.bzl", "cc_test")
|
||||
load("//:tools/cc.bzl", "COPTS")
|
||||
load("//:tools/transition.bzl", "PLATFORM", "transition_default_constraints")
|
||||
|
||||
INTEGRATION_TESTS = [
|
||||
{"src": "allocated.c"},
|
||||
{
|
||||
"src": "extent.c",
|
||||
"conf": "junk:false",
|
||||
},
|
||||
{"src": "malloc.c"},
|
||||
{
|
||||
"src": "mallocx.c",
|
||||
"conf": "junk:false",
|
||||
},
|
||||
{"src": "MALLOCX_ARENA.c"},
|
||||
{"src": "overflow.c"},
|
||||
{"src": "posix_memalign.c"},
|
||||
{"src": "rallocx.c"},
|
||||
{"src": "sdallocx.c"},
|
||||
{
|
||||
"src": "slab_sizes.c",
|
||||
"conf": "slab_sizes:1-4096:17|100-200:1|128-128:2",
|
||||
},
|
||||
{"src": "thread_arena.c"},
|
||||
{"src": "thread_tcache_enabled.c"},
|
||||
{
|
||||
"src": "xallocx.c",
|
||||
"conf": "junk:false",
|
||||
},
|
||||
]
|
||||
|
||||
INTEGRATION_DECAY_TESTS = [
|
||||
{
|
||||
"name": "%s_%s" % (
|
||||
test["name"] if "name" in test else test["src"].removesuffix(".c").replace("/", "_"),
|
||||
config["suffix"],
|
||||
),
|
||||
"src": test["src"],
|
||||
"conf": "%s,%s" % (
|
||||
test["conf"],
|
||||
config["conf"],
|
||||
) if "conf" in test else config["conf"],
|
||||
}
|
||||
for config in [
|
||||
{
|
||||
"suffix": "decay_minus_one",
|
||||
"conf": "dirty_decay_ms:-1,muzzy_decay_ms:-1",
|
||||
},
|
||||
{
|
||||
"suffix": "decay_zero",
|
||||
"conf": "dirty_decay_ms:0,muzzy_decay_ms:0",
|
||||
},
|
||||
]
|
||||
for test in INTEGRATION_TESTS
|
||||
]
|
||||
|
||||
transition_default_constraints(
|
||||
name = "testlib",
|
||||
testonly = True,
|
||||
src = "//test:testlib",
|
||||
platform = PLATFORM,
|
||||
settings = {
|
||||
"//settings:with_test": "integration",
|
||||
"//settings/flags:enable_fill": "True",
|
||||
# This needs to be pinned for testing. The MALLOC_CONF ENV depends on it. The make build allows for it to be
|
||||
# set dynamically via templating and generates a test harness around it. By requiring a value that cannot be
|
||||
# set internally by accident, this exercises the same functionality.
|
||||
"//settings/flags:jemalloc_prefix": "je_test_",
|
||||
},
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
[cc_test(
|
||||
name = test["name"] if "name" in test else test["src"].removesuffix(".c").replace("/", "_"),
|
||||
srcs = [test["src"]],
|
||||
copts = COPTS,
|
||||
env = {"JE_TEST_MALLOC_CONF": test.get("conf", "")},
|
||||
local_defines = ["JEMALLOC_INTEGRATION_TEST"],
|
||||
deps = [":testlib"],
|
||||
) for test in INTEGRATION_TESTS + INTEGRATION_DECAY_TESTS]
|
||||
|
||||
INTEGRATION_CPP_TESTS = [
|
||||
{"src": "cpp/basic.cpp"},
|
||||
{
|
||||
"src": "cpp/infallible_new_true.cpp",
|
||||
"conf": "experimental_infallible_new:true",
|
||||
},
|
||||
{
|
||||
"src": "cpp/infallible_new_false.cpp",
|
||||
"conf": "experimental_infallible_new:false",
|
||||
},
|
||||
]
|
||||
|
||||
transition_default_constraints(
|
||||
name = "testlib_cpp",
|
||||
testonly = True,
|
||||
src = "//test:testlib",
|
||||
platform = PLATFORM,
|
||||
settings = {
|
||||
"//settings:with_test": "integration_cpp",
|
||||
"//settings/flags:enable_fill": "True",
|
||||
# This needs to be pinned for testing. The MALLOC_CONF ENV depends on it. The make build allows for it to be
|
||||
# set dynamically via templating and generates a test harness around it. By requiring a value that cannot be
|
||||
# set internally by accident, this exercises the same functionality.
|
||||
"//settings/flags:jemalloc_prefix": "je_test_",
|
||||
},
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
[cc_test(
|
||||
name = test["name"] if "name" in test else test["src"].removesuffix(".cpp").replace("/", "_"),
|
||||
srcs = [test["src"]],
|
||||
copts = COPTS,
|
||||
env = {"JE_TEST_MALLOC_CONF": test.get("conf", "")},
|
||||
local_defines = ["JEMALLOC_INTEGRATION_CPP_TEST"],
|
||||
deps = [":testlib_cpp"],
|
||||
) for test in INTEGRATION_CPP_TESTS]
|
||||
|
|
@ -181,7 +181,7 @@ p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
|
|||
test_status_string(test_status_fail),
|
||||
test_counts[test_status_fail], test_count);
|
||||
|
||||
return ret;
|
||||
return (ret == test_status_skip) ? test_status_pass : ret;
|
||||
}
|
||||
|
||||
test_status_t
|
||||
|
|
|
|||
173
test/unit/BUILD.bazel
Normal file
173
test/unit/BUILD.bazel
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
load("@rules_cc//cc:defs.bzl", "cc_test")
|
||||
load("//:tools/cc.bzl", "COPTS")
|
||||
load("//:tools/transition.bzl", "PLATFORM", "transition_default_constraints")
|
||||
|
||||
# TODO: Handle conf when enable_prof = True
|
||||
#{ "src": "batch_alloc_prof.c" },
|
||||
#{ "src": "arena_reset_prof.c" },
|
||||
UNIT_TESTS = [
|
||||
{"src": "a0.c"},
|
||||
{
|
||||
"src": "arena_decay.c",
|
||||
"conf": "dirty_decay_ms:1000,muzzy_decay_ms:1000,tcache_max:1024",
|
||||
},
|
||||
{"src": "arena_reset.c"},
|
||||
{"src": "atomic.c"},
|
||||
{"src": "background_thread.c"},
|
||||
{"src": "background_thread_enable.c"},
|
||||
{"src": "base.c"},
|
||||
{"src": "batch_alloc.c"},
|
||||
{
|
||||
"src": "binshard.c",
|
||||
"conf": "narenas:1,bin_shards:1-160:16|129-512:4|256-256:8",
|
||||
},
|
||||
{"src": "bitmap.c"},
|
||||
{"src": "bit_util.c"},
|
||||
{"src": "buf_writer.c"},
|
||||
{"src": "cache_bin.c"},
|
||||
{"src": "ckh.c"},
|
||||
{"src": "counter.c"},
|
||||
{"src": "decay.c"},
|
||||
{"src": "div.c"},
|
||||
{"src": "double_free.c"},
|
||||
{"src": "edata_cache.c"},
|
||||
{"src": "emitter.c"},
|
||||
{"src": "extent_quantize.c"},
|
||||
{"src": "fb.c"},
|
||||
{"src": "fork.c"},
|
||||
{"src": "fxp.c"},
|
||||
{
|
||||
"src": "san.c",
|
||||
"conf": "san_guard_large:1,san_guard_small:1",
|
||||
},
|
||||
{"src": "san_bump.c"},
|
||||
{"src": "hash.c"},
|
||||
{"src": "hook.c"},
|
||||
{"src": "hpa.c"},
|
||||
{
|
||||
"src": "hpa_background_thread.c",
|
||||
"conf": "hpa_dirty_mult:0,hpa_min_purge_interval_ms:50,hpa_sec_nshards:0",
|
||||
},
|
||||
{"src": "hpdata.c"},
|
||||
{"src": "huge.c"},
|
||||
{"src": "inspect.c"},
|
||||
{
|
||||
"src": "junk.c",
|
||||
"conf": "abort:false,zero:false,junk:true",
|
||||
},
|
||||
{
|
||||
"name": "unit_junk_alloc",
|
||||
"src": "junk.c",
|
||||
"conf": "abort:false,zero:false,junk:alloc",
|
||||
},
|
||||
{
|
||||
"name": "unit_junk_free",
|
||||
"src": "junk.c",
|
||||
"conf": "abort:false,zero:false,junk:free",
|
||||
},
|
||||
{"src": "log.c"},
|
||||
{"src": "mallctl.c"},
|
||||
{"src": "malloc_conf_2.c"},
|
||||
{"src": "malloc_io.c"},
|
||||
{"src": "math.c"},
|
||||
{"src": "mpsc_queue.c"},
|
||||
{"src": "mq.c"},
|
||||
{"src": "mtx.c"},
|
||||
{"src": "nstime.c"},
|
||||
{"src": "oversize_threshold.c"},
|
||||
{"src": "pa.c"},
|
||||
{"src": "pack.c"},
|
||||
{"src": "pages.c"},
|
||||
{"src": "peak.c"},
|
||||
{"src": "ph.c"},
|
||||
{"src": "prng.c"},
|
||||
{"src": "prof_accum.c"},
|
||||
{"src": "prof_active.c"},
|
||||
{"src": "prof_gdump.c"},
|
||||
{"src": "prof_hook.c"},
|
||||
{"src": "prof_idump.c"},
|
||||
{"src": "prof_log.c"},
|
||||
{"src": "prof_mdump.c"},
|
||||
{"src": "prof_recent.c"},
|
||||
{"src": "prof_reset.c"},
|
||||
{"src": "prof_stats.c"},
|
||||
{"src": "prof_tctx.c"},
|
||||
{"src": "prof_thread_name.c"},
|
||||
{"src": "prof_sys_thread_name.c"},
|
||||
{"src": "psset.c"},
|
||||
{"src": "ql.c"},
|
||||
{"src": "qr.c"},
|
||||
{"src": "rb.c"},
|
||||
{"src": "retained.c"},
|
||||
{"src": "rtree.c"},
|
||||
{"src": "safety_check.c"},
|
||||
{"src": "sc.c"},
|
||||
{"src": "sec.c"},
|
||||
{"src": "seq.c"},
|
||||
{"src": "SFMT.c"},
|
||||
{"src": "size_check.c"},
|
||||
{"src": "size_classes.c"},
|
||||
{"src": "slab.c"},
|
||||
{"src": "smoothstep.c"},
|
||||
{"src": "spin.c"},
|
||||
{"src": "stats.c"},
|
||||
{"src": "stats_print.c"},
|
||||
{"src": "sz.c"},
|
||||
{
|
||||
"src": "tcache_max.c",
|
||||
"conf": "tcache_max:1024",
|
||||
},
|
||||
{"src": "test_hooks.c"},
|
||||
{"src": "thread_event.c"},
|
||||
{"src": "ticker.c"},
|
||||
{"src": "tsd.c"},
|
||||
{"src": "uaf.c"},
|
||||
{"src": "witness.c"},
|
||||
{
|
||||
"src": "zero.c",
|
||||
"conf": "abort:false,junk:false,zero:true",
|
||||
},
|
||||
{
|
||||
"src": "zero_realloc_abort.c",
|
||||
"conf": "zero_realloc:abort",
|
||||
},
|
||||
{
|
||||
"src": "zero_realloc_free.c",
|
||||
"conf": "zero_realloc:free",
|
||||
},
|
||||
{
|
||||
"src": "zero_realloc_alloc.c",
|
||||
"conf": "zero_realloc:alloc",
|
||||
},
|
||||
{
|
||||
"src": "zero_reallocs.c",
|
||||
"conf": "zero_realloc:free",
|
||||
},
|
||||
]
|
||||
|
||||
transition_default_constraints(
|
||||
name = "testlib",
|
||||
testonly = True,
|
||||
src = "//test:testlib",
|
||||
platform = PLATFORM,
|
||||
settings = {
|
||||
"//settings:enable_jet": "True",
|
||||
"//settings:with_test": "unit",
|
||||
"//settings/flags:enable_fill": "True",
|
||||
# This needs to be pinned for testing. The MALLOC_CONF ENV depends on it. The make build allows for it to be
|
||||
# set dynamically via templating and generates a test harness around it. By requiring a value that cannot be
|
||||
# set internally by accident, this exercises the same functionality.
|
||||
"//settings/flags:jemalloc_prefix": "je_test_",
|
||||
},
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
[cc_test(
|
||||
name = test["name"] if "name" in test else test["src"].removesuffix(".c").replace("/", "_"),
|
||||
srcs = [test["src"]],
|
||||
copts = COPTS,
|
||||
env = {"JE_TEST_MALLOC_CONF": test.get("conf", "")},
|
||||
linkstatic = True,
|
||||
local_defines = ["JEMALLOC_UNIT_TEST"],
|
||||
deps = [":testlib"],
|
||||
) for test in UNIT_TESTS]
|
||||
Loading…
Add table
Add a link
Reference in a new issue