
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <intuition/intuitionbase.h>
#include <devices/timer.h>
#include <graphics/gfx.h>
#include <graphics/rastport.h>
#include <exec/memory.h>
#include "posbb.h"
#include "posbb_rev.h"
#include "compiler.h" /* for compiler specific stuff */
/* #include "posbb_logo.h" */
extern FILE *fi;
extern struct Window *window;

void Perform_Test(tests,precision,freeze,mt)
ULONG tests;
int precision;
BOOL freeze,mt;
{
  ULONG r,tot;
  struct SystemConfig *cfg;
  /* Here it prints the header of the result file.*/
  fprintf(fi,"%s (Amiga)\n",VSTRING);
  fprintf(fi,"Portable OS Based Benchmark\n");
  fprintf(fi,"Created by Pietro Altomani <altomanipietro@pragmanet.it>\n");
  printf("%s (Amiga)\n",VSTRING);
  printf("Portable OS Based Benchmark\n");
  printf("Created by Pietro Altomani <altomanipietro@pragmanet.it>\n");
  ShowConfiguration(fi,TRUE);  /* this prints in the file,and if the second parameter is TRUE on the console, the system configuration   */

  if ((tests | ~(POSBB_TESTCOPYMEM)) == -1) {
  printf("CopyMem test in progress...\n");
  r = Test_CopyMem(precision,freeze,mt);
    if (r == TRUE)  printf("Test failed. Not enough free memory\n");
    else
    {
      printf("Result = %f seconds\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
      fprintf(fi,"CopyMem Test\nTest the speed of RAM access.\nTime:%f seconds\n\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
    }
   }
   if ((tests | ~(POSBB_TESTCOPYMEM_512KB)) == -1) {
  printf("CopyMem_512kb test in progress...\n");
  r = Test_CopyMem_512kb(precision,freeze,mt);
    if (r == TRUE)  printf("Test failed. Not enough free memory\n");
    else
    {
      printf("Result = %f seconds\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
      fprintf(fi,"CopyMem_512kb Test\nTest the speed of RAM access with 512 kb chunks.\nTime:%f seconds\n\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
    }
   }
  if ((tests | ~(POSBB_TESTCOPYMEM_1MB)) == -1) {
  printf("CopyMem_1Mb test in progress...\n");
  r = Test_CopyMem_1Mb(precision,freeze,mt);
    if (r == TRUE)  printf("Test failed. Not enough free memory\n");
    else
    {
      printf("Result = %f seconds\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
      fprintf(fi,"CopyMem_1Mb Test\nTest the speed of RAM access with 1 Mb chunks..\nTime:%f seconds\n\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
    }
   }
  if ((tests | ~(POSBB_TESTPRINTF)) == -1) {
    r = Test_printf(precision,freeze,mt);
    printf("Result = %f seconds\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
    fprintf(fi,"printf Test\nTests the speed of text output to stdout (console)\nTime:%f seconds\n\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
  }
  if ((tests | ~(POSBB_TESTIMATH)) == -1) {
    printf("Math test in progress...\n");
    r = Test_IMath(precision,freeze,mt);
    printf("Result = %f seconds\n", (double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
    fprintf( fi,"Math Test\nTest the speed of some math operations (+,-,*,/)\nTime:%f seconds\n\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
  }
  if ((tests | ~(POSBB_TESTFPMATH)) == -1) {
    printf("Floating Point Math test in progress...\n");
    r = Test_FPMath(precision,freeze,mt);
    printf("Result = %f seconds\n", (double)(r * POSBB_PRECISIONHIGHEST / precision)/1000);
   fprintf( fi,"FPMath Test\nTest the speed of some math operations (+,-,*,/)\nTime:%f seconds\n\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
  }
  if ((tests | ~(POSBB_TESTTMATH)) == -1) {
    printf("TMath test in progress...\n");
    r = Test_TMath(precision,freeze,mt);
    printf("Result = %f seconds\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
    fprintf( fi,"TMath Test\nTest the speed of trigonometric functions.\nTime:%f seconds\n\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
  }



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

*/
#ifdef POSBB_TESTDISK                       /* This can turn on or off the disk speed tests. In fact it isn't very useful.  */
  if ((tests | ~(POSBB_TESTREAD)) == -1) {
    printf("Write test in progress...\n");
    r = Test_Write(POSBB_DEFTESTFILE,precision,freeze,mt);
    printf("Result = %f seconds\n",(r * POSBB_PRECISIONHIGHEST/precision)/1000);
  }
  if ((tests | ~(POSBB_TESTWRITE)) == -1) {
    printf("Read test in progress...\n");
    r = Test_Read(POSBB_DEFTESTFILE,precision,freeze,mt);
    printf("Result = %d seconds\n",r);
  }
#endif
  /* Here starts gxf tests. */
  if ((tests | ~(POSBB_TESTWRITEPIXEL)) == -1) {
  printf("WritePixel test in progress...\n");
  r = Test_WritePixel(window->RPort,precision,freeze,mt);
  printf("Result = %f seconds\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
  fprintf( fi,"WritePixel Test\nTests the speed of pixel drawing.\nTime: %f seconds\n\n",(double)(r * POSBB_PRECISIONHIGHEST / precision)/1000);
  }
  if ((tests | ~(POSBB_TESTDRAWELLIPSE)) == -1) {
  printf("DrawEllipse test in progress...\n");
  r = Test_DrawEllipse(window->RPort,precision,freeze,mt);
  printf("Result = %f seconds\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
  fprintf( fi,"DrawEllipse Test\nTests the speed of ellipse drawing.\nTime: %f seconds\n\n",(double)(r * POSBB_PRECISIONHIGHEST / precision)/1000);
  }
  if ((tests | ~(POSBB_TESTDRAW)) == -1) {
  printf("Draw test in progress...\n");
  r = Test_Draw(window->RPort,precision,freeze,mt);
  printf("Result = %f seconds\n",(double) (r * POSBB_PRECISIONHIGHEST / precision)/1000);
  fprintf( fi,"Draw Test\nTests the speed of line drawing.\nTime: %f seconds\n\n",(double)(r * POSBB_PRECISIONHIGHEST / precision)/1000);
  }
}

ShowConfiguration(resfile,conflag)     /* file is the (FILE *) to write on. conflag is a flag saying if it has to write to the console,too. conflag = 1 */
FILE *resfile;
{
  fprintf(resfile,"In this version POSBB can't show system config.\n");
  if (conflag) printf("In this version POSBB can't show system configuration.\n");
  return 0;
}

