blob: 1f2fe3b226cf2f34a7076340277642fdc85a8f24 [file] [log] [blame]
Sebastien Hertz96f36672013-12-13 15:19:18 +01001/*
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 */
11static 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);
Brian Carlstrom8ae6c272014-10-27 18:57:28 -070029 fprintf(fp, " static {\n");
Sebastien Hertz96f36672013-12-13 15:19:18 +010030 for (k = 0; k < array_size; k++) {
31 fprintf(fp, " array[%d] = \"string_%04d\";\n", k, k);
32 }
Brian Carlstrom8ae6c272014-10-27 18:57:28 -070033 fprintf(fp, " }\n");
Sebastien Hertz96f36672013-12-13 15:19:18 +010034 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
57int main()
58{
59 int result;
60
61 result = createFiles(40, 2000);
62
63 return (result != 0);
64}