Mudanças entre as edições de "Ferramenta de testes de códigos C para uso didático"
Ir para navegação
Ir para pesquisar
(Criou página com '=Rascunho= ==sendjob.sh== ===Pré-requisitos=== *Professor deve passar uma lista de exercícios de até 10 questões onde o aluno deve criar códigos em C para cada questão *O...') |
|||
(7 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
Linha 1: | Linha 1: | ||
− | =Rascunho= | + | =Moodle Virtual Programming Lab - VPL= |
+ | *http://cs.smith.edu/dftwiki/index.php/Moodle_VPL_Server_Setup | ||
+ | *http://cs.smith.edu/dftwiki/index.php/Tutorial:_Moodle_VPL_--_Evaluation_Using_A_Custom_Python_Program | ||
+ | *http://acceda.ulpgc.es/bitstream/10553/9773/5/EEE3753.pdf | ||
+ | *http://docente.ifsc.edu.br/cleber.amaral/topicos/Ensino_programacao/Thiebaut_automaticEvaluationOfComputerProgramsUsingMoodlesVirtualProgrammingLabModule2.pdf | ||
+ | *[[Professores:Laboratório Virtual de Programação|Ensaios feitos pelo Sobral - Laboratório Virtual de Programação]] | ||
+ | |||
+ | =Via scripts rodando gcc e frama-c em um servidor Linux (Rascunho)= | ||
+ | |||
+ | =Objetivo= | ||
+ | *A ideia desta ferramenta é criar uma forma do aluno enviar resoluções de listas de exercícios e receber feedback automático através do servidor que fará a catalogação dos trabalhos, compilação e verificação se atende os requisitos | ||
+ | |||
+ | ==Objetivos específicos== | ||
+ | *Rodar em plataforma linux | ||
+ | *Compilar e validar programas desenvolvidos em ANSI C (C99) | ||
+ | *Ter uma forma de identificar o aluno e catalogar os trabalhos | ||
+ | *Suportar até 10 problemas por lista | ||
+ | *Realizar a compilação | ||
+ | *Suportar arquivos de script de rotinas de testes de programas. | ||
+ | |||
+ | ==Exemplo de aplicação== | ||
+ | *Uma lista de exercícios tem como primeiro exercício receber do usuário 2 números float, calcular a média e imprimir em tela | ||
+ | *Após o aluno enviar ao servidor as resoluções o sistema deve compilar e verificar se o programa atingiu os requisitos executando o script de testes que o professor montou. Neste caso o professor deverá criar um script que entra com números diversos, inteiros, fracionários, negativos, positivos, zero, enfim, para cada caso testado o próprio script deve conter o resultado esperado e testar a condição. Se todas as condições forem satisfeitas o programa da feedback positivo. | ||
+ | |||
+ | ==TODO== | ||
+ | #Add input treatment using like following code (in this example teste.c) | ||
+ | <syntaxhighlight lang=c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | void main() | ||
+ | { | ||
+ | char s1[10], s2[10]; | ||
+ | printf("Entre com uma string\n"); | ||
+ | scanf(" %[^\n]s",s1); | ||
+ | printf("Entre com outra string\n"); | ||
+ | scanf(" %[^\n]s",s2); | ||
+ | printf("A primeira string obtida foi: %s\n",s1); | ||
+ | printf("A segunda string obtida foi: %s\n",s2); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | *Conteúdo do arquivo input.txt | ||
+ | input_tst | ||
+ | input tst2 | ||
+ | |||
+ | *Código executado no terminal | ||
+ | <syntaxhighlight lang=bash> | ||
+ | $ ./teste < input.txt | ||
+ | </syntaxhighlight> | ||
+ | Entre com uma string | ||
+ | Entre com outra string | ||
+ | A primeira string obtida foi: input_tst | ||
+ | A segunda string obtida foi: input tst2 | ||
==sendjob.sh== | ==sendjob.sh== | ||
Linha 12: | Linha 64: | ||
===Procedimento=== | ===Procedimento=== | ||
− | O aluno deve resolver a lista de exercícios que foi dada pelo professor salvando os arquivos com nomes específicos. Quando for submeter o trabalho deverá então utilizar o script "sendjob.sh". | + | #O aluno deve resolver a lista de exercícios que foi dada pelo professor salvando os arquivos com nomes específicos. |
+ | #Quando for submeter o trabalho deverá então utilizar o script "sendjob.sh" na pasta que estão os códigos (q1.c, q2.c...), executar conforme abaixo | ||
+ | <syntaxhighlight lang=bash> | ||
+ | $ ./sendjob.sh nome_aluno | ||
+ | </syntaxhighlight> | ||
===Código do script sendjob.sh=== | ===Código do script sendjob.sh=== | ||
− | <code | + | <syntaxhighlight lang=bash> |
+ | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
+ | # @author Amaral, Cleber Jorge | ||
+ | # | ||
+ | # It is free software: you can redistribute it and/or modify | ||
+ | # under the terms of the GNU Lesser General Public License as published by | ||
+ | # the Free Software Foundation, either version 3 of the License, or | ||
+ | # (at your option) any later version. | ||
+ | # It is distributed in the hope that it will be useful, | ||
+ | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
+ | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
+ | # GNU Lesser General Public License for more details. | ||
+ | # You should have received a copy of the GNU Lesser General Public License | ||
+ | # along with camel_jason. If not, see <http://www.gnu.org/licenses/>. | ||
+ | # | ||
+ | # This script is doing an automated compilation process of a test or list of | ||
+ | # exercises of C programming language course. The student must develop his | ||
+ | # code and by ssh copy the files to his folder in a server where this script | ||
+ | # is running. Frama-c framework must be properly installed in the machine | ||
+ | # The files that this script process must be called as q1.c to q10.c what | ||
+ | # should be ten questions of an exercise list or test | ||
+ | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
+ | |||
if [ "$1" != "" ]; then | if [ "$1" != "" ]; then | ||
read -p "Hello $1! Press [ENTER] to send your code!" | read -p "Hello $1! Press [ENTER] to send your code!" | ||
Linha 27: | Linha 105: | ||
echo "Please enter your username" | echo "Please enter your username" | ||
fi | fi | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ===Código do script compile.sh=== | ||
+ | |||
+ | <syntaxhighlight lang=bash> | ||
+ | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
+ | # @author Amaral, Cleber Jorge | ||
+ | # | ||
+ | # It is free software: you can redistribute it and/or modify | ||
+ | # under the terms of the GNU Lesser General Public License as published by | ||
+ | # the Free Software Foundation, either version 3 of the License, or | ||
+ | # (at your option) any later version. | ||
+ | # It is distributed in the hope that it will be useful, | ||
+ | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
+ | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
+ | # GNU Lesser General Public License for more details. | ||
+ | # You should have received a copy of the GNU Lesser General Public License | ||
+ | # along with camel_jason. If not, see <http://www.gnu.org/licenses/>. | ||
+ | # | ||
+ | # This script is doing an automated compilation process of a test or list of | ||
+ | # exercises of C programming language course. The student must develop his | ||
+ | # code and by ssh copy the files to his folder in a server where this script | ||
+ | # is running. Frama-c framework must be properly installed in the machine | ||
+ | # The files that this script process must be called as q1.c to q10.c what | ||
+ | # should be ten questions of an exercise list or test | ||
+ | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
+ | |||
+ | #Getting current directory | ||
+ | BASEDIR=$(dirname "$0") | ||
+ | if [ -f "$BASEDIR/output.log" ] | ||
+ | then | ||
+ | rm $BASEDIR/output.log | ||
+ | fi | ||
+ | |||
+ | #Print in the file the user and current datetime (this first is replacing current output.log content) | ||
+ | who > $BASEDIR/output.log | ||
+ | date >> $BASEDIR/output.log | ||
+ | |||
+ | #Loop to compile each c code (questions q1 to q10). | ||
+ | COUNTER=0 | ||
+ | while [ $COUNTER != 10 ] | ||
+ | do | ||
+ | COUNTER=$[$COUNTER + 1] | ||
+ | if [ -f "$BASEDIR/q$COUNTER.c" ] | ||
+ | then | ||
+ | printf " \n\n\n\n" >> $BASEDIR/output.log | ||
+ | |||
+ | echo "gcc output compiling q$COUNTER.c: " >> $BASEDIR/output.log | ||
+ | gcc $BASEDIR/q$COUNTER.c -o $BASEDIR/q$COUNTER >> $BASEDIR/output.log | ||
+ | |||
+ | echo "Compilation on q$COUNTER.c have finished!" >> $BASEDIR/output.log | ||
+ | else | ||
+ | printf " \n\n\n\n" >> $BASEDIR/output.log | ||
+ | echo "$BASEDIR/q$COUNTER.c not found." >> $BASEDIR/output.log | ||
+ | fi | ||
+ | done | ||
+ | |||
+ | #Loop for Frama-c tests | ||
+ | COUNTER=0 | ||
+ | while [ $COUNTER != 10 ] | ||
+ | do | ||
+ | COUNTER=$[$COUNTER + 1] | ||
+ | if [ -f "$BASEDIR/q$COUNTER.c" ] | ||
+ | then | ||
+ | printf " \n\n\n\n" >> $BASEDIR/output.log | ||
+ | |||
+ | echo "Frama-c output testing q$COUNTER.c:" >> $BASEDIR/output.log | ||
+ | frama-c -val $BASEDIR/q$COUNTER.c >> $BASEDIR/output.log | ||
+ | |||
+ | echo "Frama-c tests on q$COUNTER.c have finished!" >> $BASEDIR/output.log | ||
+ | else | ||
+ | printf " \n\n\n\n" >> $BASEDIR/output.log | ||
+ | echo "$BASEDIR/q$COUNTER.c not found." >> $BASEDIR/output.log | ||
+ | fi | ||
+ | done | ||
+ | |||
+ | #Loop to register the code that was received | ||
+ | COUNTER=0 | ||
+ | while [ $COUNTER != 10 ] | ||
+ | do | ||
+ | COUNTER=$[$COUNTER + 1] | ||
+ | if [ -f "$BASEDIR/q$COUNTER.c" ] | ||
+ | then | ||
+ | printf " \n\n\n\n" >> $BASEDIR/output.log | ||
+ | |||
+ | echo "Original code of q$COUNTER.c:" >> $BASEDIR/output.log | ||
+ | cat $BASEDIR/q$COUNTER.c >> $BASEDIR/output.log | ||
+ | |||
+ | echo "Printing process of q$COUNTER.c has finished!" >> $BASEDIR/output.log | ||
+ | else | ||
+ | printf " \n\n\n\n" >> $BASEDIR/output.log | ||
+ | echo "$BASEDIR/q$COUNTER.c not found." >> $BASEDIR/output.log | ||
+ | fi | ||
+ | done | ||
</syntaxhighlight> | </syntaxhighlight> |
Edição atual tal como às 15h20min de 6 de abril de 2017
Moodle Virtual Programming Lab - VPL
- http://cs.smith.edu/dftwiki/index.php/Moodle_VPL_Server_Setup
- http://cs.smith.edu/dftwiki/index.php/Tutorial:_Moodle_VPL_--_Evaluation_Using_A_Custom_Python_Program
- http://acceda.ulpgc.es/bitstream/10553/9773/5/EEE3753.pdf
- http://docente.ifsc.edu.br/cleber.amaral/topicos/Ensino_programacao/Thiebaut_automaticEvaluationOfComputerProgramsUsingMoodlesVirtualProgrammingLabModule2.pdf
- Ensaios feitos pelo Sobral - Laboratório Virtual de Programação
Via scripts rodando gcc e frama-c em um servidor Linux (Rascunho)
Objetivo
- A ideia desta ferramenta é criar uma forma do aluno enviar resoluções de listas de exercícios e receber feedback automático através do servidor que fará a catalogação dos trabalhos, compilação e verificação se atende os requisitos
Objetivos específicos
- Rodar em plataforma linux
- Compilar e validar programas desenvolvidos em ANSI C (C99)
- Ter uma forma de identificar o aluno e catalogar os trabalhos
- Suportar até 10 problemas por lista
- Realizar a compilação
- Suportar arquivos de script de rotinas de testes de programas.
Exemplo de aplicação
- Uma lista de exercícios tem como primeiro exercício receber do usuário 2 números float, calcular a média e imprimir em tela
- Após o aluno enviar ao servidor as resoluções o sistema deve compilar e verificar se o programa atingiu os requisitos executando o script de testes que o professor montou. Neste caso o professor deverá criar um script que entra com números diversos, inteiros, fracionários, negativos, positivos, zero, enfim, para cada caso testado o próprio script deve conter o resultado esperado e testar a condição. Se todas as condições forem satisfeitas o programa da feedback positivo.
TODO
- Add input treatment using like following code (in this example teste.c)
#include <stdio.h>
void main()
{
char s1[10], s2[10];
printf("Entre com uma string\n");
scanf(" %[^\n]s",s1);
printf("Entre com outra string\n");
scanf(" %[^\n]s",s2);
printf("A primeira string obtida foi: %s\n",s1);
printf("A segunda string obtida foi: %s\n",s2);
}
- Conteúdo do arquivo input.txt
input_tst input tst2
- Código executado no terminal
$ ./teste < input.txt
Entre com uma string Entre com outra string A primeira string obtida foi: input_tst A segunda string obtida foi: input tst2
sendjob.sh
Pré-requisitos
- Professor deve passar uma lista de exercícios de até 10 questões onde o aluno deve criar códigos em C para cada questão
- O aluno deve criar arquivos C completos, compiláveis e seguir o padrão de nomes (q1.c, q2.c até q10.c)
- O servidor que possui o frama-c instalado deve estar disponível para receber conexões SSH
- A aluno deve obter o arquivo "sendjob.sh" e o arquivo de identidade "pem"
- O script sendjob.sh deve estar na mesma pasta onde estão os arquivo q1.c, q2.c...
- O arquivo pem deve ser colocado na pasta .ssh do computador do aluno
Procedimento
- O aluno deve resolver a lista de exercícios que foi dada pelo professor salvando os arquivos com nomes específicos.
- Quando for submeter o trabalho deverá então utilizar o script "sendjob.sh" na pasta que estão os códigos (q1.c, q2.c...), executar conforme abaixo
$ ./sendjob.sh nome_aluno
Código do script sendjob.sh
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# @author Amaral, Cleber Jorge
#
# It is free software: you can redistribute it and/or modify
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# It is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License
# along with camel_jason. If not, see <http://www.gnu.org/licenses/>.
#
# This script is doing an automated compilation process of a test or list of
# exercises of C programming language course. The student must develop his
# code and by ssh copy the files to his folder in a server where this script
# is running. Frama-c framework must be properly installed in the machine
# The files that this script process must be called as q1.c to q10.c what
# should be ten questions of an exercise list or test
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
if [ "$1" != "" ]; then
read -p "Hello $1! Press [ENTER] to send your code!"
scp -i ~/.ssh/cleberamaral.pem q1.c ubuntu@200.135.233.3:/home/ubuntu/prg29002/$1/
scp -i ~/.ssh/cleberamaral.pem q2.c ubuntu@200.135.233.3:/home/ubuntu/prg29002/$1/
scp -i ~/.ssh/cleberamaral.pem q3.c ubuntu@200.135.233.3:/home/ubuntu/prg29002/$1/
scp -i ~/.ssh/cleberamaral.pem q4.c ubuntu@200.135.233.3:/home/ubuntu/prg29002/$1/
scp -i ~/.ssh/cleberamaral.pem q5.c ubuntu@200.135.233.3:/home/ubuntu/prg29002/$1/
ssh -X -i ~/.ssh/cleberamaral.pem ubuntu@200.135.233.3 /home/ubuntu/prg29002/$1/compile.sh
else
echo "Please enter your username"
fi
Código do script compile.sh
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# @author Amaral, Cleber Jorge
#
# It is free software: you can redistribute it and/or modify
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# It is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License
# along with camel_jason. If not, see <http://www.gnu.org/licenses/>.
#
# This script is doing an automated compilation process of a test or list of
# exercises of C programming language course. The student must develop his
# code and by ssh copy the files to his folder in a server where this script
# is running. Frama-c framework must be properly installed in the machine
# The files that this script process must be called as q1.c to q10.c what
# should be ten questions of an exercise list or test
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#Getting current directory
BASEDIR=$(dirname "$0")
if [ -f "$BASEDIR/output.log" ]
then
rm $BASEDIR/output.log
fi
#Print in the file the user and current datetime (this first is replacing current output.log content)
who > $BASEDIR/output.log
date >> $BASEDIR/output.log
#Loop to compile each c code (questions q1 to q10).
COUNTER=0
while [ $COUNTER != 10 ]
do
COUNTER=$[$COUNTER + 1]
if [ -f "$BASEDIR/q$COUNTER.c" ]
then
printf " \n\n\n\n" >> $BASEDIR/output.log
echo "gcc output compiling q$COUNTER.c: " >> $BASEDIR/output.log
gcc $BASEDIR/q$COUNTER.c -o $BASEDIR/q$COUNTER >> $BASEDIR/output.log
echo "Compilation on q$COUNTER.c have finished!" >> $BASEDIR/output.log
else
printf " \n\n\n\n" >> $BASEDIR/output.log
echo "$BASEDIR/q$COUNTER.c not found." >> $BASEDIR/output.log
fi
done
#Loop for Frama-c tests
COUNTER=0
while [ $COUNTER != 10 ]
do
COUNTER=$[$COUNTER + 1]
if [ -f "$BASEDIR/q$COUNTER.c" ]
then
printf " \n\n\n\n" >> $BASEDIR/output.log
echo "Frama-c output testing q$COUNTER.c:" >> $BASEDIR/output.log
frama-c -val $BASEDIR/q$COUNTER.c >> $BASEDIR/output.log
echo "Frama-c tests on q$COUNTER.c have finished!" >> $BASEDIR/output.log
else
printf " \n\n\n\n" >> $BASEDIR/output.log
echo "$BASEDIR/q$COUNTER.c not found." >> $BASEDIR/output.log
fi
done
#Loop to register the code that was received
COUNTER=0
while [ $COUNTER != 10 ]
do
COUNTER=$[$COUNTER + 1]
if [ -f "$BASEDIR/q$COUNTER.c" ]
then
printf " \n\n\n\n" >> $BASEDIR/output.log
echo "Original code of q$COUNTER.c:" >> $BASEDIR/output.log
cat $BASEDIR/q$COUNTER.c >> $BASEDIR/output.log
echo "Printing process of q$COUNTER.c has finished!" >> $BASEDIR/output.log
else
printf " \n\n\n\n" >> $BASEDIR/output.log
echo "$BASEDIR/q$COUNTER.c not found." >> $BASEDIR/output.log
fi
done