Ferramenta de testes de códigos C para uso didático

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar

Rascunho

TODO

  1. 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

  1. O aluno deve resolver a lista de exercícios que foi dada pelo professor salvando os arquivos com nomes específicos.
  2. 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

  1. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  2. @author Amaral, Cleber Jorge
  3. It is free software: you can redistribute it and/or modify
  4. under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. It is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with camel_jason. If not, see <http://www.gnu.org/licenses/>.
  13. This script is doing an automated compilation process of a test or list of
  14. exercises of C programming language course. The student must develop his
  15. code and by ssh copy the files to his folder in a server where this script
  16. is running. Frama-c framework must be properly installed in the machine
  17. The files that this script process must be called as q1.c to q10.c what
  18. should be ten questions of an exercise list or test
  19. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

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

  1. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  2. @author Amaral, Cleber Jorge
  3. It is free software: you can redistribute it and/or modify
  4. under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. It is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with camel_jason. If not, see <http://www.gnu.org/licenses/>.
  13. This script is doing an automated compilation process of a test or list of
  14. exercises of C programming language course. The student must develop his
  15. code and by ssh copy the files to his folder in a server where this script
  16. is running. Frama-c framework must be properly installed in the machine
  17. The files that this script process must be called as q1.c to q10.c what
  18. should be ten questions of an exercise list or test
  19. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  1. Getting current directory

BASEDIR=$(dirname "$0") if [ -f "$BASEDIR/output.log" ] then rm $BASEDIR/output.log fi

  1. 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

  1. 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

  1. 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

  1. 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>