Skip to content

Commit

Permalink
Enable Unit Test CI
Browse files Browse the repository at this point in the history
  • Loading branch information
eandersson committed Jan 10, 2025
1 parent b5d1e36 commit 3e69073
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 5 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Unit Test
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: esp-idf build
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.4
target: esp32s3
command: GITHUB_ACTIONS="true" idf.py build
path: 'test-ci'
- name: Run tests and show result
uses: bitaxeorg/esp32-qemu-test-action@main
with:
path: 'test-ci'
- name: Inspect log
run: cat report.xml
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
files: report.xml
4 changes: 4 additions & 0 deletions components/asic/bm1366.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#include <stdlib.h>
#include <string.h>

#ifdef CONFIG_GPIO_ASIC_RESET
#define GPIO_ASIC_RESET CONFIG_GPIO_ASIC_RESET
#else
#define GPIO_ASIC_RESET 1
#endif

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40
Expand Down
4 changes: 4 additions & 0 deletions components/asic/bm1368.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#include <stdlib.h>
#include <string.h>

#ifdef CONFIG_GPIO_ASIC_RESET
#define GPIO_ASIC_RESET CONFIG_GPIO_ASIC_RESET
#else
#define GPIO_ASIC_RESET 1
#endif

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40
Expand Down
4 changes: 4 additions & 0 deletions components/asic/bm1370.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#include <stdlib.h>
#include <string.h>

#ifdef CONFIG_GPIO_ASIC_RESET
#define GPIO_ASIC_RESET CONFIG_GPIO_ASIC_RESET
#else
#define GPIO_ASIC_RESET 1
#endif

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40
Expand Down
4 changes: 4 additions & 0 deletions components/asic/bm1397.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#include "mining.h"
#include "global_state.h"

#ifdef CONFIG_GPIO_ASIC_RESET
#define GPIO_ASIC_RESET CONFIG_GPIO_ASIC_RESET
#else
#define GPIO_ASIC_RESET 1
#endif

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40
Expand Down
4 changes: 2 additions & 2 deletions components/stratum/test/test_mining.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ TEST_CASE("Test extranonce 2 generation", "[mining extranonce2]")
free(fifth);
}

TEST_CASE("Test nonce diff checking", "[mining test_nonce]")
TEST_CASE("Test nonce diff checking", "[mining test_nonce][not-on-qemu]")
{
mining_notify notify_message;
notify_message.prev_block_hash = "d02b10fc0d4711eae1a805af50a8a83312a2215e00017f2b0000000000000000";
Expand All @@ -153,7 +153,7 @@ TEST_CASE("Test nonce diff checking", "[mining test_nonce]")
TEST_ASSERT_EQUAL_INT(18, (int)diff);
}

TEST_CASE("Test nonce diff checking 2", "[mining test_nonce]")
TEST_CASE("Test nonce diff checking 2", "[mining test_nonce][not-on-qemu]")
{
mining_notify notify_message;
notify_message.prev_block_hash = "0c859545a3498373a57452fac22eb7113df2a465000543520000000000000000";
Expand Down
7 changes: 6 additions & 1 deletion components/stratum/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,12 @@ void midstate_sha256_bin(const uint8_t *data, const size_t data_len, uint8_t *de
mbedtls_sha256_update(&midstate, data, 64);

// memcpy(dest, midstate.state, 32);
flip32bytes(dest, midstate.state);
#ifdef CONFIG_MBEDTLS_HARDWARE_SHA
flip32bytes(dest, midstate.state);
#else
memcpy(dest, midstate.MBEDTLS_PRIVATE(state), 32);
#endif

}

void swap_endian_words(const char *hex_words, uint8_t *output)
Expand Down
21 changes: 21 additions & 0 deletions test-ci/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This is the project CMakeLists.txt file for the test subproject
cmake_minimum_required(VERSION 3.16)

# Include the components directory of the main application:
#
set(EXTRA_COMPONENT_DIRS "../components")

# Set the components to include the tests for.
# This can be overriden from CMake cache:
# - when invoking CMake directly: cmake -D TEST_COMPONENTS="xxxxx" ..
# - when using idf.py: idf.py -T xxxxx build
#
set(TEST_COMPONENTS "bm1397 stratum" CACHE STRING "List of components to test")

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

set(IDF_TARGET "esp32s3")

idf_build_set_property(COMPILE_DEFINITIONS "-DCONFIG_ASIC_FREQUENCY=100" APPEND)

project(unit_test_stratum)
9 changes: 9 additions & 0 deletions test-ci/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e
CODE_PATH="$1"
. $IDF_PATH/export.sh
cd test/build
esptool.py --chip esp32s3 merge_bin --fill-flash-size 16MB -o flash_image.bin @flash_args
/opt/qemu/bin/qemu-system-xtensa -nographic -no-reboot -machine esp32 -drive file=flash_image.bin,if=mtd,format=raw -serial file:output.log
grep -q -E '[[:digit:]]+ Tests [[:digit:]]+ Failures [[:digit:]]+ Ignored' output.log && ruby /opt/Unity-*/auto/parse_output.rb -xml output.log || exit 1
mv report.xml /github/workspace
2 changes: 2 additions & 0 deletions test-ci/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
idf_component_register(SRCS "unit_test_all.c"
INCLUDE_DIRS ".")
26 changes: 26 additions & 0 deletions test-ci/main/unit_test_all.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <string.h>
#include "unity.h"

static void print_banner(const char *text);

void app_main(void)
{
print_banner("Running all the registered tests");
UNITY_BEGIN();
unity_run_tests_by_tag("[not-on-qemu]", true);
UNITY_END();

// print_banner("Starting interactive test menu");
/* This function will not return, and will be busy waiting for UART input.
* Make sure that task watchdog is disabled if you use this function.
*/
// unity_run_menu();

exit(0);
}

static void print_banner(const char *text)
{
printf("\n#### %s #####\n\n", text);
}
3 changes: 3 additions & 0 deletions test-ci/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_ESP_INT_WDT=n
CONFIG_ESP_TASK_WDT=n
CONFIG_MBEDTLS_HARDWARE_SHA=n
2 changes: 1 addition & 1 deletion test/main/unit_test_all.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ void app_main(void)
static void print_banner(const char *text)
{
printf("\n#### %s #####\n\n", text);
}
}
2 changes: 1 addition & 1 deletion test/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CONFIG_ESP_INT_WDT=n
CONFIG_ESP_TASK_WDT=n
CONFIG_ESP_TASK_WDT=n

0 comments on commit 3e69073

Please sign in to comment.