66#
77# Per-example logs: results-<name>.txt
88# Final summary: results-summary.txt
9+ #
10+ # Requires GNU coreutils (date +%s%N). On macOS: brew install coreutils
11+ # and use gdate, or install GNU date.
12+
13+ set -euo pipefail
914
1015SCRIPT_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
1116cd " $SCRIPT_DIR "
1217
1318SUMMARY=" results-summary.txt"
14- echo " === Hyperlight-Unikraft Examples Run — $( date) ===" | tee " $SUMMARY "
19+ FAILURES=0
20+
21+ # Portable millisecond timer: prefer date +%s%N (GNU), fall back to
22+ # python3 if %N is unsupported (macOS).
23+ now_ns () {
24+ local ns
25+ ns=$( date +%s%N 2> /dev/null)
26+ if [ " ${# ns} " -gt 10 ]; then
27+ echo " $ns "
28+ else
29+ python3 -c ' import time; print(int(time.time()*1e9))'
30+ fi
31+ }
32+
33+ echo " === Hyperlight-Unikraft Examples Run -- $( date) ===" | tee " $SUMMARY "
1534echo " " | tee -a " $SUMMARY "
1635
1736run_example () {
1837 local name=" $1 "
1938 local repeat_cmd=" $2 " # e.g. "run-5", "run-10", or "" if none
2039 local outfile=" results-${name} .txt"
2140
22- echo " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ " | tee -a " $SUMMARY "
23- echo " ▶ $name " | tee -a " $SUMMARY "
24- echo " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ " | tee -a " $SUMMARY "
41+ echo " --- " | tee -a " $SUMMARY "
42+ echo " > $name " | tee -a " $SUMMARY "
43+ echo " --- " | tee -a " $SUMMARY "
2544
26- cd " $SCRIPT_DIR /$name "
45+ if ! cd " $SCRIPT_DIR /$name " 2> /dev/null; then
46+ echo " SKIP: directory $name not found" | tee -a " $SCRIPT_DIR /$SUMMARY "
47+ return 1
48+ fi
2749
2850 # Build
2951 printf " [build] running... "
30- local t0=$( date +%s%N)
52+ local t0
53+ t0=$( now_ns)
3154 just build < /dev/null > " $outfile " 2>&1
3255 local rc=$?
33- local t1=$( date +%s%N)
56+ local t1
57+ t1=$( now_ns)
3458 local build_ms=$(( (t1 - t0 ) / 1000000 ))
3559 if [ $rc -eq 0 ]; then
36- echo " ✓ ${build_ms} ms" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
60+ echo " ok ${build_ms} ms" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
3761 else
38- echo " ✗ FAILED (exit=$rc , ${build_ms} ms)" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
62+ echo " FAILED (exit=$rc , ${build_ms} ms)" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
63+ FAILURES=$(( FAILURES + 1 ))
3964 cd " $SCRIPT_DIR "
4065 return 1
4166 fi
4267
4368 # Rootfs
4469 printf " [rootfs] running... "
45- t0=$( date +%s%N )
70+ t0=$( now_ns )
4671 just rootfs < /dev/null >> " $outfile " 2>&1
4772 rc=$?
48- t1=$( date +%s%N )
73+ t1=$( now_ns )
4974 local rootfs_ms=$(( (t1 - t0 ) / 1000000 ))
5075 if [ $rc -eq 0 ]; then
51- echo " ✓ ${rootfs_ms} ms" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
76+ echo " ok ${rootfs_ms} ms" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
5277 else
53- echo " ✗ FAILED (exit=$rc , ${rootfs_ms} ms)" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
78+ echo " FAILED (exit=$rc , ${rootfs_ms} ms)" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
79+ FAILURES=$(( FAILURES + 1 ))
5480 cd " $SCRIPT_DIR "
5581 return 1
5682 fi
5783
5884 # Run once (cold start)
5985 printf " [run] running... "
60- t0=$( date +%s%N )
86+ t0=$( now_ns )
6187 just run < /dev/null >> " $outfile " 2>&1
6288 rc=$?
63- t1=$( date +%s%N )
89+ t1=$( now_ns )
6490 local run_ms=$(( (t1 - t0 ) / 1000000 ))
6591 if [ $rc -eq 0 ]; then
66- echo " ✓ ${run_ms} ms" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
92+ echo " ok ${run_ms} ms" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
6793 else
68- echo " ✗ FAILED (exit=$rc , ${run_ms} ms)" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
94+ echo " FAILED (exit=$rc , ${run_ms} ms)" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
95+ FAILURES=$(( FAILURES + 1 ))
6996 fi
7097
71- # Run repeated (snapshot/restore) — if a repeat command exists
98+ # Run repeated (snapshot/restore) -- if a repeat command exists
7299 if [ -n " $repeat_cmd " ]; then
73100 printf " [$repeat_cmd ] running... "
74- t0=$( date +%s%N )
101+ t0=$( now_ns )
75102 just " $repeat_cmd " < /dev/null >> " $outfile " 2>&1
76103 rc=$?
77- t1=$( date +%s%N )
104+ t1=$( now_ns )
78105 local repeat_ms=$(( (t1 - t0 ) / 1000000 ))
79106 if [ $rc -eq 0 ]; then
80- echo " ✓ ${repeat_ms} ms" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
107+ echo " ok ${repeat_ms} ms" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
81108 else
82- echo " ✗ FAILED (exit=$rc , ${repeat_ms} ms)" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
109+ echo " FAILED (exit=$rc , ${repeat_ms} ms)" | tee -a " $outfile " | tee -a " $SCRIPT_DIR /$SUMMARY "
110+ FAILURES=$(( FAILURES + 1 ))
83111 fi
84112 echo " TOTAL: build=${build_ms} ms rootfs=${rootfs_ms} ms run=${run_ms} ms ${repeat_cmd} =${repeat_ms} ms" | tee -a " $SCRIPT_DIR /$SUMMARY "
85113 else
@@ -92,9 +120,9 @@ run_example() {
92120
93121# Examples with their repeat commands (from each Justfile)
94122run_example " helloworld-c" " run-5"
95- run_example " rust" " run-5 "
123+ run_example " rust" " run-10 "
96124run_example " go" " run-10"
97- run_example " shell" " run-5 "
125+ run_example " shell" " run-10 "
98126run_example " python" " run-10"
99127run_example " python-tools" " run-10"
100128run_example " nodejs" " run-10"
@@ -107,7 +135,13 @@ run_example "multifn-c" ""
107135run_example " python-agent" " "
108136run_example " networking-py" " run-get"
109137
110- echo " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" | tee -a " $SUMMARY "
111- echo " ✅ ALL DONE — $( date) " | tee -a " $SUMMARY "
138+ echo " ---" | tee -a " $SUMMARY "
139+ if [ " $FAILURES " -gt 0 ]; then
140+ echo " DONE with $FAILURES failure(s) -- $( date) " | tee -a " $SUMMARY "
141+ else
142+ echo " ALL DONE -- $( date) " | tee -a " $SUMMARY "
143+ fi
112144echo " Per-example logs: results-<name>.txt"
113145echo " Summary: $SUMMARY "
146+
147+ exit " $FAILURES "
0 commit comments