setup for running unit tests. press cmd-sft-p "test"

This commit is contained in:
Skot Croshere 2023-05-26 00:01:45 -04:00 committed by johnny9
parent de237e1d34
commit 3bdfd6d32d
4 changed files with 168 additions and 13 deletions

159
.vscode/tasks.json vendored
View File

@ -295,6 +295,165 @@
}
}
}
},
{
"label": "Test Build - Build unit tests",
"type": "shell",
"command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py build",
"windows": {
"command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py build",
"options": {
"env": {
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
},
"cwd": "${workspaceFolder}\\test"
}
},
"options": {
"env": {
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
},
"cwd": "${workspaceFolder}/test"
},
"problemMatcher": [
{
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^\\.\\.(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
{
"owner": "cpp",
"fileLocation": "absolute",
"pattern": {
"regexp": "^[^\\.](.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
],
"group": {
"kind": "test",
"isDefault": false
}
},
{
"label": "Test Flash - Flash unit tests",
"type": "shell",
"command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py -p ${config:idf.port} -b ${config:idf.flashBaudRate} flash",
"windows": {
"command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py flash -p ${config:idf.portWin} -b ${config:idf.flashBaudRate}",
"options": {
"env": {
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
},
"cwd": "${workspaceFolder}\\test"
}
},
"options": {
"env": {
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
},
"cwd": "${workspaceFolder}/test"
},
"problemMatcher": [
{
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^\\.\\.(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
{
"owner": "cpp",
"fileLocation": "absolute",
"pattern": {
"regexp": "^[^\\.](.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
],
"group": {
"kind": "test",
"isDefault": false
}
},
{
"label": "Test Clean - Clean unit tests",
"type": "shell",
"command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py fullclean",
"windows": {
"command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py fullclean",
"options": {
"env": {
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
},
"cwd": "${workspaceFolder}\\test"
}
},
"options": {
"env": {
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
},
"cwd": "${workspaceFolder}/test"
},
"problemMatcher": [
{
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^\\.\\.(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
{
"owner": "cpp",
"fileLocation": "absolute",
"pattern": {
"regexp": "^[^\\.](.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
],
"group": {
"kind": "test",
"isDefault": false
}
}
]
}

View File

@ -62,28 +62,21 @@ bm_job construct_bm_job(mining_notify * params, const char * merkle_root) {
new_job.target = params->target;
new_job.ntime = params->ntime;
swap_endian_words(params->prev_block_hash, new_job.prev_block_hash); //copy prev_block_hash
swap_endian_words(merkle_root, new_job.merkle_root); //copy merkle_root
hex2bin(merkle_root, new_job.merkle_root, 32);
hex2bin(params->prev_block_hash, new_job.prev_block_hash, 32);
////make the midstate hash
uint8_t midstate_data[68];
uint8_t midstate_data[64];
//print the header
printf("header: %08x%s%s%08x%08x000000000000008000000000000000000000000000000000000000000000000000000000\n", params->version, params->prev_block_hash, merkle_root, params->ntime, params->target);
//copy 68 bytes header data into midstate (and deal with endianess)
memcpy(midstate_data, &new_job.version, 4); //copy version
memcpy(midstate_data + 4, new_job.prev_block_hash, 32); //copy prev_block_hash
memcpy(midstate_data + 36, new_job.merkle_root, 32); //copy merkle_root
printf("midstate_data: ");
prettyHex(midstate_data, 64);
swap_endian_words(params->prev_block_hash, midstate_data + 4); //copy prev_block_hash
memcpy(midstate_data + 36, new_job.merkle_root, 28); //copy merkle_root
midstate_sha256_bin(midstate_data, 64, new_job.midstate); //make the midstate hash
printf("midstate_hash: ");
prettyHex(new_job.midstate, 32);
reverse_bytes(new_job.midstate, 32); //reverse the midstate bytes for the BM job packet
return new_job;

View File

@ -105,7 +105,7 @@ TEST_CASE("Test nonce diff checking", "[mining test_nonce]")
notify_message.version = 0x20000004;
notify_message.target = 0x1705ae3a;
notify_message.ntime = 0x646ff1a9;
const char * merkle_root = "C459036D054643519C5A2AC50B3474E0632C7CE4F93107843FDBF1EDD9CDB126646FF1A9";
const char * merkle_root = "C459036D054643519C5A2AC50B3474E0632C7CE4F93107843FDBF1EDD9CDB126";
bm_job job = construct_bm_job(&notify_message, merkle_root);
uint32_t nonce = 0x276E8947;

View File

@ -13,4 +13,7 @@ set(EXTRA_COMPONENT_DIRS "../components")
set(TEST_COMPONENTS "stratum" CACHE STRING "List of components to test")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(IDF_TARGET "esp32s3")
project(unit_test_stratum)