<commit_before>#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you 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.

home="$(cd "$(dirname $0)"; pwd)"
scenario_name=""
parallel_run_size=1
force_build="off"
build_id="latest"
cleanup="off"

mvnw=${home}/../../mvnw
agent_home=${home}"/../../skywalking-agent"
scenarios_home="${home}/scenarios"


print_help() {
    echo  "Usage: run.sh [OPTION] SCENARIO [SCENARIO]"
    echo -e "\t-f, --force_build \t\t do force to build Plugin-Test tools and images"
    echo -e "\t--build_id, \t\t\t specify Plugin_Test's image tag. Defalt: latest"
    echo -e "\t--parallel_run_size, \t\t parallel size of test cases. Default: 1"
    echo -e "\t--cleanup, \t\t\t remove the related images and directories"
}

parse_commandline() {
    _positionals_count=0
    while test $# -gt 0
    do
        _key="$1"
        case "$_key" in
            -f|--force_build)
                force_build="on"
                shift
                ;;
            --cleanup)
                cleanup="on"
                shift
                ;;
            --build_id)
                test $# -lt 2 && exitWithMessage "Missing value for the optional argument '$_key'."
                build_id="$2"
                shift
                ;;
            --build_id=*)
                build_id="${_key##--build_id=}"
                ;;
            --parallel_run_size)
                test $# -lt 2 && exitWithMessage "Missing value for the optional argument '$_key'."
                parallel_run_size="$2"
                shift
                ;;
            --parallel_run_size=*)
                parallel_run_size="${_key##--parallel_run_size=}"
                ;;
            -h|--help)
                print_help
                exit 0
                ;;
            -h*)
                print_help
                exit 0
                ;;
            *)
                scenario_name=$1
                ;;
        esac
        shift
    done
}

exitWithMessage() {
    echo -e "\033[31m[ERROR] $1\033[0m">&2
    exitAndClean 1
}

exitAndClean() {
    elapsed=$(( `date +%s` - $start_stamp ))
    num_of_testcases="`ls -l ${task_state_house} |grep -c FINISH`"
    printf "Scenarios: %s, Testcases: %d, parallel_run_size: %d, Elapsed: %02d:%02d:%02d \n" \
        ${scenario_name} "${num_of_testcases}" "${parallel_run_size}" \
        $(( ${elapsed}/3600 )) $(( ${elapsed}%3600/60 )) $(( ${elapsed}%60 ))
    exit $1
}

waitForAvailable() {
    while [[ `ls -l ${task_state_house} |grep -c RUNNING` -ge ${parallel_run_size} ]]
    do
        sleep 2
    done

    if [[ `ls -l ${task_state_house} |grep -c FAILURE` -gt 0 ]]; then
        exitAndClean 1
    fi
}

do_cleanup() {
    docker images -q "skywalking/agent-test-*:${build_id}" | xargs -r docker rmi -f
    [[ -d ${home}/dist ]] && rm -rf ${home}/dist
    [[ -d ${home}/workspace ]] && rm -rf ${home}/workspace
}

start_stamp=`date +%s`
parse_commandline "$@"

if [[ "$cleanup" == "on" ]]; then
    do_cleanup
    exit 0
fi

if [[ ! -d ${agent_home} ]]; then
    echo "[WARN] SkyWalking Agent not exists"
    ${mvnw} -f ${home}/../../pom.xml -Pagent -DskipTests clean package 
fi
[[ "$force_build" == "on" ]] && ${mvnw} -f ${home}/pom.xml clean package -DskipTests -Dbuild_id=${build_id} docker:build

workspace="${home}/workspace/${scenario_name}"
task_state_house="${workspace}/.states"
[[ -d ${workspace} ]] && rm -rf $workspace
mkdir -p ${task_state_house}

plugin_runner_helper="${home}/dist/plugin-runner-helper.jar"
if [[ ! -f ${plugin_runner_helper} ]]; then
    exitWithMessage "Plugin Runner tools not exists, Please re-try it with '-f'"
    print_helper
fi

echo "start submit job"
scenario_home=${scenarios_home}/${scenario_name} && cd ${scenario_home}

supported_version_file=${scenario_home}/support-version.list
if [[ ! -f $supported_version_file ]]; then
    exitWithMessage "cannot found 'support-version.list' in directory ${scenario_name}"
fi

_agent_home=${agent_home}
mode=`grep "runningMode" ${scenario_home}/configuration.yml |sed -e "s/ //g" |awk -F: '{print $2}'`
if [[ "$mode" == "with_optional" ]]; then
    agent_with_optional_home=${home}/workspace/agent_with_optional
    if [[ ! -d ${agent_with_optional_home} ]]; then
        mkdir -p ${agent_with_optional_home}
        cp -r ${agent_home}/* ${agent_with_optional_home}
        mv ${agent_with_optional_home}/optional-plugins/* ${agent_with_optional_home}/plugins/
    fi
    _agent_home=${agent_with_optional_home}
elif [[ "$mode" == "with_bootstrap" ]]; then
    agent_with_bootstrap_home=${home}/workspace/agent_with_bootstrap
    if [[ ! -d ${agent_with_bootstrap_home} ]]; then
        mkdir -p ${agent_with_bootstrap_home}
        cp -r ${agent_home}/* ${agent_with_bootstrap_home}
        mv ${agent_with_bootstrap_home}/bootstrap-plugins/* ${agent_with_bootstrap_home}/plugins/
    fi
    _agent_home=${agent_with_bootstrap_home}
fi<commit_msg>Fix plugin test run.sh script parameter error (#3621)<commit_after>#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you 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.

home="$(cd "$(dirname $0)"; pwd)"
scenario_name=""
parallel_run_size=1
force_build="off"
build_id="latest"
cleanup="off"

mvnw=${home}/../../mvnw
agent_home=${home}"/../../skywalking-agent"
scenarios_home="${home}/scenarios"

print_help() {
    echo  "Usage: run.sh [OPTION] SCENARIO_NAME"
    echo -e "\t-f, --force_build \t\t do force to build Plugin-Test tools and images"
    echo -e "\t--build_id, \t\t\t specify Plugin_Test's image tag. Defalt: latest"
    echo -e "\t--parallel_run_size, \t\t parallel size of test cases. Default: 1"
    echo -e "\t--cleanup, \t\t\t remove the related images and directories"
}

parse_commandline() {
    _positionals_count=0
    while test $# -gt 0
    do
        _key="$1"
        case "$_key" in
            -f|--force_build)
                force_build="on"
                ;;
            --cleanup)
                cleanup="on"
                ;;
            --build_id)
                test $# -lt 2 && exitWithMessage "Missing value for the optional argument '$_key'."
                build_id="$2"
                shift
                ;;
            --build_id=*)
                build_id="${_key##--build_id=}"
                ;;
            --parallel_run_size)
                test $# -lt 2 && exitWithMessage "Missing value for the optional argument '$_key'."
                parallel_run_size="$2"
                shift
                ;;
            --parallel_run_size=*)
                parallel_run_size="${_key##--parallel_run_size=}"
                ;;
            -h|--help)
                print_help
                exit 0
                ;;
            -h*)
                print_help
                exit 0
                ;;
            *)
                scenario_name=$1
                ;;
        esac
        shift
    done
}

exitWithMessage() {
    echo -e "\033[31m[ERROR] $1\033[0m">&2
    exitAndClean 1
}

exitAndClean() {
    elapsed=$(( `date +%s` - $start_stamp ))
    num_of_testcases="`ls -l ${task_state_house} |grep -c FINISH`"
    printf "Scenarios: %s, Testcases: %d, parallel_run_size: %d, Elapsed: %02d:%02d:%02d \n" \
        ${scenario_name} "${num_of_testcases}" "${parallel_run_size}" \
        $(( ${elapsed}/3600 )) $(( ${elapsed}%3600/60 )) $(( ${elapsed}%60 ))
    exit $1
}

waitForAvailable() {
    while [[ `ls -l ${task_state_house} |grep -c RUNNING` -ge ${parallel_run_size} ]]
    do
        sleep 2
    done

    if [[ `ls -l ${task_state_house} |grep -c FAILURE` -gt 0 ]]; then
        exitAndClean 1
    fi
}

do_cleanup() {
    docker images -q "skywalking/agent-test-*:${build_id}" | xargs -r docker rmi -f
    [[ -d ${home}/dist ]] && rm -rf ${home}/dist
    [[ -d ${home}/workspace ]] && rm -rf ${home}/workspace
}

start_stamp=`date +%s`
parse_commandline "$@"

if [[ "$cleanup" == "on" ]]; then
    do_cleanup
    exit 0
fi

test -z "$scenario_name" && exitWithMessage "Missing value for the scenario argument"

if [[ ! -d ${agent_home} ]]; then
    echo "[WARN] SkyWalking Agent not exists"
    ${mvnw} -f ${home}/../../pom.xml -Pagent -DskipTests clean package 
fi
[[ "$force_build" == "on" ]] && ${mvnw} -f ${home}/pom.xml clean package -DskipTests -Dbuild_id=${build_id} docker:build

workspace="${home}/workspace/${scenario_name}"
task_state_house="${workspace}/.states"
[[ -d ${workspace} ]] && rm -rf $workspace
mkdir -p ${task_state_house}

plugin_runner_helper="${home}/dist/plugin-runner-helper.jar"
if [[ ! -f ${plugin_runner_helper} ]]; then
    exitWithMessage "Plugin Runner tools not exists, Please re-try it with '-f'"
    print_helper
fi

echo "start submit job"
scenario_home=${scenarios_home}/${scenario_name} && cd ${scenario_home}


supported_version_file=${scenario_home}/support-version.list
if [[ ! -f $supported_version_file ]]; then
    exitWithMessage "cannot found 'support-version.list' in directory ${scenario_name}"
fi

_agent_home=${agent_home}
mode=`grep "runningMode" ${scenario_home}/configuration.yml |sed -e "s/ //g" |awk -F: '{print $2}'`
if [[ "$mode" == "with_optional" ]]; then
    agent_with_optional_home=${home}/workspace/agent_with_optional
    if [[ ! -d ${agent_with_optional_home} ]]; then
        mkdir -p ${agent_with_optional_home}
        cp -r ${agent_home}/* ${agent_with_optional_home}
        mv ${agent_with_optional_home}/optional-plugins/* ${agent_with_optional_home}/plugins/
    fi
    _agent_home=${agent_with_optional_home}
elif [[ "$mode" == "with_bootstrap" ]]; then
    agent_with_bootstrap_home=${home}/workspace/agent_with_bootstrap
    if [[ ! -d ${agent_with_bootstrap_home} ]]; then
        mkdir -p ${agent_with_bootstrap_home}
        cp -r ${agent_home}/* ${agent_with_bootstrap_home}
        mv ${agent_with_bootstrap_home}/bootstrap-plugins/* ${agent_with_bootstrap_home}/plugins/
    fi
    _agent_home=${agent_with_bootstrap_home}
fi
{'fraction_non_alphanumeric': 0.14390654040180548, 'fraction_numerical': 0.009735374811930259, 'mean_word_length': 2.6346091990993887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5857202', 'n_tokens_mistral': 3745, 'n_tokens_neox': 3567, 'n_words': 939}