do not edit — generated by btf.
git.druid.rocksindexdruid520mptest/suites/graphs.sh

test/suites/graphs.sh


# suite: deep/complex dependency graphs -- long chains, diamonds with a
# shared middle, static multi-slot same-pkg_name trees, version
# constraints threaded through several levels, soft-dep cycle breaking,
# multi-tag choice points with pins, and pin-overrides-pref provider
# selection. every test here sets GLOBAL_DEPS=" " so the graph under test
# is exactly the graph declared, with no implicit %libc/%shell/%coreutils
# noise (that machinery has its own coverage in config_loading.sh and
# the closing sweep).
 
# an 8-level chain must install every level exactly once, in one
# invocation, and mp tree must walk the whole depth.
test_deep_chain() {
	t_begin "deep_chain"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	i=1
	while [ "$i" -le 8 ]; do
		next=$((i + 1))
		deps=""
		[ "$i" -lt 8 ] && deps="pkg_deps=\"g1l$next\""
		mkport "g1l$i" <<EOF
pkg_name="g1l$i"
pkg_ver="1.0"
$deps
install:
	touch \$MP_PREFIX/g1l$i-installed
remove:
	rm -f \$MP_PREFIX/g1l$i-installed
EOF
		i=$((i + 1))
	done
	mp install g1l1 >/tmp/g1.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	i=1
	while [ "$i" -le 8 ]; do
		assert_file_exists "$MP_PREFIX/g1l$i-installed" "$CUR_TEST" || return
		i=$((i + 1))
	done
	count=$(grep -c '^g1l' "$WD/db")
	if [ "$count" -ne 8 ]; then t_fail "$CUR_TEST (expected 8 db entries, got $count)"; return; fi
	tree_out=$(mp tree g1l1 2>&1)
	for n in g1l1 g1l3 g1l5 g1l8; do
		assert_contains "$tree_out" "$n" "$CUR_TEST" || return
	done
	t_pass
}
 
# a diamond (A->{B,C}, B->D, C->D) must install the shared middle exactly
# once -- the db must hold a single D entry, not two attempts.
test_diamond_shared() {
	t_begin "diamond_shared"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	mkport g2d <<'EOF'
pkg_name="g2d"
pkg_ver="1.0"
install:
	touch $MP_PREFIX/g2d-installed
remove:
	rm -f $MP_PREFIX/g2d-installed
EOF
	mkport g2b <<'EOF'
pkg_name="g2b"
pkg_ver="1.0"
pkg_deps="g2d"
install:
	touch $MP_PREFIX/g2b-installed
remove:
	rm -f $MP_PREFIX/g2b-installed
EOF
	mkport g2c <<'EOF'
pkg_name="g2c"
pkg_ver="1.0"
pkg_deps="g2d"
install:
	touch $MP_PREFIX/g2c-installed
remove:
	rm -f $MP_PREFIX/g2c-installed
EOF
	mkport g2a <<'EOF'
pkg_name="g2a"
pkg_ver="1.0"
pkg_deps="g2b g2c"
install:
	touch $MP_PREFIX/g2a-installed
remove:
	rm -f $MP_PREFIX/g2a-installed
EOF
	mp install g2a >/tmp/g2.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	for n in g2a g2b g2c g2d; do
		assert_file_exists "$MP_PREFIX/$n-installed" "$CUR_TEST" || return
	done
	count=$(grep -c '^g2d' "$WD/db")
	if [ "$count" -ne 1 ]; then t_fail "$CUR_TEST (expected exactly 1 g2d db entry, got $count)"; return; fi
	t_pass
}
 
# a %tag dep between two statically slotted variants of one pkg_name
# (the gcc-12/gcc-13 pattern): an explicit name:slot dep must wire the
# requested slot, a bare name dep must resolve to the auto-pick slot
# (lowest pkg_pref), and both slots coexist in one db.
test_multislot_static_deps() {
	t_begin "multislot_static_deps"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	mkport g3-12 <<'EOF'
pkg_name="g3stub"
pkg_ver="12.0"
pkg_slot="12"
pkg_pref="10"
install:
	touch $MP_PREFIX/g3stub12-installed
remove:
	rm -f $MP_PREFIX/g3stub12-installed
EOF
	mkport g3-13 <<'EOF'
pkg_name="g3stub"
pkg_ver="13.0"
pkg_slot="13"
pkg_pref="20"
install:
	touch $MP_PREFIX/g3stub13-installed
remove:
	rm -f $MP_PREFIX/g3stub13-installed
EOF
	mkport g3explicit <<'EOF'
pkg_name="g3explicit"
pkg_ver="1.0"
pkg_deps="g3stub:13"
install:
	echo "DEPLOG=[$MP_DEP_PREFIXES]" > $MP_PREFIX/g3explicit-deplog
	touch $MP_PREFIX/g3explicit-installed
remove:
	rm -f $MP_PREFIX/g3explicit-installed $MP_PREFIX/g3explicit-deplog
EOF
	mkport g3bare <<'EOF'
pkg_name="g3bare"
pkg_ver="1.0"
pkg_deps="g3stub"
install:
	touch $MP_PREFIX/g3bare-installed
remove:
	rm -f $MP_PREFIX/g3bare-installed
EOF
	mp install g3explicit g3bare >/tmp/g3.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	assert_file_exists "$MP_PREFIX/g3stub-12/g3stub12-installed" "$CUR_TEST" || return
	assert_file_exists "$MP_PREFIX/g3stub-13/g3stub13-installed" "$CUR_TEST" || return
	assert_file_exists "$MP_PREFIX/g3explicit-installed" "$CUR_TEST" || return
	assert_file_exists "$MP_PREFIX/g3bare-installed" "$CUR_TEST" || return
	deplog=$(cat "$MP_PREFIX/g3explicit-deplog" 2>/dev/null)
	assert_contains "$deplog" "g3stub-13" "$CUR_TEST" || return
	linkdeps=$(cat "$WD/linkdeps.db" 2>/dev/null)
	assert_contains "$linkdeps" "g3stub:13" "$CUR_TEST" || return
	db=$(cat "$WD/db")
	assert_contains "$db" "g3stub:12" "$CUR_TEST" || return
	assert_contains "$db" "g3stub:13" "$CUR_TEST" || return
	t_pass
}
 
# version constraints threaded through three levels: >= on a fixed port
# version, ~ prefix on the next -- all satisfied by the declared versions.
test_version_constraint_chain() {
	t_begin "version_constraint_chain"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	mkport g4c3 <<'EOF'
pkg_name="g4c3"
pkg_ver="1.2.9"
install:
	touch $MP_PREFIX/g4c3-installed
remove:
	rm -f $MP_PREFIX/g4c3-installed
EOF
	mkport g4c2 <<'EOF'
pkg_name="g4c2"
pkg_ver="2.5"
pkg_deps="g4c3~1.2"
install:
	touch $MP_PREFIX/g4c2-installed
remove:
	rm -f $MP_PREFIX/g4c2-installed
EOF
	mkport g4c1 <<'EOF'
pkg_name="g4c1"
pkg_ver="1.0"
pkg_deps="g4c2>=2.0"
install:
	touch $MP_PREFIX/g4c1-installed
remove:
	rm -f $MP_PREFIX/g4c1-installed
EOF
	mp install g4c1 >/tmp/g4.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	for n in g4c1 g4c2 g4c3; do
		assert_file_exists "$MP_PREFIX/$n-installed" "$CUR_TEST" || return
	done
	db=$(cat "$WD/db")
	assert_contains "$db" "g4c2	2.5" "$CUR_TEST" || return
	assert_contains "$db" "g4c3	1.2.9" "$CUR_TEST" || return
	t_pass
}
 
# a soft dependency that would complete a hard cycle must be skipped,
# not abort the whole install -- the soft edge is dropped and the rest
# of the graph installs normally.
test_soft_dep_cycle_broken() {
	t_begin "soft_dep_cycle_broken"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	mkport g5a <<'EOF'
pkg_name="g5a"
pkg_ver="1.0"
pkg_deps_soft="g5b"
install:
	touch $MP_PREFIX/g5a-installed
remove:
	rm -f $MP_PREFIX/g5a-installed
EOF
	mkport g5b <<'EOF'
pkg_name="g5b"
pkg_ver="1.0"
pkg_deps="g5a"
install:
	touch $MP_PREFIX/g5b-installed
remove:
	rm -f $MP_PREFIX/g5b-installed
EOF
	out=$(mp install g5a 2>&1)
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	assert_contains "$out" "skipping" "$CUR_TEST" || return
	assert_file_exists "$MP_PREFIX/g5a-installed" "$CUR_TEST" || return
	assert_file_absent "$MP_PREFIX/g5b-installed" "$CUR_TEST" || return
	t_pass
}
 
# two %tag choice points in one package, both pinned via per-package
# TARGET_<tag> -- both pins must be honored, overriding pkg_pref on
# both axes independently.
test_multi_choice_pins() {
	t_begin "multi_choice_pins"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	mkport g6t1a <<'EOF'
pkg_name="g6t1a"
pkg_ver="1.0"
pkg_tags="g6tag1"
pkg_pref="10"
install:
	touch $MP_PREFIX/g6t1a-installed
remove:
	rm -f $MP_PREFIX/g6t1a-installed
EOF
	mkport g6t1b <<'EOF'
pkg_name="g6t1b"
pkg_ver="1.0"
pkg_tags="g6tag1"
pkg_pref="20"
install:
	touch $MP_PREFIX/g6t1b-installed
remove:
	rm -f $MP_PREFIX/g6t1b-installed
EOF
	mkport g6t2a <<'EOF'
pkg_name="g6t2a"
pkg_ver="1.0"
pkg_tags="g6tag2"
pkg_pref="10"
install:
	touch $MP_PREFIX/g6t2a-installed
remove:
	rm -f $MP_PREFIX/g6t2a-installed
EOF
	mkport g6t2b <<'EOF'
pkg_name="g6t2b"
pkg_ver="1.0"
pkg_tags="g6tag2"
pkg_pref="20"
install:
	touch $MP_PREFIX/g6t2b-installed
remove:
	rm -f $MP_PREFIX/g6t2b-installed
EOF
	mkport g6need <<'EOF'
pkg_name="g6need"
pkg_ver="1.0"
pkg_deps="%g6tag1 %g6tag2"
install:
	touch $MP_PREFIX/g6need-installed
remove:
	rm -f $MP_PREFIX/g6need-installed
EOF
	cat >> "$CONF" <<'EOF'
g6need:
	TARGET_g6tag1=g6t1b
	TARGET_g6tag2=g6t2a
EOF
	mp install g6need >/tmp/g6.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	assert_file_exists "$MP_PREFIX/g6t1b-installed" "$CUR_TEST" || return
	assert_file_absent "$MP_PREFIX/g6t1a-installed" "$CUR_TEST" || return
	assert_file_exists "$MP_PREFIX/g6t2a-installed" "$CUR_TEST" || return
	assert_file_absent "$MP_PREFIX/g6t2b-installed" "$CUR_TEST" || return
	t_pass
}
 
# a TARGET_<tag> pin must beat every provider's pkg_pref: the pinned
# candidate is picked even though several higher-pref providers exist.
test_pin_overrides_pref() {
	t_begin "pin_overrides_pref"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	i=1
	while [ "$i" -le 4 ]; do
		mkport "g7p$i" <<EOF
pkg_name="g7p$i"
pkg_ver="1.0"
pkg_tags="g7tag"
pkg_pref="$((i * 10))"
install:
	touch \$MP_PREFIX/g7p$i-installed
remove:
	rm -f \$MP_PREFIX/g7p$i-installed
EOF
		i=$((i + 1))
	done
	mkport g7need <<'EOF'
pkg_name="g7need"
pkg_ver="1.0"
pkg_deps="%g7tag"
install:
	touch $MP_PREFIX/g7need-installed
remove:
	rm -f $MP_PREFIX/g7need-installed
EOF
	echo 'TARGET_g7tag=g7p3' >> "$CONF"
	mp install g7need >/tmp/g7.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	assert_file_exists "$MP_PREFIX/g7p3-installed" "$CUR_TEST" || return
	for n in g7p1 g7p2 g7p4; do
		assert_file_absent "$MP_PREFIX/$n-installed" "$CUR_TEST" || return
	done
	t_pass
}
 
# a chain whose levels alternate %tag and bare deps resolves every hop
# in order and records the full depth in one db.
test_mixed_dep_chain() {
	t_begin "mixed_dep_chain"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	mkport g8prov <<'EOF'
pkg_name="g8prov"
pkg_ver="1.0"
pkg_tags="g8tag"
install:
	touch $MP_PREFIX/g8prov-installed
remove:
	rm -f $MP_PREFIX/g8prov-installed
EOF
	mkport g8l2 <<'EOF'
pkg_name="g8l2"
pkg_ver="1.0"
pkg_deps="%g8tag"
install:
	touch $MP_PREFIX/g8l2-installed
remove:
	rm -f $MP_PREFIX/g8l2-installed
EOF
	mkport g8l1 <<'EOF'
pkg_name="g8l1"
pkg_ver="1.0"
pkg_deps="g8l2"
install:
	touch $MP_PREFIX/g8l1-installed
remove:
	rm -f $MP_PREFIX/g8l1-installed
EOF
	mp install g8l1 >/tmp/g8.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	for n in g8l1 g8l2 g8prov; do
		assert_file_exists "$MP_PREFIX/$n-installed" "$CUR_TEST" || return
	done
	t_pass
}
 
# a diamond over a %tag (two consumers, one provider) resolves the
# provider exactly once, with the second consumer reusing it.
test_tag_diamond_single_provider() {
	t_begin "tag_diamond_single_provider"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	mkport g9prov <<'EOF'
pkg_name="g9prov"
pkg_ver="1.0"
pkg_tags="g9tag"
install:
	touch $MP_PREFIX/g9prov-installed
remove:
	rm -f $MP_PREFIX/g9prov-installed
EOF
	mkport g9c1 <<'EOF'
pkg_name="g9c1"
pkg_ver="1.0"
pkg_deps="%g9tag"
install:
	touch $MP_PREFIX/g9c1-installed
remove:
	rm -f $MP_PREFIX/g9c1-installed
EOF
	mkport g9c2 <<'EOF'
pkg_name="g9c2"
pkg_ver="1.0"
pkg_deps="%g9tag"
install:
	touch $MP_PREFIX/g9c2-installed
remove:
	rm -f $MP_PREFIX/g9c2-installed
EOF
	mp install g9c1 g9c2 >/tmp/g9.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	count=$(grep -c '^g9prov' "$WD/db")
	if [ "$count" -ne 1 ]; then t_fail "$CUR_TEST (expected 1 provider line, got $count)"; return; fi
	t_pass
}
 
# a %tag chain (consumer -> tag -> tag -> provider) resolves through
# both hops.
test_tag_chain_two_hops() {
	t_begin "tag_chain_two_hops"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	mkport g10prov <<'EOF'
pkg_name="g10prov"
pkg_ver="1.0"
pkg_tags="g10tag2"
install:
	touch $MP_PREFIX/g10prov-installed
remove:
	rm -f $MP_PREFIX/g10prov-installed
EOF
	mkport g10mid <<'EOF'
pkg_name="g10mid"
pkg_ver="1.0"
pkg_tags="g10tag1"
pkg_deps="%g10tag2"
install:
	touch $MP_PREFIX/g10mid-installed
remove:
	rm -f $MP_PREFIX/g10mid-installed
EOF
	mkport g10top <<'EOF'
pkg_name="g10top"
pkg_ver="1.0"
pkg_deps="%g10tag1"
install:
	touch $MP_PREFIX/g10top-installed
remove:
	rm -f $MP_PREFIX/g10top-installed
EOF
	mp install g10top >/tmp/g10.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	for n in g10top g10mid g10prov; do
		assert_file_exists "$MP_PREFIX/$n-installed" "$CUR_TEST" || return
	done
	t_pass
}
 
# a tag with a provider that itself depends on another tag (provider
# chaining) resolves the whole subgraph.
test_provider_chain_resolves() {
	t_begin "provider_chain_resolves"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	mkport g11base <<'EOF'
pkg_name="g11base"
pkg_ver="1.0"
pkg_tags="g11basetag"
install:
	touch $MP_PREFIX/g11base-installed
remove:
	rm -f $MP_PREFIX/g11base-installed
EOF
	mkport g11prov <<'EOF'
pkg_name="g11prov"
pkg_ver="1.0"
pkg_tags="g11tag"
pkg_deps="%g11basetag"
install:
	touch $MP_PREFIX/g11prov-installed
remove:
	rm -f $MP_PREFIX/g11prov-installed
EOF
	mkport g11need <<'EOF'
pkg_name="g11need"
pkg_ver="1.0"
pkg_deps="%g11tag"
install:
	touch $MP_PREFIX/g11need-installed
remove:
	rm -f $MP_PREFIX/g11need-installed
EOF
	mp install g11need >/tmp/g11.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	for n in g11need g11prov g11base; do
		assert_file_exists "$MP_PREFIX/$n-installed" "$CUR_TEST" || return
	done
	t_pass
}
 
run_graphs_suite() {
	test_deep_chain
	test_diamond_shared
	test_multislot_static_deps
	test_version_constraint_chain
	test_soft_dep_cycle_broken
	test_multi_choice_pins
	test_pin_overrides_pref
	test_mixed_dep_chain
	test_tag_diamond_single_provider
	test_tag_chain_two_hops
	test_provider_chain_resolves
}
powered by btf.