From b661afafc7f66ecea2bba6e130b86e85106954f4 Mon Sep 17 00:00:00 2001 From: "andrewhayden@google.com" Date: Fri, 25 Jul 2014 09:52:27 +0000 Subject: [PATCH] Add clean.sh and compile_and_test_all.sh, ignore built libraries/tests/data, and make the unit tests exit with non-zero status when tests fail. git-svn-id: https://cld2.googlecode.com/svn/trunk@162 b252ecd4-b096-bf77-eb8e-91563289f87e --- internal/cld2_unittest.cc | 2 +- internal/cld2_unittest_full.cc | 2 +- internal/clean.sh | 29 +++++++++++++++ internal/compact_lang_det_impl.cc | 24 ++++++++++++- internal/compile_and_test_all.sh | 59 +++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 3 deletions(-) create mode 100755 internal/clean.sh create mode 100755 internal/compile_and_test_all.sh diff --git a/internal/cld2_unittest.cc b/internal/cld2_unittest.cc index 57766c1..5a9c331 100644 --- a/internal/cld2_unittest.cc +++ b/internal/cld2_unittest.cc @@ -359,7 +359,7 @@ int RunTests (int flags, bool get_vector) { } FinishHtmlOut(flags); - return 0; + return any_fail ? 1 : 0; } } // End namespace CLD2 diff --git a/internal/cld2_unittest_full.cc b/internal/cld2_unittest_full.cc index ed7e1e0..2648a57 100644 --- a/internal/cld2_unittest_full.cc +++ b/internal/cld2_unittest_full.cc @@ -392,7 +392,7 @@ int RunTests (int flags, bool get_vector) { } FinishHtmlOut(flags); - return 0; + return any_fail ? 1 : 0; } } // End namespace CLD2 diff --git a/internal/clean.sh b/internal/clean.sh new file mode 100755 index 0000000..067f87f --- /dev/null +++ b/internal/clean.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# +# Copyright 2014 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http:# www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -e +rm -f compact_lang_det_test_chrome +rm -f cld2_unittest +rm -f cld2_unittest_avoid +rm -f libcld2.so +rm -f libcld2_full.so +rm -f compact_lang_det_test_full +rm -f cld2_unittest_full +rm -f cld2_unittest_full_avoid +rm -f cld2_dynamic_data_tool +rm -f cld2_data.bin +rm -f compact_lang_det_dynamic_test_chrome +rm -f cld2_dynamic_unittest +rm -f libcld2_dynamic.so diff --git a/internal/compact_lang_det_impl.cc b/internal/compact_lang_det_impl.cc index 24508e5..b59c7dc 100644 --- a/internal/compact_lang_det_impl.cc +++ b/internal/compact_lang_det_impl.cc @@ -92,6 +92,7 @@ extern const short kAvgDeltaOctaScore[]; static uint32_t mmapLength = 0; bool isDataLoaded() { return dynamicDataLoaded; } + bool isDataDynamic() { return true; } // Because CLD2_DYNAMIC_MODE is defined void loadDataFromFile(const char* fileName) { if (isDataLoaded()) { @@ -124,7 +125,7 @@ extern const short kAvgDeltaOctaScore[]; dataSourceIsFile = false; // vacuous kScoringtables = NULL_TABLES; // Housekeeping: null all pointers } -#else +#else // !CLD2_DYNAMIC_MODE // This initializes kScoringtables.quadgram_obj etc. static const ScoringTables kScoringtables = { &cld_generated_CjkUni_obj, @@ -139,6 +140,27 @@ extern const short kAvgDeltaOctaScore[]; kAvgDeltaOctaScore, }; + + // Method implementations below are provided so that callers aren't *forced* + // to depend upon the CLD2_DYNAMIC_MODE flag, but can use runtime checks + // instead. For more information, refer to CLD2 issue 16: + // https://code.google.com/p/cld2/issues/detail?id=16 + bool isDataLoaded() { return true; } // Data is statically linked + bool isDataDynamic() { return false; } // Because CLD2_DYNAMIC_MODE is not defined + + void loadDataFromFile(const char* fileName) { + // This is a bug in the calling code. + fprintf(stderr, "WARNING: Dynamic mode not active, loadDataFromFile has no effect!"); + } + void loadDataFromRawAddress(const void* rawAddress, const uint32_t length) { + // This is a bug in the calling code. + fprintf(stderr, "WARNING: Dynamic mode not active, loadDataFromRawAddress has no effect!"); + } + void unloadData() { + // This is a bug in the calling code. + fprintf(stderr, "WARNING: Dynamic mode not active, unloadData has no effect!"); + } + #endif // #ifdef CLD2_DYNAMIC_MODE diff --git a/internal/compile_and_test_all.sh b/internal/compile_and_test_all.sh new file mode 100755 index 0000000..a1ba529 --- /dev/null +++ b/internal/compile_and_test_all.sh @@ -0,0 +1,59 @@ +#!/bin/sh +# +# Copyright 2014 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http:# www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -e +trap 'echo "FAILED!" && exit 1' INT TERM EXIT + +# ---------------------------------------------------------------------------- +echo "--> [1 of 7] Invoking: compile.sh..." +./compile.sh +echo "--> [2 of 7] Testing results of compile.sh..." +echo "--> compact_lang_det_test_chrome... " +echo "this is some english text" | ./compact_lang_det_test_chrome +echo -n "--> cld2_unittest... " +./cld2_unittest > /dev/null +echo -n "--> cld2_unittest_avoid... " +./cld2_unittest_avoid > /dev/null + +# ---------------------------------------------------------------------------- +echo "--> [3 of 7] Invoking: compile_libs.sh..." +./compile_libs.sh + +# ---------------------------------------------------------------------------- +echo "--> [4 of 7] Invoking: compile_full.sh..." +./compile_full.sh +echo "--> [5 of 7] Testing results of compile_full.sh..." +echo "--> compact_lang_det_test_full... " +echo "this is some english text" | ./compact_lang_det_test_full +echo -n "--> cld2_unittest_full... " +./cld2_unittest_full > /dev/null +echo -n "--> cld2_unittest_full_avoid... " +./cld2_unittest_full_avoid > /dev/null + +# ---------------------------------------------------------------------------- +echo "--> [6 of 7] Invoking: compile_dynamic.sh..." +./compile_dynamic.sh +echo "--> [6 of 7] Dumping dynamic data to cld2_data.bin..." +./cld2_dynamic_data_tool --dump cld2_data.bin +echo "--> [6 of 7] Verifying dynamic data in cld2_data.bin..." +./cld2_dynamic_data_tool --verify cld2_data.bin +echo "--> [7 of 7] Testing results of compile_dynamic.sh..." +echo "--> compact_lang_det_dynamic_test_chrome... " +echo "this is some english text" | ./compact_lang_det_dynamic_test_chrome --data-file cld2_data.bin +echo -n "--> cld2_dynamic_unittest... " +./cld2_dynamic_unittest --data-file cld2_data.bin > /dev/null + +trap - INT TERM EXIT +echo "All libraries compiled and all tests passed!" \ No newline at end of file