xref: /linux/tools/testing/selftests/damon/access_memory_even.c (revision 9907e1df31c0f4bdcebe16de809121baa754e5b5)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Artificial memory access program for testing DAMON.
4  *
5  * Receives number of regions and size of each region from user.  Allocate the
6  * regions and repeatedly access even numbered (starting from zero) regions.
7  */
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 
13 int main(int argc, char *argv[])
14 {
15 	char **regions;
16 	int nr_regions;
17 	int sz_region;
18 	int i;
19 
20 	if (argc != 3) {
21 		printf("Usage: %s <number> <size (bytes)>\n", argv[0]);
22 		return -1;
23 	}
24 
25 	nr_regions = atoi(argv[1]);
26 	sz_region = atoi(argv[2]);
27 
28 	regions = malloc(sizeof(*regions) * nr_regions);
29 	for (i = 0; i < nr_regions; i++)
30 		regions[i] = malloc(sz_region);
31 
32 	while (1) {
33 		for (i = 0; i < nr_regions; i++) {
34 			if (i % 2 == 0)
35 				memset(regions[i], i, sz_region);
36 		}
37 	}
38 	return 0;
39 }
40