Home | History | Annotate | Download | only in unit
      1 //===-- tsan_vector_test.cc -----------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file is a part of ThreadSanitizer (TSan), a race detector.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 #include "tsan_vector.h"
     14 #include "tsan_rtl.h"
     15 #include "gtest/gtest.h"
     16 
     17 namespace __tsan {
     18 
     19 TEST(Vector, Basic) {
     20   ScopedInRtl in_rtl;
     21   Vector<int> v(MBlockScopedBuf);
     22   EXPECT_EQ(v.Size(), (uptr)0);
     23   v.PushBack(42);
     24   EXPECT_EQ(v.Size(), (uptr)1);
     25   EXPECT_EQ(v[0], 42);
     26   v.PushBack(43);
     27   EXPECT_EQ(v.Size(), (uptr)2);
     28   EXPECT_EQ(v[0], 42);
     29   EXPECT_EQ(v[1], 43);
     30 }
     31 
     32 TEST(Vector, Stride) {
     33   ScopedInRtl in_rtl;
     34   Vector<int> v(MBlockScopedBuf);
     35   for (int i = 0; i < 1000; i++) {
     36     v.PushBack(i);
     37     EXPECT_EQ(v.Size(), (uptr)(i + 1));
     38     EXPECT_EQ(v[i], i);
     39   }
     40   for (int i = 0; i < 1000; i++) {
     41     EXPECT_EQ(v[i], i);
     42   }
     43 }
     44 
     45 }  // namespace __tsan
     46