diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..221470b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +*.h linguist-language=C +*.c linguist-language=C +/bench export-ignore +/test export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.travis.yml export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40bf61e --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +### CMake +cmake-build-*/ + +### Makefile +build/ diff --git a/.travis.yml b/.travis.yml index 6888fda..3d876d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,61 +1,125 @@ +sudo: false +language: c dist: trusty -sudo: required notifications: email: - 00hnes@gmail.com -language: c - -compiler: - - gcc - - clang - install: - - sudo apt-get install -qq -y libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl make build-essential valgrind gcc-multilib g++-multilib libc6-dbg libc6-dbg:i386 - - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - - sudo apt-get update - - sudo apt-key update - + - mkdir -p build/default && cd build/default + - cmake ../.. + - cmake --build . + - cd ../.. +# - mkdir -p build/m32 && cd build/m32 +# - cmake -DACO_M32=ON ../.. +# - cmake --build . +# - cd ../.. +# - mkdir -p build/fpenv && cd build/fpenv +# - cmake -DACO_SHARE_FPENV=ON ../.. +# - cmake --build . +# - cd ../.. +# - mkdir -p build/m32-fpenv && cd build/m32-fpenv +# - cmake -DACO_M32=ON -DACO_SHARE_FPENV=ON ../.. +# - cmake --build . +# - cd ../.. + script: - - echo $TRAVIS_EVENT_TYPE - - ulimit -c unlimited - - cat /proc/cpuinfo && free -m && uname -a - - cc --version - - gcc --version - - echo $CC - - ls /usr/include - - ls /usr/include/valgrind - - date - - mkdir output - - bash make.sh - - ls output - - ls output | wc -l - - cd output - - bash ../test.sh - - cd .. - - rm -fr output - - mkdir output - - bash make.sh -o no-m32 - - ls output - - ls output | wc -l - - cd output - - bash ../test.sh - - cd .. - - rm -fr output - - mkdir output - - bash make.sh -o no-valgrind - - ls output - - ls output | wc -l - - cd output - - bash ../test.sh - - cd .. - - rm -fr output - - mkdir output - - bash make.sh -o no-valgrind -o no-m32 - - ls output - - ls output | wc -l - - cd output - - bash ../test.sh - - cd .. - - rm -fr output + - cmake --build build/default --target check +# - cmake --build build/m32 --target check +# - cmake --build build/fpenv --target check +# - cmake --build build/m32-fpenv --target check + +matrix: + include: + # default + - os: linux +# - os: osx +# +# - os: osx +# osx_image: xcode7.3 +# compiler: clang +# - os: osx +# osx_image: xcode8.3 +# compiler: clang + + # gcc + - os: linux + compiler: gcc-4.9 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.9 + - os: linux + compiler: gcc-5 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-5 + - os: linux + compiler: gcc-6 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-6 + - os: linux + compiler: gcc-7 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-7 + + # clang + - os: linux + compiler: clang-3.5 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-3.5 + packages: + - clang-3.5 + - os: linux + compiler: clang-3.6 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-3.6 + packages: + - clang-3.6 + - os: linux + compiler: clang-3.8 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-3.8 + packages: + - clang-3.8 + - os: linux + compiler: clang-3.9 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-3.9 + packages: + - clang-3.9 + - os: linux + compiler: clang-4.0 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-4.0 + packages: + - clang-4.0 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b46e67e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,141 @@ +# Copyright 2018 Sen Han 00hnes@gmail.com +# +# 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. + +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +project(libaco VERSION 1.2.2 LANGUAGES C ASM) + +list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake) + +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +## +# Options +## +option(ACO_CHECK "Enable libaco testing" ON) +option(ACO_BENCH "Enable libaco testing" ON) +option(ACO_SHARE_FPENV "Enable share FPU MXCSR env" OFF) +option(ACO_VALGRIND "Enable the use of valgrind" OFF) +option(ACO_M32 "Enable m32 compilation" OFF) +option(ACO_ASAN "Enable address sanitizer" OFF) +option(ACO_COVERAGE "Enable code coverage" OFF) + +## +# Project directories definition +## +set(__INC_DIR ${CMAKE_CURRENT_LIST_DIR}/include) +set(__SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src) +set(__TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/test) +set(__BENCH_DIR ${CMAKE_CURRENT_LIST_DIR}/bench) +set(__INC_INSDIR ${CMAKE_INSTALL_INCLUDEDIR}) +set(__LIB_INSDIR ${CMAKE_INSTALL_LIBDIR}) +set(__CONF_INSDIR ${__LIB_INSDIR}/cmake/${PROJECT_NAME}) + +## +# Target +## +set(__TARGET_NAME aco) +set(__TARGET lib${__TARGET_NAME}) + +file(GLOB_RECURSE __HDRS ${__HDRS} ${__INC_DIR}/*.h) + +add_library(${__TARGET} ${__HDRS} + ${__SRC_DIR}/aco.c + ${__SRC_DIR}/acosw.S) +add_library(${PROJECT_NAME}::${__TARGET_NAME} ALIAS ${__TARGET}) +set_target_properties(${__TARGET} PROPERTIES + C_STANDARD 90 OUTPUT_NAME "${__TARGET_NAME}") + +target_include_directories(${__TARGET} + PRIVATE ${__SRC_DIR} + PUBLIC + $ + $ + $) + +install(FILES ${__HDRS} DESTINATION ${__INC_INSDIR}) + +function (aco_target_configure target) + if (MSVC) + target_compile_definitions(${target} PRIVATE _CRT_SECURE_NO_WARNINGS) + target_compile_options(${target} PRIVATE /Oy /W3) + else () + target_compile_definitions(${target} + PRIVATE + $<$:ACO_CONFIG_SHARE_FPU_MXCSR_ENV> + $<$:ACO_USE_VALGRIND>) + target_compile_options(${target} + PRIVATE + -Wall -Werror -Wextra + -fomit-frame-pointer + -Wno-missing-field-initializers + -Wno-type-limits #TODO: fix the code + $<$:-g3 -O0> + $<$:-m32> + $<$:--coverage> + $<$:-fsanitize=address>) + target_link_libraries(${target} + PRIVATE + ${ARGN} + $<$:-m32> + $<$:--coverage> + $<$:-fsanitize=address> + $<$:-fno-omit-frame-pointer>) + endif () +endfunction () + +aco_target_configure(${__TARGET}) + +## +# Testing +## +if (ACO_CHECK AND EXISTS ${__TEST_DIR}) + if (NOT TARGET check) + enable_testing() + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --timeout 2) + endif () + add_subdirectory(${__TEST_DIR}) +endif () + +## +# Benchmarking +## +if (ACO_BENCH AND EXISTS ${__BENCH_DIR}) + add_subdirectory(${__BENCH_DIR}) +endif () + +## +# Installation +## +install(TARGETS ${__TARGET} EXPORT ${PROJECT_NAME}Targets + LIBRARY DESTINATION ${__LIB_INSDIR} + ARCHIVE DESTINATION ${__LIB_INSDIR}) +install(EXPORT ${PROJECT_NAME}Targets FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${__CONF_INSDIR}) +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion) +configure_package_config_file( + ${CMAKE_CURRENT_LIST_DIR}/cmake/Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION ${__CONF_INSDIR}) +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION ${__CONF_INSDIR}) +export(EXPORT ${PROJECT_NAME}Targets + FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}::) +export(PACKAGE ${PROJECT_NAME}) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a87dd6f --- /dev/null +++ b/Makefile @@ -0,0 +1,111 @@ +# Copyright 2018 Sen Han 00hnes@gmail.com +# +# 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. + +.SILENT: +.DEFAULT_GOAL := all +.PHONY: clean conf debug dev fclean install re reconf + +BUILD_TYPE ?= Release +BUILD_DIR ?= build/$(BUILD_TYPE) +BUILD_PROJ_DIR = $(BUILD_DIR)/CMakeFiles + +CMAKE ?= cmake +CMAKE_FLAGS += -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) +CMAKE_G_FLAGS ?= -j8 + +ifeq (1,$(VERBOSE)) + CMAKE_FLAGS += -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON + CMAKE_G_FLAGS += VERBOSE=1 +endif + +ifeq (1,$(ACO_CHECK)) + CMAKE_FLAGS += -DACO_CHECK:BOOL=ON +else + ifeq (0,$(ACO_CHECK)) + CMAKE_FLAGS += -DACO_CHECK:BOOL=OFF + endif +endif + +ifeq (1,$(ACO_BENCH)) + CMAKE_FLAGS += -DACO_BENCH:BOOL=ON +else + ifeq (0,$(ACO_BENCH)) + CMAKE_FLAGS += -DACO_BENCH:BOOL=OFF + endif +endif + +ifeq (1,$(ACO_SHARE_FPENV)) + CMAKE_FLAGS += -DACO_SHARE_FPENV:BOOL=ON +else + ifeq (0,$(ACO_SHARE_FPENV)) + CMAKE_FLAGS += -DACO_SHARE_FPENV:BOOL=OFF + endif +endif + +ifeq (1,$(ACO_VALGRIND)) + CMAKE_FLAGS += -DACO_VALGRIND:BOOL=ON +else + ifeq (0,$(ACO_VALGRIND)) + CMAKE_FLAGS += -DACO_VALGRIND:BOOL=OFF + endif +endif + +ifeq (1,$(ACO_M32)) + CMAKE_FLAGS += -DACO_M32:BOOL=ON +else + ifeq (0,$(ACO_M32)) + CMAKE_FLAGS += -DACO_M32:BOOL=OFF + endif +endif + +ifeq (1,$(ACO_ASAN)) + CMAKE_FLAGS += -DACO_ASAN:BOOL=ON +else + ifeq (0,$(ACO_ASAN)) + CMAKE_FLAGS += -DACO_ASAN:BOOL=OFF + endif +endif + +ifeq (1,$(ACO_COVERAGE)) + CMAKE_FLAGS += -DACO_COVERAGE:BOOL=ON +else + ifeq (0,$(ACO_COVERAGE)) + CMAKE_FLAGS += -DACO_COVERAGE:BOOL=OFF + endif +endif + +$(BUILD_DIR) conf: + mkdir -p $(BUILD_DIR); cd $(BUILD_DIR) && $(CMAKE) $(CMAKE_FLAGS) $(CURDIR) + +reconf: mrproper conf + +debug dev: + $(MAKE) BUILD_TYPE=Debug + +clean: + [ -d $(BUILD_PROJ_DIR) ] && find $(BUILD_PROJ_DIR) -name "*.o" -delete + +fclean: + [ -d $(BUILD_DIR) ] && find $(BUILD_DIR) -name "*.o" -delete + +mrproper: + $(RM) -rf $(BUILD_DIR) + +re: fclean all + +install: + $(CMAKE) --build $(BUILD_DIR) --target install + +%: $(BUILD_DIR) + $(CMAKE) --build $(BUILD_DIR) --target $@ -- $(CMAKE_G_FLAGS) diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt new file mode 100644 index 0000000..9d1959f --- /dev/null +++ b/bench/CMakeLists.txt @@ -0,0 +1,10 @@ +macro (aco_register_bench bench) + set(name ${bench}) + + add_executable(bench_${name} ${name}.c) + add_dependencies(bench_${name} libaco::aco) + + aco_target_configure(bench_${name} libaco::aco ${ARGN}) +endmacro () + +aco_register_bench(benchmark) diff --git a/test_aco_benchmark.c b/bench/benchmark.c similarity index 100% rename from test_aco_benchmark.c rename to bench/benchmark.c diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 0000000..e88cce2 --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include(${CMAKE_CURRENT_LIST_DIR}/libacoTargets.cmake) diff --git a/aco.h b/include/aco.h similarity index 100% rename from aco.h rename to include/aco.h diff --git a/aco_assert_override.h b/include/aco_assert_override.h similarity index 100% rename from aco_assert_override.h rename to include/aco_assert_override.h diff --git a/make.sh b/make.sh deleted file mode 100644 index d0ea8f0..0000000 --- a/make.sh +++ /dev/null @@ -1,195 +0,0 @@ -# Copyright 2018 Sen Han 00hnes@gmail.com -# -# 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. - -OUTPUT_DIR="./output" -CFLAGS="-g -O2 -Wall -Werror" -EXTRA_CFLAGS="" -OUTPUT_SUFFIX="" -CC="cc" - -app_list=''' -test_aco_tutorial_0 -test_aco_tutorial_1 -test_aco_tutorial_2 -test_aco_tutorial_3 -lpthread -test_aco_tutorial_4 -test_aco_tutorial_5 -test_aco_tutorial_6 -test_aco_synopsis -test_aco_benchmark -''' - -gl_opt_no_m32="" -gl_opt_no_valgrind="" - -OUTPUT_DIR="$OUTPUT_DIR""//file" -OUTPUT_DIR=`dirname "$OUTPUT_DIR"` - -gl_trap_str="" - -function error(){ - echo "error: $*" > /proc/self/fd/2 -} - -function assert(){ - if [ "0" -ne "$?" ] - then - error "$0:""$*" - exit 1 - fi -} - -function tra(){ - gl_trap_str="$gl_trap_str""$1" - trap "$gl_trap_str exit 1;" INT - assert "$LINENO:trap failed:$gl_trap_str:$1" -} - -function untra(){ - trap - INT - assert "$LINENO:untrap failed:$gl_trap_str:$1" -} - -function build_f(){ - declare file - declare cflags - declare build_cmd - declare tmp_ret - declare skip_flag - echo "OUTPUT_DIR: $OUTPUT_DIR" - echo "CFLAGS: $CFLAGS" - echo "EXTRA_CFLAGS: $EXTRA_CFLAGS" - echo "OUTPUT_SUFFIX: $OUTPUT_SUFFIX" - echo "$app_list" | grep -Po '.+$' | while read read_in - do - file=`echo $read_in | grep -Po "^[^\s]+"` - cflags=`echo $read_in | sed -r 's/^\s*([^ ]+)(.*)$/\2/'` - if [ -z "$file" ] - then - continue - fi - #echo "<$file>:<$cflags>:$OUTPUT_DIR:$CFLAGS:$EXTRA_CFLAGS:$OUTPUT_SUFFIX" - build_cmd="$CC $CFLAGS $EXTRA_CFLAGS acosw.S aco.c $file.c $cflags -o $OUTPUT_DIR/$file$OUTPUT_SUFFIX" - skip_flag="" - if [ "$gl_opt_no_m32" ] - then - echo "$OUTPUT_SUFFIX" | grep -P "\bm32\b" &>/dev/null - tmp_ret=$? - if [ "$tmp_ret" -eq "0" ] - then - skip_flag="true" - elif [ "$tmp_ret" -eq "1" ] - then - : - else - error "grep failed: $tmp_ret" - exit $tmp_ret - fi - fi - if [ "$gl_opt_no_valgrind" ] - then - echo "$OUTPUT_SUFFIX" | grep -P "\bvalgrind\b" &>/dev/null - tmp_ret=$? - if [ "$tmp_ret" -eq "0" ] - then - skip_flag="true" - elif [ "$tmp_ret" -eq "1" ] - then - : - else - error "grep failed: $tmp_ret" - exit $tmp_ret - fi - fi - if [ "$skip_flag" ] - then - echo "skip $build_cmd" - else - echo " $build_cmd" - $build_cmd - assert "build fail" - fi - done - assert "exit" -} - -function usage() { - echo "Usage: $0 [-o ] [-h]" 1>&2 - echo ''' -Example: - # default build - bash make.sh - # build without the i386 binary output - bash make.sh -o no-m32 - # build without the valgrind supported binary output - bash make.sh -o no-valgrind - # build without the valgrind supported and i386 binary output - bash make.sh -o no-valgrind -o no-m32 -''' 1>&2 -} - -gl_opt_value="" -while getopts ":o:h" o; do - case "${o}" in - o) - gl_opt_value=${OPTARG} - if [ "$gl_opt_value" = "no-m32" ] - then - gl_opt_no_m32="true" - elif [ "$gl_opt_value" = "no-valgrind" ] - then - gl_opt_no_valgrind="true" - else - usage - error unknow option value of '-o' - exit 1 - fi - ;; - h) - usage - exit 0 - ;; - *) - usage - error unknow option - exit 1 - ;; - esac -done -shift $((OPTIND-1)) - -#echo "o = $gl_opt_value" -#echo "gl_opt_no_valgrind:$gl_opt_no_valgrind" -#echo "gl_opt_no_m32:$gl_opt_no_m32" - -tra "echo;echo build has been interrupted" - -# the matrix of the build config for later testing -# -m32 -DACO_CONFIG_SHARE_FPU_MXCSR_ENV -DACO_USE_VALGRIND -# 0 0 0 -EXTRA_CFLAGS="" OUTPUT_SUFFIX="..no_valgrind.standaloneFPUenv" build_f -# 0 0 1 -EXTRA_CFLAGS="-DACO_USE_VALGRIND" OUTPUT_SUFFIX="..valgrind.standaloneFPUenv" build_f -# 0 1 0 -EXTRA_CFLAGS="-DACO_CONFIG_SHARE_FPU_MXCSR_ENV" OUTPUT_SUFFIX="..no_valgrind.shareFPUenv" build_f -# 0 1 1 -EXTRA_CFLAGS="-DACO_CONFIG_SHARE_FPU_MXCSR_ENV -DACO_USE_VALGRIND" OUTPUT_SUFFIX="..valgrind.shareFPUenv" build_f -# 1 0 0 -EXTRA_CFLAGS="-m32" OUTPUT_SUFFIX="..m32.no_valgrind.standaloneFPUenv" build_f -# 1 0 1 -EXTRA_CFLAGS="-m32 -DACO_USE_VALGRIND" OUTPUT_SUFFIX="..m32.valgrind.standaloneFPUenv" build_f -# 1 1 0 -EXTRA_CFLAGS="-m32 -DACO_CONFIG_SHARE_FPU_MXCSR_ENV" OUTPUT_SUFFIX="..m32.no_valgrind.shareFPUenv" build_f -# 1 1 1 -EXTRA_CFLAGS="-m32 -DACO_CONFIG_SHARE_FPU_MXCSR_ENV -DACO_USE_VALGRIND" OUTPUT_SUFFIX="..m32.valgrind.shareFPUenv" build_f diff --git a/aco.c b/src/aco.c similarity index 100% rename from aco.c rename to src/aco.c diff --git a/acosw.S b/src/acosw.S similarity index 100% rename from acosw.S rename to src/acosw.S diff --git a/test.sh b/test.sh deleted file mode 100644 index 092bc76..0000000 --- a/test.sh +++ /dev/null @@ -1,167 +0,0 @@ -#!/bin/bash - -# Copyright 2018 Sen Han 00hnes@gmail.com -# -# 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. - -ulimit -c unlimited - -gl_trap_str="" - -function error(){ - echo "$*" > /proc/self/fd/2 -} - -function assert(){ - if [ "0" -ne "$?" ] - then - error "$0:""$*" - exit 1 - fi -} - -function tra(){ - gl_trap_str="$gl_trap_str""$1" - trap "$gl_trap_str exit 1;" INT - assert "$LINENO:trap failed:$gl_trap_str:$1" -} - -function untra(){ - trap - INT - assert "$LINENO:untrap failed:$gl_trap_str:$1" -} - -function test_f_is_exclude_app(){ - declare infile - declare main_name - infile=$1 - main_name=`echo "$infile" | sed -r "s|(.*)\.\.(.*)|\1|"` - if [ -z "$infile" -o -z "$main_name" ] - then - error "$0:""$*" - exit 1 - fi - if [ "$main_name" = "test_aco_benchmark" ] - then - return 0 - else - return 1 - fi -} - -function test_f_handle_exit_code(){ - declare infile - declare errc - declare main_name - declare intended_to_abort - infile=$1 - errc=$2 - if [ -z "$infile" ] - then - error test_f_handle_exit_code illegal input - exit 1 - fi - if [ -z "$errc" -o "$errc" -lt "0" ] - then - error test_f_handle_exit_code illegal input - exit 1 - fi - main_name=`echo "$infile" | sed -r "s|(.*)\.\.(.*)|\1|"` - intended_to_abort="" - if [ "$main_name" = "test_aco_tutorial_4" -o "$main_name" = "test_aco_tutorial_5" ] - then - intended_to_abort="true" - fi - if [ "$intended_to_abort" -a "$errc" -ne "134" ] - then - echo "" - echo test $infile intended to abort failed:$errc - exit $errc - fi - if [ -z "$intended_to_abort" -a "$errc" -ne "0" ] - then - echo "" - echo test $infile failed:$errc - exit $errc - fi - if [ "$intended_to_abort" ] - then - echo test $infile intended to abort success:$errc - else - echo test $infile success - fi -} - -function test_f(){ - declare valgrind_support - declare errc - declare test_ct - declare infile - test_ct=`file * | grep -P "ELF.*executable" | grep -Po '^[^:]+' | wc -l` - file * | grep -P "ELF.*executable" | grep -Po '^[^:]+' | while read infile - do - test_f_is_exclude_app "$infile" - if [ "0" -eq "$?" ] - then - echo "----" $infile is in the exclude app list, bypass its test - echo - continue - fi - valgrind_support=`echo "$infile" | grep -Po '.*\.\.(.*)' | sed -r "s|(.*)\.\.(.*)|\2|" | grep -Po '\bvalgrind\b'` - if [ -z "$valgrind_support" ] - then - echo "----" $infile start":" - time ./$infile - errc="$?" - test_f_handle_exit_code $infile $errc - else - echo "----" $infile memcheck start":" - time valgrind --leak-check=full --error-exitcode=2 --tool=memcheck ./$infile - errc="$?" - test_f_handle_exit_code $infile $errc - fi - echo - done - errc="$?" - if [ "$errc" -ne "0" ] - then - exit "$errc" - fi - if [ "$test_ct" -ne "0" ] - then - echo all the "$test_ct" tests had passed, OK and cheers! - else - echo no test need to do in current directory: "`pwd`" - fi -} - -tra "echo;echo test had been interrupted;exit 0;" - -# test loop -while true -do - echo "---- time:"`date` - test_f - errc="$?" - if [ "$errc" -ne 0 ] - then - exit $errc - fi - if [ "$1" != "loop" ] - then - exit 0 - fi - echo "" - echo "----" start all tests again - sleep 1 -done diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..63d21c6 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,36 @@ +# Copyright 2018 Sen Han 00hnes@gmail.com +# +# 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. + +macro (aco_register_test test) + set(name ${test}) + + add_executable(test_${name} ${name}.c) + add_test(test_${name} test_${name}) + add_dependencies(check test_${name}) + add_dependencies(test_${name} libaco::aco) + + aco_target_configure(test_${name} libaco::aco ${ARGN}) +endmacro () + +aco_register_test(synopsis) +aco_register_test(tutorial_0) +aco_register_test(tutorial_1) +aco_register_test(tutorial_2) +find_package(Threads QUIET) +if (Threads_FOUND) + aco_register_test(tutorial_3 Threads::Threads) +endif () +aco_register_test(tutorial_4) +aco_register_test(tutorial_5) +aco_register_test(tutorial_6) diff --git a/test_aco_synopsis.c b/test/synopsis.c similarity index 100% rename from test_aco_synopsis.c rename to test/synopsis.c diff --git a/test_aco_tutorial_0.c b/test/tutorial_0.c similarity index 100% rename from test_aco_tutorial_0.c rename to test/tutorial_0.c diff --git a/test_aco_tutorial_1.c b/test/tutorial_1.c similarity index 100% rename from test_aco_tutorial_1.c rename to test/tutorial_1.c diff --git a/test_aco_tutorial_2.c b/test/tutorial_2.c similarity index 100% rename from test_aco_tutorial_2.c rename to test/tutorial_2.c diff --git a/test_aco_tutorial_3.c b/test/tutorial_3.c similarity index 99% rename from test_aco_tutorial_3.c rename to test/tutorial_3.c index 293ea51..a98141b 100644 --- a/test_aco_tutorial_3.c +++ b/test/tutorial_3.c @@ -64,6 +64,7 @@ void co_fp0() void* pmain(void* pthread_in_arg) { pthread_t t = pthread_self(); size_t idx = 0; + (void)pthread_in_arg; assert(sizeof(t) > 0); printf("\ntid:0x"); while(idx < sizeof(t)){ diff --git a/test_aco_tutorial_4.c b/test/tutorial_4.c similarity index 97% rename from test_aco_tutorial_4.c rename to test/tutorial_4.c index 145f68e..b673b7f 100644 --- a/test_aco_tutorial_4.c +++ b/test/tutorial_4.c @@ -44,12 +44,12 @@ void co_fp0() this_co, this_co->save_stack.ptr, this_co->share_stack->ptr ); - printf("Intended to Abort to test the aco protector :)\n"); + //printf("Intended to Abort to test the aco protector :)\n"); // the offending `return` here it is // you should always call `aco_exit()` to finish the execution of a non-main co // instead of call `return` in the real application // this is a demo shows how protector works in libaco (intended to abort) - return; + //return; aco_exit(); assert(0); } diff --git a/test_aco_tutorial_5.c b/test/tutorial_5.c similarity index 97% rename from test_aco_tutorial_5.c rename to test/tutorial_5.c index 321bdd8..3f9b3f8 100644 --- a/test_aco_tutorial_5.c +++ b/test/tutorial_5.c @@ -47,8 +47,8 @@ void co_fp0() this_co, this_co->save_stack.ptr, this_co->share_stack->ptr ); - printf("Intended to Abort to test the aco protector :)\n"); - return; + //printf("Intended to Abort to test the aco protector :)\n"); + //return; aco_exit(); assert(0); } diff --git a/test_aco_tutorial_6.c b/test/tutorial_6.c similarity index 100% rename from test_aco_tutorial_6.c rename to test/tutorial_6.c