OILS / test / ltrace.sh View on Github | oils.pub

82 lines, 35 significant
1#!/usr/bin/env bash
2#
3# Usage:
4# test/ltrace.sh <function name>
5
6: ${LIB_OSH=stdlib/osh}
7source $LIB_OSH/bash-strict.sh
8source $LIB_OSH/task-five.sh
9
10source test/common.sh # log
11
12BASE_DIR=_tmp/ltrace
13
14test-home-dir() {
15 mkdir -p $BASE_DIR
16 rm -f -v $BASE_DIR/*
17
18 # ltrace doesn't work with ASAN, etc.
19 local osh=_bin/cxx-dbg/osh
20 ninja $osh
21
22 # zsh calls getpwuid
23 # bash on my Ubuntu machine doesn't call it, but seems to in the Debian CI
24 # image
25 # could test mksh, but it's not in the CI image
26 for sh in $osh dash "$@"; do
27 local trace
28 trace=$BASE_DIR/$(basename $sh).txt
29
30 set +o errexit
31
32 set -x
33 ltrace -e getpwuid -- $sh -c 'echo hi' 2> $trace
34 local status=$?
35 set +x
36 echo "status=$status"
37
38 set -o errexit
39 echo
40 done
41
42 wc -l $BASE_DIR/*.txt
43 echo
44
45 head $BASE_DIR/*.txt
46
47 if grep getpwuid $BASE_DIR/*.txt; then
48 log "ERROR: shells should not call getpwuid()"
49 return 1
50 fi
51
52 return 0
53}
54
55soil-run() {
56 # 2025-11: ltrace doesn't seem to work on Github Actions, with podman, even
57 # podman 4.9 on Ubuntu
58 #
59 # This test does NOT fail, but it doesn't test anything either.
60 # This is even with PTRACE_FLAGS in soil/host-shim.sh, which fixed ASAN, but
61 # not ltrace.
62 #
63 # ==> _tmp/ltrace/dash.txt <==
64 # failed to init breakpoints 1648
65 # failed to initialize process 1648: Permission denied
66 # couldn't open program '/usr/bin/dash': Permission denied
67 #
68 # ==> _tmp/ltrace/osh.txt <==
69 # failed to init breakpoints 1645
70 # failed to initialize process 1645: Permission denied
71 # couldn't open program '_bin/cxx-dbg/osh': Permission denied
72
73 # Did it ever work with Docker? It's not clear.
74 # In any case, we want to switch to podman, and this test is not that
75 # important.
76 # We could make it a separate Soil task in the future, so it's easier to
77 # debug.
78
79 test-home-dir
80}
81
82task-five "$@"