2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 * TODO: enable thread local storage.
48 char bss_buf
[1024]; /* just to see ELF info */
51 THREAD
int tls_bss_int
;
52 THREAD
char tls_bss_buf
[8192];
54 THREAD
int tls_data_int
= 10;
55 THREAD
char tls_data_buf
[128] = "Hello world\n";
60 printf("%s\n", tls_data_buf
);
64 void test_fmt(char *fmt
, int val
)
66 fputs(fmt
, stdout
); putc(':', stdout
);
71 void test_fp_fmt(char *fmt
, double val
)
73 fputs(fmt
, stdout
); putc(':', stdout
);
78 void test_fp_val(double val
)
80 printf("\n123456789012345678901234567890"
81 "123456789012345678901234567890\n");
82 test_fp_fmt("%e", val
);
83 test_fp_fmt("%30.15e.", val
);
84 test_fp_fmt("%-30.15e.", val
);
85 test_fp_fmt("%f.", val
);
86 test_fp_fmt("%30.15f.", val
);
87 test_fp_fmt("%-30.15f.", val
);
94 printf("one half is %e\n", 0.5);
95 printf("one half is %f\n", 0.5);
96 printf("one third is %e\n", 1.0/3.0);
97 printf("one third is %f\n", 1.0/3.0);
100 test_fp_fmt("%.500e", 1.0);
117 /* TODO: the code below doesn't compile on Windows
118 NOTE: disabled this code for all platforms
119 to be able to do with one golden file */
120 d
= 1.234567e+310; /* inf */
123 d
= 1.234567e+310; /* inf */
127 d
= 0.0/0.0; /* nan */
129 #endif /*NACL_WINDOWS*/
132 void test_malloc(void)
135 printf("test_malloc: entered\n");
137 fprintf(stderr
, "# got 0x%08x\n", (unsigned int) p
);
138 printf("test_malloc: leaving\n");
144 printf("test_time: entered\n");
146 fprintf(stderr
, "# current time is %d \n", (int) tval
);
147 printf("test_time: leaving\n");
150 void test_fopen(const char* fn
)
157 printf("test_fopen: entered\n");
158 fp
= fopen(fn
, "rb");
160 printf("could not open file %s!\n", fn
);
163 printf("reading file\n");
164 while (EOF
!= (c
= fgetc(fp
))) {
167 TODO: make sure the input files are identical
168 on all platforms, so we won't need the if.
175 while (0 != (rv
= (fputs("input: ", stdout
),
177 fgets(line
, sizeof line
, stdin
)))) {
178 printf("Got line: <<%s>>, %d\n", rv
, strlen(rv
));
180 printf("test_fopen: done\n");
184 int NaClMain(const char* fn
)
186 char const *hello
= "Hello world\n";
187 char const *bye
= "Goodbye cruel world";
190 r
= write(1, hello
, strlen(hello
));
192 printf("write returned %d.\n", r
);
193 test_fmt("<%04d>", r
);
194 test_fmt("<%-d>", r
);
195 test_fmt("<%-04d>", r
);
198 test_fmt("<%04d>", r
);
199 test_fmt("<%-d>", r
);
200 test_fmt("<%-04d>", r
);
202 printf("The message was \"%s\".\n", hello
);
204 printf("Bye message: \"%25s\".\n", bye
);
205 printf("Bye message: \"%-25s\".\n", bye
);
213 fprintf(stderr
, "# Hello is at address 0x%08lx\n", (long) hello
);
214 fprintf(stderr
, "# Hello is at address %p\n", hello
);
217 unsigned short us
= (unsigned short) -1;
219 printf("s = %hd\n", s
);
220 printf("us = %hu\n", us
);
223 printf("Goodbye cruel world. Really.\n");
224 fprintf(stderr
, "My pid is %d\n", getpid());
231 static char const hello
[] = "Hello from SimpleMain\n";
233 write(1, hello
, -1 + sizeof(hello
));
237 int main(int argc
, char *argv
[], char **ep
)
240 printf("you must specify a file to read\n");
244 return NaClMain(argv
[1]);
250 void test_start(char *arg
, ...)
257 argc
= *(int *)(argv
-1);
258 envp
= argv
+ argc
+ 1;
262 exit(main(argc
, argv
, envp
));