proteum icon indicating copy to clipboard operation
proteum copied to clipboard

Do not recognize functions of SUT

Open magsilva opened this issue 9 years ago • 5 comments

Proteum fails to recognize functions within a software under testing. That's quite frequent. For instance, if a function makes use of 'sprintf', it is not recognized by Proteum. See Righetto's report:

""" a ferramenta não consegue reconhecer todas as funções do código; não sei ao certo o porque isso acontece, mas fiz alguns testes e utilizar a função "sprintf" faz com que a função não seja reconhecida, ou utilizar acesso de vetor ou criação estática em uma função diferente da main. Porém, esta ultima afirmação eu não tenho total certeza porque em programas como QuadTree existe uma sctruct com declaração estática de vetor e funciona. """

magsilva avatar Mar 21 '16 12:03 magsilva

Example:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

long int getPrevNumber(long int x) {
    char buffer[1024];
    sprintf(buffer,"%ld",x);
    int count[16] = {};
    int sizeBuffer = strlen(buffer);
    long int prev = 0;
    int i=0;
    for(i=0;i<sizeBuffer;i++)  {
        int c=-1;
        int j=9;
        for(j=9;j>=0;j--)   {
            if(count[j] == 2)
                continue;
            count[j]++;
            int tlen = 0;
            long int mn = j;
            long int ten = 10;
            int k=0;
            for(k=0;k<10;k++) {
                int l=count[k];
                for (l=count[k];l<2;l++) {
                    if (tlen < sizeBuffer-i-1) {
                        mn = mn*10+k;
                        tlen++;
                        ten *= 10;
                    }
                }
            }
            count[j]--;
            if (prev*ten + mn <= x)  {
                c = j;
                break;
            }
        }
        if (c != -1) {
            prev = prev*10+c; 
            count[c]++;
        }
    }
    return prev;
}

int main() {
    long int x;
    while(scanf("%ld",&x) != EOF)
        printf("%ld\n",getPrevNumber(x));
    return 0;
}

magsilva avatar Mar 21 '16 12:03 magsilva

Another example. In this one it fails to parse the functions when calling the function long2char within isPrime:

long int isPrime(long int N)
{
    long int* Prime = (long int*)calloc(1,sizeof(long int));
    long int i;
    long int count[16] = {0,0,0};
    long2char(N); //Sem esta linha, a proteum reconhece todas as funções.

magsilva avatar Mar 21 '16 12:03 magsilva

Parsing of array declarations is also somewhat faulty. Empty array declaration does not work (char b[2] = {}), but this works: char b[2] = {0,0};

magsilva avatar Mar 21 '16 12:03 magsilva

Parser also seems buggy when handling spaces:

char int2char( int i )
{ 
    if ( i < 0 ) { return '~'; }
    if ( i < 10 ) { return '0' + i; }
    if ( i < 36 ) { return 'a' + i - 10; }
    if ( i < 62 ) { return 'A' + i - 36; }

    return '$'; 
}

magsilva avatar Mar 21 '16 12:03 magsilva

Full examples. examples.zip

magsilva avatar Mar 21 '16 12:03 magsilva