feisty meow concerns codebase 2.140
test_sequence_tracker.cpp
Go to the documentation of this file.
1/*
2* Name : test_sequence_tracker
3* Author : Chris Koeritz
4* Purpose: Runs a couple of tests on the sequence tracker object.
5**
6* Copyright (c) 2003-$now By Author. This program is free software; you can *
7* redistribute it and/or modify it under the terms of the GNU General Public *
8* License as published by the Free Software Foundation; either version 2 of *
9* the License or (at your option) any later version. This is online at: *
10* http://www.fsf.org/copyleft/gpl.html *
11* Please send any updates to: fred@gruntose.com *
12*/
13
15#include <basis/byte_array.h>
16#include <basis/astring.h>
18#include <mathematics/chaos.h>
19#include <sockets/machine_uid.h>
21#include <structures/set.h>
23#include <unit_test/unit_base.h>
24
25//#include <stdio.h>
26//#include <string.h>
27
28using namespace application;
29using namespace basis;
30using namespace loggers;
31using namespace mathematics;
32using namespace sockets;
33using namespace structures;
34using namespace textual;
35using namespace timely;
36using namespace unit_test;
37
38#define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
39
40class test_sequence_tracker : public virtual unit_base, virtual public application_shell
41{
42public:
43 test_sequence_tracker() {}
44 DEFINE_CLASS_NAME("test_sequence_tracker");
45 virtual int execute();
46};
47
48int test_sequence_tracker::execute()
49{
50 FUNCDEF("execute");
51 // some arbitrary ip addresses.
52 abyte arb1[] = { 127, 0, 0, 1 };
53 abyte arb2[] = { 192, 168, 0, 1 };
54 abyte arb3[] = { 28, 42, 56, 253 };
55
59
60 sequence_tracker chevy(1 * MINUTE_ms, 10 * MINUTE_ms);
61
62 int_set eep_set;
63 int adds = randomizer().inclusive(400, 900);
64 int starter = 12092;
65 while (adds--) {
66 int seq = starter + randomizer().inclusive(1, 129);
67 eep_set += seq;
68 chevy.add_pair(eep, seq);
69 }
70
71 int_set op_set;
72 adds = randomizer().inclusive(200, 600);
73 starter = 1222;
74 while (adds--) {
75 int seq = starter + randomizer().inclusive(1, 129);
76 op_set += seq;
77 chevy.add_pair(op, seq);
78 }
79
80 int_set ork_set;
81 adds = randomizer().inclusive(200, 600);
82 starter = 992981;
83 while (adds--) {
84 int seq = starter + randomizer().inclusive(1, 129);
85 ork_set += seq;
86 chevy.add_pair(ork, seq);
87 }
88
89 int i;
90 for (i = 0; i < eep_set.elements(); i++) {
91 int seq = eep_set[i];
92 if (!chevy.have_seen(eep, seq)) {
93 log(a_sprintf("missing sequence is %d", seq));
94 log(chevy.text_form(true));
95 deadly_error("test_sequence_tracker", "eep check", "missing sequence");
96 }
97 }
98 for (i = 0; i < op_set.elements(); i++) {
99 int seq = op_set[i];
100 if (!chevy.have_seen(op, seq)) {
101 log(a_sprintf("missing sequence is %d", seq));
102 log(chevy.text_form(true));
103 deadly_error("test_sequence_tracker", "op check", "missing sequence");
104 }
105 }
106 for (i = 0; i < ork_set.elements(); i++) {
107 int seq = ork_set[i];
108 if (!chevy.have_seen(ork, seq)) {
109 log(a_sprintf("missing sequence is %d", seq));
110 log(chevy.text_form(true));
111 deadly_error("test_sequence_tracker", "ork check", "missing sequence");
112 }
113 }
114
115 return final_report();
116}
117
118HOOPLE_MAIN(test_sequence_tracker, )
119
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
a_sprintf is a specialization of astring that provides printf style support.
Definition astring.h:440
A very common template for a dynamic array of bytes.
Definition byte_array.h:36
this will keep track of sequencing for a communication process on a per host basis.
A simple object that wraps a templated set of ints.
Definition set.h:156
int elements() const
Returns the number of elements in this set.
Definition set.h:47
#define deadly_error(c, f, i)
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition enhance_cpp.h:42
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition enhance_cpp.h:54
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition hoople_main.h:61
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
unsigned char abyte
A fairly important unit which is seldom defined...
Definition definitions.h:51
const int MINUTE_ms
Number of milliseconds in a minute.
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
Definition averager.h:21
Provides access to the operating system's socket methods.
A dynamic container class that holds any kind of object via pointers.
Definition amorph.h:55
#include <time.h>
Useful support functions for unit testing, especially within hoople.
Definition unit_base.cpp:35
#define randomizer()