2023-04-10 14:52:12 +08:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
2024-07-18 15:37:20 +08:00
|
|
|
#include "kafka.h"
|
2023-04-10 14:52:12 +08:00
|
|
|
#include "sf_metrics.h"
|
|
|
|
|
|
2024-07-18 15:37:20 +08:00
|
|
|
#if 1
|
|
|
|
|
TEST(SF_METRICS, TEST1)
|
2023-04-10 14:52:12 +08:00
|
|
|
{
|
2024-07-18 15:37:20 +08:00
|
|
|
uint16_t thr_idx0 = 0;
|
|
|
|
|
uint16_t thr_idx1 = 1;
|
2023-11-22 14:49:25 +08:00
|
|
|
|
2024-07-18 15:37:20 +08:00
|
|
|
struct kafka *kfk = kafka_create("./test_resource/sce.conf");
|
|
|
|
|
EXPECT_TRUE(kfk != NULL);
|
|
|
|
|
struct sf_metrics *metrics = sf_metrics_create("./test_resource/sce.conf", kfk);
|
|
|
|
|
EXPECT_TRUE(metrics != NULL);
|
2023-11-22 14:49:25 +08:00
|
|
|
|
2024-07-18 15:37:20 +08:00
|
|
|
struct sf_metrics_key key1 = {0};
|
|
|
|
|
key1.vsys_id = 1;
|
|
|
|
|
key1.rule_id = 2;
|
|
|
|
|
key1.sff_profile_id = 3;
|
|
|
|
|
key1.sf_profile_id = 4;
|
2023-11-22 14:49:25 +08:00
|
|
|
struct sf_metrics_key key2 = {0};
|
2024-07-18 15:37:20 +08:00
|
|
|
key2.vsys_id = 4;
|
|
|
|
|
key2.rule_id = 3;
|
2023-11-22 14:49:25 +08:00
|
|
|
key2.sff_profile_id = 2;
|
2024-07-18 15:37:20 +08:00
|
|
|
key2.sf_profile_id = 1;
|
|
|
|
|
|
|
|
|
|
// thread 0
|
|
|
|
|
// uint64_t rx_pkts, uint64_t rx_bytes, uint64_t tx_pkts, uint64_t tx_bytes);
|
|
|
|
|
sf_metrics_input(metrics, thr_idx0, &key1, 1, 2, 2, 4);
|
|
|
|
|
sf_metrics_input(metrics, thr_idx0, &key2, 2, 4, 1, 2);
|
|
|
|
|
sf_metrics_output(metrics, thr_idx0);
|
|
|
|
|
sf_metrics_reset(metrics, thr_idx0);
|
|
|
|
|
|
|
|
|
|
printf("\n========================================\nworker thread 0 done\n========================================\n");
|
|
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
|
|
// thread 1
|
|
|
|
|
sf_metrics_input(metrics, thr_idx1, &key1, 2, 4, 1, 2);
|
|
|
|
|
sf_metrics_input(metrics, thr_idx1, &key2, 1, 2, 2, 4);
|
|
|
|
|
sf_metrics_output(metrics, thr_idx1);
|
|
|
|
|
sf_metrics_reset(metrics, thr_idx1);
|
|
|
|
|
|
|
|
|
|
printf("\n========================================\nworker thread 1 done\n========================================\n");
|
|
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
|
|
sf_metrics_destory(metrics);
|
|
|
|
|
kafka_destroy(kfk);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
TEST(SF_METRICS, TEST2)
|
|
|
|
|
{
|
|
|
|
|
uint16_t thr_idx0 = 0;
|
|
|
|
|
uint16_t thr_idx1 = 1;
|
|
|
|
|
|
|
|
|
|
struct kafka *kfk = kafka_create("./test_resource/sce.conf");
|
|
|
|
|
EXPECT_TRUE(kfk != NULL);
|
|
|
|
|
struct sf_metrics *metrics = sf_metrics_create("./test_resource/sce.conf", kfk);
|
|
|
|
|
EXPECT_TRUE(metrics != NULL);
|
|
|
|
|
|
|
|
|
|
struct sf_metrics_key key1 = {0};
|
|
|
|
|
key1.vsys_id = 1;
|
|
|
|
|
key1.rule_id = 2;
|
|
|
|
|
key1.sff_profile_id = 3;
|
|
|
|
|
key1.sf_profile_id = 4;
|
|
|
|
|
struct sf_metrics_key key2 = {0};
|
2023-11-22 14:49:25 +08:00
|
|
|
key2.vsys_id = 4;
|
2024-07-18 15:37:20 +08:00
|
|
|
key2.rule_id = 3;
|
|
|
|
|
key2.sff_profile_id = 2;
|
|
|
|
|
key2.sf_profile_id = 1;
|
|
|
|
|
|
|
|
|
|
// thread 0
|
|
|
|
|
// uint64_t rx_pkts, uint64_t rx_bytes, uint64_t tx_pkts, uint64_t tx_bytes);
|
|
|
|
|
sf_metrics_input(metrics, thr_idx0, &key1, 1, 2, 2, 4);
|
|
|
|
|
sf_metrics_input(metrics, thr_idx0, &key2, 2, 4, 1, 2);
|
|
|
|
|
sf_metrics_output(metrics, thr_idx0);
|
|
|
|
|
sf_metrics_reset(metrics, thr_idx0);
|
|
|
|
|
|
|
|
|
|
printf("\n========================================\nworker thread 0 done\n========================================\n");
|
|
|
|
|
|
|
|
|
|
// thread 1
|
|
|
|
|
sf_metrics_input(metrics, thr_idx1, &key1, 2, 4, 1, 2);
|
|
|
|
|
sf_metrics_input(metrics, thr_idx1, &key2, 1, 2, 2, 4);
|
|
|
|
|
sf_metrics_output(metrics, thr_idx1);
|
|
|
|
|
sf_metrics_reset(metrics, thr_idx1);
|
|
|
|
|
|
|
|
|
|
printf("\n========================================\nworker thread 1 done\n========================================\n");
|
|
|
|
|
sleep(3);
|
2023-11-22 14:49:25 +08:00
|
|
|
|
2023-04-10 14:52:12 +08:00
|
|
|
sf_metrics_destory(metrics);
|
2024-07-18 15:37:20 +08:00
|
|
|
kafka_destroy(kfk);
|
2023-04-10 14:52:12 +08:00
|
|
|
}
|
2024-07-18 15:37:20 +08:00
|
|
|
#endif
|
2023-04-10 14:52:12 +08:00
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
|
}
|