jdk

Форк
0
/
testutils.cpp 
69 строк · 2.4 Кб
1
/*
2
 * Copyright (c) 2021, 2023 SAP SE. All rights reserved.
3
 * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
 *
6
 * This code is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License version 2 only, as
8
 * published by the Free Software Foundation.
9
 *
10
 * This code is distributed in the hope that it will be useful, but WITHOUT
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
 * version 2 for more details (a copy is included in the LICENSE file that
14
 * accompanied this code).
15
 *
16
 * You should have received a copy of the GNU General Public License version
17
 * 2 along with this work; if not, write to the Free Software Foundation,
18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
 *
20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
 * or visit www.oracle.com if you need additional information or have any
22
 * questions.
23
 */
24

25
#include "precompiled.hpp"
26
#include "runtime/os.hpp"
27
#include "utilities/align.hpp"
28
#include "utilities/ostream.hpp"
29

30
#include "testutils.hpp"
31
#include "unittest.hpp"
32

33
#include <string.h>
34

35
// Note: these could be made more suitable for covering large ranges (e.g. just mark one byte per page).
36

37
void GtestUtils::mark_range_with(void* p, size_t s, uint8_t mark) {
38
  if (p != nullptr && s > 0) {
39
    ::memset(p, mark, s);
40
  }
41
}
42

43
bool GtestUtils::is_range_marked(const void* p, size_t s, uint8_t expected) {
44
  if (p == nullptr || s == 0) {
45
    return true;
46
  }
47

48
  const char* first_wrong = nullptr;
49
  char* p2 = (char*)p;
50
  const char* const end = p2 + s;
51
  while (p2 < end) {
52
    if (*p2 != (char)expected) {
53
      first_wrong = p2;
54
      break;
55
    }
56
    p2 ++;
57
  }
58

59
  if (first_wrong != nullptr) {
60
    tty->print_cr("check_range [" PTR_FORMAT ".." PTR_FORMAT "), 0x%X, : wrong pattern around " PTR_FORMAT,
61
                  p2i(p), p2i(p) + s, expected, p2i(first_wrong));
62
    // Note: We deliberately print the surroundings too without bounds check. Might be interesting,
63
    // and os::print_hex_dump uses SafeFetch, so this is fine without bounds checks.
64
    os::print_hex_dump(tty, (address)(align_down(p2, 0x10) - 0x10),
65
                            (address)(align_up(end, 0x10) + 0x10), 1);
66
  }
67

68
  return first_wrong == nullptr;
69
}
70

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.