tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

prefetch_test.cc (2512B)


      1 // Copyright 2023 The Abseil Authors
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     https://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 #include "absl/base/prefetch.h"
     16 
     17 #include <memory>
     18 
     19 #include "gtest/gtest.h"
     20 
     21 namespace {
     22 
     23 // Below tests exercise the functions only to guarantee they compile and execute
     24 // correctly. We make no attempt at verifying any prefetch instructions being
     25 // generated and executed: we assume the various implementation in terms of
     26 // __builtin_prefetch() or x86 intrinsics to be correct and well tested.
     27 
     28 TEST(PrefetchTest, PrefetchToLocalCache_StackA) {
     29  char buf[100] = {};
     30  absl::PrefetchToLocalCache(buf);
     31  absl::PrefetchToLocalCacheNta(buf);
     32  absl::PrefetchToLocalCacheForWrite(buf);
     33 }
     34 
     35 TEST(PrefetchTest, PrefetchToLocalCache_Heap) {
     36  auto memory = std::make_unique<char[]>(200 << 10);
     37  memset(memory.get(), 0, 200 << 10);
     38  absl::PrefetchToLocalCache(memory.get());
     39  absl::PrefetchToLocalCacheNta(memory.get());
     40  absl::PrefetchToLocalCacheForWrite(memory.get());
     41  absl::PrefetchToLocalCache(memory.get() + (50 << 10));
     42  absl::PrefetchToLocalCacheNta(memory.get() + (50 << 10));
     43  absl::PrefetchToLocalCacheForWrite(memory.get() + (50 << 10));
     44  absl::PrefetchToLocalCache(memory.get() + (100 << 10));
     45  absl::PrefetchToLocalCacheNta(memory.get() + (100 << 10));
     46  absl::PrefetchToLocalCacheForWrite(memory.get() + (100 << 10));
     47  absl::PrefetchToLocalCache(memory.get() + (150 << 10));
     48  absl::PrefetchToLocalCacheNta(memory.get() + (150 << 10));
     49  absl::PrefetchToLocalCacheForWrite(memory.get() + (150 << 10));
     50 }
     51 
     52 TEST(PrefetchTest, PrefetchToLocalCache_Nullptr) {
     53  absl::PrefetchToLocalCache(nullptr);
     54  absl::PrefetchToLocalCacheNta(nullptr);
     55  absl::PrefetchToLocalCacheForWrite(nullptr);
     56 }
     57 
     58 TEST(PrefetchTest, PrefetchToLocalCache_InvalidPtr) {
     59  absl::PrefetchToLocalCache(reinterpret_cast<const void*>(0x785326532L));
     60  absl::PrefetchToLocalCacheNta(reinterpret_cast<const void*>(0x785326532L));
     61  absl::PrefetchToLocalCacheForWrite(reinterpret_cast<const void*>(0x78532L));
     62 }
     63 
     64 }  // namespace