PageRenderTime 26ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/sys_basher-1.1.24/win_main.c

#
C | 403 lines | 345 code | 35 blank | 23 comment | 93 complexity | a06dfb72f2210924e42723dddaabe2ba MD5 | raw file
  1. /* Copyright (c) 2006,2007,2008,2009 Polybus Systems Corp., Westford, MA, USA */
  2. /* All rights reserved. */
  3. /* Redistribution and use in source and binary forms, with or without modification, */
  4. /* are permitted provided that the following conditions are met: */
  5. /* * Redistributions of source code must retain the above copyright notice, this */
  6. /* list of conditions and the following disclaimer. */
  7. /* * Redistributions in binary form must reproduce the above copyright notice, */
  8. /* this list of conditions and the following disclaimer in the documentation */
  9. /* and/or other materials provided with the distribution. */
  10. /* * Neither the name of the Polybus Systems Corp nor the names of its contributors */
  11. /* may be used to endorse or promote products derived from this software */
  12. /* without specific prior written permission. */
  13. /* THIS SOFTWARE IS PROVIDED BY POLYBUS AND CONTRIBUTORS ''AS IS'' AND ANY */
  14. /* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
  15. /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  16. /* DISCLAIMED. IN NO EVENT SHALL POLYBUS OR CONTRIBUTORS BE LIABLE FOR ANY */
  17. /* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  18. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
  19. /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
  20. /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  21. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
  22. /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  23. #include "sys_basher.h"
  24. int main(long argc, char *argv[])
  25. {
  26. static exp_data expected;
  27. long errors,loops=1,i,j,k,l,value,threads=2,use_total=0,select=0;
  28. long align,test;
  29. long long *base,limit,free_space,sizepls,words,long_limit,indx,offset,addr_limit,total_minus=0;
  30. long long totalram,freeram,totalswap,freeswap,sharedram,bufferram,dutycycle=100,tstart,tend;
  31. double minutes=0,stime=0,etime=0,ctime=0,dutyscale,ttime,cpu=0,mb=0,max_cpu=0,max_mb=0;
  32. double exp_d[8];
  33. float exp_s[8];
  34. char isPath;
  35. my_sysinfo sys_info;
  36. file_info finfo;
  37. thread_data t_data[258];
  38. void *mem;
  39. for(i=0;i<NUM_FP_TESTS;i++)
  40. {
  41. for(j=0;j<32;j++)
  42. {
  43. expected.dbl[j][i] = 0;
  44. expected.fp[j][i] = 0;
  45. }
  46. }
  47. explainIt();
  48. sync();
  49. sync();
  50. mySysInfo(&sys_info);
  51. finfo.num_paths = 0;
  52. i = 1;
  53. select = 0;
  54. dutycycle = 100;
  55. while(argv[i])
  56. {
  57. if(0 == strcmp(argv[i],"-swap"))
  58. {
  59. select |= SWAP_ONLY;
  60. i++;
  61. }
  62. else if(0 == strcmp(argv[i],"-fast"))
  63. {
  64. select |= BAND_ONLY | DISK_ONLY;
  65. i++;
  66. }
  67. else if((0 == strcmp(argv[i],"-diskonly")) ||
  68. (0 == strcmp(argv[i],"-disk_only")) ||
  69. (0 == strcmp(argv[i],"-disk")))
  70. {
  71. select |= DISK_ONLY;
  72. i++;
  73. }
  74. else if((0 == strcmp(argv[i],"-fponly")) ||
  75. (0 == strcmp(argv[i],"-fp_only")) ||
  76. (0 == strcmp(argv[i],"-fp")))
  77. {
  78. select |= FP_ONLY;
  79. i++;
  80. }
  81. else if((0 == strcmp(argv[i],"-intonly")) ||
  82. (0 == strcmp(argv[i],"-int_only")) ||
  83. (0 == strcmp(argv[i],"-int")))
  84. {
  85. select |= INT_ONLY;
  86. i++;
  87. }
  88. else if((0 == strcmp(argv[i],"-mbandwidth")) ||
  89. (0 == strcmp(argv[i],"-mb"))
  90. )
  91. {
  92. select |= BAND_ONLY;
  93. i++;
  94. }
  95. else if((0 == strcmp(argv[i],"-memonly")) ||
  96. (0 == strcmp(argv[i],"-mem"))
  97. )
  98. {
  99. select |= MEM_ONLY;
  100. i++;
  101. }
  102. else if(0 == strcmp(argv[i],"-loops"))
  103. {
  104. i++;
  105. if(argv[i])
  106. {
  107. value = strToInt(argv[i]);
  108. if(value != 0L)
  109. {
  110. loops = value;
  111. i++;
  112. }
  113. }
  114. }
  115. else if(0 == strcmp(argv[i],"-hours"))
  116. {
  117. i++;
  118. if(argv[i])
  119. {
  120. value = strToInt(argv[i]);
  121. if(value != 0L)
  122. {
  123. minutes = value * 60.0;
  124. i++;
  125. }
  126. }
  127. }
  128. else if(0 == strcmp(argv[i],"-minutes"))
  129. {
  130. i++;
  131. if(argv[i])
  132. {
  133. value = strToInt(argv[i]);
  134. if(value != 0L)
  135. {
  136. minutes = value;
  137. i++;
  138. }
  139. }
  140. }
  141. else if(0 == strcmp(argv[i],"-dutycycle"))
  142. {
  143. i++;
  144. if(argv[i])
  145. {
  146. value = strToInt(argv[i]);
  147. if(value != 0L)
  148. {
  149. dutycycle = value;
  150. i++;
  151. }
  152. }
  153. }
  154. else if(0 == strcmp(argv[i],"-path"))
  155. {
  156. i++;
  157. isPath = 0;
  158. if(argv[i]) isPath = argv[i][0] != '-';
  159. while(isPath)
  160. {
  161. if(finfo.num_paths < 31)
  162. {
  163. pathCopy(finfo.path[finfo.num_paths],argv[i],511);
  164. finfo.num_paths++;
  165. }
  166. i++;
  167. isPath = 0;
  168. if(argv[i]) isPath = argv[i][0] != '-';
  169. }
  170. }
  171. else if(0 == strcmp(argv[i],"-totalmem"))
  172. {
  173. i++;
  174. if(argv[i])
  175. {
  176. value = strToInt(argv[i]);
  177. total_minus = value * 0x100000LL;
  178. use_total = 1;
  179. i++;
  180. }
  181. }
  182. else if(0 == strcmp(argv[i],"-threads"))
  183. {
  184. i++;
  185. if(argv[i])
  186. {
  187. value = strToInt(argv[i]);
  188. if(value != 0L)
  189. {
  190. printf("Multithreading is not supported on Windows\n");
  191. i++;
  192. }
  193. }
  194. }
  195. else
  196. {
  197. i++;
  198. }
  199. }
  200. totalram = (long long)sys_info.totalram * (long long)sys_info.mem_unit;
  201. freeram = (long long)sys_info.freeram * (long long)sys_info.mem_unit;
  202. totalswap = (long long)sys_info.totalswap * (long long)sys_info.mem_unit;
  203. freeswap = (long long)sys_info.freeswap * (long long)sys_info.mem_unit;
  204. bufferram = (long long)sys_info.bufferram * (long long)sys_info.mem_unit;
  205. printf("\n");
  206. mprint(12L,"Total RAM",totalram);
  207. mprint(12L,"Free RAM",freeram);
  208. mprint(12L,"Total Swap",totalswap);
  209. mprint(12L,"Free Swap",freeswap);
  210. mprint(12L,"Buffer RAM",bufferram);
  211. printf("\n");
  212. if(finfo.num_paths == 0)
  213. {
  214. pathCopy(finfo.path[finfo.num_paths],".",511);
  215. finfo.num_paths++;
  216. }
  217. free_space = freeram + freeswap;
  218. limit = free_space * 4LL;
  219. limit /= 5L;
  220. sizepls = totalram;
  221. sizepls *= 5LL;
  222. sizepls /= 4LL;
  223. if(sizepls > limit) sizepls = limit;
  224. sizepls &= 0xFFFFFFFFFFFF0000LL;
  225. if(dutycycle >= 100L)
  226. {
  227. dutyscale = 0.0;
  228. }
  229. else
  230. {
  231. dutyscale = dutycycle;
  232. dutyscale = 100.0/dutyscale;
  233. dutyscale = dutyscale - 1.0;
  234. }
  235. mem = malloc(sizepls);
  236. while((mem == NULL) && (sizepls > 0x1000000))
  237. {
  238. sizepls /= 2LL;
  239. limit = sizepls;
  240. mem = malloc(sizepls);
  241. }
  242. if(mem == NULL)
  243. {
  244. printf("Can't allocate enough memory, please close all open applications\n");
  245. exit(1L);
  246. }
  247. align = (long)mem;
  248. align += 0x0FFFFLL;
  249. align &= 0xFFFFFFFFFFFF0000LL;
  250. base = (void *)align;
  251. if(use_total)
  252. {
  253. limit = totalram;
  254. limit -= total_minus;
  255. }
  256. else
  257. {
  258. if(totalram > 0x40000000LL)
  259. {
  260. limit = totalram - 0x10000000LL;
  261. }
  262. else
  263. {
  264. limit = totalram >> 2;
  265. limit *= 3LL;
  266. }
  267. if(freeram < limit) limit = freeram;
  268. }
  269. if(limit > sizepls)
  270. {
  271. limit = sizepls;
  272. }
  273. limit &= 0xFFFFFFFFFFFF0000LL;
  274. errors = 0;
  275. minutes *= 60.0;
  276. stime = getTime();
  277. stime /= 1000000.0;
  278. etime = stime + minutes;
  279. i=0;
  280. //-- Initialize the FP tests
  281. words = limit/8LL;
  282. offset = words;
  283. offset &= 0xFFFFFFFFFFFF0000LL;
  284. addr_limit = offset * 8LL;
  285. long_limit = sizepls;
  286. long_limit &= 0xFFFFFFFFFFFF0000LL;
  287. indx = 0;
  288. t_data[0].base = &base[indx];
  289. t_data[0].limit = addr_limit;
  290. t_data[0].long_limit = long_limit;
  291. t_data[0].errors = 0;
  292. t_data[0].num = 1;
  293. t_data[0].num_threads = 1;
  294. t_data[0].finfo = &finfo;
  295. t_data[0].firsttime = 1;
  296. t_data[0].expected = &expected;
  297. if(testEnb(FP_TST,select))
  298. {
  299. t_data[0].test = FP_TST;
  300. runTests(&t_data[0]);
  301. }
  302. if(testEnb(INT_TST,select))
  303. {
  304. t_data[0].test = INT_TST;
  305. runTests(&t_data[0]);
  306. }
  307. i=0;
  308. while((i < loops) || (ctime < etime))
  309. {
  310. printf("Loop:%ld of %ld\n",i,loops);
  311. words = limit/8LL;
  312. for(test=0;test<NUM_TESTS;test++)
  313. {
  314. if(testEnb(test,select))
  315. {
  316. offset = words;
  317. offset &= 0xFFFFFFFFFFFF0000LL;
  318. addr_limit = offset * 8LL;
  319. long_limit = sizepls;
  320. long_limit &= 0xFFFFFFFFFFFF0000LL;
  321. tstart = getTime();
  322. indx = 0;
  323. t_data[0].base = &base[0];
  324. t_data[0].limit = addr_limit;
  325. t_data[0].long_limit = long_limit;
  326. t_data[0].errors = 0;
  327. t_data[0].num = 1;
  328. t_data[0].num_threads = 1;
  329. t_data[0].test = test;
  330. t_data[0].finfo = &finfo;
  331. t_data[0].firsttime = 0;
  332. t_data[0].expected = &expected;
  333. runTests(&t_data[0]);
  334. errors += t_data[0].errors;
  335. sync();
  336. sync();
  337. tend = getTime();
  338. ttime = tend - tstart;
  339. cpuRest(ttime,dutyscale);
  340. }
  341. }
  342. i++;
  343. ctime = getTime();
  344. ctime /= 1000000LL;
  345. }
  346. etime = ctime - stime;
  347. if(errors == 0L)
  348. {
  349. printf("PASSED, ran for %0.2f seconds\n",etime);
  350. }
  351. else
  352. {
  353. printf("FAILED, %ld errors\n",errors);
  354. }
  355. free(mem);
  356. if(errors == 0L)
  357. {
  358. exit(0);
  359. }
  360. else
  361. {
  362. exit(1);
  363. }
  364. }
  365. long fileTest(char *base,long num, long num_threads,file_info *finfo,long long limit)
  366. {
  367. return(1L);
  368. }