Skip to content

Commit ee57852

Browse files
authored
Merge pull request #96 from qimcis/cs537-spring-2018-fs-checker
[lab] CS537 Spring 2018 Project 5
2 parents 4f95253 + 155ace1 commit ee57852

File tree

6 files changed

+868
-0
lines changed

6 files changed

+868
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
default:
3+
image: gcc:12
4+
command: sleep infinity
5+
working_dir: /workspace
6+
x-init:
7+
- preprocess.sh
8+
x-local:
9+
CFLAGS: "-Wall -Werror -O2"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"instance_id": "cs537-projects-spring-2018__filesystems_checker",
3+
"course_id": "cs537-projects-spring-2018",
4+
"timeout_minutes": 25,
5+
"tags": ["operating-systems", "filesystems", "fsck", "c"],
6+
"artifacts": [
7+
"ostep-projects/filesystems-checker/xcheck.c"
8+
]
9+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
echo "=== Evaluation ==="
5+
6+
cd /workspace/ostep-projects/filesystems-checker
7+
8+
echo "Verifying protected files were not modified"
9+
if [ -f /tmp/checksums/protected.sha256 ]; then
10+
sha256sum -c /tmp/checksums/protected.sha256 || {
11+
echo "FAIL: Protected files were modified"
12+
exit 1
13+
}
14+
fi
15+
echo "All protected files unchanged"
16+
17+
if [ ! -f xcheck.c ]; then
18+
echo "FAIL: xcheck.c not found"
19+
exit 1
20+
fi
21+
22+
echo "Building xcheck"
23+
gcc -Wall -Werror -O2 -o xcheck xcheck.c
24+
25+
run_case() {
26+
local name=$1
27+
local cmd=$2
28+
local expected_rc=$3
29+
local expected_out=$4
30+
local expected_err=$5
31+
local stdout
32+
local stderr
33+
local rc
34+
35+
set +e
36+
stdout=$(eval "$cmd" 2>"/tmp/${name}.err")
37+
rc=$?
38+
set -e
39+
40+
stderr=$(cat "/tmp/${name}.err")
41+
stdout=$(printf "%s" "$stdout" | sed 's/[[:space:]]*$//')
42+
stderr=$(printf "%s" "$stderr" | sed 's/[[:space:]]*$//')
43+
44+
if [ "$rc" -ne "$expected_rc" ]; then
45+
echo "FAIL: $name expected rc $expected_rc, got $rc"
46+
exit 1
47+
fi
48+
49+
if [ "$stdout" != "$expected_out" ]; then
50+
echo "FAIL: $name unexpected stdout"
51+
echo "--- expected ---"
52+
printf "%s\n" "$expected_out"
53+
echo "--- actual ---"
54+
printf "%s\n" "$stdout"
55+
exit 1
56+
fi
57+
58+
if [ "$stderr" != "$expected_err" ]; then
59+
echo "FAIL: $name unexpected stderr"
60+
echo "--- expected ---"
61+
printf "%s\n" "$expected_err"
62+
echo "--- actual ---"
63+
printf "%s\n" "$stderr"
64+
exit 1
65+
fi
66+
67+
echo "PASS: $name"
68+
}
69+
70+
run_case "usage" "./xcheck" 1 "" "Usage: xcheck <file_system_image>"
71+
run_case "missing" "./xcheck tests/images/missing.img" 1 "" "image not found."
72+
run_case "valid" "./xcheck tests/images/valid.img" 0 "" ""
73+
run_case "bad_inode" "./xcheck tests/images/bad_inode.img" 1 "" "ERROR: bad inode."
74+
run_case "bad_direct" "./xcheck tests/images/bad_direct.img" 1 "" "ERROR: bad direct address in inode."
75+
run_case "bad_indirect" "./xcheck tests/images/bad_indirect.img" 1 "" "ERROR: bad indirect address in inode."
76+
run_case "bad_root" "./xcheck tests/images/bad_root.img" 1 "" "ERROR: root directory does not exist."
77+
run_case "bad_dirformat" "./xcheck tests/images/bad_dirformat.img" 1 "" "ERROR: directory not properly formatted."
78+
run_case "bad_bitmap" "./xcheck tests/images/bad_bitmap.img" 1 "" "ERROR: address used by inode but marked free in bitmap."
79+
run_case "bad_bitmap_marked" "./xcheck tests/images/bad_bitmap_marked.img" 1 "" "ERROR: bitmap marks block in use but it is not in use."
80+
run_case "bad_direct_twice" "./xcheck tests/images/bad_direct_twice.img" 1 "" "ERROR: direct address used more than once."
81+
run_case "bad_indirect_twice" "./xcheck tests/images/bad_indirect_twice.img" 1 "" "ERROR: indirect address used more than once."
82+
run_case "bad_inode_referred" "./xcheck tests/images/bad_inode_referred.img" 1 "" "ERROR: inode referred to in directory but marked free."
83+
run_case "bad_inode_unreferenced" "./xcheck tests/images/bad_inode_unreferenced.img" 1 "" "ERROR: inode marked use but not found in a directory."
84+
run_case "bad_refcount" "./xcheck tests/images/bad_refcount.img" 1 "" "ERROR: bad reference count for file."
85+
run_case "bad_dir_dup" "./xcheck tests/images/bad_dir_dup.img" 1 "" "ERROR: directory appears more than once in file system."
86+
87+
echo "PASS: All tests passed"
88+
exit 0

0 commit comments

Comments
 (0)