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

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: Rebased patch, conflict resolved. Created 8 years, 7 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
« no previous file with comments | « src/trusted/validator_mips/address_set.cc ('k') | src/trusted/validator_mips/build.scons » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 100644
index 0000000000000000000000000000000000000000..01445c7898de26f7733c2ec132018ad7d0d708df
--- /dev/null
+++ b/src/trusted/validator_mips/address_set_test.cc
@@ -0,0 +1,77 @@
+/*
+ * 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 <vector>
+#include <string>
+#include <sstream>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "gtest/gtest.h"
+#include "native_client/src/include/nacl_macros.h"
+#include "native_client/src/include/portability.h"
+#include "native_client/src/trusted/validator_mips/address_set.h"
+
+using nacl_mips_val::AddressSet;
+
+
+class AddressTests : public ::testing::Test {
+};
+
+TEST_F(AddressTests, TestMutation) {
+ 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++) {
+ EXPECT_TRUE(as.Contains(expected[i])) << "Set should contain "
+ << std::hex << expected[i]
+ << ", does not.";
+ }
+
+ uint32_t x = 0;
+ for (AddressSet::Iterator it = as.Begin(); !it.Equals(as.End());
+ it.Next(), ++x) {
+ EXPECT_EQ(it.GetAddress(), expected[x]) << "At " << x
+ << "\n Expected: " << std::hex
+ << expected[x]
+ << "\n Actual: " << std::hex
+ << it.GetAddress();
+ }
+ EXPECT_EQ(x, NACL_ARRAY_SIZE(expected)) << "Expected iterator to step"
+ << NACL_ARRAY_SIZE(expected)
+ << " times \n" << "Actual: " << x;
+
+ // Unsuccessful additions:
+ uint32_t unexpected[] = { 0x1200, 0x1230, base+size, base+size+100 };
+ for (uint32_t i = 0; i < NACL_ARRAY_SIZE(unexpected); i++) {
+ EXPECT_FALSE(as.Contains(unexpected[i])) << "Set should not contain "
+ << std::hex << unexpected[i];
+ }
+}
+
+int main(int argc, char *argv[]) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
« no previous file with comments | « src/trusted/validator_mips/address_set.cc ('k') | src/trusted/validator_mips/build.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698