#!/bin/bash

# This file is part of the openHiTLS project.
#
# openHiTLS is licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#
#     http://license.coscl.org.cn/MulanPSL2
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# Build different miniaturized targets and perform basic functional testing.

set -eu

PARAM_LIST=$@

COMMON_PARAM=""
TEST=""
ASM_TYPE=""
CUR_DIR=`pwd`
HITLS_ROOT_DIR=`realpath $CUR_DIR/../../`

parse_option()
{
    for i in $PARAM_LIST
    do
        case "${i}" in
            "bsl"|"md"|"mac"|"kdf"|"cipher"|"bn"|"ecc"|"pkey"|"pki"|"all"|"tls"|"provider")
                TEST=$i
                ;;
            "x8664"|"armv8")
                ASM_TYPE=$i
                COMMON_PARAM="$COMMON_PARAM $i"
                ;;
            "linux")
                COMMON_PARAM="$COMMON_PARAM $i"
                ;;
            "32")
                COMMON_PARAM="$COMMON_PARAM $i"
                ;;
            "big")
                COMMON_PARAM="$COMMON_PARAM $i"
                ;;
            "tls-debug")
                COMMON_PARAM="$COMMON_PARAM $i"
                ;;
            "debug"|"asan")
                COMMON_PARAM="$COMMON_PARAM $i"
                ;;
            *)
                echo "Wrong parameter: $i" 
                exit 1
                ;;
        esac
    done
}

test_bsl()
{
    NO_LIB="no-crypto no-tls linux"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=asn1 test=asn1
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=base64 test=base64
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=buffer test=buffer
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=err test=err
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=hash test=hash
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=init test=init
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=list test=list
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=log test=log
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=obj_default test=obj
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=obj_custom,hash,sal_thread test=obj # depends on thread to init hash
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=params test=params
    # PEM cases read cert/key files via BSL_SAL_ReadFile, so sal_file is required.
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=pem,sal_file test=pem

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=sal test=sal
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=sal_mem test=sal_mem
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=sal_thread test=sal_thread
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=sal_lock test=sal_lock
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=sal_time test=sal_time
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=sal_file test=sal_file
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=sal_net test=sal_net
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=sal_str test=sal_str
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=sal_dl test=sal_dl

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=tlv test=tlv

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=uio test=uio
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=uio_buffer
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=uio_mem
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=uio_sctp
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=uio_tcp
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=uio_udp
}

test_md()
{
    NO_LIB="no-tls"
    if [ "$ASM_TYPE" = "armv8" ]; then
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sm3 test=sm3
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,ealinit,sha1 test=sha1
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,ealinit,sha2 test=sha2
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,ealinit,sha224 test=sha224
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,ealinit,sha256 test=sha256
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha384 test=sha384
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha512 test=sha512
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha3 test=sha3
    elif [ "$ASM_TYPE" = "x8664" ]; then
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sm3,ealinit test=sm3
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,md5 test=md5
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha1 test=sha1
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha2 test=sha2
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha224 test=sha224
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha256 test=sha256
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha384 test=sha384
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha512 test=sha512
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha3 test=sha3
    else
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,md5 test=md5
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sm3 test=sm3
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha1 test=sha1
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha2 test=sha2
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha224 test=sha224
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha256 test=sha256
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha384 test=sha384
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha512 test=sha512
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sha3 test=sha3
    fi
}

test_mac()
{
    NO_LIB="no-tls"
    ASM_EALINIT=""
    if [ "$ASM_TYPE" != "" ]; then
        ASM_EALINIT=",ealinit"
    fi
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,hmac,md5 test=hmac
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,hmac,sha1 test=hmac
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,hmac,sha2 test=hmac
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,hmac,sha224 test=hmac
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,hmac,sha256 test=hmac
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,hmac,sha384 test=hmac
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,hmac,sha512 test=hmac
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,hmac,sha3 test=hmac
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,hmac,sm3${ASM_EALINIT} test=hmac

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,gmac test=gmac

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,cmac_aes test=cmac_aes
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,cmac_sm4 test=cmac_sm4
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,cbc_mac test=cbc_mac

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,siphash test=siphash
}

test_kdf()
{
    NO_LIB="no-tls"
    ASM_EALINIT=""
    if [ "$ASM_TYPE" != "" ]; then
        ASM_EALINIT=",ealinit"
    fi
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,scrypt test=scrypt

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,hkdf,md5 test=hkdf
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,hkdf,sha1 test=hkdf
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,hkdf,sha2 test=hkdf

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,pbkdf2,md5 test=pbkdf2
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,pbkdf2,sha1 test=pbkdf2
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,pbkdf2,sha2 test=pbkdf2
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,pbkdf2,sha3 test=pbkdf2
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,pbkdf2,sm3${ASM_EALINIT} test=pbkdf2

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,kdftls12,sha256 test=kdftls12
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,kdftls12,sha384 test=kdftls12
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,kdftls12,sha512 test=kdftls12
}

test_cipher()
{
    NO_LIB="no-tls"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,aes,modes test=aes
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,aes,cbc test=aes
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,aes,ctr test=aes
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,aes,ecb test=aes # SDV_CRYPTO_AES_ENCRYPT_FUNC_TC001
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,aes,xts test=aes # SDV_CRYPTO_EAL_AES_FUNC_TC001
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,aes,ccm test=aes
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,aes,gcm test=aes
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,aes,cfb test=aes
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,aes,ofb test=aes

    if [ "$ASM_TYPE" = "x8664" ]; then
        # depends on ealinit
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,ealinit,sm4,modes test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,ealinit,sm4,xts test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,ealinit,sm4,cbc test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,ealinit,sm4,ecb test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,ealinit,sm4,ctr test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,ealinit,sm4,gcm test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,ealinit,sm4,cfb test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,ealinit,sm4,ofb test=sm4
    else
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sm4,modes test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sm4,xts test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sm4,cbc test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sm4,ecb test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sm4,ctr test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sm4,gcm test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sm4,cfb test=sm4
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,sm4,ofb test=sm4
    fi

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,chacha20 test=chacha20
}

test_bn()
{
    NO_LIB="no-tls"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=bn
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=bn_basic
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal_bn
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=bn_rand
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=bn_prime
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=bn_str_conv
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=bn_cb
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=bn_prime_rfc
}

test_ecc()
{
    NO_LIB="no-tls"
    ASM_EALINIT=""
    EAL_BN_ENABLE="eal,eal_bn"
    if [ "$ASM_TYPE" != "" ]; then
        ASM_EALINIT=",ealinit"
        EAL_BN_ENABLE="eal,eal_bn,ealinit"
    fi
    if [ "$ASM_TYPE" = "armv8" -o "$ASM_TYPE" = "x8664" ]; then
        # The curves that support assembly are: curve_sm2, curve_nistp256
        # all curves.
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,eal_bn,ecdh,ecdsa,sm2,drbg_hash,entropy,sha2,ecc,ealinit test=curve_nistp224 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SHA256" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON"
        # sm2, depends on sm3
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,eal_bn,sm2,drbg_hash,entropy,ealinit test=sm2 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SM3" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON" add-feature-options="-DHITLS_CRYPTO_DRBG_GM=ON"
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,eal_bn,sm2_crypt,drbg_hash,entropy,ealinit test=sm2_crypt add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SM3" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON" add-feature-options="-DHITLS_CRYPTO_DRBG_GM=ON"
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,eal_bn,sm2_exch,drbg_hash,entropy,ealinit test=sm2_exch add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SM3" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON" add-feature-options="-DHITLS_CRYPTO_DRBG_GM=ON"
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,eal_bn,sm2_sign,drbg_hash,entropy,ealinit test=sm2_sign add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SM3" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON" add-feature-options="-DHITLS_CRYPTO_DRBG_GM=ON"
        # nistp256
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=eal,eal_bn,ecdh,ecdsa,drbg_hash,entropy,sha2,curve_nistp256,ealinit test=curve_nistp256 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SHA256" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON"
    fi

    # Test all curves.
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},ecdh,ecdsa,sm2,drbg_hash,entropy,sha2,ecc test=curve_nistp224 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SHA256" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON"

    # nist192/224/256/384/521
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},ecdh,ecdsa,drbg_hash,entropy,sha2,curve_nistp192 test=curve_nistp192 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SHA256" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},ecdh,ecdsa,drbg_hash,entropy,sha2,curve_nistp224 test=curve_nistp224 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SHA256" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},ecdh,ecdsa,drbg_hash,entropy,sha2,curve_nistp256 test=curve_nistp256 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SHA256" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},ecdh,ecdsa,drbg_hash,entropy,sha2,curve_nistp384 test=curve_nistp384 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SHA256" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},ecdh,ecdsa,drbg_hash,entropy,sha2,curve_nistp521 test=curve_nistp521 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SHA256" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON"

    # br256/384/512
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},ecdh,ecdsa,drbg_hash,entropy,sha2,curve_bp256r1 test=curve_bp256r1 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SHA256" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},ecdh,ecdsa,drbg_hash,entropy,sha2,curve_bp384r1 test=curve_bp384r1 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SHA256" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},ecdh,ecdsa,drbg_hash,entropy,sha2,curve_bp512r1 test=curve_bp512r1 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SHA256" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON"

    # sm2 depends on sm3 by default.
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},sm2,drbg_hash,entropy test=sm2 add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SM3" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON" add-feature-options="-DHITLS_CRYPTO_DRBG_GM=ON"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},sm2_crypt,drbg_hash,entropy test=sm2_crypt add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SM3" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON" add-feature-options="-DHITLS_CRYPTO_DRBG_GM=ON"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},sm2_exch,drbg_hash,entropy test=sm2_exch add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SM3" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON" add-feature-options="-DHITLS_CRYPTO_DRBG_GM=ON"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},sm2_sign,drbg_hash,entropy test=sm2_sign add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SM3" add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON" add-feature-options="-DHITLS_CRYPTO_DRBG_GM=ON"
}

test_pkey()
{
    NO_LIB="no-tls"
    EAL_ENABLE="eal"
    EAL_BN_ENABLE="eal,eal_bn"
    if [ "$ASM_TYPE" = "x8664" -o "$ASM_TYPE" = "armv8" ]; then
        EAL_ENABLE="eal,ealinit"
        EAL_BN_ENABLE="eal,eal_bn,ealinit"
        # The pkey that support assembly is: x25519.
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=x25519,sha2,ealinit
        bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},x25519,drbg_hash,sha2 test=x25519
    fi
    # rsa
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa,rsa_bssa,drbg_hash,sha1,sha2 test=rsa
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa,drbg_hash,sha1,sha2 test=rsa

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_gen,drbg_hash,sha1,sha2 test=rsa_gen

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_sign,rsa_emsa_pss,sha1,sha2,drbg_hash test=rsa_sign
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_sign,rsa_emsa_pss,drbg_hash,sha1,sha2 test=rsa_sign
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_sign,rsa_emsa_pkcsv15,sha1,sha2 test=rsa_sign # not need drbg
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_verify,rsa_emsa_pss,sha1,sha2 test=rsa_verify # not need drbg
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_verify,rsa_emsa_pkcsv15,sha1,sha2 test=rsa_verify # not need drbg

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_encrypt,rsa_no_pad,sha1,sha2 test=rsa_encrypt # not need drbg
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_encrypt,rsaes_oaep,drbg_hash,sha1,sha2 test=rsa_encrypt
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_encrypt,rsaes_pkcsv15,drbg_hash,sha1,sha2 test=rsa_encrypt
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_encrypt,rsaes_pkcsv15_tls,drbg_hash,sha1,sha2 test=rsa_encrypt

    # rsa_decrypt: not need drbg
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_decrypt,rsa_no_pad,sha1,sha2 test=rsa_decrypt
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_decrypt,rsaes_oaep,sha1,sha2 test=rsa_decrypt
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_decrypt,rsaes_pkcsv15,sha1,sha2 test=rsa_decrypt
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_decrypt,rsaes_pkcsv15_tls,sha1,sha2 test=rsa_decrypt

    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_sign,rsa_blinding,rsa_emsa_pkcsv15,drbg_hash,sha1,sha2 test=rsa_sign
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_decrypt,rsa_blinding,rsaes_oaep,drbg_hash,sha1,sha2 test=rsa_decrypt
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_sign,rsa_bssa,rsa_blinding,rsa_emsa_pss,drbg_hash,sha1,sha2 test=rsa_sign
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},rsa_sign,rsa_verify,rsa_bssa,rsa_emsa_pss,drbg_hash,sha1,sha2 test=rsa_sign

    # dsa
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_BN_ENABLE},dsa,drbg_hash,sha2 test=dsa

    # dh
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},dh,drbg_hash,sha2 test=dh

    # curve25519: ed25519 depends on sha512 by default.
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},x25519,drbg_hash,sha2 test=x25519
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},ed25519,drbg_hash,sha2 test=ed25519

    # mldsa
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},mldsa,pkey_cmp,drbg_hash,sha2 test=mldsa

    # paillier
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},paillier,drbg_hash,sha2 test=paillier

    # mlkem
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},mlkem,pkey_cmp,drbg_hash,sha2 test=mlkem

    # hybridkem
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},hybridkem,x25519,ecdh,ecc,drbg_hash,sha2 test=hybridkem

    # elgamal
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},elgamal,drbg_hash,sha2 test=elgamal

    # slh_dsa
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},slh_dsa,drbg_hash,sha2 test=slh_dsa
    
    # xmss
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB enable=${EAL_ENABLE},xmss,xmssmt,drbg_hash,sha2 test=xmss
}

test_tls()
{
    NO_LIB=""
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB feature-config=tlcp_feature \
        test=base,asn1,base64,buffer,err,hash,init,list,log,obj,params,pem,tlv,sal,sal_mem,sal_lock,sal_str,sal_file,sal_thread,sal_net,sal_time,aes,bn,chacha20,cmac_aes,drbg_ctr,drbg_hash,ecc,ecdh,ecdsa,entropy,gcm,hkdf,hpke,mlkem,mldsa,sha256,sha384,sha512,slh_dsa,sm2,sm3,sm4,x25519,curve_nistp256,curve_nistp384,curve_nistp521,x509_crl_gen,x509_crl_parse,x509_csr_gen,x509_csr_parse,x509_crt_gen,x509_crt_parse,x509_vfy,tlcp \
        linux \
        add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SHA256" \
        add-feature-options="-DHITLS_CRYPTO_ENTROPY_DEVRANDOM=ON" \
        add-feature-options="-DHITLS_CRYPTO_MLKEM_CMP=ON" \
        add-feature-options="-DHITLS_CRYPTO_MLDSA_CMP=ON"
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB feature-config=nokem_feature test=base linux
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB feature-config=mtu_feature test=mtu linux
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB feature-config=max_send_fragment_feature test=max_send_fragment linux
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB feature-config=ca_list_feature test=ca_list linux
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB feature-config=no_dfx_feature test=no_dfx add-options="-fno-short-enums" linux
    TLS_PARSE_MSG_BUILD_OPTS="add-feature-options=-DHITLS_PRESET_LOADED=ON \
        add-feature-options=-DHITLS_BUILD_SHARED=ON \
        add-feature-options=-DHITLS_BSL_LOG=ON \
        add-feature-options=-DHITLS_CRYPTO_EAL=ON \
        add-feature-options=-DHITLS_CRYPTO_EALINIT=ON \
        add-feature-options=-DHITLS_CRYPTO_ENTROPY=ON \
        add-feature-options=-DHITLS_CRYPTO_DRBG_HASH=ON \
        add-feature-options=-DHITLS_CRYPTO_SHA1=ON \
        add-feature-options=-DHITLS_CRYPTO_SHA2=ON \
        add-feature-options=-DHITLS_CRYPTO_HKDF=ON \
        add-feature-options=-DHITLS_CRYPTO_AES=ON \
        add-feature-options=-DHITLS_CRYPTO_CBC=ON \
        add-feature-options=-DHITLS_CRYPTO_BN=ON \
        add-feature-options=-DHITLS_CRYPTO_RSA=ON \
        add-feature-options=-DHITLS_CRYPTO_ECDH=ON \
        add-feature-options=-DHITLS_CRYPTO_ECDSA=ON \
        add-feature-options=-DHITLS_CRYPTO_ECC=ON \
        add-feature-options=-DHITLS_CRYPTO_CURVE_NISTP256=ON \
        add-feature-options=-DHITLS_CRYPTO_CODECSKEY=ON \
        add-feature-options=-DHITLS_TLS_CALLBACK_SAL=ON \
        add-feature-options=-DHITLS_TLS_CALLBACK_CERT=ON \
        add-feature-options=-DHITLS_TLS_CALLBACK_CRYPT=ON \
        add-feature-options=-DHITLS_TLS_CONFIG=ON \
        add-feature-options=-DHITLS_TLS_FEATURE_SESSION=ON \
        add-feature-options=-DHITLS_TLS_FEATURE_SESSION_TICKET=ON \
        add-feature-options=-DHITLS_TLS_FEATURE_SESSION_ID=ON \
        add-feature-options=-DHITLS_TLS_PROTO_TLS12=ON \
        add-feature-options=-DHITLS_TLS_SUITE_ECDHE_RSA_WITH_AES_128_CBC_SHA=ON \
        add-feature-options=-DHITLS_PKI_X509=ON"
    # Build-only checks: shared linking catches parser references removed by host-specific macro pruning.
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB linux $TLS_PARSE_MSG_BUILD_OPTS \
        add-feature-options=-DHITLS_TLS_HOST_CLIENT=ON
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB linux $TLS_PARSE_MSG_BUILD_OPTS \
        add-feature-options=-DHITLS_TLS_HOST_SERVER=ON
}

test_pki()
{
    PKI_EAL_ENABLE="eal"
    if [ "$ASM_TYPE" != "" ]; then
        PKI_EAL_ENABLE="eal,ealinit"
    fi
    PKI_PROVIDER_CIPHER_EAL_ENABLE="${PKI_EAL_ENABLE}"
    if [[ ",${PKI_PROVIDER_CIPHER_EAL_ENABLE}," != *,ealinit,* ]]; then
        PKI_PROVIDER_CIPHER_EAL_ENABLE="${PKI_PROVIDER_CIPHER_EAL_ENABLE},ealinit"
    fi
    bash mini_build_test.sh no-tls enable=sal_thread,eal,codecskey,rsa,drbg_hash,cipher,modes,sha256,hmac
    bash mini_build_test.sh no-tls enable=sal_thread,eal,key_epki,key_encode,rsa,drbg_hash,cipher,modes,sha256,hmac
    bash mini_build_test.sh no-tls enable=sal_thread,eal,key_encode,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,key_decode,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,x509,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,x509_crt,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,x509_crt_gen,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,x509_crt_parse,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,x509_csr,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,x509_csr_gen,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,x509_csr_parse,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,x509_crl,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,x509_crl_gen,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,x509_crl_parse,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,x509_vfy,rsa,sha256,drbg_hash
    bash mini_build_test.sh no-tls enable=sal_thread,eal,pkcs12,rsa,sha256,drbg_hash,md,cipher,modes,hmac
    bash mini_build_test.sh no-tls enable=sal_thread,eal,pkcs12_gen,rsa,sha256,drbg_hash,md,cipher,modes,hmac
    bash mini_build_test.sh no-tls enable=sal_thread,eal,pkcs12_parse,rsa,drbg_hash,md,cipher,modes,hmac
    bash mini_build_test.sh no-tls enable=sal_thread,eal,info_crt,x509_crt_gen,rsa,drbg_hash,md,cipher,modes,hmac
    bash mini_build_test.sh no-tls enable=sal_thread,eal,info_csr,x509_csr_gen,rsa,drbg_hash,md,cipher,modes,hmac
    bash mini_build_test.sh no-tls enable=sal_thread,eal,info_crl,x509_crl_gen,rsa,drbg_hash,md,cipher,modes,hmac
    bash mini_build_test.sh no-tls enable=sal_thread,eal,info_crt,x509_crt_parse,rsa,drbg_hash,md,cipher,modes,hmac
    bash mini_build_test.sh no-tls enable=sal_thread,eal,info_csr,x509_csr_parse,rsa,drbg_hash,md,cipher,modes,hmac
    bash mini_build_test.sh no-tls enable=sal_thread,eal,info_crl,x509_crl_parse,rsa,drbg_hash,md,cipher,modes,hmac

    #### key gen ####
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_encode,sal_file,pem,rsa,sha256,drbg_hash test=key_encode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_encode,pem,ed25519,drbg_hash test=key_encode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_encode,key_epki,pem,x25519,drbg_hash,cipher,modes,sha256,hmac test=key_encode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_encode,sal_file,sm2,sha256,drbg_hash test=key_encode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_encode,pem,ecdsa,curve_nistp256,sha256,drbg_hash test=key_encode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_encode,pem,mldsa,sha256,drbg_hash test=key_encode

    #### key parse ####
    echo "Test: key_decode without provider"
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode,sal_file,pem,rsa,sha256,drbg_hash test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode,sal_file,pem,ed25519,drbg_hash test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode,key_epki,sal_file,pem,x25519,drbg_hash,cipher,modes,sha256,hmac test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode,sal_file,sm2,sha256,drbg_hash test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode,sal_file,pem,ecdsa,curve_nistp256,sha256,drbg_hash test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode,sal_file,pem,mldsa,sha256,drbg_hash test=key_decode

    echo "Test: key_decode with provider"
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode,provider,sal_dl,sal_file,pem,rsa,sha256,drbg_hash test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode,provider,sal_dl,sal_file,pem,ed25519,drbg_hash test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_PROVIDER_CIPHER_EAL_ENABLE},key_decode,key_epki,provider,sal_dl,sal_file,pem,x25519,drbg_hash,cipher,modes,sha256,hmac test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode,provider,sal_dl,sal_file,sm2,sha256,drbg_hash test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode,provider,sal_dl,sal_file,pem,ecdsa,curve_nistp256,sha256,drbg_hash test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode,provider,sal_dl,sal_file,pem,mldsa,sha256,drbg_hash test=key_decode

    echo "Test: key_decode_chain (with provider)"
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode_chain,sal_dl,sal_file,pem,rsa,sha256,drbg_hash test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode_chain,sal_dl,sal_file,pem,ed25519,drbg_hash test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_PROVIDER_CIPHER_EAL_ENABLE},key_decode_chain,key_epki,provider,sal_dl,sal_file,pem,x25519,drbg_hash,cipher,modes,sha256,hmac test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode_chain,sal_dl,sal_file,sm2,sha256,drbg_hash test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode_chain,sal_dl,sal_file,pem,ecdsa,curve_nistp256,sha256,drbg_hash test=key_decode
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},key_decode_chain,sal_dl,sal_file,pem,mldsa,sha256,drbg_hash test=key_decode

    #### crl gen ####
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_crl_gen,rsa,sal_file,pem,sha256,drbg_hash test=x509_crl_gen
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_crl_gen,pem,ed25519,drbg_hash test=x509_crl_gen
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_crl_gen,sm2,sha256,drbg_hash test=x509_crl_gen
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_crl_gen,sal_file,ecdsa,curve_nistp256,sha256,drbg_hash test=x509_crl_gen

    #### crl parse ####
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_crl_parse,pem,sal_file,rsa,sha256,drbg_hash test=x509_crl_parse
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_crl_parse,sal_file,ed25519,sha256,drbg_hash test=x509_crl_parse
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_crl_parse,pem,sal_file,sm2,sha256,drbg_hash test=x509_crl_parse
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_crl_parse,sal_file,ecdsa,curve_nistp256,sha256,drbg_hash test=x509_crl_parse

    #### csr gen ####
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_csr_gen,x509_csr_attr,x509_csr_get,pem,rsa,sha256,drbg_hash test=x509_csr_gen
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_csr_gen,x509_csr_attr,x509_csr_get,sal_file,ed25519,drbg_hash test=x509_csr_gen add-feature-options="-DHITLS_CRYPTO_ED25519_CHECK=ON"
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_csr_gen,x509_csr_attr,x509_csr_get,sm2,sha256,drbg_hash test=x509_csr_gen
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_csr_gen,x509_csr_attr,x509_csr_get,sal_file,pem,ecdsa,curve_nistp256,sha256,drbg_hash test=x509_csr_gen

    #### csr parse ####
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_csr_parse,x509_csr_attr,x509_csr_get,sal_file,rsa,sha256,drbg_hash test=x509_csr_parse
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_csr_parse,x509_csr_attr,x509_csr_get,sal_file,pem,ed25519,drbg_hash test=x509_csr_parse
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_csr_parse,x509_csr_attr,x509_csr_get,sal_file,pem,sm2,sha256,drbg_hash test=x509_csr_parse
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_csr_parse,x509_csr_attr,x509_csr_get,sal_file,ecdsa,curve_nistp256,sha256,drbg_hash test=x509_csr_parse

    #### cert gen ####
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=${PKI_EAL_ENABLE},x509_crt_gen,pem,rsa,sha256,drbg_hash,sal_str,sal_thread test=x509_crt_gen
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=${PKI_EAL_ENABLE},x509_crt_gen,sal_file,pem,ed25519,drbg_hash,sal_str,sal_thread test=x509_crt_gen
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=${PKI_EAL_ENABLE},x509_crt_gen,sal_file,sm2,sha256,drbg_hash,sal_str,sal_thread test=x509_crt_gen
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=${PKI_EAL_ENABLE},x509_crt_gen,ecdsa,curve_nistp256,sha256,drbg_hash,sal_str,sal_thread test=x509_crt_gen

    #### cert parse ####
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_crt_parse,sal_file,sal_str,pem,rsa,sha256,drbg_hash test=x509_crt_parse
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_crt_parse,sal_file,sal_str,ed25519,drbg_hash test=x509_crt_parse
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_crt_parse,sal_file,sal_str,sm2,sha256,drbg_hash test=x509_crt_parse
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_crt_parse,sal_file,sal_str,pem,ecdsa,curve_nistp256,curve_nistp384,sha256,drbg_hash test=x509_crt_parse

    #### cert chain ####
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},x509_vfy,sal_file,sal_str,pem,rsa,ecdsa,curve_nistp256,curve_nistp384,ed25519,sm2,sha2,drbg_hash test=x509_vfy

    ### pkcs12 gen ####
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},sal_file,sal_str,pkcs12_gen,key_decode,x509_crl,sal_file,pem,rsa,ecdsa,curve_nistp256,ed25519,sm2,drbg_hash,cipher,modes,md,hmac test=pkcs12_gen
    bash mini_build_test.sh $COMMON_PARAM linux no-tls enable=sal_thread,${PKI_EAL_ENABLE},pkcs12_parse,x509_crl,x509_crt,x509_crl,x509_vfy,sal_file,sal_str,pem,rsa,ecdsa,curve_nistp256,curve_nistp384,curve_nistp521,ed25519,sm2,cipher,modes,md,drbg_hash,hmac test=pkcs12_parse
}

provider_test_check()
{
    set +e
    nm $HITLS_ROOT_DIR/build/libhitls_crypto.a | grep CRYPT_SHA2_256_
    if [ "$?" != "1" ]; then
        echo "Error: CRYPT_SHA2_256_ is found in libhitls_crypto.a"
        exit 1
    fi
    nm $HITLS_ROOT_DIR/build/libhitls_crypto.a | grep CRYPT_EAL_ProviderMdNewCtx
    if [ "$?" != "0" ]; then
        echo "Error: CRYPT_EAL_ProviderMdNewCtx is not found in libhitls_crypto.a"
        exit 1
    fi
}

test_provider()
{
    NO_LIB="no-tls"
    MD_CONFIG_PARAM="add-feature-options=-DHITLS_CRYPTO_MD=ON add-feature-options=-DHITLS_CRYPTO_SHA256=OFF add-feature-options=-DHITLS_CRYPTO_SHA224=OFF add-feature-options=-DHITLS_CRYPTO_SM3=OFF"

    # sha256
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB $MD_CONFIG_PARAM linux enable=eal,provider,sal_dl test=provider add-feature-options="-DHITLS_CRYPTO_MD=ON"
    provider_test_check

    # hmac
    # build without sha256, and not check config
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB $MD_CONFIG_PARAM linux enable=eal,provider,sal_dl,hmac test=provider add-feature-options="-DHITLS_SKIP_CONFIG_CHECK=ON"
    provider_test_check

    # hkdf
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB $MD_CONFIG_PARAM linux enable=eal,provider,sal_dl,hkdf test=provider add-feature-options="-DHITLS_SKIP_CONFIG_CHECK=ON"
    provider_test_check

    # pbkdf2
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB $MD_CONFIG_PARAM linux enable=eal,provider,sal_dl,pbkdf2 test=provider add-feature-options="-DHITLS_SKIP_CONFIG_CHECK=ON"
    provider_test_check

    # kdftls12
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB $MD_CONFIG_PARAM linux enable=eal,provider,sal_dl,kdftls12 test=provider add-feature-options="-DHITLS_SKIP_CONFIG_CHECK=ON"
    provider_test_check

    # rsa
    bash mini_build_test.sh $COMMON_PARAM $NO_LIB $MD_CONFIG_PARAM linux enable=eal,provider,sal_dl,rsa,sm3,drbg_hash,entropy,ealinit test=provider add-feature-options="-DHITLS_SEED_DRBG_INIT_RAND_ALG=CRYPT_RAND_SM3" add-feature-options="-DHITLS_CRYPTO_DRBG_GM=ON" add-feature-options="-DHITLS_SKIP_CONFIG_CHECK=ON"
    provider_test_check
}

parse_option

case $TEST in
    "all")
        test_bsl
        test_md
        test_mac
        test_kdf
        test_cipher
        test_bn
        test_ecc
        test_pkey
        test_pki
        test_tls
        test_provider
        ;;
    "bsl")
        test_bsl
        ;;
    "md")
        test_md
        ;;
    "mac")
        test_mac
        ;;
    "kdf")
        test_kdf
        ;;
    "cipher")
        test_cipher
        ;;
    "bn")
        test_bn
        ;;
    "ecc")
        test_ecc
        ;;
    "pkey")
        test_pkey
        ;;
    "pki")
        test_pki
        ;;
    "tls")
        test_tls
        ;;
    "provider")
        test_provider
        ;;
    *)
        ;;
esac