2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2019-06-10 22:03:15 -07:00
|
|
|
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/Utility.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-07-08 14:17:21 -07:00
|
|
|
#ifndef _WIN32
|
2016-05-20 17:30:37 -07:00
|
|
|
#include <cxxabi.h>
|
|
|
|
|
#include <execinfo.h>
|
2017-07-08 14:17:21 -07:00
|
|
|
#endif
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2017-07-08 14:17:21 -07:00
|
|
|
#include <cstdio>
|
2016-09-21 23:48:54 -07:00
|
|
|
#include <cstdlib>
|
2016-11-01 20:12:08 -07:00
|
|
|
#include <cstring>
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <hal/DriverStation.h>
|
2019-11-08 22:53:20 -08:00
|
|
|
#include <hal/FRCUsageReporting.h>
|
2018-04-29 23:33:19 -07:00
|
|
|
#include <wpi/Path.h>
|
|
|
|
|
#include <wpi/SmallString.h>
|
2019-08-12 23:45:45 -07:00
|
|
|
#include <wpi/StackTrace.h>
|
2018-04-29 23:33:19 -07:00
|
|
|
#include <wpi/raw_ostream.h>
|
2017-12-01 22:12:50 -08:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/ErrorBase.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
bool wpi_assert_impl(bool conditionValue, const wpi::Twine& conditionText,
|
|
|
|
|
const wpi::Twine& message, wpi::StringRef fileName,
|
|
|
|
|
int lineNumber, wpi::StringRef funcName) {
|
2015-06-25 15:07:55 -04:00
|
|
|
if (!conditionValue) {
|
2018-04-29 23:33:19 -07:00
|
|
|
wpi::SmallString<128> locBuf;
|
|
|
|
|
wpi::raw_svector_ostream locStream(locBuf);
|
|
|
|
|
locStream << funcName << " [" << wpi::sys::path::filename(fileName) << ":"
|
2017-12-01 22:12:50 -08:00
|
|
|
<< lineNumber << "]";
|
2016-02-04 22:29:11 -08:00
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
wpi::SmallString<128> errorBuf;
|
|
|
|
|
wpi::raw_svector_ostream errorStream(errorBuf);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
errorStream << "Assertion \"" << conditionText << "\" ";
|
|
|
|
|
|
2017-12-01 22:12:50 -08:00
|
|
|
if (message.isTriviallyEmpty() ||
|
|
|
|
|
(message.isSingleStringRef() && message.getSingleStringRef().empty())) {
|
2017-05-15 23:10:40 -07:00
|
|
|
errorStream << "failed.\n";
|
2017-12-01 22:12:50 -08:00
|
|
|
} else {
|
|
|
|
|
errorStream << "failed: " << message << "\n";
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-12 23:45:45 -07:00
|
|
|
std::string stack = wpi::GetStackTrace(2);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
// Print the error and send it to the DriverStation
|
2017-12-01 22:12:50 -08:00
|
|
|
HAL_SendError(1, 1, 0, errorBuf.c_str(), locBuf.c_str(), stack.c_str(), 1);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return conditionValue;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-16 00:33:51 -08:00
|
|
|
* Common error routines for wpi_assertEqual_impl and wpi_assertNotEqual_impl.
|
|
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* This should not be called directly; it should only be used by
|
2016-05-20 17:30:37 -07:00
|
|
|
* wpi_assertEqual_impl and wpi_assertNotEqual_impl.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
void wpi_assertEqual_common_impl(const wpi::Twine& valueA,
|
|
|
|
|
const wpi::Twine& valueB,
|
|
|
|
|
const wpi::Twine& equalityType,
|
|
|
|
|
const wpi::Twine& message,
|
|
|
|
|
wpi::StringRef fileName, int lineNumber,
|
|
|
|
|
wpi::StringRef funcName) {
|
|
|
|
|
wpi::SmallString<128> locBuf;
|
|
|
|
|
wpi::raw_svector_ostream locStream(locBuf);
|
|
|
|
|
locStream << funcName << " [" << wpi::sys::path::filename(fileName) << ":"
|
2017-12-01 22:12:50 -08:00
|
|
|
<< lineNumber << "]";
|
2016-02-04 22:29:11 -08:00
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
wpi::SmallString<128> errorBuf;
|
|
|
|
|
wpi::raw_svector_ostream errorStream(errorBuf);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
errorStream << "Assertion \"" << valueA << " " << equalityType << " "
|
|
|
|
|
<< valueB << "\" ";
|
|
|
|
|
|
2017-12-01 22:12:50 -08:00
|
|
|
if (message.isTriviallyEmpty() ||
|
|
|
|
|
(message.isSingleStringRef() && message.getSingleStringRef().empty())) {
|
2017-05-15 23:10:40 -07:00
|
|
|
errorStream << "failed.\n";
|
2017-12-01 22:12:50 -08:00
|
|
|
} else {
|
|
|
|
|
errorStream << "failed: " << message << "\n";
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-12 23:45:45 -07:00
|
|
|
std::string trace = wpi::GetStackTrace(3);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
// Print the error and send it to the DriverStation
|
2017-12-01 22:12:50 -08:00
|
|
|
HAL_SendError(1, 1, 0, errorBuf.c_str(), locBuf.c_str(), trace.c_str(), 1);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2017-12-01 22:12:50 -08:00
|
|
|
bool wpi_assertEqual_impl(int valueA, int valueB,
|
2018-04-29 23:33:19 -07:00
|
|
|
const wpi::Twine& valueAString,
|
|
|
|
|
const wpi::Twine& valueBString,
|
|
|
|
|
const wpi::Twine& message, wpi::StringRef fileName,
|
|
|
|
|
int lineNumber, wpi::StringRef funcName) {
|
2015-06-25 15:07:55 -04:00
|
|
|
if (!(valueA == valueB)) {
|
|
|
|
|
wpi_assertEqual_common_impl(valueAString, valueBString, "==", message,
|
|
|
|
|
fileName, lineNumber, funcName);
|
|
|
|
|
}
|
|
|
|
|
return valueA == valueB;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-12-20 22:08:24 -08:00
|
|
|
bool wpi_assertNotEqual_impl(int valueA, int valueB,
|
2018-04-29 23:33:19 -07:00
|
|
|
const wpi::Twine& valueAString,
|
|
|
|
|
const wpi::Twine& valueBString,
|
2018-05-13 17:09:56 -07:00
|
|
|
const wpi::Twine& message, wpi::StringRef fileName,
|
|
|
|
|
int lineNumber, wpi::StringRef funcName) {
|
2015-06-25 15:07:55 -04:00
|
|
|
if (!(valueA != valueB)) {
|
|
|
|
|
wpi_assertEqual_common_impl(valueAString, valueBString, "!=", message,
|
|
|
|
|
fileName, lineNumber, funcName);
|
|
|
|
|
}
|
|
|
|
|
return valueA != valueB;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|