jdk

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

24
#include "precompiled.hpp"
25
#ifndef _WIN32
26
#include "runtime/os.hpp"
27
#include "utilities/ostream.hpp"
28
#include "unittest.hpp"
29

30
#include <errno.h>
31
#include <signal.h>
32
#include <stdio.h>
33
#include <sys/ucontext.h>
34
#include <string.h>
35

36
extern "C" {
37
  static void sig_handler(int sig) {
38
    printf( " HANDLER (1) " );
39
  }
40
}
41

42
class PosixSignalTest : public ::testing::Test {
43
  public:
44

45
  static void check_handlers() {
46
    struct sigaction act, old_SIGFPE_act, old_SIGILL_act;
47
    act.sa_handler = sig_handler;
48
    sigemptyset(&act.sa_mask);
49
    act.sa_flags = 0;
50
    ASSERT_NE(sigaction(SIGFPE, &act, &old_SIGFPE_act), -1) << "Setting SIGFPE handler failed: " << os::strerror(errno) << " (" << errno << ")";
51
    ASSERT_NE(sigaction(SIGILL, &act, &old_SIGILL_act), -1) << "Setting SIGILL handler failed: " <<  os::strerror(errno) << " (" << errno << ")";
52

53
    // Use local stringStream to capture output from run_periodic_checks() calls to
54
    // print_signal_handlers().
55
    stringStream st;
56
    os::run_periodic_checks(&st);
57
    char* res = (char *)st.base(); // res can't be const because some strstr()'s have non-const first args.
58

59
    // Restore signal handlers.
60
    ASSERT_NE(sigaction(SIGFPE, &act, &old_SIGFPE_act), -1) << "Restoring SIGFPE handler failed: " << os::strerror(errno) << " (" << errno << ")";
61
    ASSERT_NE(sigaction(SIGILL, &act, &old_SIGILL_act), -1) << "Restoring SIGILL handler failed: " << os::strerror(errno) << " (" << errno << ")";
62

63
    // Check that "Handler was modified" occurs exactly twice in the tty output.
64
    char* modified = strstr(res, "Handler was modified!");
65
    ASSERT_NE(modified, nullptr) << "No message found";
66

67
    modified = strstr(modified + 1, "Handler was modified!");
68
    ASSERT_NE(modified, nullptr) << "Only one message found";
69
    ASSERT_EQ(strstr(modified + 1, "Handler was modified!"), nullptr) << "Too many messages found";
70
  }
71
};
72

73
// This tests the fix for JDK-8285792.
74
TEST_OTHER_VM(PosixSignalTest, check_handlers) {
75
  PosixSignalTest::check_handlers();
76
}
77

78
#endif
79

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

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

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

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