kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

tools-kitchen.sh (4507B)


      1 #!/bin/sh
      2 # Coarse Tier 1 kitchen-sink smoke for driver utility tools.
      3 
      4 set -u
      5 
      6 script_dir=$(cd "$(dirname "$0")" && pwd)
      7 repo_root=$(cd "$script_dir/../../.." && pwd)
      8 KIT="${KIT:-$repo_root/build/kit}"
      9 
     10 if [ ! -x "$KIT" ]; then
     11     echo "tools-kitchen: kit binary not found at $KIT" >&2
     12     exit 2
     13 fi
     14 
     15 work=$(mktemp -d "${TMPDIR:-/tmp}/kit-t1-tools.XXXXXX")
     16 trap 'rm -rf "$work"' EXIT
     17 
     18 KIT_KIT_DIR="$repo_root/test/lib"
     19 . "$repo_root/test/lib/kit_sh_kit.sh"
     20 kit_report_init
     21 
     22 printf 'tier1 tools\000bytes\377\n' > "$work/data.bin"
     23 run_ok xxd-dump "$KIT" xxd "$work/data.bin"
     24 run_ok xxd-plain "$KIT" xxd -p "$work/data.bin"
     25 "$KIT" xxd -r "$work/xxd-dump.out" > "$work/data.rt" 2> "$work/xxd-rt.err"
     26 same_file xxd-roundtrip "$work/data.bin" "$work/data.rt"
     27 run_ok cmp-identical "$KIT" cmp "$work/data.bin" "$work/data.rt"
     28 run_fail cmp-different "$KIT" cmp "$work/data.bin" "$work/xxd-plain.out"
     29 
     30 run_ok hash-sha "$KIT" hash -a sha256 "$work/data.bin"
     31 contains hash-sha-output "$work/hash-sha.out" "  "
     32 run_ok hash-alias "$KIT" crc32 "$work/data.bin"
     33 
     34 printf 'compressible tier1 payload\n%.0s' 1 2 3 4 5 > "$work/text.txt"
     35 "$KIT" compress -z gzip "$work/text.txt" | "$KIT" compress -d > "$work/text.gzip.rt" 2> "$work/compress-gzip.err"
     36 same_file compress-gzip-roundtrip "$work/text.txt" "$work/text.gzip.rt"
     37 "$KIT" compress -z lz4 "$work/text.txt" | "$KIT" compress -d > "$work/text.lz4.rt" 2> "$work/compress-lz4.err"
     38 same_file compress-lz4-roundtrip "$work/text.txt" "$work/text.lz4.rt"
     39 
     40 run_ok disas-aa64 "$KIT" disas -target aarch64 -x "1f 20 03 d5"
     41 contains disas-aa64-nop "$work/disas-aa64.out" "nop"
     42 run_ok mc-aa64 "$KIT" mc -target aarch64 -p "add x0, x1, x2"
     43 run_ok mc-disas "$KIT" disas -target aarch64 -x "$(cat "$work/mc-aa64.out")"
     44 contains mc-disas-add "$work/mc-disas.out" "add x0, x1, x2"
     45 
     46 cat > "$work/a.c" <<'SRC'
     47 int tier1_a(int x) { return x + 1; }
     48 SRC
     49 cat > "$work/b.c" <<'SRC'
     50 extern int tier1_a(int);
     51 int tier1_b(int x) { return tier1_a(x) + 2; }
     52 SRC
     53 run_ok cc-a "$KIT" cc -target riscv64-linux -g -c "$work/a.c" -o "$work/a.o"
     54 run_ok cc-b "$KIT" cc -target riscv64-linux -g -c "$work/b.c" -o "$work/b.o"
     55 run_ok ar-create "$KIT" ar rcs "$work/libtier1.a" "$work/a.o" "$work/b.o"
     56 run_ok ranlib "$KIT" ranlib "$work/libtier1.a"
     57 run_ok ar-list "$KIT" ar t "$work/libtier1.a"
     58 contains ar-has-a "$work/ar-list.out" "a.o"
     59 contains ar-has-b "$work/ar-list.out" "b.o"
     60 
     61 run_ok objdump-archive "$KIT" objdump -f "$work/libtier1.a"
     62 contains objdump-rv64 "$work/objdump-archive.out" "elf64-riscv64"
     63 run_ok objcopy-rename "$KIT" objcopy --rename-section=.text=.tier1_text \
     64     "$work/a.o" "$work/a.renamed.o"
     65 run_ok objdump-renamed "$KIT" objdump -h "$work/a.renamed.o"
     66 contains objcopy-renamed-section "$work/objdump-renamed.out" ".tier1_text"
     67 run_ok strip-debug "$KIT" strip --strip-debug "$work/a.o" -o "$work/a.stripped.o"
     68 run_ok objdump-stripped "$KIT" objdump -h "$work/a.stripped.o"
     69 if grep '\.debug_' "$work/objdump-stripped.out" >/dev/null 2>&1; then
     70     not_ok strip-drops-debug "$work/objdump-stripped.out"
     71 else
     72     ok strip-drops-debug
     73 fi
     74 
     75 printf 'abc\000tier1-string\000' > "$work/strings.bin"
     76 run_ok strings-basic "$KIT" strings "$work/strings.bin"
     77 contains strings-finds "$work/strings-basic.out" "tier1-string"
     78 
     79 mkdir -p "$work/payload/root/sub" "$work/ex"
     80 printf 'hello cpio\n' > "$work/payload/root/sub/file.txt"
     81 ( cd "$work/payload" && "$KIT" cpio -o -F "$work/root.cpio" root ) \
     82     > "$work/cpio-create.out" 2> "$work/cpio-create.err"
     83 [ "$?" -eq 0 ] && ok cpio-create || not_ok cpio-create "$work/cpio-create.err"
     84 run_ok cpio-list "$KIT" cpio -t -F "$work/root.cpio"
     85 contains cpio-has-file "$work/cpio-list.out" "root/sub/file.txt"
     86 ( cd "$work/ex" && "$KIT" cpio -i -F "$work/root.cpio" ) \
     87     > "$work/cpio-extract.out" 2> "$work/cpio-extract.err"
     88 [ "$?" -eq 0 ] && ok cpio-extract || not_ok cpio-extract "$work/cpio-extract.err"
     89 same_file cpio-roundtrip "$work/payload/root/sub/file.txt" "$work/ex/root/sub/file.txt"
     90 
     91 cat > "$work/kernel.s" <<'SRC'
     92 .globl _start
     93 .section .text
     94 _start:
     95   ret
     96 .section .rodata
     97   .byte 0x11, 0x22, 0x33, 0x44
     98 SRC
     99 run_ok image-build "$KIT" build-exe -target x86_64-none-elf -nostdlib \
    100     -static -no-pie -e _start "$work/kernel.s" -o "$work/kernel.elf"
    101 run_ok image-bin "$KIT" image --format bin "$work/kernel.elf" -o "$work/kernel.bin"
    102 run_ok objcopy-bin "$KIT" objcopy -O binary "$work/kernel.elf" "$work/kernel.objcopy.bin"
    103 same_file image-matches-objcopy "$work/kernel.bin" "$work/kernel.objcopy.bin"
    104 
    105 kit_summary tools-kitchen
    106 kit_exit