
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "posbb.h"
#include "posbb_rev.h"

extern FILE *fi;
  
void Perform_Test(tests,precision)
long tests;
int precision;
{
  int r,tot;

  /* Here it prints the header of the result file.*/
  fprintf(fi,"%s (generic)\n",VSTRING);
  fprintf(fi,"Portable OS Based Benchmark\n");
  fprintf(fi,"Created by Pietro Altomani <altomanipietro@pragmanet.it>\n");
  printf("%s (generic) \n",VSTRING);
  printf("Portable OS Based Benchmark\n");
  printf("Created by Pietro Altomani <altomanipietro@pragmanet.it>\n");;
  if ((tests | ~(POSBB_TESTCOPYMEM)) == -1) {
  printf("CopyMem test in progress...\n");
  r = Test_CopyMem(precision);
    if (r != -1)
    {
      printf("Result = %d seconds\n",(r*POSBB_PRECISIONHIGHEST/precision));
      fprintf(fi,"CopyMem Test\nTest the speed of memory copying.\nTime:%d seconds\n\n",(r*POSBB_PRECISIONHIGHEST/precision));
    }
    else printf("Test failed. Not enough free memory\n");
   }
   if ((tests | ~(POSBB_TESTCOPYMEM_1MB)) == -1) {
    printf("CopyMem_1MB test in progress...\n");
    r = Test_CopyMem_1Mb(precision);
    if (r != -1)
    {
      printf("Result = %d seconds\n",(r*POSBB_PRECISIONHIGHEST/precision));
      fprintf(fi,"CopyMem_1Mb  Test\nTest the speed of memory copying with 1 Mbyte chunks.\nTime:%d seconds\n\n",(r*POSBB_PRECISIONHIGHEST/precision));
    }
    else printf("Test failed. Not enough free memory\n");
   }
  if ((tests | ~(POSBB_TESTCOPYMEM_512KB)) == -1) {
    printf("CopyMem_512kb test in progress...\n");
    r = Test_CopyMem_512kb(precision);
    if (r != -1)
    {
      printf("Result = %d seconds\n",(r*POSBB_PRECISIONHIGHEST/precision));
      fprintf(fi,"CopyMem_512kb  Test\nTest the speed of memory copying with 512 kb chunks.\nTime:%d seconds\n\n",(r*POSBB_PRECISIONHIGHEST/precision));
    }
    else printf("Test failed. Not enough free memory\n");
   }
  if ((tests | ~(POSBB_TESTPRINTF)) == -1) {
    r = Test_printf(precision);
    printf("Result = %d seconds\n",(r*POSBB_PRECISIONHIGHEST/precision));
    fprintf(fi,"printf Test\nTests the speed of text output to stdout (console)\nTime:%d seconds\n\n",(r*POSBB_PRECISIONHIGHEST/precision));
  }

  if ((tests | ~(POSBB_TESTIMATH)) == -1) {
    printf("Math test in progress...\n");
    r = Test_IMath(precision);
    printf("Result = %d seconds\n",(r*POSBB_PRECISIONHIGHEST/precision));
    fprintf( fi,"Math Test\nTest the speed of some math operations (+,-,*,/)\nTime:%d seconds\n\n",(r*POSBB_PRECISIONHIGHEST/precision));
  }
  if ((tests | ~(POSBB_TESTFPMATH)) == -1) {
    printf("Floating Point Math test in progress...\n");
    r = Test_FPMath(precision);
    printf("Result = %d seconds\n",(r*POSBB_PRECISIONHIGHEST/precision));
   fprintf( fi,"FPMath Test\nTest the speed of some math operations (+,-,*,/)\nTime:%d seconds\n\n",(r*POSBB_PRECISIONHIGHEST/precision));
  }

  if ((tests | ~(POSBB_TESTFPMATH)) == -1) {
    printf("Trigonometry test in progress...\n");
    r = Test_TMath(precision);
    printf("Result = %d seconds\n",(r*POSBB_PRECISIONHIGHEST/precision));
   fprintf( fi,"Trigonometry  Test\nTest the speed of some trigonometric functions\nTime:%d seconds\n\n",(r*POSBB_PRECISIONHIGHEST/precision));
  }

  /* Disk tests doen't work in the generic version,yet.
  if ((tests | ~(POSBB_TESTREAD)) == -1) {
  printf("Write test in progress...\n");
  r = Test_Write(precision);
  printf("Result = %d seconds\n",(r*POSBB_PRECISIONHIGHEST/precision));
  }

  if ((tests | ~(POSBB_TESTWRITE)) == -1) {
  printf("Read test in progress...\n");
  r = Test_Read(precision);
  printf("Result = %d seconds\n",(r*POSBB_PRECISIONHIGHEST/precision));
  }
  */
  /* Test_qsort isn't finished,yet.
  if ((tests | ~(POSBB_TESTQSORT)) == -1) {
  printf("qsort test in progress...\n");
  r = Test_qsort(precision);
  printf("Result = %d seconds\n",(r*POSBB_PRECISIONHIGHEST/precision));
  }
  */
}

