26 fatal_helper_env = os.environ.get(
"FOLLY_FATAL_HELPER")
30 build_dir = os.path.join(os.getcwd(),
"buck-out",
"gen")
31 self.
helper = os.path.join(
32 build_dir,
"folly",
"logging",
"test",
"fatal_helper" 36 """Run the helper and verify it crashes. 38 Check that it crashes with SIGABRT and prints nothing on stdout. 39 Returns the data printed to stderr. 42 self.assertEqual(returncode, -signal.SIGABRT)
43 self.assertEqual(out, b
"")
49 Returns a tuple of [returncode, stdout_output, stderr_output] 51 env = kwargs.pop(
"env",
None)
53 raise TypeError(
"unexpected keyword arguments: %r" % (
list(kwargs.keys())))
58 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env
60 out, err = p.communicate()
61 return p.returncode, out, err
65 self.assertEqual(b
"", err)
66 self.assertEqual(0, returncode)
67 if out.strip() == b
"DEBUG=1":
69 elif out.strip() == b
"DEBUG=0":
72 self.fail(
"unexpected output from --check_debug: {}".
format(out))
76 prefix = br
"^F[0-9]{4} .* FatalHelper.cpp:[0-9]+\] " 78 prefix = br
"^FATAL:.*FatalHelper.cpp:[0-9]+: " 79 regex = prefix + re.escape(msg) + b
"$" 80 return re.compile(regex, re.MULTILINE)
86 self.assertEqual(0, returncode)
87 self.assertEqual(b
"", out)
88 self.assertEqual(b
"", err)
91 handler_setings =
"default=stream:stream=stderr,async=true" 92 err = self.
run_helper(
"--logging=;" + handler_setings)
96 handler_setings =
"default=stream:stream=stderr,async=false" 97 err = self.
run_helper(
"--logging=;" + handler_setings)
107 err = self.
run_helper(
"--category=foo.bar",
"--logging",
".=FATAL")
109 br
"^F[0-9]{4} .* FatalHelper.cpp:[0-9]+\] " 110 br
"crashing to category foo\.bar$",
113 self.assertRegex(err, regex)
116 err = self.
run_helper(env={
"CRASH_DURING_INIT":
"1"})
117 regex = self.
get_crash_regex(br
"crashing during static initialization")
118 self.assertRegex(err, regex)
121 err = self.
run_helper(
"--crash=no", env={
"CRASH_DURING_INIT":
"shutdown"})
127 br
"^(FATAL|C[0-9]{4}).*FatalHelper.cpp:.* " 128 br
"crashing during static destruction$",
131 self.assertRegex(err, regex)
136 err = self.
run_helper(
"--fail_fatal_xlog_if",
"--crash=no")
137 self.assertRegex(err, self.
get_crash_regex(b
"--fail_fatal_xlog_if specified!"))
141 "--fail_dfatal_xlog_if",
"--crash=no" 145 self.assertRegex(err, self.
get_crash_regex(b
"--fail_dfatal_xlog_if specified!"))
146 self.assertEqual(b
"", out)
148 self.assertEqual(-signal.SIGABRT, returncode)
150 self.assertEqual(0, returncode)
155 err = self.
run_helper(
"--fail_xcheck",
"--crash=no")
159 b
"Check failed: !FLAGS_fail_xcheck : --fail_xcheck specified!" 164 err = self.
run_helper(
"--fail_xcheck_nomsg",
"--crash=no")
171 self.assertEqual(b
"", out)
176 b
"Check failed: !FLAGS_fail_xdcheck : --fail_xdcheck specified!" 179 self.assertEqual(-signal.SIGABRT, returncode)
181 self.assertEqual(b
"", err)
182 self.assertEqual(0, returncode)
def run_helper(self, args, kwargs)
def test_static_destruction(self)
def test_other_category(self)
def test_dfatal_xlog_if(self)
def run_helper_nochecks(self, args, kwargs)
def test_xcheck_nomsg(self)
Encoder::MutableCompressedList list
def test_fatal_xlog_if(self)
def test_static_init(self)
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
def get_crash_regex(self, msg=b"test program crashing!", glog=True)