add "HITLS_ATOMIC_THREAD_LOCK" macro to cover the thread-lock implemented atomic

Co-authored-by: Liu-Ermeng<liuermeng2@huawei.com>

# message auto-generated for no-merge-commit merge:
merge workflow into openhitls-0.2

add "HITLS_ATOMIC_THREAD_LOCK" macro to cover the thread-lock implemented atomic

Created-by: dumb
Commit-by: Liu-Ermeng
Merged-by: fly2x
Description: add pure-c and minitest workflows
add "HITLS_ATOMIC_THREAD_LOCK" macro to cover the thread-lock implemented atomic

See merge request: openHiTLS/openhitls!311

Signed-off-by: lanming <lanming@huawei.com>
This commit is contained in:
dumb
2025-05-28 19:22:43 +08:00
committed by lanming
parent 99c41c6c54
commit 0d8a22464a
10 changed files with 146 additions and 9 deletions
@@ -50,3 +50,64 @@ jobs:
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
pure-c:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 1
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cd testcode/script && bash build_hitls.sh no_sctp asan gcov pure_c add-options="-DHITLS_ATOMIC_THREAD_LOCK"
- name: Build
# Build your program with the given configuration
working-directory: ${{github.workspace}}/build
run: make -j
- name: Test
working-directory: ${{github.workspace}}/testcode/script
# Execute tests defined by the CMake configuration.
run: bash build_sdv.sh no-sctp asan gcov add-options="-DHITLS_ATOMIC_THREAD_LOCK" && bash execute_sdv.sh
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: openhitls-pure-c
path: ${{ github.workspace }}/build
retention-days: 5
- name: Upload coverage
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
mini-test:
uses: ./.github/workflows/minitest-reusable-job.yml
with:
param1: 'all'
param2: 'mini-test-pure-c'
param3: 'ubuntu-latest'
mini-test-x86:
uses: ./.github/workflows/minitest-reusable-job.yml
with:
param1: 'all x8664'
param2: 'mini-test-x86'
param3: 'ubuntu-latest'
# TODO: fix the 'Illegal instruction' when run on ubuntu-22.04-
#
# mini-test-armv8:
# uses: ./.github/workflows/reusable-job.yml
# with:
# param1: 'all armv8'
# param2: 'mini-test-armv8'
# param3: 'ubuntu-22.04-arm'
@@ -0,0 +1,44 @@
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: Minitest Reusable Job
on:
workflow_call:
inputs:
param1:
description: 'mini-test build parameter'
required: true
type: string
param2:
description: 'mini-test name'
required: true
type: string
param3:
description: 'mini-test run platform'
required: true
type: string
jobs:
reusable-job:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ${{ inputs.param3 }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 1
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: lscpu && cd testcode/script && bash all_mini_test.sh ${{ inputs.param1 }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: openhitls-${{ inputs.param2 }}
path: ${{ github.workspace }}/build
retention-days: 5
+2 -2
View File
@@ -39,7 +39,7 @@ int BSL_SAL_AtomicAdd(int *val, int amount, int *ref, BSL_SAL_ThreadLockHandle l
* memory_order_relaxed only ensures the atomicity of the current operation
* and does not consider the synchronization between threads.
*/
#if defined(SAL_HAVE_C11_ATOMICS) && defined(ATOMIC_INT_LOCK_FREE) && ATOMIC_INT_LOCK_FREE > 0
#if defined(SAL_HAVE_C11_ATOMICS) && defined(ATOMIC_INT_LOCK_FREE) && ATOMIC_INT_LOCK_FREE > 0 && !defined(HITLS_ATOMIC_THREAD_LOCK)
#define SAL_USE_ATOMICS_LIB_FUNC
typedef struct {
atomic_int count;
@@ -61,7 +61,7 @@ static inline int BSL_SAL_AtomicDownReferences(BSL_SAL_RefCount *references, int
}
/* Atom operation mode 2, using the function provided by the GCC. */
#elif defined(__GNUC__) && defined(__ATOMIC_RELAXED) && __GCC_ATOMIC_INT_LOCK_FREE > 0
#elif defined(__GNUC__) && defined(__ATOMIC_RELAXED) && __GCC_ATOMIC_INT_LOCK_FREE > 0 && !defined(HITLS_ATOMIC_THREAD_LOCK)
#define SAL_USE_ATOMICS_LIB_FUNC
typedef struct {
int count;
+1 -1
View File
@@ -157,7 +157,7 @@ int32_t CRYPT_EAL_PkeyCopyCtx(CRYPT_EAL_PkeyCtx *to, const CRYPT_EAL_PkeyCtx *fr
to->method->freeCtx(to->key);
to->key = NULL;
}
BSL_SAL_ReferencesFree(&(to->references));
return PkeyCopyCtx(to, from);
}
+1
View File
@@ -118,6 +118,7 @@ int32_t CRYPT_ELGAMAL_SetPrvKey(CRYPT_ELGAMAL_Ctx *ctx, const BSL_Param *para)
ELGAMAL_FREE_PRV_KEY(ctx->prvKey);
ctx->prvKey = newCtx->prvKey;
BSL_SAL_ReferencesFree(&(newCtx->references));
BSL_SAL_FREE(newCtx);
return ret;
+1
View File
@@ -156,6 +156,7 @@ int32_t CRYPT_PAILLIER_SetPrvKey(CRYPT_PAILLIER_Ctx *ctx, const BSL_Param *para)
PAILLIER_FREE_PRV_KEY(ctx->prvKey);
ctx->prvKey = newCtx->prvKey;
BSL_SAL_ReferencesFree(&(newCtx->references));
BSL_SAL_FREE(newCtx);
return ret;
ERR:
+1
View File
@@ -189,6 +189,7 @@ int32_t CRYPT_RSA_SetPrvKey(CRYPT_RSA_Ctx *ctx, const BSL_Param *para)
ctx->prvKey = newCtx->prvKey;
ctx->pad = newCtx->pad;
BSL_SAL_ReferencesFree(&(newCtx->references));
BSL_SAL_FREE(newCtx);
return ret;
ERR:
+1
View File
@@ -134,6 +134,7 @@ void HITLS_X509_CsrFree(HITLS_X509_Csr *csr)
if (ret > 0) {
return;
}
BSL_SAL_ReferencesFree(&(csr->references));
if (csr->flag == HITLS_X509_CSR_GEN_FLAG) {
BSL_LIST_FREE(csr->reqInfo.subjectName, (BSL_LIST_PFUNC_FREE)HITLS_X509_FreeNameNode);
BSL_SAL_FREE(csr->reqInfo.reqInfoRawData);
+26 -6
View File
@@ -29,6 +29,25 @@ LIB_TYPE="static"
enable_sctp="--enable-sctp"
BITS=64
usage()
{
printf "%-50s %-30s\n" "Build openHiTLS Code" "sh build_hitls.sh"
printf "%-50s %-30s\n" "Build openHiTLS Code With Gcov" "sh build_hitls.sh gcov"
printf "%-50s %-30s\n" "Build openHiTLS Code With Debug" "sh build_hitls.sh debug"
printf "%-50s %-30s\n" "Build openHiTLS Code With Asan" "sh build_hitls.sh asan"
printf "%-50s %-30s\n" "Build openHiTLS Code With Pure C" "sh build_hitls.sh pure_c"
printf "%-50s %-30s\n" "Build openHiTLS Code With X86_64" "sh build_hitls.sh x86_64"
printf "%-50s %-30s\n" "Build openHiTLS Code With Armv8_be" "sh build_hitls.sh armv8_be"
printf "%-50s %-30s\n" "Build openHiTLS Code With Armv8_le" "sh build_hitls.sh armv8_le"
printf "%-50s %-30s\n" "Build openHiTLS Code With Add Options" "sh build_hitls.sh add-options=xxx"
printf "%-50s %-30s\n" "Build openHiTLS Code With No Provider" "sh build_hitls.sh no-provider"
printf "%-50s %-30s\n" "Build openHiTLS Code With No Sctp" "sh build_hitls.sh no_sctp"
printf "%-50s %-30s\n" "Build openHiTLS Code With Bits" "sh build_hitls.sh bits=xxx"
printf "%-50s %-30s\n" "Build openHiTLS Code With Lib Type" "sh build_hitls.sh shared"
printf "%-50s %-30s\n" "Build openHiTLS Code With Lib Fuzzer" "sh build_hitls.sh libfuzzer"
printf "%-50s %-30s\n" "Build openHiTLS Code With Help" "sh build_hitls.sh help"
}
clean()
{
rm -rf ${HITLS_ROOT_DIR}/build
@@ -91,6 +110,9 @@ parse_option()
key=${i%%=*}
value=${i#*=}
case "${key}" in
"add-options")
add_options="${add_options} ${value}"
;;
"no-provider")
dis_options="--disable feature_provider provider codecs"
;;
@@ -133,15 +155,13 @@ parse_option()
export CC=clang
;;
"help")
printf "%-50s %-30s\n" "Build openHiTLS Code" "sh build_hitls.sh"
printf "%-50s %-30s\n" "Build openHiTLS Code With Gcov" "sh build_hitls.sh gcov"
printf "%-50s %-30s\n" "Build openHiTLS Code With Debug" "sh build_hitls.sh debug"
printf "%-50s %-30s\n" "Build openHiTLS Code With Asan" "sh build_hitls.sh asan"
usage
exit 0
;;
*)
echo "${i} option is not recognized, Please run <sh build_hitls.sh> get supported options."
exit -1
echo "${i} option is not recognized, Please run <sh build_hitls.sh help> get supported options."
usage
exit 0
;;
esac
done
+8
View File
@@ -20,6 +20,8 @@ usage()
printf "%-05s %-30s\n" "* Script :" "${BASH_SOURCE[0]}"
printf "%-50s %-30s\n" "* Usage Option :" ""
printf "%-50s %-30s\n" "* --help|-h : Help information." ""
printf "%-50s %-30s\n" "* add-options : Add options." "bash ${BASH_SOURCE[0]} add-options=xxx"
printf "%-50s %-30s\n" "* no-provider : Disable provider." "bash ${BASH_SOURCE[0]} no-provider"
printf "%-50s %-30s\n" "* tls-debug : Enable the debug mode." "bash ${BASH_SOURCE[0]} tls-debug"
printf "%-50s %-30s\n" "* no-crypto : Custom crypto testcase." "bash ${BASH_SOURCE[0]} no-crypto"
printf "%-50s %-30s\n" "* no-bsl : Custom bsl testcase." "bash ${BASH_SOURCE[0]} no-bsl"
@@ -174,6 +176,12 @@ options()
key=${1%%=*}
value=${1#*=}
case ${key} in
add-options)
CUSTOM_CFLAGS="${CUSTOM_CFLAGS} ${value}"
;;
no-provider)
dis_options="--disable feature_provider provider codecs"
;;
tls-debug)
TLS_DEBUG=ON
;;