Tutorial: Moodle VPL -- Test Function of Student Program Multiple Times
--D. Thiebaut (talk) 22:44, 21 October 2014 (EDT)
This VPL activity tests an assembly program that contains a function (_printHex) that is declared global. The module invalidates the _global label of the student program, links it with a test program (test.asm) which calls _printHex several times with different parameter values. The vpl_validate.sh script checks the correct output of the function.
Vpl_run.sh
#! /bin/bash
cat > vpl_execution <<EOF
#! /bin/bash
prog=Hw4_4
# replace the _start label in the student program
# so that the test program will start.
sed -i 's/_start/start/g' \$prog.asm
nasm -f elf test.asm
nasm -f elf \$prog.asm
ld -melf_i386 -o \$prog \$prog.o test.o
./\$prog | cat -v
EOF
chmod +x vpl_execution
vpl_evaluate.sh
#! /bin/bash
cat > vpl_execution <<EOF
#! /bin/bash
prog=Hw4_4
# replace the _start label in the student program
# so that the test program will start.
sed -i 's/_start/start/g' \$prog.asm
nasm -f elf test.asm
nasm -f elf \$prog.asm
ld -melf_i386 -o \$prog \$prog.o test.o
./\$prog | cat -v | grep -i ERROR &> grepLines.out
if [ -s grepLines.out ] ; then
echo "Comment :=>> _printHex modifies some of the registers"
echo "Grade :=>> 40"
exit
fi
for pattern in 12345678 ABCDEF00 ; do
./\$prog | cat -v | grep -i \$pattern &> grepLines.out
if [ ! -s grepLines.out ] ; then
echo "Comment :=>> _printHex does not correctly prints \$pattern"
echo "Grade :=>> 40"
exit
fi
done
echo "Comment :=>> Congrats, your _printHex passes the tests."
echo "Grade :=>> 100"
EOF
chmod +x vpl_execution
test.asm
;;; test.asm
;;; D. Thiebaut
extern _printHex
;;; ------------------------------------------------------------
;;; data areas
;;; ------------------------------------------------------------
section .data
linefeed db 10
msg db 10,"ERROR:",10
db "Your _printHex function modifies some of the registers"
db 10,10,10
MSGLEN equ $-msg
section .text
global _start
setRegs: mov ebx, 0x1234567A
mov edx, 0xaaaa5555
mov ecx, 0xffff0000
mov esi, 0xaaaabbbb
mov edi, 0xeeeeffff
ret
testRegs: cmp ebx, 0x1234567A
jne bad
cmp edx, 0xaaaa5555
jne bad
cmp ecx, 0xffff0000
jne bad
cmp esi, 0xaaaabbbb
jne bad
cmp edi, 0xeeeeffff
jne bad
ret
bad: mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, MSGLEN
int 0x80
jmp exit
printLn: pushad
mov ecx, linefeed
mov edx, 1
mov eax, 4
mov ebx, 1
int 0x80
popad
ret
_start:
mov eax, 0
call setRegs
call _printHex
call testRegs
call printLn
mov eax, 0x12345678
call _printHex
call printLn
mov eax, 0xABCDEF00
call _printHex
call printLn
;;; exit()
exit:
mov eax,1
mov ebx,0
int 0x80 ; final system call
Solution Program: Hw4_4.asm