OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2012 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can | |
4 * be found in the LICENSE file. | |
5 * Copyright 2012, Google Inc. | |
6 */ | |
7 | |
8 /* | |
9 * A simple test for AddressSet. | |
10 */ | |
11 | |
12 #include <stdio.h> | |
13 #include <stdlib.h> | |
14 | |
15 #include "native_client/src/include/portability.h" | |
16 #include "native_client/src/include/nacl_macros.h" | |
17 #include "native_client/src/trusted/validator_mips/address_set.h" | |
18 | |
19 using nacl_mips_val::AddressSet; | |
Brad Chen
2012/05/04 22:49:50
Please avoid using "using", as per the style guide
petarj
2012/05/08 14:54:19
validator_arm/address_set_test.cc has it, so we as
Derek Schuff
2012/05/08 15:59:15
According to the style guide, 'using' is ok for a
| |
20 | |
21 static void test_mutation() { | |
22 uint32_t base = 0x1234; | |
23 uint32_t size = 0x1000; | |
24 AddressSet as(base, size); | |
25 | |
26 as.add(0x1200); // Becomes a no-op | |
27 as.add(base + (31 * 4)); // Added | |
28 as.add(0x1240); // Added | |
29 as.add(0x1230); // No-op | |
30 as.add(base+size); // No-op | |
31 as.add(0x1235); // Added as 1234 | |
32 as.add(0x1238); // Added | |
33 as.add(0x2000); // Added | |
34 as.add(base+size + 100); // No-op | |
35 as.add(0x1400); // Added | |
36 | |
37 // Successful additions in ascending order: | |
38 uint32_t expected[] = { 0x1234, 0x1238, 0x1240, base+(31*4), 0x1400, 0x2000 }; | |
39 for (uint32_t i = 0; i < NACL_ARRAY_SIZE(expected); i++) { | |
40 if (!as.contains(expected[i])) { | |
41 fprintf(stderr, "Set should contain %08X, does not.\n", expected[i]); | |
42 abort(); | |
Brad Chen
2012/05/04 22:49:50
Please add a TODO(petarj) comment someplace that s
| |
43 } | |
44 } | |
45 | |
46 uint32_t x = 0; | |
47 for (AddressSet::Iterator it = as.begin(); it != as.end(); ++it, ++x) { | |
48 if (*it != expected[x]) { | |
49 fprintf(stderr, "At %" NACL_PRIu32 ": expecting %08X, got %08X\n", | |
50 x, expected[x], *it); | |
51 abort(); | |
52 } | |
53 } | |
54 if (x != NACL_ARRAY_SIZE(expected)) { | |
55 fprintf(stderr, "Expected iterator to step %" NACL_PRIuS | |
56 " times, got %" NACL_PRIu32 "\n", | |
57 NACL_ARRAY_SIZE(expected), x); | |
58 abort(); | |
59 } | |
60 | |
61 // Unsuccessful additions: | |
62 uint32_t unexpected[] = { 0x1200, 0x1230, base+size, base+size+100 }; | |
63 for (uint32_t i = 0; i < NACL_ARRAY_SIZE(unexpected); i++) { | |
64 if (as.contains(unexpected[i])) { | |
65 fprintf(stderr, "Set should not contain %08X.\n", unexpected[i]); | |
66 abort(); | |
67 } | |
68 } | |
69 } | |
70 | |
71 int main() { | |
72 test_mutation(); | |
73 puts("Tests successful."); | |
74 return 0; | |
75 } | |
OLD | NEW |