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



int main();
void Perform_Test();
FILE *fi = 0;
unsigned char Version []=VERSTAG;
unsigned char Copyright []=VERS;



int main( argc, argv )
int argc;
char *argv[];
{
long tests = 0;
int c,precision = POSBB_PRECISIONLOW;
   if (argc == 1)  
   {
      printf("POSBB Portable OS Based Benchmark   ( Generic version )\n Created by Pietro Altomani <altomanipietro@pragmanet.it>\nUsage: %s <options>\nOptions:\n  -all  Perform all tests\n  -mem Perform only memory tests\n  -disk Perform only disk tests\n  -math Perform only math tests\n  -o <filename> Output file name\n  -p <precision> Set precision. <precision> can be 'low','medium','high','higher' or 'highest'.\nRead docs for more infos.\n",argv[0]);
      return 10;
   }
   for (c=0;c<argc;c++)
   {
      if (strcmp(argv[c],"-all") == 0)
      {
	 tests = -1;
      }
      if (strcmp(argv[c],"-gfx") == 0)
      {
	 tests |= POSBB_TESTWRITEPIXEL;
      }
      if (strcmp(argv[c],"-disk") == 0)
      {
	 tests |= (POSBB_TESTREAD | POSBB_TESTWRITE);
      }
      if (strcmp(argv[c],"-math") == 0)
      {
	 tests |= (POSBB_TESTIMATH | POSBB_TESTFPMATH);
      }
      if (strcmp(argv[c],"-mem") == 0)
      {
	 tests |= (POSBB_TESTCOPYMEM);
      }
      if (strcmp(argv[c],"-sort") == 0)
      {
	 tests |= (POSBB_TESTQSORT);
      }
      if ((strcmp(argv[c],"-o")) == 0)
      {
	 fi = fopen(argv[c+1],"w");
      }
      if ((strcmp(argv[c],"-p")) == 0)
      {
	 if ((strcmp(argv[c+1],"low")) == 0) precision = POSBB_PRECISIONLOW;
	 if ((strcmp(argv[c+1],"medium")) == 0) precision = POSBB_PRECISIONMEDIUM;
	 if ((strcmp(argv[c+1],"high")) == 0) precision = POSBB_PRECISIONHIGH;
	 if ((strcmp(argv[c+1],"higher")) == 0) precision = POSBB_PRECISIONHIGHER;
	 if ((strcmp(argv[c+1],"highest")) == 0) precision = POSBB_PRECISIONHIGHEST;
      }
   }

   if (fi == 0) fi = fopen(POSBB_DEFRESULTFILE,"w");
   Perform_Test(tests,precision);
   fclose( ( FILE * ) fi );
   return 0;
}

void Perform_Test(tests,precision)
long tests;
int precision;
{
  int r,tot;

  /* Here it prints the header of the result file.*/
  fprintf(fi,"%s\n",VSTRING);
  fprintf(fi,"Portable OS Based Benchmark\n");
  fprintf(fi,"Created by Pietro Altomani <altomanipietro@pragmanet.it>\n");
  fprintf(fi,"Generic Version\n");
  printf("%s\n",VSTRING);
  printf("Portable OS Based Benchmark\n");
  printf("Created by Pietro Altomani <altomanipietro@pragmanet.it>\n");
  printf("Generic Version\n");
  if ((tests | ~(POSBB_TESTCOPYMEM)) == -1) {
  printf("CopyMem test in progress...\n");
  r = Test_CopyMem(precision);
    if (r != 0)
    {
      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_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));
  }
  */
}

