add socks_decoder, stratum_decoder and session_flags
This commit is contained in:
41
test/decoders/stratum/CMakeLists.txt
Normal file
41
test/decoders/stratum/CMakeLists.txt
Normal file
@@ -0,0 +1,41 @@
|
||||
set(DECODER_NAME stratum)
|
||||
|
||||
add_library(${DECODER_NAME}_test SHARED stratum_test_plugin.cpp)
|
||||
add_dependencies(${DECODER_NAME}_test ${DECODER_NAME})
|
||||
set_target_properties(${DECODER_NAME}_test PROPERTIES PREFIX "")
|
||||
|
||||
set(TEST_RUN_DIR ${CMAKE_BINARY_DIR}/testing)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/deps/toml)
|
||||
include_directories(${CMAKE_BINARY_DIR}/vendors/cjson/src/cjson/include)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/decoders/stratum)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include/stellar)
|
||||
|
||||
add_executable(gtest_pcap_stratum stratum_decoder_pcap_gtest.cpp dummy.c ${PROJECT_SOURCE_DIR}/decoders/stratum/stratum_decoder.cpp)
|
||||
target_link_libraries(gtest_pcap_stratum gtest pcap cjson-static logger)
|
||||
|
||||
add_executable(stratum_test_main plugin_test_main.cpp)
|
||||
set_target_properties(stratum_test_main
|
||||
PROPERTIES
|
||||
LINK_OPTIONS
|
||||
"-rdynamic"
|
||||
)
|
||||
set_target_properties(stratum_test_main
|
||||
PROPERTIES
|
||||
LINK_FLAGS
|
||||
"-rdynamic"
|
||||
)
|
||||
set(LINK_FLAGS "-rdynamic")
|
||||
#target_link_options(stratum_test_main PRIVATE -Wl,--whole-archive logger -Wl,--no-whole-archive)
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
target_link_libraries(stratum_test_main gtest cjson-static logger stellar_lib)
|
||||
|
||||
add_subdirectory(test_based_on_stellar)
|
||||
|
||||
#copy pcap file folder to build directory
|
||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/pcap DESTINATION ${CMAKE_BINARY_DIR}/test/decoders/stratum)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(gtest_pcap_stratum)
|
||||
86
test/decoders/stratum/dummy.c
Normal file
86
test/decoders/stratum/dummy.c
Normal file
@@ -0,0 +1,86 @@
|
||||
#include "stellar/stellar.h"
|
||||
#include "stellar/session.h"
|
||||
#include "stellar/stellar_mq.h"
|
||||
#include "stellar/stellar_exdata.h"
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
void stellar_session_plugin_dettach_current_session(struct session *sess)
|
||||
{
|
||||
UNUSED(sess);
|
||||
}
|
||||
|
||||
const struct packet *session_get0_current_packet(const struct session *sess)
|
||||
{
|
||||
UNUSED(sess);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *packet_get_payload(const struct packet *pkt)
|
||||
{
|
||||
UNUSED(pkt);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint16_t packet_get_payload_len(const struct packet *pkt)
|
||||
{
|
||||
UNUSED(pkt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct logger *stellar_get_logger(struct stellar *st)
|
||||
{
|
||||
UNUSED(st);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int session_mq_publish_message(struct session *sess, int topic_id, void *msg)
|
||||
{
|
||||
UNUSED(sess);
|
||||
UNUSED(topic_id);
|
||||
UNUSED(msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stellar_mq_create_topic(struct stellar *st, const char *topic_name, stellar_msg_free_cb_func *msg_free_cb, void *msg_free_arg)
|
||||
{
|
||||
UNUSED(st);
|
||||
UNUSED(topic_name);
|
||||
UNUSED(msg_free_cb);
|
||||
UNUSED(msg_free_arg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stellar_mq_get_topic_id(struct stellar *st, const char *topic_name)
|
||||
{
|
||||
UNUSED(st);
|
||||
UNUSED(topic_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stellar_session_mq_subscribe(struct stellar *st, int topic_id, on_session_msg_cb_func *plugin_on_msg_cb, int plugin_id)
|
||||
{
|
||||
UNUSED(st);
|
||||
UNUSED(topic_id);
|
||||
UNUSED(plugin_on_msg_cb);
|
||||
UNUSED(plugin_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stellar_session_plugin_register(struct stellar *st, session_ctx_new_func session_ctx_new, session_ctx_free_func session_ctx_free, void *plugin_env)
|
||||
{
|
||||
UNUSED(st);
|
||||
UNUSED(session_ctx_new);
|
||||
UNUSED(session_ctx_free);
|
||||
UNUSED(plugin_env);
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
test/decoders/stratum/pcap/01-bch_f2pool_cpuminer_1.pcapng
Normal file
BIN
test/decoders/stratum/pcap/01-bch_f2pool_cpuminer_1.pcapng
Normal file
Binary file not shown.
BIN
test/decoders/stratum/pcap/02-eth-antpool.pcapng
Normal file
BIN
test/decoders/stratum/pcap/02-eth-antpool.pcapng
Normal file
Binary file not shown.
BIN
test/decoders/stratum/pcap/03-xmr_f2pool_nanominer_1.pcapng
Normal file
BIN
test/decoders/stratum/pcap/03-xmr_f2pool_nanominer_1.pcapng
Normal file
Binary file not shown.
BIN
test/decoders/stratum/pcap/04-zec-antpool.pcapng
Normal file
BIN
test/decoders/stratum/pcap/04-zec-antpool.pcapng
Normal file
Binary file not shown.
11
test/decoders/stratum/pcap/stratum_result.json
Normal file
11
test/decoders/stratum/pcap/stratum_result.json
Normal file
@@ -0,0 +1,11 @@
|
||||
[
|
||||
{
|
||||
"stratum":
|
||||
{
|
||||
"Tuple4": "192.168.50.243:58748-120.26.148.222:1228-6-0",
|
||||
"type": "OTHER",
|
||||
"mining_program": "cpuminer/2.5.1",
|
||||
"mining_subscribe": "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": [\"cpuminer/2.5.1\"]}\n"
|
||||
}
|
||||
}
|
||||
]
|
||||
135
test/decoders/stratum/plugin_test_main.cpp
Normal file
135
test/decoders/stratum/plugin_test_main.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
#include "cJSON.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#include "stellar/stellar.h"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// #define IGNORE_PRINTF
|
||||
#ifdef IGNORE_PRINTF
|
||||
#define printf(fmt, ...) (0)
|
||||
#endif
|
||||
static cJSON *g_test_result_root = NULL;
|
||||
static cJSON *g_load_result_root = NULL;
|
||||
static const char *result_json_path = NULL;
|
||||
|
||||
extern "C" int commit_test_result_json(cJSON *node, const char *name)
|
||||
{
|
||||
(void)name;
|
||||
if (g_test_result_root)
|
||||
{
|
||||
// cJSON_AddItemToObject(g_test_result_root, name, node);
|
||||
// cJSON_AddStringToObject(node, "name", name);
|
||||
cJSON_AddItemToArray(g_test_result_root, node);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static cJSON *load_result_from_jsonfile(const char *json_path)
|
||||
{
|
||||
if (json_path == NULL)
|
||||
return NULL;
|
||||
|
||||
long file_len = 0;
|
||||
char *file_content = NULL;
|
||||
FILE *fp = NULL;
|
||||
|
||||
fp = fopen(json_path, "r+");
|
||||
if (NULL == fp)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
fseek(fp, 0, SEEK_END);
|
||||
file_len = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
if (file_len == 0)
|
||||
{
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
file_content = (char *)malloc(file_len + 1);
|
||||
fread(file_content, file_len, 1, fp);
|
||||
file_content[file_len] = '\0';
|
||||
cJSON *load = cJSON_Parse(file_content);
|
||||
free(file_content);
|
||||
fclose(fp);
|
||||
|
||||
return load;
|
||||
}
|
||||
|
||||
TEST(PROTOCOL, compare_result_json)
|
||||
{
|
||||
EXPECT_EQ(cJSON_GetArraySize(g_test_result_root), cJSON_GetArraySize(g_load_result_root));
|
||||
int ret = cJSON_Compare(g_test_result_root, g_load_result_root, 0);
|
||||
EXPECT_EQ(1, ret);
|
||||
|
||||
if (ret != 1)
|
||||
{
|
||||
char *load_json_str = cJSON_Print(g_load_result_root);
|
||||
printf("LOAD Raw:\n%s\n", load_json_str);
|
||||
free(load_json_str);
|
||||
char *result_json_str = cJSON_Print(g_test_result_root);
|
||||
printf("TEST Raw:\n%s\n", result_json_str);
|
||||
free(result_json_str);
|
||||
|
||||
cJSON *t_load = g_load_result_root->child, *t_test = g_test_result_root->child;
|
||||
while (t_load != NULL)
|
||||
{
|
||||
ret = cJSON_Compare(t_load, t_test, 0);
|
||||
if (ret != 1)
|
||||
{
|
||||
load_json_str = cJSON_Print(t_load);
|
||||
printf("LOAD Diff:\n%s\n", load_json_str);
|
||||
free(load_json_str);
|
||||
result_json_str = cJSON_Print(t_test);
|
||||
printf("TEST Diff:\n%s\n", result_json_str);
|
||||
free(result_json_str);
|
||||
goto fail;
|
||||
}
|
||||
t_load = t_load->next;
|
||||
t_test = t_test->next;
|
||||
}
|
||||
}
|
||||
cJSON_Delete(g_load_result_root);
|
||||
cJSON_Delete(g_test_result_root);
|
||||
return;
|
||||
fail:
|
||||
cJSON_Delete(g_load_result_root);
|
||||
cJSON_Delete(g_test_result_root);
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("Usage: %s <result_json_path>\n", argv[0]);
|
||||
result_json_path = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
result_json_path = argv[1];
|
||||
g_test_result_root = cJSON_CreateArray();
|
||||
g_load_result_root = load_result_from_jsonfile(result_json_path);
|
||||
assert(g_load_result_root != NULL && g_test_result_root != NULL);
|
||||
}
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
struct stellar *st = stellar_new("./conf/stellar.toml", "./plugin/spec.toml", "./conf/log.toml");
|
||||
stellar_run(st);
|
||||
if (result_json_path != NULL)
|
||||
{
|
||||
ret = RUN_ALL_TESTS();
|
||||
}
|
||||
stellar_free(st);
|
||||
return ret;
|
||||
}
|
||||
179
test/decoders/stratum/stratum_decoder_pcap_gtest.cpp
Normal file
179
test/decoders/stratum/stratum_decoder_pcap_gtest.cpp
Normal file
@@ -0,0 +1,179 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip6.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/ether.h>
|
||||
#include <pcap/sll.h>
|
||||
#include <pcap/pcap.h>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "stellar/stratum_decoder.h"
|
||||
|
||||
#include <stellar/session.h>
|
||||
|
||||
|
||||
#define LINUX_COOKED_CAPTURE 20
|
||||
|
||||
struct pcap_loop_arg
|
||||
{
|
||||
pcap_t *pcap_handle;
|
||||
void *ctx;
|
||||
};
|
||||
|
||||
extern struct stratum_field *stratum_data_process(struct stratum_decoder_info *stratum_decoder_info, const char *tcpdata, size_t datalen);
|
||||
extern void free_stratum_filed(struct stratum_field *stratum_field);
|
||||
extern "C" void *stratum_decoder_init(struct stellar *st);
|
||||
|
||||
struct stratum_decoder_info *stratum_decoder_info = NULL;
|
||||
|
||||
static void pcap_handle_cb(pcap_loop_arg *userarg, const struct pcap_pkthdr *pkthdr, const u_char *packet)
|
||||
{
|
||||
struct pcap_loop_arg *arg = (struct pcap_loop_arg *)userarg;
|
||||
int payload_len = 0;
|
||||
char *payload = NULL;
|
||||
unsigned short eth_proto_type;
|
||||
unsigned char *ip_header;
|
||||
|
||||
int data_link_type = pcap_datalink(arg->pcap_handle);
|
||||
switch (data_link_type) {
|
||||
case DLT_EN10MB:
|
||||
eth_proto_type = ntohs(*(unsigned short *)(packet + 12));
|
||||
ip_header = (unsigned char *)(packet + sizeof(struct ethhdr));
|
||||
break;
|
||||
case 276://DLT_LINUX_SLL2
|
||||
eth_proto_type = ntohs(*(unsigned short *)packet);
|
||||
ip_header = (unsigned char *)(packet + LINUX_COOKED_CAPTURE);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (eth_proto_type == ETH_P_IP) {
|
||||
int l4_proto = *(unsigned char *)(ip_header + 9);
|
||||
if (l4_proto == IPPROTO_TCP) {
|
||||
int ip_total_len = ntohs(*(unsigned short *)(ip_header + 2));
|
||||
int ip_header_len = (*(unsigned char *)ip_header & 0x0f) * 4;
|
||||
int tcp_header_len = 4 * ((*(unsigned char *)(ip_header + sizeof(iphdr) + 12) & 0xf0) >> 4);
|
||||
payload_len = ip_total_len - ip_header_len - tcp_header_len;
|
||||
payload = (char *)ip_header + ip_header_len + tcp_header_len;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (eth_proto_type == ETH_P_IPV6) {
|
||||
int l4_proto = *(unsigned char *)(ip_header + 6);
|
||||
if (l4_proto == IPPROTO_TCP) {
|
||||
int tcp_header_len = 4 * ((*(unsigned char *)(ip_header + sizeof(struct ip6_hdr) + 12) & 0xf0) >> 4);
|
||||
payload_len = pkthdr->caplen - (ip_header - packet) - sizeof(struct ip6_hdr) - tcp_header_len;
|
||||
payload = (char *)ip_header + sizeof(struct ip6_hdr) + tcp_header_len;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
struct stratum_field *stratum = stratum_data_process(stratum_decoder_info, payload, payload_len);
|
||||
if (stratum != NULL)
|
||||
{
|
||||
arg->ctx = stratum;
|
||||
pcap_breakloop(arg->pcap_handle);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(stratum_decoder, parse01)
|
||||
{
|
||||
char error[100];
|
||||
struct pcap_loop_arg arg;
|
||||
pcap_t *handle = pcap_open_offline("pcap/01-bch_f2pool_cpuminer_1.pcapng", error);
|
||||
ASSERT_NE(handle, nullptr);
|
||||
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
arg.pcap_handle = handle;
|
||||
pcap_loop(handle, -1, (pcap_handler)pcap_handle_cb, (u_char *)&arg);
|
||||
|
||||
struct stratum_field *stratum = (struct stratum_field *)arg.ctx;
|
||||
EXPECT_EQ(stratum->type, OTHER);
|
||||
EXPECT_STREQ((const char *)stratum->mining_program.iov_base, "cpuminer/2.5.1");
|
||||
EXPECT_EQ(stratum->mining_pools.iov_len, 0);
|
||||
EXPECT_STREQ((const char *)stratum->mining_subscribe.iov_base, "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": [\"cpuminer/2.5.1\"]}\n");
|
||||
|
||||
pcap_close(handle);
|
||||
free_stratum_filed(stratum);
|
||||
}
|
||||
|
||||
TEST(stratum_decoder, parse02)
|
||||
{
|
||||
char error[100];
|
||||
struct pcap_loop_arg arg;
|
||||
pcap_t *handle = pcap_open_offline("pcap/02-eth-antpool.pcapng", error);
|
||||
ASSERT_NE(handle, nullptr);
|
||||
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
arg.pcap_handle = handle;
|
||||
pcap_loop(handle, -1, (pcap_handler)pcap_handle_cb, (u_char *)&arg);
|
||||
|
||||
struct stratum_field *stratum = (struct stratum_field *)arg.ctx;
|
||||
EXPECT_EQ(stratum->type, ETH);
|
||||
EXPECT_STREQ((const char *)stratum->mining_program.iov_base, "lolMinerWorker");
|
||||
EXPECT_EQ(stratum->mining_pools.iov_len, 0);
|
||||
EXPECT_STREQ((const char *)stratum->mining_subscribe.iov_base, "{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_submitLogin\",\"worker\":\"lolMinerWorker\",\"params\":[\"0xa0279Ad2aA6BDb440f041Aa0947178431d9Bd253.lolMinerWorker\", \"x\"]} \n");
|
||||
|
||||
pcap_close(handle);
|
||||
free_stratum_filed(stratum);
|
||||
}
|
||||
|
||||
TEST(stratum_decoder, parse03)
|
||||
{
|
||||
char error[100];
|
||||
struct pcap_loop_arg arg;
|
||||
pcap_t *handle = pcap_open_offline("pcap/03-xmr_f2pool_nanominer_1.pcapng", error);
|
||||
ASSERT_NE(handle, nullptr);
|
||||
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
arg.pcap_handle = handle;
|
||||
pcap_loop(handle, -1, (pcap_handler)pcap_handle_cb, (u_char *)&arg);
|
||||
|
||||
struct stratum_field *stratum = (struct stratum_field *)arg.ctx;
|
||||
EXPECT_EQ(stratum->type, OTHER);
|
||||
EXPECT_STREQ((const char *)stratum->mining_program.iov_base, "nanominer/3.3.5-cuda11");
|
||||
EXPECT_EQ(stratum->mining_pools.iov_len, 0);
|
||||
EXPECT_STREQ((const char *)stratum->mining_subscribe.iov_base, "{\"id\": 1, \"method\": \"login\", \"params\": { \"login\":\"yhzzhk.001.001\",\"pass\" : \"x\", \"agent\" : \"nanominer/3.3.5-cuda11\"}}\n");
|
||||
|
||||
pcap_close(handle);
|
||||
free_stratum_filed(stratum);
|
||||
}
|
||||
|
||||
TEST(stratum_decoder, parse04)
|
||||
{
|
||||
char error[100];
|
||||
struct pcap_loop_arg arg;
|
||||
pcap_t *handle = pcap_open_offline("pcap/04-zec-antpool.pcapng", error);
|
||||
ASSERT_NE(handle, nullptr);
|
||||
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
arg.pcap_handle = handle;
|
||||
pcap_loop(handle, -1, (pcap_handler)pcap_handle_cb, (u_char *)&arg);
|
||||
|
||||
struct stratum_field *stratum = (struct stratum_field *)arg.ctx;
|
||||
EXPECT_EQ(stratum->type, OTHER);
|
||||
EXPECT_STREQ((const char *)stratum->mining_program.iov_base, "nheqminer/0.5c");
|
||||
EXPECT_STREQ((const char*)stratum->mining_pools.iov_base, "stratum-zec.antpool.com");
|
||||
EXPECT_STREQ((const char *)stratum->mining_subscribe.iov_base, "{\"id\":1,\"method\":\"mining.subscribe\",\"params\":[\"nheqminer/0.5c\", null,\"stratum-zec.antpool.com\",\"8899\"]}\n");
|
||||
|
||||
pcap_close(handle);
|
||||
free_stratum_filed(stratum);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
stratum_decoder_info = (struct stratum_decoder_info*)stratum_decoder_init(NULL);
|
||||
|
||||
int result = RUN_ALL_TESTS();
|
||||
|
||||
return result;
|
||||
}
|
||||
72
test/decoders/stratum/stratum_test_plugin.cpp
Normal file
72
test/decoders/stratum/stratum_test_plugin.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "stellar/stellar.h"
|
||||
#include "stellar/session.h"
|
||||
#include "stellar/stellar_mq.h"
|
||||
#include "stellar/stellar_exdata.h"
|
||||
|
||||
#include "stratum_decoder.h"
|
||||
|
||||
#define unused(x) ((void)(x))
|
||||
extern "C" int commit_test_result_json(cJSON *node, const char *name);
|
||||
|
||||
int g_test_stratum_decoder_plugin_id = 0;
|
||||
int g_stratum_message_topic_id = 0;
|
||||
|
||||
void *ctx_new(struct session *session, void *plugin_env)
|
||||
{
|
||||
unused(plugin_env);
|
||||
unused(session);
|
||||
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
return (void *)root;
|
||||
}
|
||||
|
||||
void ctx_free(struct session *sess, void *session_ctx, void *plugin_env)
|
||||
{
|
||||
unused(sess);
|
||||
unused(plugin_env);
|
||||
|
||||
commit_test_result_json((cJSON *)session_ctx, "socks_decoder_test");
|
||||
}
|
||||
|
||||
void test_stratum_decoder_on_message(struct session *session, int topic_id, const void *msg, void *per_session_ctx, void *plugin_env)
|
||||
{
|
||||
unused(plugin_env);
|
||||
unused(topic_id);
|
||||
|
||||
struct stratum_field *stratum = (struct stratum_field *)msg;
|
||||
cJSON *root = (cJSON *)per_session_ctx;
|
||||
|
||||
cJSON *stratum_json = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, "stratum", stratum_json);
|
||||
|
||||
cJSON_AddStringToObject(stratum_json, "Tuple4", session_get0_readable_addr(session));
|
||||
cJSON_AddStringToObject(stratum_json, "type", stratum->type == ETH ? "ETH" : "OTHER");
|
||||
cJSON_AddStringToObject(stratum_json, "mining_pools", (char *)stratum->mining_pools.iov_base);
|
||||
cJSON_AddStringToObject(stratum_json, "mining_program", (char *)stratum->mining_program.iov_base);
|
||||
cJSON_AddStringToObject(stratum_json, "mining_subscribe", (char *)stratum->mining_subscribe.iov_base);
|
||||
|
||||
}
|
||||
|
||||
extern "C" void *STRATUM_DECODER_TEST_PLUG_INIT(struct stellar *st)
|
||||
{
|
||||
g_test_stratum_decoder_plugin_id = stellar_session_plugin_register(st, ctx_new, ctx_free, NULL);
|
||||
g_stratum_message_topic_id = stellar_mq_get_topic_id(st, STRATUM_MESSAGE_TOPIC);
|
||||
|
||||
if (stellar_session_mq_subscribe(st, g_stratum_message_topic_id, test_stratum_decoder_on_message, g_test_stratum_decoder_plugin_id) < 0)
|
||||
{
|
||||
printf("subscribe topic %s failed\n", STRATUM_MESSAGE_TOPIC);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern "C" void STRATUM_DECODER_TEST_PLUG_DESTROY(void * plugin_env)
|
||||
{
|
||||
unused(plugin_env);
|
||||
}
|
||||
37
test/decoders/stratum/test_based_on_stellar/CMakeLists.txt
Normal file
37
test/decoders/stratum/test_based_on_stellar/CMakeLists.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
set(DECODER_NAME stratum)
|
||||
|
||||
set(TEST_RUN_DIR ${CMAKE_BINARY_DIR}/test/decoders/stratum)
|
||||
set(SAPP_DEVEL_DIR ${TEST_RUN_DIR}/lib)
|
||||
set(TEST_MAIN stratum_test_main)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/test)
|
||||
include_directories(/usr/local/include/cjson)
|
||||
include_directories(/opt/tsg/framework/include/stellar)
|
||||
include_directories(/opt/MESA/include/MESA)
|
||||
include_directories(/opt/tsg/stellar/include/)
|
||||
|
||||
#various ways to add -rdynamic for centos7, centos8, and different cmake version
|
||||
add_definitions(-rdynamic)
|
||||
link_directories(${SAPP_DEVEL_DIR})
|
||||
|
||||
# assemble test env
|
||||
add_test(NAME STRATUM_MKDIR_METRIC COMMAND sh -c "mkdir -p ${TEST_RUN_DIR}/metrics; mkdir -p ${TEST_RUN_DIR}/plugin; mkdir -p ${TEST_RUN_DIR}/log; mkdir -p ${TEST_RUN_DIR}/pcap")
|
||||
add_test(NAME STRATUM_COPY_SPEC COMMAND sh -c "mkdir -p ${TEST_RUN_DIR}/plugin/ && cp ${CMAKE_CURRENT_SOURCE_DIR}/env/spec.toml ${TEST_RUN_DIR}/plugin/spec.toml")
|
||||
add_test(NAME STRATUM_COPY_CONF COMMAND sh -c "mkdir -p ${TEST_RUN_DIR}/conf/ && cp ${CMAKE_CURRENT_SOURCE_DIR}/env/stellar.toml ${TEST_RUN_DIR}/conf/stellar.toml")
|
||||
add_test(NAME STRATUM_COPY_LOG_CONF COMMAND sh -c "mkdir -p ${TEST_RUN_DIR}/conf/ && cp ${CMAKE_CURRENT_SOURCE_DIR}/env/log.toml ${TEST_RUN_DIR}/conf/log.toml")
|
||||
|
||||
# update plugin to be tested
|
||||
add_test(NAME STRATUM_CP_DECODER_SO COMMAND sh -c "cp ${CMAKE_BINARY_DIR}/decoders/stratum/stratum_dyn.so ${TEST_RUN_DIR}/plugin/${DECODER_NAME}.so")
|
||||
add_test(NAME STRATUM_CP_DECODER_GTEST_SO COMMAND sh -c "cp ${CMAKE_BINARY_DIR}/test/decoders/stratum/${DECODER_NAME}_test.so ${TEST_RUN_DIR}/plugin/${DECODER_NAME}_test.so")
|
||||
|
||||
set_tests_properties(STRATUM_MKDIR_METRIC STRATUM_COPY_SPEC
|
||||
STRATUM_COPY_CONF STRATUM_COPY_LOG_CONF
|
||||
STRATUM_CP_DECODER_SO STRATUM_CP_DECODER_GTEST_SO
|
||||
PROPERTIES FIXTURES_SETUP TestFixture)
|
||||
|
||||
set(TEST_PCAP_DIR ${PROJECT_SOURCE_DIR}/test/decoders/stratum/pcap)
|
||||
|
||||
# run tests
|
||||
add_test(NAME STRATUM_DECODER_PLUGIN_TEST COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/01-bch_f2pool_cpuminer_1.pcapng ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_PCAP_DIR}/stratum_result.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
|
||||
4
test/decoders/stratum/test_based_on_stellar/env/log.toml
vendored
Normal file
4
test/decoders/stratum/test_based_on_stellar/env/log.toml
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[log]
|
||||
output = "stderr" # stderr, file
|
||||
file = "log/stellar.log"
|
||||
level = "INFO" # TRACE, DEBUG, INFO, WARN, ERROR, FATAL
|
||||
9
test/decoders/stratum/test_based_on_stellar/env/spec.toml
vendored
Normal file
9
test/decoders/stratum/test_based_on_stellar/env/spec.toml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
[[plugin]]
|
||||
path = "./plugin/stratum.so"
|
||||
init = "stratum_decoder_init"
|
||||
exit = "stratum_decoder_exit"
|
||||
|
||||
[[plugin]]
|
||||
path = "./plugin/stratum_test.so"
|
||||
init = "STRATUM_DECODER_TEST_PLUG_INIT"
|
||||
exit = "STRATUM_DECODER_TEST_PLUG_DESTROY"
|
||||
64
test/decoders/stratum/test_based_on_stellar/env/stellar.toml
vendored
Normal file
64
test/decoders/stratum/test_based_on_stellar/env/stellar.toml
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
[instance]
|
||||
id = 1 # range: [0, 4095] (20 bit)
|
||||
|
||||
[packet_io]
|
||||
mode = "pcapfile" # pcapfile, pcaplist, marsio
|
||||
app_symbol = "stellar"
|
||||
dev_symbol = "nf_0_fw"
|
||||
pcap_path = "./pcap/test.pcap"
|
||||
nr_worker_thread = 1 # range: [1, 256]
|
||||
cpu_mask = [5, 6, 7, 8, 9, 10, 11, 12]
|
||||
idle_yield_interval_ms = 90 # range: [0, 60000] (ms)
|
||||
|
||||
[ip_reassembly]
|
||||
enable = 1
|
||||
bucket_entries = 32 # range: [1, 4294967295] (must be power of 2)
|
||||
bucket_num = 1024 # range: [1, 4294967295]
|
||||
|
||||
ip_frag_timeout_ms = 1000 # range: [1, 60000] (ms)
|
||||
ip_frag_expire_polling_interval_ms = 0 # range: [0, 60000] (ms)
|
||||
ip_frag_expire_polling_limit = 1024 # range: [1, 1024]
|
||||
|
||||
[session_manager]
|
||||
tcp_session_max = 500
|
||||
udp_session_max = 500
|
||||
|
||||
evict_old_on_tcp_table_limit = 1 # range: [0, 1]
|
||||
evict_old_on_udp_table_limit = 1 # range: [0, 1]
|
||||
|
||||
expire_period_ms = 0 # range: [0, 60000] (ms)
|
||||
expire_batch_max = 1024 # range: [1, 1024]
|
||||
|
||||
[session_manager.tcp_timeout_ms]
|
||||
init = 500 # range: [1, 60000] (ms)
|
||||
handshake = 500 # range: [1, 60000] (ms)
|
||||
data = 500 # range: [1, 15999999000] (ms)
|
||||
half_closed = 500 # range: [1, 604800000] (ms)
|
||||
time_wait = 500 # range: [1, 600000] (ms)
|
||||
discard_default = 1000 # range: [1, 15999999000] (ms)
|
||||
unverified_rst = 500 # range: [1, 600000] (ms)
|
||||
|
||||
[session_manager.udp_timeout_ms]
|
||||
data = 500 # range: [1, 15999999000] (ms)
|
||||
discard_default = 500 # range: [1, 15999999000] (ms)
|
||||
|
||||
[session_manager.duplicated_packet_bloom_filter]
|
||||
enable = 0
|
||||
capacity = 1000000 # range: [1, 4294967295]
|
||||
time_window_ms = 10000 # range: [1, 60000] (ms)
|
||||
error_rate = 0.00001 # range: [0.0, 1.0]
|
||||
|
||||
[session_manager.evicted_session_bloom_filter]
|
||||
enable = 0 # range: [0, 1]
|
||||
capacity = 1000000 # range: [1, 4294967295]
|
||||
time_window_ms = 10000 # range: [1, 60000] (ms)
|
||||
error_rate = 0.00001 # range: [0.0, 1.0]
|
||||
|
||||
[session_manager.tcp_reassembly]
|
||||
enable = 1 # range: [0, 1]
|
||||
timeout_ms = 100 # range: [1, 60000] (ms)
|
||||
buffered_segments_max = 256 # range: [2, 4096] per flow
|
||||
|
||||
[stat]
|
||||
merge_interval_ms = 500 # range: [0, 60000] (ms)
|
||||
output_interval_ms = 1000 # range: [0, 60000] (ms)
|
||||
Reference in New Issue
Block a user