Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1273)

Unified Diff: src/trusted/validator_mips/address_set_test.cc

Issue 9979025: [MIPS] Adding validator for MIPS architecture. (Closed) Base URL: http://src.chromium.org/native_client/trunk/src/native_client/
Patch Set: Minor style changes. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/trusted/validator_mips/address_set_test.cc
diff --git a/src/trusted/validator_mips/address_set_test.cc b/src/trusted/validator_mips/address_set_test.cc
new file mode 100755
index 0000000000000000000000000000000000000000..6b1eb01ddde0cfce6a4b10e354054b3248af8ad9
--- /dev/null
+++ b/src/trusted/validator_mips/address_set_test.cc
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2012 The Native Client Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can
+ * be found in the LICENSE file.
+ * Copyright 2012, Google Inc.
+ */
+
+/*
+ * A simple test for AddressSet.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "native_client/src/include/portability.h"
+#include "native_client/src/include/nacl_macros.h"
+#include "native_client/src/trusted/validator_mips/address_set.h"
+
+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
+
+static void test_mutation() {
+ uint32_t base = 0x1234;
+ uint32_t size = 0x1000;
+ AddressSet as(base, size);
+
+ as.add(0x1200); // Becomes a no-op
+ as.add(base + (31 * 4)); // Added
+ as.add(0x1240); // Added
+ as.add(0x1230); // No-op
+ as.add(base+size); // No-op
+ as.add(0x1235); // Added as 1234
+ as.add(0x1238); // Added
+ as.add(0x2000); // Added
+ as.add(base+size + 100); // No-op
+ as.add(0x1400); // Added
+
+ // Successful additions in ascending order:
+ uint32_t expected[] = { 0x1234, 0x1238, 0x1240, base+(31*4), 0x1400, 0x2000 };
+ for (uint32_t i = 0; i < NACL_ARRAY_SIZE(expected); i++) {
+ if (!as.contains(expected[i])) {
+ fprintf(stderr, "Set should contain %08X, does not.\n", expected[i]);
+ abort();
Brad Chen 2012/05/04 22:49:50 Please add a TODO(petarj) comment someplace that s
+ }
+ }
+
+ uint32_t x = 0;
+ for (AddressSet::Iterator it = as.begin(); it != as.end(); ++it, ++x) {
+ if (*it != expected[x]) {
+ fprintf(stderr, "At %" NACL_PRIu32 ": expecting %08X, got %08X\n",
+ x, expected[x], *it);
+ abort();
+ }
+ }
+ if (x != NACL_ARRAY_SIZE(expected)) {
+ fprintf(stderr, "Expected iterator to step %" NACL_PRIuS
+ " times, got %" NACL_PRIu32 "\n",
+ NACL_ARRAY_SIZE(expected), x);
+ abort();
+ }
+
+ // Unsuccessful additions:
+ uint32_t unexpected[] = { 0x1200, 0x1230, base+size, base+size+100 };
+ for (uint32_t i = 0; i < NACL_ARRAY_SIZE(unexpected); i++) {
+ if (as.contains(unexpected[i])) {
+ fprintf(stderr, "Set should not contain %08X.\n", unexpected[i]);
+ abort();
+ }
+ }
+}
+
+int main() {
+ test_mutation();
+ puts("Tests successful.");
+ return 0;
+}

Powered by Google App Engine
This is Rietveld 408576698