github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/bin/valgrind_test_nbre.sh (about) 1 #!/bin/bash 2 3 # Copyright (C) 2018 go-nebulas authors 4 # 5 # This file is part of the go-nebulas library. 6 # 7 # the go-nebulas library is free software: you can redistribute it and/or 8 # modify 9 # it under the terms of the GNU General Public License as published by 10 # the Free Software Foundation, either version 3 of the License, or 11 # (at your option) any later version. 12 # 13 # the go-nebulas library is distributed in the hope that it will be useful, 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 # GNU General Public License for more details. 17 # 18 # You should have received a copy of the GNU General Public License 19 # along with the go-nebulas library. If not, see 20 # <http://www.gnu.org/licenses/>. 21 # 22 23 USE_CASE_ARRAY=("nasir" "blockgen" "naxer") 24 PROGRAM_SELF_NAME="valgrind_test_nbre.sh" 25 VALGRIND_ARGUMENTS="--leak-check=yes" 26 VALGRIND_OUTPUT="./valgrind_report" 27 28 show_test_cases() 29 { 30 echo "Test Case Name:" 31 for i in "${USE_CASE_ARRAY[@]}" 32 do 33 echo -e "\t ${i} " 34 done 35 } 36 37 usage() 38 { 39 echo "Usage:" 40 echo -e "\t$PROGRAM_SELF_NAME -h" 41 echo -e "\t$PROGRAM_SELF_NAME -l" 42 echo -e "\t$PROGRAM_SELF_NAME -t <test case name>" 43 echo -e "\t$PROGRAM_SELF_NAME -o <output_report_path> -t <test case name>" 44 echo -e "\t$PROGRAM_SELF_NAME -a" 45 echo -e "Parameter:" 46 echo -e "\t-h: help" 47 echo -e "\t-l: list name of test case" 48 echo -e "\t-t: test" 49 echo -e "\t-o: output path" 50 echo -e "\t-a: run all test case" 51 exit 1 52 } 53 54 check_environment() 55 { 56 if [ ! -x "/usr/bin/valgrind" ]; then 57 echo "Valgrind don't exist, please execute: sudo apt install valgrind" 58 exit 1 59 fi 60 61 if [ ! -x "./"$1 ]; then 62 echo "Program $1 don't exist!" 63 exit 1 64 fi 65 } 66 67 check_test_cases() { 68 for i in "${USE_CASE_ARRAY[@]}" 69 do 70 if [ $1 = $i ]; then 71 return 0 72 fi 73 done 74 75 echo "Test case don't exist!" 76 exit 1 77 } 78 79 execute_test() 80 { 81 check_environment 82 check_test_cases $1 83 84 mkdir -p $VALGRIND_OUTPUT 85 86 if [ $1 = "nasir" ]; then 87 echo "Valgrind is checking memory leak of "$1 88 valgrind $VALGRIND_ARGUMENTS ./nasir \ 89 --input ../test/data/test_nasir.json \ 90 --output nr.bc > $VALGRIND_OUTPUT"/"$1_report 2>&1 91 elif [ $1 = "blockgen" ]; then 92 echo "Valgrind is checking memory leak of "$1 93 valgrind $VALGRIND_ARGUMENTS ./blockgen \ 94 --ir_binary ./nr.bc \ 95 --block_conf ../test/data/test_blockgen.json > $VALGRIND_OUTPUT"/"$1_report 2>&1 96 elif [ $1 = "naxer" ]; then 97 echo "Valgrind is checking memory leak of "$1 98 valgrind $VALGRIND_ARGUMENTS ./naxer \ 99 --module nr \ 100 --height 1000 > $VALGRIND_OUTPUT"/"$1_report 2>&1 101 else 102 echo "nothing" 103 fi 104 } 105 106 execute_all_test() 107 { 108 for i in "${USE_CASE_ARRAY[@]}" 109 do 110 execute_test $i 111 done 112 } 113 114 if [ $# = 0 ]; then 115 usage 116 exit 1 117 fi 118 119 while getopts "l t:o: a h" opt; do 120 case "$opt" in 121 h) 122 usage 123 ;; 124 l) 125 show_test_cases 126 ;; 127 t) 128 execute_test $OPTARG 129 ;; 130 o) 131 VALGRIND_OUTPUT=$OPTARG 132 ;; 133 a) 134 execute_all_test 135 ;; 136 *) 137 echo "ERROR: unknow parameter \"$opt\"" 138 usage 139 ;; 140 esac 141 done 142 shift $((OPTIND-1)) 143 144 145