Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile.cbm
Original file line number Diff line number Diff line change
Expand Up @@ -1114,10 +1114,12 @@ MIMALLOC_OBJ_TEST = $(BUILD_DIR)/mimalloc.o
MIMALLOC_OBJ_TSAN = $(BUILD_DIR)/tsan_mimalloc.o
MIMALLOC_OBJ_PROD = $(BUILD_DIR)/prod_mimalloc.o

$(BUILD_DIR)/mimalloc.o: $(MIMALLOC_SRC) | $(BUILD_DIR)
$(BUILD_DIR)/mimalloc.o: $(MIMALLOC_SRC) $(wildcard vendored/mimalloc/src/*.c) \
$(wildcard vendored/mimalloc/include/*.h) Makefile.cbm | $(BUILD_DIR)
$(CC) $(MIMALLOC_CFLAGS_TEST) -c -o $@ $<

$(BUILD_DIR)/tsan_mimalloc.o: $(MIMALLOC_SRC) | $(BUILD_DIR)
$(BUILD_DIR)/tsan_mimalloc.o: $(MIMALLOC_SRC) $(wildcard vendored/mimalloc/src/*.c) \
$(wildcard vendored/mimalloc/include/*.h) Makefile.cbm | $(BUILD_DIR)
$(CC) $(MIMALLOC_CFLAGS_TEST) $(TSAN_SANITIZE) -c -o $@ $<

# static.c is an AMALGAMATION: it #includes options.c and friends, none of which
Expand Down
7 changes: 6 additions & 1 deletion internal/cbm/doclink_perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,9 @@ static int pl_pkg_order_cmp(const void *a, const void *b) {
/* Give every declaration the index of its name's P record (names in order of
* their first declaration) and write the P records. */
static void pl_number_packages(pl_walk_t *w, pl_sb_t *sb) {
if (w->npkgs == 0) {
return;
}
qsort(w->pkgs, (size_t)w->npkgs, sizeof(pl_pkg_t), pl_pkg_name_cmp);
for (int i = 0; i < w->npkgs; i++) { /* index = order of the name's first declaration */
bool repeat =
Expand Down Expand Up @@ -1572,7 +1575,9 @@ static int pl_subdecl_cmp(const void *a, const void *b) {
/* One S record per sub definition of the file, with the package the tree
* places it in. */
static void pl_put_subs(CBMExtractCtx *ctx, pl_walk_t *w, pl_sb_t *sb) {
qsort(w->subs, (size_t)w->nsubs, sizeof(pl_subdecl_t), pl_subdecl_cmp);
if (w->nsubs > SKIP_ONE) {
qsort(w->subs, (size_t)w->nsubs, sizeof(pl_subdecl_t), pl_subdecl_cmp);
}
const CBMDefArray *defs = &ctx->result->defs;
for (int i = 0; i < defs->count; i++) {
const CBMDefinition *d = &defs->items[i];
Expand Down
6 changes: 4 additions & 2 deletions scripts/ci/test-impact-shadow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
# scripts/test-impact/predict.py map it to suites with the lane
# selector's run-all triggers. Writes DIR/prediction.json and
# DIR/summary.md (appended to $GITHUB_STEP_SUMMARY when set). The
# graph is only consulted when C sources changed.
# graph is only consulted when C sources changed and the lane
# selector has not already required every suite.
# Exit: 0 = prediction written · 1 = the tooling broke · 2 = usage error.
set -euo pipefail

Expand Down Expand Up @@ -135,7 +136,8 @@ VERSION=$("$BINARY" --version 2>/dev/null | head -1 || true)
DETECT_ARGS=()
T_INDEX="-"
T_DETECT="-"
if [ "$(python3 "$PREDICT" --needs-graph --changed "$OUT/changed-files.txt")" = yes ]; then
if [ "$(python3 "$PREDICT" --needs-graph --changed "$OUT/changed-files.txt" \
--selection "$OUT/selection.json")" = yes ]; then
python3 -c 'import json, sys; json.dump({"repo_path": sys.argv[1]}, open(sys.argv[2], "w"))' \
"$ROOT" "$WORK/index-args.json"
t0=$(date +%s)
Expand Down
10 changes: 6 additions & 4 deletions scripts/test-impact/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

Usage: predict.py --root DIR --changed FILE --selection FILE [--detect FILE]
[--depth N] [--meta JSON] --out FILE [--summary FILE]
predict.py --needs-graph --changed FILE (prints yes|no)
predict.py --needs-graph --changed FILE [--selection FILE] (prints yes|no)
"""
import argparse
import json
Expand Down Expand Up @@ -205,13 +205,15 @@ def main():
a = ap.parse_args()
with open(a.changed, encoding="utf-8") as fh:
changed = sorted({line.strip() for line in fh if line.strip()})
selection = {}
if a.selection:
with open(a.selection, encoding="utf-8") as fh:
selection = json.load(fh)
if a.needs_graph:
print("yes" if needs_graph(changed) else "no")
print("yes" if needs_graph(changed) and not selection.get("full") else "no")
return 0
if not (a.root and a.selection and a.out):
ap.error("--root, --selection and --out are required")
with open(a.selection, encoding="utf-8") as fh:
selection = json.load(fh)
detect = None
if a.detect:
with open(a.detect, encoding="utf-8") as fh:
Expand Down
1 change: 1 addition & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ fi
# release artifacts free of it; scripts/ci/check-binary-composition.sh proves
# they stay that way.
echo "=== Step 5: parent-death watchdog regression (#406/#407) ==="
CC="$CC" bash "$ROOT/tests/test_mimalloc_preinit.sh"
make -j"$NPROC" -f Makefile.cbm cbm TEST_SEAMS=1 ${MAKE_ARGS[@]+"${MAKE_ARGS[@]}"}
WATCHDOG_BINARY="$ROOT/$BUILD_DIR/codebase-memory-mcp"
CBM_TEST_BINARY="$WATCHDOG_BINARY" bash "$ROOT/tests/test_parent_watchdog.sh"
Expand Down
12 changes: 8 additions & 4 deletions src/mcp/mcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20753,13 +20753,17 @@ static char *handle_detect_changes(cbm_mcp_server_t *srv, const char *args) {
char hunk_cmd[CBM_SZ_2K];
#ifdef _WIN32
snprintf(hunk_cmd, sizeof(hunk_cmd),
"git -C \"%s\" diff --relative --unified=0 \"%s\" \"%s\" -- 2>NUL && "
"git -C \"%s\" diff --relative --unified=0 -- 2>NUL",
"git -C \"%s\" " CBM_TEST_IMPACT_GIT_PINS
" diff --relative " CBM_TEST_IMPACT_DIFF_FLAGS " \"%s\" \"%s\" -- 2>NUL && "
"git -C \"%s\" " CBM_TEST_IMPACT_GIT_PINS
" diff --relative " CBM_TEST_IMPACT_DIFF_FLAGS " -- 2>NUL",
root_path, merge_base, head_oid, root_path);
#else
snprintf(hunk_cmd, sizeof(hunk_cmd),
"git -C '%s' diff --relative --unified=0 '%s' '%s' -- 2>/dev/null && "
"git -C '%s' diff --relative --unified=0 -- 2>/dev/null",
"git -C '%s' " CBM_TEST_IMPACT_GIT_PINS
" diff --relative " CBM_TEST_IMPACT_DIFF_FLAGS " '%s' '%s' -- 2>/dev/null && "
"git -C '%s' " CBM_TEST_IMPACT_GIT_PINS
" diff --relative " CBM_TEST_IMPACT_DIFF_FLAGS " -- 2>/dev/null",
root_path, merge_base, head_oid, root_path);
#endif
char hunk_output_path[CBM_SZ_2K] = {0};
Expand Down
4 changes: 3 additions & 1 deletion src/pipeline/doc_links_perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ static bool pr_index_packages(pr_index_t *ix, const cbm_doclink_build_in_t *in)
if (ix->oom) {
return false;
}
qsort(ix->decls, (size_t)ix->ndecls, sizeof(pr_decl_t), pr_decl_cmp);
if (ix->ndecls > SKIP_ONE) {
qsort(ix->decls, (size_t)ix->ndecls, sizeof(pr_decl_t), pr_decl_cmp);
}
ix->pkg = cbm_ht_create_in(CBM_MEM_CLASS_OTHER, (uint32_t)(ix->ndecls + SKIP_ONE));
if (!ix->pkg) {
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/pipeline/doc_links_rst.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ static void rr_destroy(void *index) {
/* The documentation set a document belongs to: the nearest conf.py at or
* above its directory; NULL for none. */
static const rr_conf_t *rr_conf_for(const rr_index_t *x, const char *doc) {
if (x->nconfs == 0) {
return NULL;
}
char dir[RR_PATH_CAP];
const char *b = rr_base(doc);
size_t dl = b > doc ? (size_t)(b - doc - SKIP_ONE) : 0;
Expand Down
6 changes: 6 additions & 0 deletions tests/test_extraction.c
Original file line number Diff line number Diff line change
Expand Up @@ -12612,6 +12612,12 @@ TEST(doc_perl_module_doc_is_the_pod_no_sub_holds) {
ASSERT_NOT_NULL(r);
ASSERT_NULL(r->module_doc);
cbm_free_result(r);
/* POD without any declarations leaves both scope sort inputs empty. */
r = extract("=head1 NAME\n\nStandalone module.\n\n=cut\n", CBM_LANG_PERL, "t", "Standalone.pm");
ASSERT_NOT_NULL(r);
ASSERT_EQ(count_defs_with_label(r, "Function"), 0);
ASSERT_STR_EQ(r->module_doc, "=head1 NAME\n\nStandalone module.\n\n=cut");
cbm_free_result(r);
PASS();
}

Expand Down
12 changes: 5 additions & 7 deletions tests/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,12 @@ static void tf_cleanup_cache_sentinel(void) {
}
}

/* Client home overrides the CLI honours BEFORE $HOME, so redirecting HOME alone
* does not isolate them: cbm_codex_config_dir() and its siblings return the
* ambient path and the suite resolves against the developer's real config —
* reading its state and writing to it. Same inventory the shell fixtures are
* already required to neutralize (tests/test_smoke_fixture_contract.sh), kept
* in one place so a new client cannot be isolated in the smoke scripts and
* forgotten here. A test that exercises one of these sets it after setup. */
/* These paths take precedence over HOME and can escape the private fixture.
* A test that exercises an override sets it after setup. */
static const char *const tf_client_home_overrides[] = {
"XDG_CONFIG_HOME",
"XDG_DATA_HOME",
"XDG_CACHE_HOME",
"CLAUDE_CONFIG_DIR",
"CODEX_HOME",
"KIRO_HOME",
Expand Down
3 changes: 2 additions & 1 deletion tests/test_mcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20478,7 +20478,8 @@ static bool dc_walk_fixture_open(dc_walk_fixture_t *fx) {
}
/* Same git invocation rules as the #1363 fixture above. */
char cmd[1200];
const char *steps[] = {"init -q", "add -A", "commit -q -m init"};
const char *steps[] = {"init -q", "config diff.mnemonicPrefix true", "add -A",
"commit -q -m init"};
for (size_t s = 0; s < sizeof(steps) / sizeof(steps[0]); s++) {
snprintf(cmd, sizeof(cmd),
"git -C \"%s\" -c user.name=t -c user.email=t@t.io -c init.defaultBranch=main "
Expand Down
31 changes: 31 additions & 0 deletions tests/test_mimalloc_preinit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail

# ELF preinitializers run before allocator constructors, independent of libc version.
if [[ "$(uname -s)" != Linux ]]; then
echo "mimalloc pre-init regression: ELF-only check not applicable"
exit 0
fi
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
probe_dir="$(mktemp -d "${TMPDIR:-/tmp}/cbm-mi-preinit.XXXXXX")"
trap 'rm -rf "$probe_dir"' EXIT

cat >"$probe_dir/probe.c" <<'C'
#include <stddef.h>
#include "mimalloc.h"
static void before_init(void) { mi_free(NULL); }
__attribute__((used, section(".preinit_array")))
static void (*const preinit)(void) = before_init;
int main(void) {
void *p = mi_malloc(16);
if (!p) return 1;
mi_free(p);
return 0;
}
C
"${CC:-cc}" -O2 -DMI_DEBUG=0 -DMI_OVERRIDE=0 \
-I"$ROOT/vendored/mimalloc/include" -I"$ROOT/vendored/mimalloc/src" \
"$probe_dir/probe.c" "$ROOT/vendored/mimalloc/src/static.c" \
-lpthread -lm -o "$probe_dir/probe"
"$probe_dir/probe"
echo "mimalloc pre-init free(NULL) regression passed"
4 changes: 3 additions & 1 deletion tests/test_smoke_fixture_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ CLIENT_HOME_OVERRIDES = (
# so it needs the same neutralization — otherwise a green run on a developer
# machine only proves the ambient config happened to be writable.
test_main = read("tests/test_main.c")
for variable in CLIENT_HOME_OVERRIDES:
for variable in CLIENT_HOME_OVERRIDES + (
"XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME"
):
require(
f'"{variable}"' in test_main,
f"tests/test_main.c must neutralize ambient {variable}",
Expand Down
12 changes: 12 additions & 0 deletions tests/test_test_impact_predict.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ for changed, want in ((["README.md"], "no"), (["src/store/store.c"], "yes"),
if out != want:
failures.append(f"--needs-graph for {changed}: {out!r}, expected {want!r}")
for selection, want in ((NARROW, "yes"), ({"tier": "T5-core", "full": True}, "no")):
(work / "needs.txt").write_text("src/store/store.c\n")
(work / "selection.json").write_text(json.dumps(selection))
proc = subprocess.run([sys.executable, predict, "--needs-graph", "--changed",
str(work / "needs.txt"), "--selection", str(work / "selection.json")],
capture_output=True, text=True)
if proc.returncode != 0 or proc.stdout.strip() != want:
failures.append(f"--needs-graph with {selection}: {proc.stdout!r}, expected {want!r}")
expect("run-all without indexing still selects every suite",
predict_for("full-no-graph", ["Makefile.cbm", "src/store/store.c"],
{"tier": "T5-core", "full": True}), "all", ALL)
if failures:
print("TEST-IMPACT PREDICTION CONTRACT VIOLATED:")
for failure in failures:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_venue_parity_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ test-infrastructure/vm/vm-run-tests.sh
test-infrastructure/vm/win.sh
"
for entry in $HELP_ENTRIES; do
out=$(cd "$ROOT" && bash "$entry" --help 2>&1) && rc=0 || rc=$?
case "$entry" in
*.py) out=$(cd "$ROOT" && python3 "$entry" --help 2>&1) && rc=0 || rc=$? ;;
*) out=$(cd "$ROOT" && bash "$entry" --help 2>&1) && rc=0 || rc=$? ;;
esac
# Substring test in-shell: piping into `grep -q` is unsafe under
# `set -o pipefail` because grep exits at the first match and the
Expand Down
Loading