/sys_basher-1.1.24/win_main.c
C | 403 lines | 345 code | 35 blank | 23 comment | 93 complexity | a06dfb72f2210924e42723dddaabe2ba MD5 | raw file
- /* Copyright (c) 2006,2007,2008,2009 Polybus Systems Corp., Westford, MA, USA */
- /* All rights reserved. */
- /* Redistribution and use in source and binary forms, with or without modification, */
- /* are permitted provided that the following conditions are met: */
- /* * Redistributions of source code must retain the above copyright notice, this */
- /* list of conditions and the following disclaimer. */
- /* * Redistributions in binary form must reproduce the above copyright notice, */
- /* this list of conditions and the following disclaimer in the documentation */
- /* and/or other materials provided with the distribution. */
- /* * Neither the name of the Polybus Systems Corp nor the names of its contributors */
- /* may be used to endorse or promote products derived from this software */
- /* without specific prior written permission. */
- /* THIS SOFTWARE IS PROVIDED BY POLYBUS AND CONTRIBUTORS ''AS IS'' AND ANY */
- /* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
- /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
- /* DISCLAIMED. IN NO EVENT SHALL POLYBUS OR CONTRIBUTORS BE LIABLE FOR ANY */
- /* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
- /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
- /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
- /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
- /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
- /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
- #include "sys_basher.h"
- int main(long argc, char *argv[])
- {
- static exp_data expected;
- long errors,loops=1,i,j,k,l,value,threads=2,use_total=0,select=0;
- long align,test;
- long long *base,limit,free_space,sizepls,words,long_limit,indx,offset,addr_limit,total_minus=0;
- long long totalram,freeram,totalswap,freeswap,sharedram,bufferram,dutycycle=100,tstart,tend;
- double minutes=0,stime=0,etime=0,ctime=0,dutyscale,ttime,cpu=0,mb=0,max_cpu=0,max_mb=0;
- double exp_d[8];
- float exp_s[8];
- char isPath;
- my_sysinfo sys_info;
- file_info finfo;
- thread_data t_data[258];
- void *mem;
- for(i=0;i<NUM_FP_TESTS;i++)
- {
- for(j=0;j<32;j++)
- {
- expected.dbl[j][i] = 0;
- expected.fp[j][i] = 0;
- }
- }
- explainIt();
- sync();
- sync();
- mySysInfo(&sys_info);
- finfo.num_paths = 0;
- i = 1;
- select = 0;
- dutycycle = 100;
- while(argv[i])
- {
- if(0 == strcmp(argv[i],"-swap"))
- {
- select |= SWAP_ONLY;
- i++;
- }
- else if(0 == strcmp(argv[i],"-fast"))
- {
- select |= BAND_ONLY | DISK_ONLY;
- i++;
- }
- else if((0 == strcmp(argv[i],"-diskonly")) ||
- (0 == strcmp(argv[i],"-disk_only")) ||
- (0 == strcmp(argv[i],"-disk")))
- {
- select |= DISK_ONLY;
- i++;
- }
- else if((0 == strcmp(argv[i],"-fponly")) ||
- (0 == strcmp(argv[i],"-fp_only")) ||
- (0 == strcmp(argv[i],"-fp")))
- {
- select |= FP_ONLY;
- i++;
- }
- else if((0 == strcmp(argv[i],"-intonly")) ||
- (0 == strcmp(argv[i],"-int_only")) ||
- (0 == strcmp(argv[i],"-int")))
- {
- select |= INT_ONLY;
- i++;
- }
- else if((0 == strcmp(argv[i],"-mbandwidth")) ||
- (0 == strcmp(argv[i],"-mb"))
- )
- {
- select |= BAND_ONLY;
- i++;
- }
- else if((0 == strcmp(argv[i],"-memonly")) ||
- (0 == strcmp(argv[i],"-mem"))
- )
- {
- select |= MEM_ONLY;
- i++;
- }
- else if(0 == strcmp(argv[i],"-loops"))
- {
- i++;
- if(argv[i])
- {
- value = strToInt(argv[i]);
- if(value != 0L)
- {
- loops = value;
- i++;
- }
- }
- }
- else if(0 == strcmp(argv[i],"-hours"))
- {
- i++;
- if(argv[i])
- {
- value = strToInt(argv[i]);
- if(value != 0L)
- {
- minutes = value * 60.0;
- i++;
- }
- }
- }
- else if(0 == strcmp(argv[i],"-minutes"))
- {
- i++;
- if(argv[i])
- {
- value = strToInt(argv[i]);
- if(value != 0L)
- {
- minutes = value;
- i++;
- }
- }
- }
- else if(0 == strcmp(argv[i],"-dutycycle"))
- {
- i++;
- if(argv[i])
- {
- value = strToInt(argv[i]);
- if(value != 0L)
- {
- dutycycle = value;
- i++;
- }
- }
- }
- else if(0 == strcmp(argv[i],"-path"))
- {
- i++;
- isPath = 0;
- if(argv[i]) isPath = argv[i][0] != '-';
- while(isPath)
- {
- if(finfo.num_paths < 31)
- {
- pathCopy(finfo.path[finfo.num_paths],argv[i],511);
- finfo.num_paths++;
- }
- i++;
- isPath = 0;
- if(argv[i]) isPath = argv[i][0] != '-';
- }
- }
- else if(0 == strcmp(argv[i],"-totalmem"))
- {
- i++;
- if(argv[i])
- {
- value = strToInt(argv[i]);
- total_minus = value * 0x100000LL;
- use_total = 1;
- i++;
- }
- }
- else if(0 == strcmp(argv[i],"-threads"))
- {
- i++;
- if(argv[i])
- {
- value = strToInt(argv[i]);
- if(value != 0L)
- {
- printf("Multithreading is not supported on Windows\n");
- i++;
- }
- }
- }
- else
- {
- i++;
- }
- }
- totalram = (long long)sys_info.totalram * (long long)sys_info.mem_unit;
- freeram = (long long)sys_info.freeram * (long long)sys_info.mem_unit;
- totalswap = (long long)sys_info.totalswap * (long long)sys_info.mem_unit;
- freeswap = (long long)sys_info.freeswap * (long long)sys_info.mem_unit;
- bufferram = (long long)sys_info.bufferram * (long long)sys_info.mem_unit;
- printf("\n");
- mprint(12L,"Total RAM",totalram);
- mprint(12L,"Free RAM",freeram);
- mprint(12L,"Total Swap",totalswap);
- mprint(12L,"Free Swap",freeswap);
- mprint(12L,"Buffer RAM",bufferram);
- printf("\n");
-
- if(finfo.num_paths == 0)
- {
- pathCopy(finfo.path[finfo.num_paths],".",511);
- finfo.num_paths++;
- }
- free_space = freeram + freeswap;
- limit = free_space * 4LL;
- limit /= 5L;
-
- sizepls = totalram;
- sizepls *= 5LL;
- sizepls /= 4LL;
- if(sizepls > limit) sizepls = limit;
- sizepls &= 0xFFFFFFFFFFFF0000LL;
- if(dutycycle >= 100L)
- {
- dutyscale = 0.0;
- }
- else
- {
- dutyscale = dutycycle;
- dutyscale = 100.0/dutyscale;
- dutyscale = dutyscale - 1.0;
- }
- mem = malloc(sizepls);
- while((mem == NULL) && (sizepls > 0x1000000))
- {
- sizepls /= 2LL;
- limit = sizepls;
- mem = malloc(sizepls);
- }
- if(mem == NULL)
- {
- printf("Can't allocate enough memory, please close all open applications\n");
- exit(1L);
- }
- align = (long)mem;
- align += 0x0FFFFLL;
- align &= 0xFFFFFFFFFFFF0000LL;
- base = (void *)align;
- if(use_total)
- {
- limit = totalram;
- limit -= total_minus;
- }
- else
- {
- if(totalram > 0x40000000LL)
- {
- limit = totalram - 0x10000000LL;
- }
- else
- {
- limit = totalram >> 2;
- limit *= 3LL;
- }
- if(freeram < limit) limit = freeram;
- }
-
- if(limit > sizepls)
- {
- limit = sizepls;
- }
- limit &= 0xFFFFFFFFFFFF0000LL;
- errors = 0;
- minutes *= 60.0;
- stime = getTime();
- stime /= 1000000.0;
- etime = stime + minutes;
- i=0;
- //-- Initialize the FP tests
- words = limit/8LL;
- offset = words;
- offset &= 0xFFFFFFFFFFFF0000LL;
- addr_limit = offset * 8LL;
- long_limit = sizepls;
- long_limit &= 0xFFFFFFFFFFFF0000LL;
- indx = 0;
- t_data[0].base = &base[indx];
- t_data[0].limit = addr_limit;
- t_data[0].long_limit = long_limit;
- t_data[0].errors = 0;
- t_data[0].num = 1;
- t_data[0].num_threads = 1;
- t_data[0].finfo = &finfo;
- t_data[0].firsttime = 1;
- t_data[0].expected = &expected;
- if(testEnb(FP_TST,select))
- {
- t_data[0].test = FP_TST;
- runTests(&t_data[0]);
- }
- if(testEnb(INT_TST,select))
- {
- t_data[0].test = INT_TST;
- runTests(&t_data[0]);
- }
- i=0;
- while((i < loops) || (ctime < etime))
- {
- printf("Loop:%ld of %ld\n",i,loops);
- words = limit/8LL;
- for(test=0;test<NUM_TESTS;test++)
- {
- if(testEnb(test,select))
- {
- offset = words;
- offset &= 0xFFFFFFFFFFFF0000LL;
- addr_limit = offset * 8LL;
- long_limit = sizepls;
- long_limit &= 0xFFFFFFFFFFFF0000LL;
- tstart = getTime();
- indx = 0;
- t_data[0].base = &base[0];
- t_data[0].limit = addr_limit;
- t_data[0].long_limit = long_limit;
- t_data[0].errors = 0;
- t_data[0].num = 1;
- t_data[0].num_threads = 1;
- t_data[0].test = test;
- t_data[0].finfo = &finfo;
- t_data[0].firsttime = 0;
- t_data[0].expected = &expected;
- runTests(&t_data[0]);
- errors += t_data[0].errors;
- sync();
- sync();
- tend = getTime();
- ttime = tend - tstart;
- cpuRest(ttime,dutyscale);
- }
- }
- i++;
- ctime = getTime();
- ctime /= 1000000LL;
- }
- etime = ctime - stime;
- if(errors == 0L)
- {
- printf("PASSED, ran for %0.2f seconds\n",etime);
- }
- else
- {
- printf("FAILED, %ld errors\n",errors);
- }
- free(mem);
- if(errors == 0L)
- {
- exit(0);
- }
- else
- {
- exit(1);
- }
- }
- long fileTest(char *base,long num, long num_threads,file_info *finfo,long long limit)
- {
- return(1L);
- }