${TEST_FILES}
)
+add_subdirectory ( test )
+
install (FILES ${PACKET_IO_INCLUDES}
DESTINATION "${INCLUDE_INSTALL_PATH}/packet_io"
)
for ( unsigned i = 0; i < MAX_DAQ_VERDICT; i++ )
daq_stats.verdicts[i] = daq_stats_delta.verdicts[i];
- daq_stats.outstanding = new_daq_stats.hw_packets_received -
- new_daq_stats.packets_filtered - new_daq_stats.packets_received;
+ daq_stats.outstanding = new_daq_stats.packets_outstanding;
+
if ( daq_stats.outstanding > daq_stats.outstanding_max )
daq_stats.outstanding_max = daq_stats.outstanding;
--- /dev/null
+add_cpputest(sfdaq_counters_test
+ SOURCES
+ ../sfdaq_module.cc
+)
--- /dev/null
+//--------------------------------------------------------------------------
+// Copyright (C) 2024 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation. You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//--------------------------------------------------------------------------
+// sfdaq_counters_test.cc author Arunkumar Kayambu <akayambu@cisco.com>
+
+// -----------------------------------------------------------------------------
+// unit tests
+// -----------------------------------------------------------------------------
+
+#include "packet_io/sfdaq.h"
+#include "packet_io/sfdaq_module.h"
+#include "sfdaq_module_stubs.h"
+
+#include <CppUTest/CommandLineTestRunner.h>
+#include <CppUTest/TestHarness.h>
+#include <CppUTestExt/MockSupport.h>
+
+using namespace snort;
+
+static DAQ_Stats_t* mock_stats_ptr = nullptr;
+SFDAQInstance *local_instance = nullptr;
+
+const DAQ_Stats_t* SFDAQ::get_stats() {
+ mock().actualCall("get_stats");
+ mock_stats_ptr->packets_outstanding = 20;
+ return mock_stats_ptr;
+}
+
+SFDAQInstance* SFDAQ::get_local_instance() {
+ mock().actualCall("get_local_instance");
+ return local_instance;
+}
+
+TEST_GROUP(sfdaq_module_counters)
+{
+ void setup() {
+ mock_stats_ptr = new DAQ_Stats_t();
+ local_instance = new SFDAQInstance(nullptr, 0, nullptr);
+ }
+
+ void teardown() {
+ mock().clear();
+ delete mock_stats_ptr;
+ delete local_instance;
+ }
+};
+
+TEST(sfdaq_module_counters, check_outstanding_counter)
+{
+ SFDAQModule sfdm;
+ const PegInfo* infos = sfdm.get_pegs();
+
+ // Set up the expectation
+ mock().expectOneCall("get_stats");
+ mock().expectOneCall("get_local_instance");
+
+ sfdm.prep_counts(false);
+ PegCount* p = sfdm.get_counts();
+ mock().checkExpectations();
+ for ( unsigned i = 0; infos[i].name; i++ )
+ {
+ if ( strcmp(infos[i].name, "packets_outstanding") == 0 )
+ CHECK(20 == p[i]);
+ }
+}
+
+int main(int argc, char** argv)
+{
+ return CommandLineTestRunner::RunAllTests(argc, argv);
+}
--- /dev/null
+//--------------------------------------------------------------------------
+// Copyright (C) 2024 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation. You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//--------------------------------------------------------------------------
+// sfdaq_module_stubs.h author Arunkumar Kayambu <akayambu@cisco.com>
+
+#include "main/snort.h"
+#include "packet_io/sfdaq_instance.h"
+#include "packet_io/sfdaq_config.h"
+#include "../trough.h"
+
+#ifndef SFDAQ_MODULE_STUBS_H
+#define SFDAQ_MODULE_STUBS_H
+
+namespace snort
+{
+Module::Module(char const*, char const*, snort::Parameter const*, bool)
+{
+ help = nullptr;
+ name = nullptr;
+ params = nullptr;
+ list = false;
+}
+PegCount Module::get_global_count(const char*) const { return 0; }
+void Module::sum_stats(bool) { }
+void Module::init_stats(bool) { }
+void Module::main_accumulate_stats() { }
+void Module::show_interval_stats(std::vector<unsigned>&, FILE*) { }
+void Module::show_stats() { }
+void Module::reset_stats() { }
+void ParseError(char const*, ...) {}
+SFDAQInstance::SFDAQInstance(char const*, unsigned int, SFDAQConfig const*)
+{
+ batch_size = 0;
+ instance_id = 1;
+ daq_msgs = nullptr;
+}
+SFDAQInstance::~SFDAQInstance() { }
+}
+
+SFDAQConfig::SFDAQConfig()
+{
+ batch_size = 0;
+ mru_size = 0;
+ timeout = 0;
+}
+SFDAQConfig::~SFDAQConfig() = default;
+void SFDAQModuleConfig::set_variable(char const*){}
+void SFDAQConfig::add_module_dir(char const*){}
+void SFDAQConfig::add_input(char const*){}
+void SFDAQConfig::set_mru_size(int){}
+void SFDAQConfig::set_batch_size(unsigned int){}
+void SFDAQConfig::overlay(SFDAQConfig const*){}
+std::atomic<unsigned> Trough::file_count{0};
+#endif