From 1d8c85670d03ce745e32bbc57147835b210fe560 Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Thu, 12 Mar 2015 16:05:28 +0800 Subject: [PATCH] Save intermediate logs Signed-off-by: Junjie Mao --- .gitignore | 2 +- labcodes/autotest.sh | 28 ++++++++++++++++++-- labcodes/formatter.py | 44 +++++++++++++++++++++++++++++++ labcodes/lab1/tools/grade.sh | 2 ++ labcodes/lab2/tools/grade.sh | 2 ++ labcodes/lab3/tools/grade.sh | 2 ++ labcodes/lab4/tools/grade.sh | 2 ++ labcodes/lab5/tools/grade.sh | 2 ++ labcodes/lab6/tools/grade.sh | 2 ++ labcodes/lab7/tools/grade.sh | 2 ++ labcodes/lab8/tools/grade.sh | 2 ++ labcodes/tools/split_score_log.py | 29 ++++++++++++++++++++ 12 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 labcodes/formatter.py create mode 100644 labcodes/tools/split_score_log.py diff --git a/.gitignore b/.gitignore index 2332926..062b38f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,5 +15,5 @@ tags *.project *.workspace a.out -make.log +*.log *.exe diff --git a/labcodes/autotest.sh b/labcodes/autotest.sh index 1ce5b53..cb74eab 100755 --- a/labcodes/autotest.sh +++ b/labcodes/autotest.sh @@ -1,10 +1,23 @@ #!/bin/bash +# change working dir to where this script resides in +pushd `dirname "$0"` > /dev/null + +if [ -n "$1" ]; then + RESULT_SAVETO=`realpath $1` +fi BASE_COMMIT=95a80f598fc57c60aed3737c60ee437d94eb8540 +if [ -n "$2" ] && git log $2 > /dev/null 2>&1; then + BASE_COMMIT=$2 +elif ! git log $BASE_COMMIT > /dev/null 2>&1; then + echo "No valid base commit found." + exit 0 +fi LABS=`git diff $BASE_COMMIT --stat | grep -o "lab[0-9]" | uniq` +COMMIT=`git rev-parse HEAD` if [ "$LABS" = "" ]; then - echo "No solutions provided. Skip this time." + echo "No updated lab found. Skip." exit 0 fi @@ -19,6 +32,14 @@ for lab in $LABS; do if ! make grade > .score 2>&1; then failed=`echo $lab | grep -o [0-9]` fi + if [ -n "$RESULT_SAVETO" ]; then + mkdir -p $RESULT_SAVETO/$COMMIT/$lab + mv .score .score_orig + ../tools/split_score_log.py .score_orig > .score + for i in .*.log .*.error; do + cp $i $RESULT_SAVETO/$COMMIT/$lab/${i#.} + done + fi score=`egrep -o "Score: [0-9]+/[0-9]+" .score` echo "$lab $score" >> $summary make clean > /dev/null @@ -35,7 +56,10 @@ echo for lab in $LABS; do echo "================================ $lab ===============================" cat $lab/.score - rm $lab/.score done +find . -name '.*' -delete + +popd > /dev/null + exit $failed diff --git a/labcodes/formatter.py b/labcodes/formatter.py new file mode 100644 index 0000000..f4071ad --- /dev/null +++ b/labcodes/formatter.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +import os, sys +import re + +if len(sys.argv) < 5: + print 'Usage: formatter.py
' + sys.exit() + +tid_regex = re.compile('([a-z0-9]+)-.*') +lab_title = re.compile('=* (lab[0-9]) =*') +test_entry_title = re.compile('^([\w][\w -]+)(:.*)') + +section = sys.argv[1] +result_dir = sys.argv[2] +repo = sys.argv[3] +tid = sys.argv[4] +m = tid_regex.match(tid) +if not m: + print 'Invalid tid' + sys.exit() +commit = m.group(1) + +lab = '' +while True: + l = sys.stdin.readline() + if not l: + break + line = l.rstrip('\n') + output = line + m = test_entry_title.match(line) + if m and lab: + test_entry = m.group(1).lower().replace(' ', '_') + test_log = os.path.join(result_dir, repo, commit, lab, test_entry + ".error") + if os.path.exists(test_log): + rest = m.group(2) + output = '' + m.group(1) + '' + rest + m = lab_title.match(line) + if m: + lab = m.group(1) + + sys.stdout.write(output + '
') + +sys.stdout.flush() diff --git a/labcodes/lab1/tools/grade.sh b/labcodes/lab1/tools/grade.sh index 8ea2a23..ccf4078 100644 --- a/labcodes/lab1/tools/grade.sh +++ b/labcodes/lab1/tools/grade.sh @@ -183,6 +183,8 @@ build_run() { run_qemu show_time + + cp $qemu_out .`echo $tag | tr '[:upper:]' '[:lower:]' | sed 's/ /_/g'`.log } check_result() { diff --git a/labcodes/lab2/tools/grade.sh b/labcodes/lab2/tools/grade.sh index 5ab3e0e..b239dc6 100644 --- a/labcodes/lab2/tools/grade.sh +++ b/labcodes/lab2/tools/grade.sh @@ -183,6 +183,8 @@ build_run() { run_qemu show_time + + cp $qemu_out .`echo $tag | tr '[:upper:]' '[:lower:]' | sed 's/ /_/g'`.log } check_result() { diff --git a/labcodes/lab3/tools/grade.sh b/labcodes/lab3/tools/grade.sh index 02fc22d..7e4f150 100644 --- a/labcodes/lab3/tools/grade.sh +++ b/labcodes/lab3/tools/grade.sh @@ -183,6 +183,8 @@ build_run() { run_qemu show_time + + cp $qemu_out .`echo $tag | tr '[:upper:]' '[:lower:]' | sed 's/ /_/g'`.log } check_result() { diff --git a/labcodes/lab4/tools/grade.sh b/labcodes/lab4/tools/grade.sh index 502ca6b..3aab81a 100644 --- a/labcodes/lab4/tools/grade.sh +++ b/labcodes/lab4/tools/grade.sh @@ -183,6 +183,8 @@ build_run() { run_qemu show_time + + cp $qemu_out .`echo $tag | tr '[:upper:]' '[:lower:]' | sed 's/ /_/g'`.log } check_result() { diff --git a/labcodes/lab5/tools/grade.sh b/labcodes/lab5/tools/grade.sh index 382603e..4b46529 100644 --- a/labcodes/lab5/tools/grade.sh +++ b/labcodes/lab5/tools/grade.sh @@ -183,6 +183,8 @@ build_run() { run_qemu show_time + + cp $qemu_out .`echo $tag | tr '[:upper:]' '[:lower:]' | sed 's/ /_/g'`.log } check_result() { diff --git a/labcodes/lab6/tools/grade.sh b/labcodes/lab6/tools/grade.sh index a30feee..f8bbdaa 100644 --- a/labcodes/lab6/tools/grade.sh +++ b/labcodes/lab6/tools/grade.sh @@ -183,6 +183,8 @@ build_run() { run_qemu show_time + + cp $qemu_out .`echo $tag | tr '[:upper:]' '[:lower:]' | sed 's/ /_/g'`.log } check_result() { diff --git a/labcodes/lab7/tools/grade.sh b/labcodes/lab7/tools/grade.sh index 9fae5ad..58dc875 100644 --- a/labcodes/lab7/tools/grade.sh +++ b/labcodes/lab7/tools/grade.sh @@ -183,6 +183,8 @@ build_run() { run_qemu show_time + + cp $qemu_out .`echo $tag | tr '[:upper:]' '[:lower:]' | sed 's/ /_/g'`.log } check_result() { diff --git a/labcodes/lab8/tools/grade.sh b/labcodes/lab8/tools/grade.sh index 345effd..62987e3 100644 --- a/labcodes/lab8/tools/grade.sh +++ b/labcodes/lab8/tools/grade.sh @@ -183,6 +183,8 @@ build_run() { run_qemu show_time + + cp $qemu_out .`echo $tag | tr '[:upper:]' '[:lower:]' | sed 's/ /_/g'`.log } check_result() { diff --git a/labcodes/tools/split_score_log.py b/labcodes/tools/split_score_log.py new file mode 100644 index 0000000..fc90eff --- /dev/null +++ b/labcodes/tools/split_score_log.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# +# Note: This script is intended to be executed at labcodes/labX + +import sys, os +import re + +if len(sys.argv) < 2: + print 'Usage: split_score_log.py ' + sys.exit() + +raw_log_f = sys.argv[1] +test_entry_title = re.compile('^([\w][\w -]+): *\([0-9.]*s\)') + +raw_log = open(raw_log_f, 'r') +current_test = '' +for line in raw_log.readlines(): + line = line.strip('\n') + m = test_entry_title.match(line) + if m: + print line + current_test = m.group(1) + error_log = open('.' + current_test.lower().replace(' ', '_') + '.error', 'w+') + print >> error_log, line + continue + if (not line or line[0] == ' ') and current_test != '': + print >> error_log, line + if (line and line[0] != ' ') or line.find('-check') >= 0: + print line