interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tools / mutpool.sh

52 lines · 2314 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Bounded parallel pool for mutation sweeps. SOURCE this file (". tools/mutpool.sh"):
18# mp_init once, before the first job
19# mp_run cmd args... queue one mutant job (a shell function or command)
20# mp_wait wait for all jobs, print each job's output in the order
21# the jobs were queued, return 1 if any job failed
22# Each job runs in its own subshell (inheriting the caller's set -e) with its own output and exit-code files, so a
23# job's "exit 1" ends only that job. Pool size: MUTANT_JOBS (default nproc);
24# MUTANT_JOBS=1 is the old serial behaviour. Output and verdicts are identical to
25# running the jobs one after another, except that after a failure the remaining
26# jobs still run and are reported.
27mp_init() {
28 MP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/mutpool.XXXXXX") || return 1
29 MP_N=0; MP_PIDS=""; MP_RUNNING=0
30 MP_MAX=${MUTANT_JOBS:-$(nproc 2>/dev/null || echo 1)}
31 case $MP_MAX in ''|*[!0-9]*|0) MP_MAX=1;; esac
32}
33mp_run() {
34 MP_N=$((MP_N + 1)); _mp_i=$MP_N
35 if [ "$MP_RUNNING" -ge "$MP_MAX" ]; then
36 _mp_first=${MP_PIDS%% *}; MP_PIDS=${MP_PIDS#"$_mp_first"}; MP_PIDS=${MP_PIDS# }
37 wait "$_mp_first" 2>/dev/null; MP_RUNNING=$((MP_RUNNING - 1))
38 fi
39 case $- in *e*) _mp_e=-e;; *) _mp_e=+e;; esac
40 ( set +e; ( set $_mp_e; "$@" ) > "$MP_DIR/$_mp_i.out" 2>&1; echo "$?" > "$MP_DIR/$_mp_i.rc" ) &
41 MP_PIDS="$MP_PIDS${MP_PIDS:+ }$!"; MP_RUNNING=$((MP_RUNNING + 1))
42}
43mp_wait() {
44 wait; _mp_bad=0; _mp_i=1
45 while [ "$_mp_i" -le "$MP_N" ]; do
46 cat "$MP_DIR/$_mp_i.out"
47 [ "$(cat "$MP_DIR/$_mp_i.rc" 2>/dev/null || echo 1)" = 0 ] || _mp_bad=1
48 _mp_i=$((_mp_i + 1))
49 done
50 rm -rf "$MP_DIR"
51 [ "$_mp_bad" = 0 ]
52}