aboutsummaryrefslogtreecommitdiff
path: root/testcases/cpuidle/test_usb_cpuidle.c
blob: 985f2f28a32c39a9749ef27396abefd809ff87cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * PM-QA validation test suite for the power management on ARM
 *
 * Copyright (C) 2011, Linaro Limited.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Contributors:
 *     Torez Smith <torez.smith@linaro.org> (IBM Corporation)
 *       - initial API and implementation
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
//void usleep(unsigned long usec);


#define MAX_COUNT 1024
int main(int argc, char *argv[])
{
	int err = 0;
	FILE *fp = 0;
	int byteCount = 0;
	int iterCount = 0;
	char dataArray[MAX_COUNT];
/*
	printf("\nUSB mass storage test: parameters --device_name, byte to read, times to run\n");
*/
	if(argc!=4) {
		printf("Error: No of argumets not proper\n");
		return 0;
	}
	byteCount = atoi(argv[2]);
	iterCount = atoi(argv[3]);
/*
	printf("Device to open=%s, bytes read =%d, iteration =%d\n",argv[1], byteCount, iterCount);
*/
	fp = fopen(argv[1], "r");
	if(fp == NULL)
	{
		printf("Error: Invalid device name passed\n");
		return 0;
	}

	/*Init random generator*/
	srand((unsigned int)time(NULL));
	while(iterCount != 0) {	
		/*read from the begining*/	
		err = fread(dataArray,1,byteCount,fp);
		if(err < 0) {
			printf("Error: Data read failed\n");
			return 0;
		}
		fseek(fp,((iterCount%5)*100*1024), SEEK_SET);
		if(err < 0) {
			printf("Error: Data seek failed\n");
			return 0;
		}

		/*read from somewhere in the middle*/	
		err = fread(dataArray,1,byteCount,fp);
		if(err < 0) {
			printf("Error: Data read failed\n");
			return 0;
		}
		fseek(fp, byteCount, SEEK_END);
		if(err < 0) {
			printf("Error: Data seek failed\n");
			return 0;
		}

		/*read from the end*/	
		err = fread(dataArray,1,byteCount,fp);
		if(err < 0) {
			printf("Error: Data read failed\n");
			return 0;
		}
		
		rewind(fp);
		iterCount--;
		fclose(fp);
		/*sleep between 1ms to 50ms*/
		usleep(((rand()%50) + 1)*1000);
		fp = fopen(argv[1], "r");
	}
	fclose(fp);
	return 0;
}