OILS / regtest / aports-guest.sh View on Github | oils.pub

99 lines, 54 significant
1#!/usr/bin/env bash
2#
3# Code that runs inside Alpine chroot.
4#
5# Usage:
6# regtest/aports-guest.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12log() {
13 echo "$@" >& 2
14}
15
16# copied from build/deps.sh
17my-time-tsv() {
18 python3 benchmarks/time_.py \
19 --tsv \
20 --time-span --rusage \
21 "$@"
22 # TODO: could add --rusage-2 to measure page faults / context switches
23 # for tuning the xargs -P value - for thrashing and so forth
24}
25
26my-time-tsv-test() {
27 # Doesn't output to stdout
28 # my-time-tsv sleep 0.5
29
30 my-time-tsv -o /tmp/my-time sleep 0.5
31 cat /tmp/my-time
32}
33
34readonly LOG_DIR=_tmp/aports-guest
35
36timestamp() {
37 date '+%H:%M:%S'
38}
39
40build-one-package() {
41 # Copied from build/deps.sh maybe-install-wedge
42 #
43 # Difference vs. build-package: do not need $config here
44
45 local pkg=${1:-lua5.4}
46 local a_repo=${2:-main}
47 local xargs_slot=${3:-99} # recorded in tasks.tsv
48 local more_abuild_flags=${4:-} # e.g. for -k
49 local timeout_secs=${5:-$(( 5 * 60 ))} # 5 minutes by default
50
51 printf -v xargs_str '%2s' $xargs_slot
52 echo " TASK $xargs_str $(timestamp) $pkg"
53
54 local task_file=$LOG_DIR/$pkg.task.tsv
55 local log_file=$LOG_DIR/$pkg.log.txt
56
57 mkdir -p $(dirname $task_file)
58
59 my-time-tsv --print-header \
60 --field xargs_slot \
61 --field pkg \
62 --field pkg_HREF \
63 --output $task_file
64
65 # DISABLE rootbld for now - bwrap doesn't work inside chroot, because user
66 # namespaces don't compose with chroots
67 local -a cmd=( abuild -f -r -C ~/aports/$a_repo/$pkg $more_abuild_flags )
68
69 # Give it 1 second to respond to SIGTERM, then SIGKILL
70 local -a timeout_cmd=( timeout -k 1 $timeout_secs "${cmd[@]}" )
71
72 #set -x
73 # NOTE: log/foo.log.txt is the relative path after copy-results; sync-results
74 set +o errexit
75 my-time-tsv \
76 --field "$xargs_slot" \
77 --field "$pkg" \
78 --field "log/$pkg.log.txt" \
79 --append \
80 --output $task_file \
81 -- \
82 "${timeout_cmd[@]}" >$log_file 2>&1
83 local status=$?
84 set -o errexit
85
86 if test "$status" -eq 0; then
87 echo " OK $(timestamp) $pkg"
88 else
89 echo " FAIL $(timestamp) $pkg"
90 fi
91
92 # Note: should we try not to fetch here? I think the caching of "abuilt
93 # fetch" might make this OK
94
95 # TODO: avoid running tests and building the APK itself/
96 # Only "abuild builddeps,build" is enough to start?
97}
98
99"$@"