-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun_coreutils_tests.sh
More file actions
executable file
·273 lines (220 loc) · 9.39 KB
/
run_coreutils_tests.sh
File metadata and controls
executable file
·273 lines (220 loc) · 9.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/usr/bin/env bash
################################################################################
# manual_coreutils_tests.sh
#
# Manually tests a subset of coreutils binaries through lind-boot with
# hardcoded absolute paths to work around the cwd/chroot issue (#742).
#
# Tests 3+ utilities from each category:
# File Management: ls, cp, mv, rm, mkdir, rmdir, ln, touch
# Text Processing: cat, head, tail, wc, sort, uniq, cut, paste
# Permissions/Info: chmod, df, du, pwd, dd
# Text Manipulation: echo, printf, tr, expand, unexpand
################################################################################
set -uo pipefail
LIND_WASM_ROOT="${LIND_WASM_ROOT:-/home/lind/lind-wasm}"
LINDBOOT_BIN="$LIND_WASM_ROOT/build/lind-boot"
LINDFS_ROOT="$LIND_WASM_ROOT/lindfs"
WASM_DIR="$LIND_WASM_ROOT/lind-wasm-apps/build/bin/coreutils/wasm32-wasi"
LINDFS_BIN="/opt/coreutils"
# Test working directory — absolute path so sandbox can see it
TEST_DIR="tmp/lind-manual-tests-$$"
PASS=0
FAIL=0
TOTAL=0
LOG_FILE="manual_coreutils_results.log"
# ── Setup ────────────────────────────────────────────────────────────────────
setup() {
# Ensure bind mounts are in place
sudo mkdir -p "$LINDFS_ROOT/tmp" "$LINDFS_ROOT/home" "$LINDFS_ROOT/dev"
mkdir -p "$LINDFS_ROOT/$TEST_DIR"
}
cleanup() {
rm -rf "$LINDFS_ROOT/$TEST_DIR"
}
lind_run_stderr() {
cat $LINDFS_ROOT/tmp/lind_run_stderr
}
# ── Helper: run a test ───────────────────────────────────────────────────────
run_test() {
local name="$1"
local expected="$2"
local actual="$3"
((TOTAL++))
if [ "$expected" = "$actual" ]; then
echo " PASS: $name"
((PASS++))
else
echo " FAIL: $name"
echo " expected: $(echo "$expected" | head -3)"
echo " actual: $(echo "$actual" | head -3)"
local err=$(lind_run_stderr)
[ -n "$err" ] && echo " stderr: $(echo "$err" | head -3)"
((FAIL++))
fi
}
run_test_exitcode() {
local name="$1"
local expected_exit="$2"
shift 2
((TOTAL++))
"$@" >/dev/null 2>&1
local actual_exit=$?
if [ "$expected_exit" = "$actual_exit" ]; then
echo " PASS: $name"
((PASS++))
else
echo " FAIL: $name (expected exit $expected_exit, got $actual_exit)"
((FAIL++))
fi
}
run_test_contains() {
local name="$1"
local needle="$2"
local actual="$3"
((TOTAL++))
if echo "$actual" | grep -q "$needle"; then
echo " PASS: $name"
((PASS++))
else
echo " FAIL: $name"
echo " expected to contain: $needle"
echo " actual: $(echo "$actual" | head -3)"
local err=$(lind_run_stderr)
[ -n "$err" ] && echo " stderr: $(echo "$err" | head -3)"
((FAIL++))
fi
}
# ══════════════════════════════════════════════════════════════════════════════
setup
echo "=== Manual Coreutils Tests via Lind-boot ===" | tee "$LOG_FILE"
echo "Test dir: $TEST_DIR" | tee -a "$LOG_FILE"
echo "" | tee -a "$LOG_FILE"
# Redirect all remaining output to both terminal and log
exec > >(tee -a "$LOG_FILE") 2>&1
# ── FILE MANAGEMENT ──────────────────────────────────────────────────────────
cd $LINDFS_ROOT
echo "--- File Management ---"
# touch: create a file
lind_run bin/touch "$TEST_DIR/touchfile"
run_test "touch: create file" "yes" "$([ -f "$TEST_DIR/touchfile" ] && echo yes || echo no)"
# ls: list files
echo "hello" > "$TEST_DIR/lsfile1"
echo "world" > "$TEST_DIR/lsfile2"
actual=$(lind_run bin/ls "$TEST_DIR/lsfile1" "$TEST_DIR/lsfile2")
run_test_contains "ls: list files" "lsfile1" "$actual"
# mkdir: create directory
lind_run bin/mkdir "$TEST_DIR/newdir"
run_test "mkdir: create dir" "yes" "$([ -d "$TEST_DIR/newdir" ] && echo yes || echo no)"
# rmdir: remove directory
lind_run bin/mkdir "$TEST_DIR/removeme"
lind_run bin/rmdir "$TEST_DIR/removeme"
run_test "rmdir: remove dir" "no" "$([ -d "$TEST_DIR/removeme" ] && echo yes || echo no)"
# cp: copy file
echo "copytest" > "$TEST_DIR/original"
lind_run bin/cp "$TEST_DIR/original" "$TEST_DIR/copied"
run_test "cp: copy file" "copytest" "$(cat "$TEST_DIR/copied")"
# mv: move file
echo "movetest" > "$TEST_DIR/movesrc"
lind_run bin/mv "$TEST_DIR/movesrc" "$TEST_DIR/movedst"
run_test "mv: move file" "movetest" "$(cat "$TEST_DIR/movedst")"
run_test "mv: source removed" "no" "$([ -f "$TEST_DIR/movesrc" ] && echo yes || echo no)"
# rm: remove file
echo "deleteme" > "$TEST_DIR/rmfile"
lind_run bin/rm "$TEST_DIR/rmfile"
run_test "rm: remove file" "no" "$([ -f "$TEST_DIR/rmfile" ] && echo yes || echo no)"
# ln: create symlink
echo "linktest" > "$TEST_DIR/linkoriginal"
lind_run bin/ln -s "$TEST_DIR/linkoriginal" "$TEST_DIR/symlink"
run_test "ln: create symlink" "linktest" "$(cat "$TEST_DIR/symlink")"
echo ""
# ── TEXT PROCESSING ──────────────────────────────────────────────────────────
echo "--- Text Processing ---"
# cat: read file
echo "cattest" > "$TEST_DIR/catfile"
actual=$(lind_run bin/cat "$TEST_DIR/catfile")
run_test "cat: read file" "cattest" "$actual"
# head: first lines
printf "line1\nline2\nline3\nline4\nline5\n" > "$TEST_DIR/headfile"
actual=$(lind_run bin/head -n 2 "$TEST_DIR/headfile")
expected=$(printf "line1\nline2")
run_test "head: first 2 lines" "$expected" "$actual"
# tail: last lines
actual=$(lind_run bin/tail -n 2 "$TEST_DIR/headfile")
expected=$(printf "line4\nline5")
run_test "tail: last 2 lines" "$expected" "$actual"
# wc: word count
echo "one two three" > "$TEST_DIR/wcfile"
actual=$(lind_run bin/wc -w "$TEST_DIR/wcfile")
run_test_contains "wc: word count" "3" "$actual"
# sort: sort lines
printf "banana\napple\ncherry\n" > "$TEST_DIR/sortfile"
actual=$(lind_run bin/sort "$TEST_DIR/sortfile")
expected=$(printf "apple\nbanana\ncherry")
run_test "sort: alphabetical" "$expected" "$actual"
# uniq: deduplicate
printf "aaa\naaa\nbbb\nccc\nccc\n" > "$TEST_DIR/uniqfile"
actual=$(lind_run bin/uniq "$TEST_DIR/uniqfile")
expected=$(printf "aaa\nbbb\nccc")
run_test "uniq: deduplicate" "$expected" "$actual"
# cut: extract fields
printf "a:b:c\nd:e:f\n" > "$TEST_DIR/cutfile"
actual=$(lind_run bin/cut -d: -f2 "$TEST_DIR/cutfile")
expected=$(printf "b\ne")
run_test "cut: extract field 2" "$expected" "$actual"
# paste: merge lines
printf "A\nB\n" > "$TEST_DIR/paste1"
printf "1\n2\n" > "$TEST_DIR/paste2"
actual=$(lind_run bin/paste "$TEST_DIR/paste1" "$TEST_DIR/paste2")
expected=$(printf "A\t1\nB\t2")
run_test "paste: merge files" "$expected" "$actual"
echo ""
# ── PERMISSIONS & INFO ───────────────────────────────────────────────────────
echo "--- Permissions & Info ---"
# chmod: change permissions
echo "chmodtest" > "$TEST_DIR/chmodfile"
lind_run bin/chmod 755 "$TEST_DIR/chmodfile"
actual=$(stat -c %a "$TEST_DIR/chmodfile")
run_test "chmod: set 755" "755" "$actual"
# pwd: print working directory
actual=$(lind_run bin/pwd)
# pwd might return / (lindfs root) or something else, just check it runs
run_test_contains "pwd: outputs a path" "/" "$actual"
# du: disk usage
echo "dutest" > "$TEST_DIR/dufile"
actual=$(lind_run bin/du "$TEST_DIR/dufile")
run_test_contains "du: reports usage" "$TEST_DIR/dufile" "$actual"
# df: disk free
actual=$(lind_run bin/df)
run_test_contains "df: shows filesystem" "/" "$actual"
# dd: copy bytes
echo "ddtest" > "$TEST_DIR/ddinput"
lind_run bin/dd if="$TEST_DIR/ddinput" of="$TEST_DIR/ddoutput"
run_test "dd: copy file" "ddtest" "$(cat "$TEST_DIR/ddoutput")"
echo ""
# ── TEXT MANIPULATION ────────────────────────────────────────────────────────
echo "--- Text Manipulation ---"
# echo: print text
actual=$(lind_run bin/echo "hello world")
run_test "echo: print text" "hello world" "$actual"
# printf: formatted output
actual=$(lind_run bin/printf "%s-%s\n" "foo" "bar")
run_test "printf: format string" "foo-bar" "$actual"
# tr: translate characters
actual=$(echo "hello" | lind_run bin/tr 'a-z' 'A-Z')
run_test "tr: lowercase to upper" "HELLO" "$actual"
# expand: tabs to spaces
printf "a\tb\n" > "$TEST_DIR/expandfile"
actual=$(lind_run bin/expand "$TEST_DIR/expandfile")
run_test_contains "expand: tab to spaces" "a" "$actual"
# unexpand: spaces to tabs
printf "a b\n" > "$TEST_DIR/unexpandfile"
actual=$(lind_run bin/unexpand -a "$TEST_DIR/unexpandfile")
run_test_contains "unexpand: spaces to tab" "a" "$actual"
echo ""
# ── SUMMARY ──────────────────────────────────────────────────────────────────
echo "================================"
echo "=== Results ==="
echo "PASS: $PASS | FAIL: $FAIL | TOTAL: $TOTAL"
echo "Log saved to: $LOG_FILE"
echo "================================"