Difference between revisions of "Tutorial Moodle VPL Tips & Tricks"

From dftwiki3
Jump to: navigation, search
(Generating a vpl_evaluate.cases File)
(Generating a vpl_evaluate.cases File Quickly)
Line 53: Line 53:
 
# You should be ready to evaluate the solution program and get 100/100 as a grade.
 
# You should be ready to evaluate the solution program and get 100/100 as a grade.
 
<br />
 
<br />
 +
==Creating a ''vpl_execution'' script that measures the size of a program==
 +
<br />
 +
Imagine that the assignment for the student is to create a program that solves a particular problem (which can be tested separately for the correctness of its output), but the requirement is to make the program executable as small as possible.
 +
The grade given to the submitted program will be 100 if the size is equal to the size of the solution program, and some lower grade depending on how large the file is.
 +
<br />
 +
Here's a '''bash''' script that will do the trick
 +
<br />
 +
:<source lang="bash">
 +
#! /bin/bash
 +
#set -x
 +
 +
file="printStars"  # whatever executable is to be tested
 +
 +
# assemble and link the executable
 +
nasm -f elf -F stabs ${file}.asm
 +
ld -melf_i386 -o $file ${file}.o
 +
 +
# run the executable in a subshell to catch any segmentation fault error
 +
# that may result.
 +
{ ./$file &> /dev/null ; } &> log
 +
 +
# if an error occured, automatically return 0
 +
if [ $? -eq 139 ]; then
 +
    echo "0";
 +
    exit 0;
 +
fi
 +
 +
# print out the size of the file
 +
size=$(stat -c%s "$file")
 +
echo $size
 +
</source>
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
[[Category:Moodle]][[Category:VPL]][[Category:Tutorials]]
 +
 
==Creating a ''vpl_execution'' script that measures the size of a program==
 
==Creating a ''vpl_execution'' script that measures the size of a program==
 
<br />
 
<br />

Revision as of 14:23, 12 June 2014

--D. Thiebaut (talk) 20:31, 11 June 2014 (EDT)




MoodleVPLLogo.png


This is a collection of tips, tricks, observations, recommendations, and modifications related to using VPL with Moodle.


Tips & Tricks

Output of Evaluate Step

  • The output of the Evaluate action is a bit illogical:
 +------------------------------+
 |  3 tests run/ 0 tests failed   | 
 +------------------------------+
  • To change it into something more intuitive, such as this:
 +------------------------------+
 |  3 tests run/ 3 tests passed  |  
 +------------------------------+
we simply need to modify the code of vpl_evaluate.cpp on the moodle server, in /var/www/html/moodle/mod/vpl/jail/default_scripts (or whatever directory the vpl files reside).
  • The diff of the modification is shown below:
1058,1059c1058,1060
< 				printf(">| %2d %s run/%2d %s failed |\n",
< 						nruns, nruns==1?stest[0]:stest[1], nerrors, nerrors==1?stest[0]:stest[1]);
---
> 				printf(">| %2d %s run/%2d %s passed |\n",
> 						nruns, nruns==1?stest[0]:stest[1], nruns-nerrors, 
> 				                (nruns-nerrors)==1?stest[0]:stest[1]);


Generating a vpl_evaluate.cases File Quickly


Recommendations
  1. write a solution program first.
  2. run it on several cases you want to test your students' programs with.
  3. capture the outputs of the solution program on different cases. Copy paste into the vpl_evaluate.cases file. Don't worry yet about making it exactly correct.
  4. evaluate the solution program. You will get mismatches between the generated output and the expected output. Just copy/paste the generated output back into the vpl_evaluate.cases file. You will also be able to include the extra characters generated by the input statements.
  5. You should be ready to evaluate the solution program and get 100/100 as a grade.


Creating a vpl_execution script that measures the size of a program


Imagine that the assignment for the student is to create a program that solves a particular problem (which can be tested separately for the correctness of its output), but the requirement is to make the program executable as small as possible. The grade given to the submitted program will be 100 if the size is equal to the size of the solution program, and some lower grade depending on how large the file is.
Here's a bash script that will do the trick

#! /bin/bash
#set -x

file="printStars"  # whatever executable is to be tested

# assemble and link the executable
nasm -f elf -F stabs ${file}.asm
ld -melf_i386 -o $file ${file}.o

# run the executable in a subshell to catch any segmentation fault error
# that may result.
{ ./$file &> /dev/null ; } &> log

# if an error occured, automatically return 0
if [ $? -eq 139 ]; then
    echo "0";
    exit 0;
fi

# print out the size of the file
size=$(stat -c%s "$file")
echo $size











Creating a vpl_execution script that measures the size of a program


Imagine that the assignment for the student is to create a program that solves a particular problem (which can be tested separately for the correctness of its output), but the requirement is to make the program executable as small as possible. The grade given to the submitted program will be 100 if the size is equal to the size of the solution program, and some lower grade depending on how large the file is.
Here's a bash script that will do the trick

#! /bin/bash
#set -x

file="printStars"  # whatever executable is to be tested

# assemble and link the executable
nasm -f elf -F stabs ${file}.asm
ld -melf_i386 -o $file ${file}.o

# run the executable in a subshell to catch any segmentation fault error
# that may result.
{ ./$file &> /dev/null ; } &> log

# if an error occured, automatically return 0
if [ $? -eq 139 ]; then
    echo "0";
    exit 0;
fi

# print out the size of the file
size=$(stat -c%s "$file")
echo $size