summaryrefslogtreecommitdiffstats
path: root/test/303-verification-stress/classes-gen.c
blob: 1f2fe3b226cf2f34a7076340277642fdc85a8f24 (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
/*
 * Copyright 2013 The Android Open Source Project
 *
 * Generate a big pile of classes with big <clinit>.
 */
#include <stdio.h>

/*
 * Create N files.
 */
static int createFiles(int count, int array_size)
{
    FILE* fp;
    int i;
    int k;

    for (i = 0; i < count; i++) {
        char nameBuf[32];

        snprintf(nameBuf, sizeof(nameBuf), "src/Test%03d.java", i);
        fp = fopen(nameBuf, "w");
        if (fp == NULL) {
            fprintf(stderr, "ERROR: unable to open %s\n", nameBuf);
            return -1;
        }

        fprintf(fp, "public class Test%03d {\n", i);
        fprintf(fp, "    static String[] array = new String[%d];\n", array_size);
        fprintf(fp, "    static {\n");
        for (k = 0; k < array_size; k++) {
            fprintf(fp, "        array[%d] = \"string_%04d\";\n", k, k);
        }
        fprintf(fp, "    }\n");
        fprintf(fp, "}\n");
        fclose(fp);
    }

    // Create test class.
    fp = fopen("src/MainTest.java", "w");
    if (fp == NULL) {
        fprintf(stderr, "ERROR: unable to open src/MainTest.java\n");
        return -1;
    }
    fprintf(fp, "public class MainTest {\n");
    fprintf(fp, "    public static void run() {\n");
    for (i = 0; i < count; i++) {
        fprintf(fp, "        System.out.println(\"Create new Test%03d\");\n", i);
        fprintf(fp, "        new Test%03d();\n", i);
    }
    fprintf(fp, "    }\n");
    fprintf(fp, "}\n");
    fclose(fp);

    return 0;
}

int main()
{
    int result;

    result = createFiles(40, 2000);

    return (result != 0);
}