2012-01-16 12:28:10 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
2011-10-05 05:20:07 +00:00
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2012-01-17 10:29:24 +00:00
|
|
|
#include "platform/assert.h"
|
|
|
|
|
2018-04-27 23:30:48 +00:00
|
|
|
#include "include/dart_api.h"
|
2012-01-16 13:23:40 +00:00
|
|
|
#include "platform/globals.h"
|
2019-04-22 20:15:43 +00:00
|
|
|
#include "platform/syslog.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
2018-05-03 17:59:44 +00:00
|
|
|
bool Expect::failed_ = false;
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2018-05-03 17:59:44 +00:00
|
|
|
void DynamicAssertionHelper::Print(const char* format, va_list arguments) {
|
2016-06-21 19:50:43 +00:00
|
|
|
// Take only the last 1KB of the file name if it is longer.
|
|
|
|
const intptr_t file_len = strlen(file_);
|
|
|
|
const intptr_t file_offset = (file_len > (1 * KB)) ? file_len - (1 * KB) : 0;
|
|
|
|
const char* file = file_ + file_offset;
|
|
|
|
|
|
|
|
// Print the file and line number into the buffer.
|
|
|
|
char buffer[4 * KB];
|
2016-10-05 23:54:18 +00:00
|
|
|
MSAN_UNPOISON(buffer, sizeof(buffer));
|
2016-06-21 19:50:43 +00:00
|
|
|
intptr_t file_and_line_length =
|
|
|
|
snprintf(buffer, sizeof(buffer), "%s: %d: error: ", file, line_);
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2016-06-21 19:50:43 +00:00
|
|
|
// Print the error message into the buffer.
|
|
|
|
vsnprintf(buffer + file_and_line_length,
|
2016-11-03 21:25:16 +00:00
|
|
|
sizeof(buffer) - file_and_line_length, format, arguments);
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2016-07-08 21:18:44 +00:00
|
|
|
// Print the buffer on stderr and/or syslog.
|
2019-04-22 20:15:43 +00:00
|
|
|
Syslog::PrintErr("%s\n", buffer);
|
2018-05-03 17:59:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Assert::Fail(const char* format, ...) {
|
|
|
|
va_list arguments;
|
|
|
|
va_start(arguments, format);
|
|
|
|
Print(format, arguments);
|
|
|
|
va_end(arguments);
|
|
|
|
|
|
|
|
// Abort right away.
|
2018-09-04 21:16:39 +00:00
|
|
|
Dart_DumpNativeStackTrace(NULL);
|
2019-04-22 20:15:43 +00:00
|
|
|
Dart_PrepareToAbort();
|
|
|
|
abort();
|
2018-05-03 17:59:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Expect::Fail(const char* format, ...) {
|
|
|
|
va_list arguments;
|
|
|
|
va_start(arguments, format);
|
|
|
|
Print(format, arguments);
|
|
|
|
va_end(arguments);
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2018-05-03 17:59:44 +00:00
|
|
|
// Wait until the program is exiting before producing a non-zero exit
|
2011-10-05 05:20:07 +00:00
|
|
|
// code through abort.
|
2016-09-06 17:10:40 +00:00
|
|
|
failed_ = true;
|
2011-10-05 05:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dart
|