Mudanças entre as edições de "Ferramenta de testes de códigos C para uso didático"
(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...') |
|||
Linha 1: | Linha 1: | ||
=Rascunho= | =Rascunho= | ||
+ | |||
+ | ==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 | ||
+ | $ ./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== | ==sendjob.sh== | ||
Linha 12: | Linha 40: | ||
===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 | ||
+ | #*$ ./sendjob.sh nome_aluno | ||
===Código do script sendjob.sh=== | ===Código do script sendjob.sh=== | ||
<code> | <code> | ||
+ | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
+ | # @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 79: | ||
echo "Please enter your username" | echo "Please enter your username" | ||
fi | fi | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ===Código do script compile.sh=== | ||
+ | |||
+ | <code> | ||
+ | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
+ | # @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 das 12h11min de 5 de julho de 2016
Rascunho
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
</syntaxhighlight>
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
</syntaxhighlight>