1 /*
2  * Copyright 2013 The Android Open Source Project
3  *
4  * Generate a big pile of classes with big <clinit>.
5  */
6 #include <stdio.h>
7 
8 /*
9  * Create N files.
10  */
createFiles(int count,int array_size)11 static int createFiles(int count, int array_size)
12 {
13     FILE* fp;
14     int i;
15     int k;
16 
17     for (i = 0; i < count; i++) {
18         char nameBuf[32];
19 
20         snprintf(nameBuf, sizeof(nameBuf), "src/Test%03d.java", i);
21         fp = fopen(nameBuf, "w");
22         if (fp == NULL) {
23             fprintf(stderr, "ERROR: unable to open %s\n", nameBuf);
24             return -1;
25         }
26 
27         fprintf(fp, "public class Test%03d {\n", i);
28         fprintf(fp, "    static String[] array = new String[%d];\n", array_size);
29         fprintf(fp, "    static {\n", array_size);
30         for (k = 0; k < array_size; k++) {
31             fprintf(fp, "        array[%d] = \"string_%04d\";\n", k, k);
32         }
33         fprintf(fp, "    }\n", array_size);
34         fprintf(fp, "}\n");
35         fclose(fp);
36     }
37 
38     // Create test class.
39     fp = fopen("src/MainTest.java", "w");
40     if (fp == NULL) {
41         fprintf(stderr, "ERROR: unable to open src/MainTest.java\n");
42         return -1;
43     }
44     fprintf(fp, "public class MainTest {\n");
45     fprintf(fp, "    public static void run() {\n");
46     for (i = 0; i < count; i++) {
47         fprintf(fp, "        System.out.println(\"Create new Test%03d\");\n", i);
48         fprintf(fp, "        new Test%03d();\n", i);
49     }
50     fprintf(fp, "    }\n");
51     fprintf(fp, "}\n");
52     fclose(fp);
53 
54     return 0;
55 }
56 
main()57 int main()
58 {
59     int result;
60 
61     result = createFiles(40, 2000);
62 
63     return (result != 0);
64 }
65