#!/usr/bin/expect -f

proc print {msg} {
    puts "GRADE: $msg"
    flush stdout
}

set timeout 10
log_user 0

spawn bash -c "make qemu"
set qemu_pid [exp_pid -i $spawn_id]

set scores {
    {"Yield aff" 0}
}

proc grade {} {
    global scores
    set score 0
    foreach x $scores {
        set name [lindex $x 0]
        set n [lindex $x 1]
        print "$name: $n"
        incr score $n
    }
    global qemu_pid
    exec kill -9 $qemu_pid
    exit $score
}

trap {
    grade
} SIGINT

expect {
    "Main thread on cpu 0" {
        expect "Main thread exits on cpu_id: 3" {
            lset scores {0 1} 5
            grade
        }
    }
    timeout {
        grade
    }
}

grade
