diff options
Diffstat (limited to 'indra/test')
| -rw-r--r-- | indra/test/CMakeLists.txt | 3 | ||||
| -rwxr-xr-x | indra/test/blowfish.1.bin | 1 | ||||
| -rwxr-xr-x | indra/test/blowfish.2.bin | bin | 40 -> 0 bytes | |||
| -rw-r--r-- | indra/test/blowfish.digits.txt | 1 | ||||
| -rwxr-xr-x | indra/test/blowfish.pl | 79 | ||||
| -rw-r--r-- | indra/test/llblowfish_tut.cpp | 141 | ||||
| -rw-r--r-- | indra/test/llevents_tut.cpp | 31 | ||||
| -rw-r--r-- | indra/test/llhttpdate_tut.cpp | 7 | ||||
| -rw-r--r-- | indra/test/lltut.h | 2 | ||||
| -rw-r--r-- | indra/test/test.cpp | 82 |
10 files changed, 91 insertions, 256 deletions
diff --git a/indra/test/CMakeLists.txt b/indra/test/CMakeLists.txt index 745c0eedf8..246fc5e6f8 100644 --- a/indra/test/CMakeLists.txt +++ b/indra/test/CMakeLists.txt @@ -13,7 +13,6 @@ include(bugsplat) set(test_SOURCE_FILES io.cpp llapp_tut.cpp - llblowfish_tut.cpp llbuffer_tut.cpp lldoubledispatch_tut.cpp llevents_tut.cpp @@ -114,7 +113,7 @@ if (LL_TESTS) # but the CMake $<TARGET_FILE_DIR> generator expression isn't evaluated by # CREATE_LINK, so fudge it. add_custom_command( TARGET lltest POST_BUILD - COMMAND cmake -E create_symlink ${SHARED_LIB_STAGING_DIR} ${CMAKE_BINARY_DIR}/test/Resources + COMMAND ${CMAKE_COMMAND} -E create_symlink ${SHARED_LIB_STAGING_DIR} ${CMAKE_BINARY_DIR}/test/Resources ) endif() endif (LL_TESTS) diff --git a/indra/test/blowfish.1.bin b/indra/test/blowfish.1.bin deleted file mode 100755 index 61286e45e3..0000000000 --- a/indra/test/blowfish.1.bin +++ /dev/null @@ -1 +0,0 @@ -.A„Ä3ŒLÜE ``òøÝKÛ@¼ûÇ;M[ÚBë·ø„>ËÊC—'
\ No newline at end of file diff --git a/indra/test/blowfish.2.bin b/indra/test/blowfish.2.bin Binary files differdeleted file mode 100755 index ef72d96bbf..0000000000 --- a/indra/test/blowfish.2.bin +++ /dev/null diff --git a/indra/test/blowfish.digits.txt b/indra/test/blowfish.digits.txt deleted file mode 100644 index fce1fed943..0000000000 --- a/indra/test/blowfish.digits.txt +++ /dev/null @@ -1 +0,0 @@ -01234567890123456789012345678901234 diff --git a/indra/test/blowfish.pl b/indra/test/blowfish.pl deleted file mode 100755 index 30f41dcd4c..0000000000 --- a/indra/test/blowfish.pl +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/perl -# -# Test Perl Crypt::CBC Blowfish algorithm and initial parameter settings -# for compatibility with OpenSSL's Blowfish algorithm/settings. -# -# Used by outbound LSL email (openssl C library) and mailglue (Perl library) -use strict; -use warnings; - -# *TODO: specify test count here -use Test::More qw(no_plan); - -use Crypt::CBC; -use MIME::Base64; - -my $init_vector = "\x00" x 8; -# my $key = pack("H*", "ef5a8376eb0c99fe0dafa487d15bec19cae63d1e25fe31d8d92f7ab0398246d70ee733108e47360e16359654571cf5bab6c3375b42cee4fa"); -# my $key = "d263eb8a78034e40"; - #"8d082918aa369174"; -my $key = "\x00" x 16; - -my $cipher = Crypt::CBC->new( { cipher => 'Blowfish', - regenerate_key => 0, - key => $key, - iv => $init_vector, - header => 'none', - prepend_iv => 0, - keysize => 16 } ); - -#my $blocks = $cipher->blocksize(); -#print "blocksize $blocks\n"; - -my $len; -my $input = "01234567890123456789012345678901234\n"; -#my $input = "a whale of a tale I tell you lad, a whale of a tale for me, a whale of a tale and the fiddlers three"; -$len = length($input); -is ($len, 36, "input length"); - -$len = length($key); -is ($len, 16, "key length"); - - -my $encrypted = $cipher->encrypt($input); -is (length($encrypted), 40, "encrypted length"); - -open(FH, "blowfish.1.bin"); -my $bin = scalar <FH>; -is ($encrypted, $bin, "matches openssl"); -close(FH); - -my $base64 = encode_base64($encrypted); -is ($base64, "LkGExDOMTNxFIGBg8gP43UvbQLz7xztNWwYF2kLrtwT4hD7LykOXJw==\n", - "base64 output"); - -my $unbase64 = decode_base64($base64); -is( $encrypted, $unbase64, "reverse base64" ); - -my $output = $cipher->decrypt($unbase64); -is ($input, $output, "reverse encrypt"); - -$key = pack("H[32]", "526a1e07a19dbaed84c4ff08a488d15e"); -$cipher = Crypt::CBC->new( { cipher => 'Blowfish', - regenerate_key => 0, - key => $key, - iv => $init_vector, - header => 'none', - prepend_iv => 0, - keysize => 16 } ); -$encrypted = $cipher->encrypt($input); -is (length($encrypted), 40, "uuid encrypted length"); -$output = $cipher->decrypt($encrypted); -is ($input, $output, "uuid reverse encrypt"); - -open(FH, "blowfish.2.bin"); -$bin = scalar <FH>; -close(FH); -is( $encrypted, $bin, "uuid matches openssl" ); - -print encode_base64($encrypted); diff --git a/indra/test/llblowfish_tut.cpp b/indra/test/llblowfish_tut.cpp deleted file mode 100644 index a8690ccb33..0000000000 --- a/indra/test/llblowfish_tut.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/** - * @file llblowfish_tut.cpp - * @author James Cook, james@lindenlab.com - * @date 2007-02-04 - * - * Data files generated with: - * openssl enc -bf-cbc -in blowfish.digits.txt -out blowfish.1.bin -K 00000000000000000000000000000000 -iv 0000000000000000 -p - * openssl enc -bf-cbc -in blowfish.digits.txt -out blowfish.2.bin -K 526a1e07a19dbaed84c4ff08a488d15e -iv 0000000000000000 -p - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#include "linden_common.h" -#include "lltut.h" - -#include "llblowfishcipher.h" - -#include "lluuid.h" - -namespace tut -{ - class LLData - { - public: - unsigned char* mInput; - int mInputSize; - - LLData() - { - // \n to make it easier to create text files - // for testing with command line openssl - mInput = (unsigned char*)"01234567890123456789012345678901234\n"; - mInputSize = 36; - } - - bool matchFile(const std::string& filename, - const std::string& data) - { - LLFILE* fp = LLFile::fopen(filename, "rb"); - if (!fp) - { - // sometimes test is run inside the indra directory - std::string path = "test/"; - path += filename; - fp = LLFile::fopen(path, "rb"); - } - if (!fp) - { - LL_WARNS() << "unable to open " << filename << LL_ENDL; - return false; - } - - std::string good; - good.resize(256); - size_t got = fread(&good[0], 1, 256, fp); - LL_DEBUGS() << "matchFile read " << got << LL_ENDL; - fclose(fp); - good.resize(got); - - return (good == data); - } - }; - typedef test_group<LLData> blowfish_test; - typedef blowfish_test::object blowfish_object; - // Create test with name that can be selected on - // command line of test app. - tut::blowfish_test blowfish("blowfish"); - - template<> template<> - void blowfish_object::test<1>() - { - LLUUID blank; - LLBlowfishCipher cipher(&blank.mData[0], UUID_BYTES); - - U32 dst_len = cipher.requiredEncryptionSpace(36); - ensure("encryption space 36", - (dst_len == 40) ); - - // Blowfish adds an additional 8-byte block if your - // input is an exact multiple of 8 - dst_len = cipher.requiredEncryptionSpace(8); - ensure("encryption space 8", - (dst_len == 16) ); - } - - template<> template<> - void blowfish_object::test<2>() - { - LLUUID blank; - LLBlowfishCipher cipher(&blank.mData[0], UUID_BYTES); - - std::string result; - result.resize(256); - U32 count = cipher.encrypt(mInput, mInputSize, - (U8*) &result[0], 256); - - ensure("encrypt output count", - (count == 40) ); - result.resize(count); - - ensure("encrypt null key", matchFile("blowfish.1.bin", result)); - } - - template<> template<> - void blowfish_object::test<3>() - { - // same as base64 test id - LLUUID id("526a1e07-a19d-baed-84c4-ff08a488d15e"); - LLBlowfishCipher cipher(&id.mData[0], UUID_BYTES); - - std::string result; - result.resize(256); - U32 count = cipher.encrypt(mInput, mInputSize, - (U8*) &result[0], 256); - - ensure("encrypt output count", - (count == 40) ); - result.resize(count); - - ensure("encrypt real key", matchFile("blowfish.2.bin", result)); - } -} diff --git a/indra/test/llevents_tut.cpp b/indra/test/llevents_tut.cpp index bf5cd3f853..c5d5dcb9d4 100644 --- a/indra/test/llevents_tut.cpp +++ b/indra/test/llevents_tut.cpp @@ -44,15 +44,12 @@ #include <typeinfo> // external library headers #include <boost/bind.hpp> -#include <boost/assign/list_of.hpp> // other Linden headers #include "tests/listener.h" // must PRECEDE lltut.h #include "lltut.h" #include "catch_and_store_what_in.h" #include "stringize.h" -using boost::assign::list_of; - template<typename T> T make(const T& value) { @@ -178,7 +175,7 @@ void events_object::test<2>() LLBoundListener bound0 = listener0.listenTo(per_frame, &Listener::callstop); LLBoundListener bound1 = listener1.listenTo(per_frame, &Listener::call, // after listener0 - make<LLEventPump::NameList>(list_of(listener0.getName()))); + make<LLEventPump::NameList>(LLEventPump::NameList{ listener0.getName() })); ensure("enabled", per_frame.enabled()); ensure("connected 0", bound0.connected()); ensure("unblocked 0", !bound0.blocked()); @@ -278,24 +275,24 @@ void events_object::test<6>() button.listen("Mary", boost::bind(&Collect::add, boost::ref(collector), "Mary", _1), // state that "Mary" must come after "checked" - make<NameList> (list_of("checked"))); + make<NameList>(NameList{ "checked" })); button.listen("checked", boost::bind(&Collect::add, boost::ref(collector), "checked", _1), // "checked" must come after "spot" - make<NameList> (list_of("spot"))); + make<NameList>(NameList{ "spot" })); button.listen("spot", boost::bind(&Collect::add, boost::ref(collector), "spot", _1)); button.post(1); - ensure_equals(collector.result, make<StringVec>(list_of("spot")("checked")("Mary"))); + ensure_equals(collector.result, make<StringVec>(StringVec{ "spot", "checked", "Mary" })); collector.clear(); button.stopListening("Mary"); button.listen("Mary", boost::bind(&Collect::add, boost::ref(collector), "Mary", _1), LLEventPump::empty, // no after dependencies // now "Mary" must come before "spot" - make<NameList>(list_of("spot"))); + make<NameList>(NameList{ "spot" })); button.post(2); - ensure_equals(collector.result, make<StringVec>(list_of("Mary")("spot")("checked"))); + ensure_equals(collector.result, make<StringVec>(StringVec{ "Mary", "spot", "checked" })); collector.clear(); button.stopListening("spot"); std::string threw = catch_what<LLEventPump::Cycle>( @@ -303,7 +300,7 @@ void events_object::test<6>() button.listen("spot", boost::bind(&Collect::add, boost::ref(collector), "spot", _1), // after "Mary" and "checked" -- whoops! - make<NameList>(list_of("Mary")("checked"))); + make<NameList>(NameList{ "Mary", "checked" })); }); // Obviously the specific wording of the exception text can // change; go ahead and change the test to match. @@ -321,20 +318,18 @@ void events_object::test<6>() ensure_contains("cyclic dependencies", threw, "after (\"Mary\", \"checked\") -> \"spot\""); button.listen("yellow", - boost::bind(&Collect::add, boost::ref(collector), "yellow", _1), - make<NameList>(list_of("checked"))); + boost::bind(&Collect::add, boost::ref(collector), "yellow", _1), make<NameList>(NameList{ "checked" })); button.listen("shoelaces", - boost::bind(&Collect::add, boost::ref(collector), "shoelaces", _1), - make<NameList>(list_of("checked"))); + boost::bind(&Collect::add, boost::ref(collector), "shoelaces", _1), make<NameList>(NameList{ "checked" })); button.post(3); - ensure_equals(collector.result, make<StringVec>(list_of("Mary")("checked")("yellow")("shoelaces"))); + ensure_equals(collector.result, make<StringVec>(StringVec{ "Mary", "checked", "yellow", "shoelaces" })); collector.clear(); threw = catch_what<LLEventPump::OrderChange>( [&button, &collector](){ button.listen("of", boost::bind(&Collect::add, boost::ref(collector), "of", _1), - make<NameList>(list_of("shoelaces")), - make<NameList>(list_of("yellow"))); + make<NameList>(NameList{ "shoelaces" }), + make<NameList>(NameList{ "yellow" })); }); // Same remarks about the specific wording of the exception. Just // ensure that it contains enough information to clarify the @@ -347,7 +342,7 @@ void events_object::test<6>() ensure_contains("old order", threw, "was: Mary, checked, yellow, shoelaces"); ensure_contains("new order", threw, "now: Mary, checked, shoelaces, of, yellow"); button.post(4); - ensure_equals(collector.result, make<StringVec>(list_of("Mary")("checked")("yellow")("shoelaces"))); + ensure_equals(collector.result, make<StringVec>(StringVec{ "Mary", "checked", "yellow", "shoelaces" })); } template<> template<> diff --git a/indra/test/llhttpdate_tut.cpp b/indra/test/llhttpdate_tut.cpp index a47602dec5..b580b09a9f 100644 --- a/indra/test/llhttpdate_tut.cpp +++ b/indra/test/llhttpdate_tut.cpp @@ -112,13 +112,8 @@ namespace tut void httpdate_object::test<4>() { // test localization of http dates -#if LL_WINDOWS - const char *en_locale = "english"; - const char *fr_locale = "french"; -#else - const char *en_locale = "en_GB.UTF-8"; + const char *en_locale = "en_US.UTF-8"; const char *fr_locale = "fr_FR.UTF-8"; -#endif std::string prev_locale = LLStringUtil::getLocale(); std::string prev_clocale = std::string(setlocale(LC_TIME, NULL)); diff --git a/indra/test/lltut.h b/indra/test/lltut.h index e56b4e8d1c..581a08654d 100644 --- a/indra/test/lltut.h +++ b/indra/test/lltut.h @@ -135,7 +135,7 @@ namespace tut inline void ensure_memory_matches(const void* actual, U32 actual_len, const void* expected,U32 expected_len) { - ensure_memory_matches(NULL, actual, actual_len, expected, expected_len); + ensure_memory_matches("", actual, actual_len, expected, expected_len); } template <class T,class Q> diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 6e280819df..f6f5b5a5fc 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -36,7 +36,6 @@ #include "linden_common.h" #include "llerrorcontrol.h" -#include "llexception.h" #include "lltut.h" #include "chained_callback.h" #include "stringize.h" @@ -57,6 +56,13 @@ #include <boost/iostreams/tee.hpp> #include <boost/iostreams/stream.hpp> +// On Mac, got: +// #error "Boost.Stacktrace requires `_Unwind_Backtrace` function. Define +// `_GNU_SOURCE` macro or `BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED` if +// _Unwind_Backtrace is available without `_GNU_SOURCE`." +#define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED +#include <boost/stacktrace.hpp> + #include <fstream> void wouldHaveCrashed(const std::string& message); @@ -78,12 +84,14 @@ public: virtual void replay(std::ostream&) {} }; -class RecordToTempFile : public LLError::Recorder, public boost::noncopyable +class RecordToTempFile : public LLError::Recorder { public: + RecordToTempFile(const RecordToTempFile&) = delete; + RecordToTempFile& operator=(const RecordToTempFile&) = delete; + RecordToTempFile() : LLError::Recorder(), - boost::noncopyable(), mTempFile("log", ""), mFile(mTempFile.getName().c_str()) { @@ -122,12 +130,14 @@ private: llofstream mFile; }; -class LLReplayLogReal: public LLReplayLog, public boost::noncopyable +class LLReplayLogReal: public LLReplayLog { public: + LLReplayLogReal(const LLReplayLogReal&) = delete; + LLReplayLogReal& operator=(const LLReplayLogReal&) = delete; + LLReplayLogReal(LLError::ELevel level) : LLReplayLog(), - boost::noncopyable(), mOldSettings(LLError::saveAndResetSettings()), mRecorder(new RecordToTempFile()) { @@ -506,6 +516,64 @@ void wouldHaveCrashed(const std::string& message) static LLTrace::ThreadRecorder* sMasterThreadRecorder = NULL; +// this is used in platform-generic code -- define outside #if LL_WINDOWS +struct Windows_SEH_exception: public std::runtime_error +{ + Windows_SEH_exception(const std::string& what): std::runtime_error(what) {} +}; + +#if LL_WINDOWS + +static constexpr U32 STATUS_MSC_EXCEPTION = 0xE06D7363; // compiler specific +static constexpr U32 STATUS_STACK_FULL = 0xC00000FD; + +U32 seh_filter(U32 code, struct _EXCEPTION_POINTERS*) +{ + if (code == STATUS_MSC_EXCEPTION) + { + // C++ exception, go on -- but TUT is supposed to have caught those already?! + return EXCEPTION_CONTINUE_SEARCH; + } + else + { + // This is a non-C++ exception, e.g. hardware check. + // By the time the handler gets control, the stack has been unwound, + // so report the stack trace now at filter() time. + // Sadly, even though, at the time of this writing, stack overflow is + // the problem we would most like to diagnose, calling another + // function when the stack is already blown only terminates us faster. + if (code != STATUS_STACK_FULL) + { + std::cerr << boost::stacktrace::stacktrace() << std::endl; + } + // pass control into the handler block + return EXCEPTION_EXECUTE_HANDLER; + } +} + +template <typename CALLABLE0, typename CALLABLE1> +void seh_catcher(CALLABLE0&& trycode, CALLABLE1&& handler) +{ + __try + { + trycode(); + } + __except (seh_filter(GetExceptionCode(), GetExceptionInformation())) + { + handler(GetExceptionCode()); + } +} + +#else // not LL_WINDOWS + +template <typename CALLABLE0, typename CALLABLE1> +void seh_catcher(CALLABLE0&& trycode, CALLABLE1&&) +{ + trycode(); +} + +#endif // not LL_WINDOWS + int main(int argc, char **argv) { ll_init_apr(); @@ -638,7 +706,7 @@ int main(int argc, char **argv) // a chained_callback subclass must be linked with previous mycallback->link(); - LL::seh::catcher( + seh_catcher( // __try [test_group] { @@ -652,7 +720,7 @@ int main(int argc, char **argv) } }, // __except - [mycallback](U32 code, const std::string& /*stacktrace*/) + [mycallback](U32 code) { static std::map<U32, const char*> codes = { { 0xC0000005, "Access Violation" }, |
