-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify_args.cc
163 lines (133 loc) · 4.37 KB
/
verify_args.cc
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright 2016 Yahoo Inc.
// Licensed under the terms of the New-BSD license. Please see LICENSE file in the project root for terms.
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dlfcn.h>
#include <pthread.h>
#include <sys/types.h>
#include "args.h"
#include <assert.h>
// poor mans cppunit.
void testNoNmt() {
const char * const testArgv[] = { "-Dosgi.requiredJavaVersion=1.6", //
"-XstartOnFirstThread", //
"-Dorg.eclipse.swt.internal.carbon.smallFonts", //
"-XX:MaxPermSize=256m", //
"-Xms40m", //
"-Xmx512m", //
"-Xdock:icon=../Resources/Eclipse.icns", //
"-XstartOnFirstThread", //
"-Dorg.eclipse.swt.internal.carbon.smallFonts", //
NULL, //
};
int testArgc = 0;
const char * const *cp = testArgv;
while (NULL != *cp++) {
++testArgc;
}
JavaArgs jargs = { 0, };
findJavaArgs(jargs, testArgv, testArgc);
if (NULL != jargs.enableNMT) {
printf("got nmt: %s\n", jargs.enableNMT);
}
assert(NULL==jargs.enableNMT);
if (0 != jargs.stacksize) {
printf("got stacksize: %llu\n", jargs.stacksize);
}
assert(0 == jargs.stacksize);
}
// poor mans cppunit.
void testMainClassArgs1() {
const char * const testArgv[] = { "-Dosgi.requiredJavaVersion=1.6", //
"-XstartOnFirstThread", //
"-Dorg.eclipse.swt.internal.carbon.smallFonts", //
"-XX:MaxPermSize=256m", //
"-Xms40m", //
"-Xmx512m", //
"-Xdock:icon=../Resources/Eclipse.icns", //
"-XstartOnFirstThread", //
"-Dorg.eclipse.swt.internal.carbon.smallFonts", //
"TestMain", //
NULL //
};
int testArgc = 0;
const char * const *cp = testArgv;
while (NULL != *cp++) {
++testArgc;
}
JavaArgs jargs = { 0, };
findJavaArgs(jargs, testArgv, testArgc);
char **values = NULL;
size_t numValues = 0;
createJavaMainArgs(jargs, &values, numValues);
assert(0 == strcmp(jargs.argv[jargs.mainClassNameIndex], "TestMain"));
assert(9 == jargs.mainClassNameIndex);
assert(NULL==jargs.argv[jargs.startJavaArgs]);
assert(NULL==jargs.argv[jargs.lastArg]);
assert(NULL==values);
assert(0 == numValues);
}
// poor mans cppunit.
void testMainClassArgs2() {
const char * const testArgv[] = { "-Dosgi.requiredJavaVersion=1.6", //
"-XstartOnFirstThread", //
"-Dorg.eclipse.swt.internal.carbon.smallFonts", //
"-XX:MaxPermSize=256m", //
"-Xms40m", //
"-Xmx512m", //
"-Xdock:icon=../Resources/Eclipse.icns", //
"-XstartOnFirstThread", //
"-Dorg.eclipse.swt.internal.carbon.smallFonts", //
"TestMain", //
"a1", //
"-B2", //
"-XssT$", //
NULL };
int testArgc = 0;
const char * const *cp = testArgv;
while (NULL != *cp++) {
++testArgc;
}
JavaArgs jargs = { 0, };
findJavaArgs(jargs, testArgv, testArgc);
char **values;
size_t numValues = 0;
createJavaMainArgs(jargs, &values, numValues);
assert(0 == strcmp(jargs.argv[jargs.mainClassNameIndex], "TestMain"));
assert(9 == jargs.mainClassNameIndex);
assert(3 == numValues);
assert(NULL!=jargs.argv[jargs.startJavaArgs]);
assert(NULL==jargs.argv[jargs.lastArg]);
assert(NULL!=values);
for (int i = 0; i < numValues; i++) {
assert(NULL != values[i]);
assert(strlen(values[i]) > 0);
}
}
void compare(char *in, const char *str, size_t len) {
printf("%s == %s: %d\n", in, str, strncmp(in, str, len));
}
int main(int argc, char **argv) {
// for (int i=0;i<argc;i++) {
// printf ("argv[%d]=%s\n",i, argv[i]);
// }
// JavaArgs jargs={0,};
// findJavaArgs(jargs,argv,argc);
// dumpArgs(jargs);
// JavaVMOption *vmOptions = NULL;
// int nOptions=0;
// setupVmOptions(jargs, &vmOptions, nOptions);
// dumpJavaVMOptions(vmOptions, nOptions);
// printf ("%d\n",atol(argv[1]));
// printf ("%llu\n",parseXss(argv[1]));
// compare(argv[1], NMT_ARG_STRING, NMT_ARG_LEN);
// compare(argv[1], XSS_ARG_STRING, XSS_ARG_LEN);
// compare(argv[1], XTSS_ARG_STRING, XTSS_ARG_LEN);
// printf("%s\n", parseNmt(argv[1]));
//testNoNmt();
testMainClassArgs1();
testMainClassArgs2();
}