Skip to content

Commit

Permalink
update test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jleni committed Sep 2, 2024
1 parent ae1e50a commit 45745ba
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 141 deletions.
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 125
DerivePointerAlignment: false
PointerAlignment: Right
22 changes: 22 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Checks: "-*,
clang-diagnostic-*,
clang-analyzer-*,
cppcoreguidelines-init-variables,
google-runtime-int,
google-readability-avoid-underscore-in-googletest-name,
misc-*,
performance-*,
portability-*,
readability-*,
-misc-no-recursion,
-readability-function-cognitive-complexity"
WarningsAsErrors: "*"
CheckOptions:
- key: readability-identifier-length.MinimumVariableNameLength
value: 2
- key: readability-identifier-length.MinimumParameterNameLength
value: 2
- key: readability-identifier-length.MinimumLoopCounterNameLength
value: 1
- key: readability-magic-numbers.IgnorePowersOf2IntegerValues
value: true
16 changes: 0 additions & 16 deletions .editorconfig

This file was deleted.

75 changes: 27 additions & 48 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,55 +47,34 @@
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

\cmake-build-debug
\.idea/
/tmp/
/deps/nano2-sdk/

# Created by cmake
googletest-download/
googletest-src/
googletest-build/
CMakeFiles/
CMakeCache.txt
unittests
*.cmake
Testing/
cmake-build-fuzz/

# Others
/cmake-build-debug/
/cmake-build-fuzz/
\.idea
/app/bin/
/app/debug/
/app/obj/

\deps/*
!\deps/nanos-secure-sdk
!\deps/nanox-secure-sdk
!\deps/ledger-zxlib
!\deps/tinycbor
!\deps/tinycbor-ledger
!\deps/BLAKE

app/src/glyphs.c

app/src/glyphs.h
/build
.vscode/dryrun.log
.vscode/targets.log

##########################

tests_zemu/.yarn/*
tests_zemu/!.yarn/patches
tests_zemu/!.yarn/releases
tests_zemu/!.yarn/plugins
tests_zemu/!.yarn/sdks
tests_zemu/!.yarn/versions
tests_zemu/.pnp.*
#########################

.vscode
.idea

node_modules
fuzz/corpora

!build/.gitkeep


build/*
cmake-build-debug
app/build/*
.DS_Store

tests_zemu/snapshots-tmp
tests_zemu/yarn.lock
tests_tools/target
fuzz-*.log
/fuzz/corpora

.vscode/
tests_zemu/yarn.lock
/scan-build
82 changes: 60 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,33 @@
#* See the License for the specific language governing permissions and
#* limitations under the License.
#********************************************************************************
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.28)
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/cpp-pm/hunter/archive/v0.25.5.tar.gz"
SHA1 "a20151e4c0740ee7d0f9994476856d813cdead29"
LOCAL
)

project(ledger-cosmos VERSION 0.0.0)
enable_testing()
if(CMAKE_GENERATOR MATCHES "Ninja")
message(FATAL_ERROR "This project does not support the Ninja generator. "
"Please use Unix Makefiles or another supported generator. "
"This error is typical in CLion. In this case, switch to generator Unix Makefiles.")
endif()

########################################################

project(ledger-spacemesh VERSION 0.0.0)

set(CMAKE_CXX_STANDARD 17)
cmake_policy(SET CMP0025 NEW)
set(CMAKE_CXX_STANDARD 11)
cmake_policy(SET CMP0144 NEW)

set(HUNTER_STATUS_DEBUG ON)
set(HUNTER_TLS_VERIFY OFF)

enable_testing()

option(ENABLE_FUZZING "Build with fuzzing instrumentation and build fuzz targets" OFF)
option(ENABLE_COVERAGE "Build with source code coverage instrumentation" OFF)
option(ENABLE_SANITIZERS "Build with ASAN and UBSAN" OFF)
Expand All @@ -42,8 +52,10 @@ add_definitions(-DAPP_STANDARD)

hunter_add_package(fmt)
find_package(fmt CONFIG REQUIRED)

hunter_add_package(jsoncpp)
find_package(jsoncpp CONFIG REQUIRED)

hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)

Expand All @@ -66,9 +78,9 @@ if(ENABLE_FUZZING)
endif()
else()
message(FATAL_ERROR
"You are using an unsupported compiler! Fuzzing only works with Clang 10.\n"
"Unsupported compiler! Fuzzing requires Clang 10.\n"
"1. Install clang-10 \n"
"2. Pass -DCMAKE_C_COMPILER=clang-10 -DCMAKE_CXX_COMPILER=clang++-10")
"2. Use -DCMAKE_C_COMPILER=clang-10 -DCMAKE_CXX_COMPILER=clang++-10")
endif()

string(APPEND CMAKE_C_FLAGS " -fsanitize=fuzzer-no-link")
Expand All @@ -88,12 +100,37 @@ if(ENABLE_SANITIZERS)
string(APPEND CMAKE_LINKER_FLAGS " -fsanitize=address,undefined -fsanitize-recover=address,undefined")
endif()

set (RETRIEVE_MAJOR_CMD
"cat ${CMAKE_CURRENT_SOURCE_DIR}/app/Makefile.version | grep APPVERSION_M | cut -b 14- | tr -d '\n'"
)
set (RETRIEVE_MINOR_CMD
"cat ${CMAKE_CURRENT_SOURCE_DIR}/app/Makefile.version | grep APPVERSION_N | cut -b 14- | tr -d '\n'"
)
execute_process(
COMMAND bash "-c" ${RETRIEVE_MAJOR_CMD}
RESULT_VARIABLE MAJOR_RESULT
OUTPUT_VARIABLE MAJOR_VERSION
)
execute_process(
COMMAND bash "-c" ${RETRIEVE_MINOR_CMD}
RESULT_VARIABLE MINOR_RESULT
OUTPUT_VARIABLE MINOR_VERSION
)

message(STATUS "LEDGER_MAJOR_VERSION [${MAJOR_RESULT}]: ${MAJOR_VERSION}" )
message(STATUS "LEDGER_MINOR_VERSION [${MINOR_RESULT}]: ${MINOR_VERSION}" )

add_definitions(
-DLEDGER_MAJOR_VERSION=${MAJOR_VERSION}
-DLEDGER_MINOR_VERSION=${MINOR_VERSION}
)

string(APPEND CMAKE_CXX_FLAGS " -fsanitize=address -fno-omit-frame-pointer")
string(APPEND CMAKE_LINKER_FLAGS " -fsanitize=address -fno-omit-frame-pointer")

##############################################################
##############################################################
# static libs
# Static Libraries
file(GLOB_RECURSE JSMN_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/jsmn/src/jsmn.c
)
Expand Down Expand Up @@ -142,20 +179,35 @@ target_include_directories(app_lib PUBLIC
target_link_libraries(app_lib PUBLIC)

##############################################################
# Fuzz Targets
if(ENABLE_FUZZING)
set(FUZZ_TARGETS
parser_parse
parser_message_parse
)

foreach(target ${FUZZ_TARGETS})
add_executable(fuzz-${target} ${CMAKE_CURRENT_SOURCE_DIR}/fuzz/${target}.cpp)
target_link_libraries(fuzz-${target} PRIVATE app_lib)
target_link_options(fuzz-${target} PRIVATE "-fsanitize=fuzzer")
endforeach()
else()
##############################################################
# Tests
file(GLOB_RECURSE TESTS_SRC
${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cpp)

add_executable(unittests ${TESTS_SRC})
target_include_directories(unittests PRIVATE
${gtest_SOURCE_DIR}/include
${gmock_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/deps/jsmn/src
${CMAKE_CURRENT_SOURCE_DIR}/deps/tinycbor/src
)

target_link_libraries(unittests PRIVATE
GTest::gtest_main
app_lib
GTest::gtest_main
fmt::fmt
JsonCpp::JsonCpp)

Expand All @@ -164,18 +216,4 @@ add_compile_definitions(APP_TESTING=1)
add_compile_definitions(COMPILE_TEXTUAL=1)
add_test(NAME unittests COMMAND unittests)
set_tests_properties(unittests PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)

##############################################################
##############################################################
# Fuzz Targets
if(ENABLE_FUZZING)
set(FUZZ_TARGETS
parser_parse
)

foreach(target ${FUZZ_TARGETS})
add_executable(fuzz-${target} ${CMAKE_CURRENT_SOURCE_DIR}/fuzz/${target}.cpp)
target_link_libraries(fuzz-${target} PRIVATE app_lib)
target_link_options(fuzz-${target} PRIVATE "-fsanitize=fuzzer")
endforeach()
endif()
12 changes: 0 additions & 12 deletions tests_zemu/.editorconfig

This file was deleted.

24 changes: 0 additions & 24 deletions tests_zemu/.eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion tests_zemu/.npmignore

This file was deleted.

36 changes: 36 additions & 0 deletions tests_zemu/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
globals: {
window: 'readonly',
document: 'readonly',
process: 'readonly',
require: 'readonly',
},
parserOptions: {
project: 'tsconfig.json',
},
},
ignores: ['dist/*', 'node_modules/*'],
plugins: {
'unused-imports': require('eslint-plugin-unused-imports'),
'@typescript-eslint': require('@typescript-eslint/eslint-plugin'),
'eslint-plugin-tsdoc': require('eslint-plugin-tsdoc'),
},
rules: {
curly: 'warn',
'prefer-const': 'warn',
'no-else-return': 'warn',
complexity: ['warn', 1000],
'no-unneeded-ternary': 'warn',
'no-alert': 'warn',
'no-empty': 'warn',
'no-useless-catch': 'error',
'require-await': 'warn',
'no-continue': 'warn',
'no-console': 'warn',
'unused-imports/no-unused-imports': 'warn',
'no-magic-numbers': 'off',
},
}
25 changes: 15 additions & 10 deletions tests_zemu/globalsetup.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import Zemu from '@zondax/zemu'
const Zemu = require('@zondax/zemu')

const catchExit = async () => {
process.on('SIGINT', () => {
Zemu.stopAllEmuContainers(function () {
process.exit()
})
/**
* Sets up a handler to stop all emulator containers when a SIGINT is received.
*/
const catchExit = () => {
process.on('SIGINT', async () => {
await Zemu.default.stopAllEmuContainers()
process.exit()
})
}

/**
* Initializes the emulator environment by setting up exit handlers,
* pulling the latest emulator image, and stopping any running emulator containers.
*/
module.exports = async () => {
await catchExit()
await Zemu.checkAndPullImage()
await Zemu.stopAllEmuContainers()
catchExit()
await Zemu.default.checkAndPullImage()
await Zemu.default.stopAllEmuContainers()
}
//
Loading

0 comments on commit 45745ba

Please sign in to comment.