this repo has no description
at trunk 60 lines 1.8 kB view raw
1// Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) 2#include <stdlib.h> 3 4#include <csignal> 5 6#include "gtest/gtest.h" 7 8#include "builtins.h" 9#include "file.h" 10#include "os.h" 11#include "runtime.h" 12#include "test-utils.h" 13 14namespace py { 15namespace testing { 16 17using FaulthandlerModuleDeathTest = RuntimeFixture; 18using FaulthandlerModuleTest = RuntimeFixture; 19 20TEST_F(FaulthandlerModuleTest, DumpTracebackWritesToFileDescriptor) { 21 TemporaryDirectory tempdir; 22 std::string temp_file = tempdir.path + "traceback"; 23 int fd = 24 File::open(temp_file.c_str(), File::kCreate | File::kWriteOnly, 0777); 25 ASSERT_NE(fd, -1); 26 27 HandleScope scope(thread_); 28 Object file(&scope, SmallInt::fromWord(fd)); 29 Object all_threads(&scope, Bool::falseObj()); 30 Object result(&scope, runBuiltin(FUNC(faulthandler, dump_traceback), file, 31 all_threads)); 32 ASSERT_TRUE(result.isNoneType()); 33 ASSERT_EQ(File::close(fd), 0); 34 35 word length; 36 FILE* fp = std::fopen(temp_file.c_str(), "r"); 37 unique_c_ptr<byte> actual(OS::readFile(fp, &length)); 38 std::fclose(fp); 39 char expected[] = R"(Stack (most recent call first): 40 File "", line ??? in <anonymous> 41)"; 42 43 word expected_length = std::strlen(expected); 44 ASSERT_EQ(length, expected_length); 45 EXPECT_EQ(std::memcmp(actual.get(), expected, expected_length), 0); 46} 47 48TEST_F(FaulthandlerModuleTest, DumpTracebackHandlesPendingSignal) { 49 HandleScope scope(thread_); 50 Object file(&scope, SmallInt::fromWord(File::kStderr)); 51 Object all_threads(&scope, Bool::falseObj()); 52 53 runtime_->setPendingSignal(thread_, SIGINT); 54 EXPECT_TRUE( 55 raised(runBuiltin(FUNC(faulthandler, dump_traceback), file, all_threads), 56 LayoutId::kKeyboardInterrupt)); 57} 58 59} // namespace testing 60} // namespace py