xref: /aosp_15_r20/external/ltp/testcases/kernel/io/ltp-aiodio/dirty.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker 
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2004 Daniel McNeil <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker  *               2004 Open Source Development Lab
5*49cdfc7eSAndroid Build Coastguard Worker  *   This program is free software;  you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker  *   it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker  *   the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker  *   (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  *   This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13*49cdfc7eSAndroid Build Coastguard Worker  *   the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker  *
15*49cdfc7eSAndroid Build Coastguard Worker  *   You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker  *   along with this program;  if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker  *
19*49cdfc7eSAndroid Build Coastguard Worker  * Module: .c
20*49cdfc7eSAndroid Build Coastguard Worker  */
21*49cdfc7eSAndroid Build Coastguard Worker 
22*49cdfc7eSAndroid Build Coastguard Worker /*
23*49cdfc7eSAndroid Build Coastguard Worker  * Change History:
24*49cdfc7eSAndroid Build Coastguard Worker  *
25*49cdfc7eSAndroid Build Coastguard Worker  * 2/2004  Marty Ridgeway ([email protected]) Changes to adapt to LTP
26*49cdfc7eSAndroid Build Coastguard Worker  *
27*49cdfc7eSAndroid Build Coastguard Worker  */
28*49cdfc7eSAndroid Build Coastguard Worker 
29*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
30*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
31*49cdfc7eSAndroid Build Coastguard Worker #include <memory.h>
32*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
33*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
34*49cdfc7eSAndroid Build Coastguard Worker #include <limits.h>
35*49cdfc7eSAndroid Build Coastguard Worker 
main(void)36*49cdfc7eSAndroid Build Coastguard Worker int main(void)
37*49cdfc7eSAndroid Build Coastguard Worker {
38*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
39*49cdfc7eSAndroid Build Coastguard Worker 	int i;
40*49cdfc7eSAndroid Build Coastguard Worker 	char buf[32 * 1024];
41*49cdfc7eSAndroid Build Coastguard Worker 	char filename[PATH_MAX];
42*49cdfc7eSAndroid Build Coastguard Worker 
43*49cdfc7eSAndroid Build Coastguard Worker 	printf("Starting dirty tests...\n");
44*49cdfc7eSAndroid Build Coastguard Worker 
45*49cdfc7eSAndroid Build Coastguard Worker 	snprintf(filename, sizeof(filename), "%s/aiodio/file.xx.%d",
46*49cdfc7eSAndroid Build Coastguard Worker 		 getenv("TMP") ? getenv("TMP") : "/tmp", getpid());
47*49cdfc7eSAndroid Build Coastguard Worker 
48*49cdfc7eSAndroid Build Coastguard Worker 	fd = open(filename, O_CREAT | O_WRONLY, 0666);
49*49cdfc7eSAndroid Build Coastguard Worker 
50*49cdfc7eSAndroid Build Coastguard Worker 	memset(buf, 0xaa, sizeof(buf));
51*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < 3000; i++)
52*49cdfc7eSAndroid Build Coastguard Worker 		write(fd, buf, sizeof(buf));
53*49cdfc7eSAndroid Build Coastguard Worker 	fsync(fd);
54*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
55*49cdfc7eSAndroid Build Coastguard Worker 	unlink(filename);
56*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
57*49cdfc7eSAndroid Build Coastguard Worker }
58