Skip to content

Commit

Permalink
Merge pull request #49 from NeverRaR/dev/runtime_test
Browse files Browse the repository at this point in the history
fix: fix runtime c test
  • Loading branch information
i-zhen authored Feb 21, 2024
2 parents 8ed585b + e6e105e commit 985afce
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 55 deletions.
4 changes: 2 additions & 2 deletions smart_ir/src/runtime/stdlib/stdlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ extern int32_t get_call_result_length(void);
// get_call_result hostapi
extern void get_call_result(char *result);

uint256_t div256_u256_rem(uint256_t dividend, uint256_t divisor, uint256_t *remainder);
extern uint256_t div256_u256_rem(uint256_t dividend, uint256_t divisor, uint256_t *remainder);

uint256_t div256_u256(uint256_t dividend, uint256_t divisor);
extern uint256_t div256_u256(uint256_t dividend, uint256_t divisor);

void
runtime_abort(char *msg, uint32_t msg_length,
Expand Down
10 changes: 5 additions & 5 deletions smart_ir/src/runtime/stdlib/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ __strlen(const char *s);
extern bool
__memcmp(uint8_t *left, uint32_t left_len, uint8_t *right, uint32_t right_len);

//bigint div
uint256_t div256_u256_rem(uint256_t dividend, uint256_t divisor, uint256_t *remainder);

uint256_t div256_u256(uint256_t dividend, uint256_t divisor);

#ifndef CC_LIB_TEST_MOCK
void *
__malloc(size_t size);
Expand Down Expand Up @@ -94,11 +99,6 @@ __strtoi256(const char *__restrict nptr, char **__restrict endptr, int base);
uint256_t
__strtou256(const char *__restrict nptr, char **__restrict endptr, int base);

//bigint div
uint256_t div256_u256_rem(uint256_t dividend, uint256_t divisor, uint256_t *remainder);

uint256_t div256_u256(uint256_t dividend, uint256_t divisor);

#define malloc __malloc

/*
Expand Down
107 changes: 60 additions & 47 deletions smart_ir/src/runtime/stdlib/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
# Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved. Use of this
# source code is governed by a BSD-style license that can be found in the
# LICENSE file.

cmake_minimum_required(VERSION 3.1)
project(TEST)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 \
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -std=c99 \
-Xclang \
-fexperimental-max-bitint-width=256 \
-Wno-int-conversion \
-Wno-pointer-sign \
-Wno-int-to-pointer-cast \
-Wno-extra-tokens \
-Wno-writable-strings \
-Wno-deprecated-declarations \
-Wno-incompatible-library-redeclaration \
-Wno-implicit-function-declaration \
-Wno-pragma-once-outside-header \
-Wno-pointer-to-int-cast")

set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS}\
-Xclang \
-fexperimental-max-bitint-width=256 \
-Wno-int-conversion \
-Wno-pointer-sign \
-Wno-int-to-pointer-cast \
Expand All @@ -21,51 +39,46 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 \
add_definitions(-w)
add_definitions(-DCC_LIB_TEST_MOCK)

add_library(cc-test-lib
ir_c_mock.cc
../base64.c
../hex.c
../call_log.c
../stream.c
../rlp.c
../data_stream_builtin.c
../data_stream.c
../json.c
../mycrypto.c
../math.c
../qhash.c
../qhashtbl.c
../qstring.c
../qvector.c
../stdlib.c
../wasmheap.c
../ir_type.c
../ssz.c
../chain.c
test.cc
)
add_library(
cc-test-lib
ir_c_mock.cc
../base64.c
../hex.c
../call_log.c
../stream.c
../rlp.c
../data_stream_builtin.c
../data_stream.c
../json.c
../mycrypto.c
../math.c
../qhash.c
../qhashtbl.c
../qstring.c
../qvector.c
../stdlib.c
../wasmheap.c
../ir_type.c
../ssz.c
../chain.c
test.cc)

set(CCTestSources
qhashtbl_test.cc
qstring_test.cc
qvector_test.cc
math_test.cc
base64_test.cc
hex_test.cc
ir_type_test.cc
rlp_test.cc
ssz-c/ssz_test.cc
ssz-c/ssz_contract_test.cc
ssz-c/ssz_contract_artifact_test.cc
ssz-c/ssz_account_test.cc)

add_executable(cc-test
${CCTestSources}
test_main.cc
)
qhashtbl_test.cc
qstring_test.cc
qvector_test.cc
math_test.cc
base64_test.cc
hex_test.cc
ir_type_test.cc
rlp_test.cc
ssz-c/ssz_test.cc
ssz-c/ssz_contract_test.cc
ssz-c/ssz_contract_artifact_test.cc
ssz-c/ssz_account_test.cc)

add_executable(cc-test ${CCTestSources} test_main.cc)

target_link_libraries(cc-test
cc-test-lib
)
target_link_libraries(cc-test cc-test-lib)

include_directories(.)
2 changes: 1 addition & 1 deletion smart_ir/src/runtime/stdlib/test/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e
echo "building ir c lib unit tests"
# need clang12. clang14 not supported i256/u256
cmake -S . -B build -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_BUILD_TYPE=Debug
cmake -S . -B build -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=Debug
cmake --build build -j8
PWD=`pwd`
cd build
Expand Down

0 comments on commit 985afce

Please sign in to comment.