31 using namespace basis;
42 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
51 test_bcast_spocket() {}
53 virtual int execute();
62 const char *last_period = 0;
63 bool got_digit =
false;
64 for (
const char *address = input.
s(); *address; address++) {
65 if ( (*address <=
'9') && (*address >=
'0') ) {
67 current_byte += *address -
'0';
69 }
else if (*address ==
'.') {
71 if (last_period + 1 == address) {
72 LOG(
"The IP address entry has an empty digit. Exiting.");
75 last_period = address;
76 if (current_byte > 255) {
77 LOG(
"The IP address entry has an illegal abyte. Exiting.");
80 ip_address[index] =
abyte(current_byte);
86 LOG(
"The IP address entry has illegal characters. Exiting.");
91 if ( (index == 3) && got_digit) {
92 if (current_byte > 255) {
93 LOG(
"The IP address entry has an illegal abyte. Exiting.");
96 ip_address[index] = current_byte;
97 }
else if (index < 4) {
98 LOG(
"The IP address entry is too short. Exiting.");
104 int test_bcast_spocket::execute()
114 const char *DEFAULT_HOST =
"127.0.0.1";
115 const int DEFAULT_PORT = 12342;
116 const int DEFAULT_SEND_SIZE = 1008;
117 const int DEFAULT_SEND_COUNT = 10;
122 This program takes six command line arguments to begin operation.\n\
123 These arguments (in order) are:\n\
124 \tIP address for src\tIn the form w.x.y.z\n\
125 \tIP address for dest\tIn the form w.x.y.z\n\
126 \tReceive Port number\tAs a short integer\n\
127 \tSending Port number\tAs a short integer\n\
128 \tSend size\t\tThe size of the data to exchange.\n\
129 \tSend count\t\tThe number of \"packets\" to exchange.\n\
130 Note: it is expected that the testers have equal send sizes; this\n\
131 allows the receiver to know when it's gotten all the data that's\n\
132 expected during a cycle.");
135 parse_address(DEFAULT_HOST, ip_address);
136 parse_address(DEFAULT_HOST, dest_addr);
137 rcv_port = DEFAULT_PORT;
138 send_port = DEFAULT_PORT + 1;
139 send_size = DEFAULT_SEND_SIZE;
140 send_count = DEFAULT_SEND_COUNT;
149 LOG(
"failed to parse source address.");
154 (
int)ip_address[0], (
int)ip_address[1], (
int)ip_address[2],
155 (
int)ip_address[3]));
158 LOG(
"failed to parse dest address.");
162 LOG(
a_sprintf(
"\tParsed a destination of: \"%d.%d.%d.%d\".",
163 (
int)dest_addr[0], (
int)dest_addr[1], (
int)dest_addr[2],
168 LOG(
"The port entry is malformed. Exiting.");
171 LOG(
a_sprintf(
"\tGot a receive port of %d.", rcv_port));
175 LOG(
"The port entry is malformed. Exiting.");
182 LOG(
"The send size entry is malformed. Exiting.");
189 LOG(
"The send count entry is malformed. Exiting.");
192 LOG(
a_sprintf(
"\tGot a send count of %d.", send_count));
200 astring(DEFAULT_HOST) +
" " + DEFAULT_HOST +
" "
203 +
" " +
a_sprintf(
"%d", DEFAULT_SEND_SIZE) +
" " +
a_sprintf(
"%d", DEFAULT_SEND_COUNT),
204 launch_process::RETURN_IMMEDIATELY, kidnum);
205 ASSERT_EQUAL(result, 0,
"launching paired process should start successfully");
216 bool outcome = tester.connect();
218 LOG(
astring(
"Failed to connect on the tester."));
222 LOG(
a_sprintf(
"you now have %d seconds; get other side ready.",
225 LOG(
"starting test");
229 outcome = tester.perform_test(dest, send_size, send_count * 2, stats);
232 LOG(
"Failed out of send_data; maybe other side terminated.");
243 LOG(
"\t\tsend stats\t\treceive stats");
244 LOG(
"\t\t----------\t\t-------------");
The application_shell is a base object for console programs.
a_sprintf is a specialization of astring that provides printf style support.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
A very common template for a dynamic array of bytes.
Outcomes describe the state of completion for an operation.
Provides the capability to start processes in a variety of ways to run other applications.
static basis::un_int run(const basis::astring &app_name, const basis::astring &command_line, int flag, basis::un_int &child_id)
starts an application using the "app_name" as the executable to run.
this type of address describes a destination out on the internet.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Provides macros that implement the 'main' program of an application.
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
unsigned char abyte
A fairly important unit which is seldom defined...
const int SECOND_ms
Number of milliseconds in a second.
unsigned int un_int
Abbreviated name for unsigned integers.
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
Provides access to the operating system's socket methods.
A dynamic container class that holds any kind of object via pointers.
Useful support functions for unit testing, especially within hoople.
HOOPLE_MAIN(test_bcast_spocket,)
abyte ip_address_holder[4]
#define ASSERT_EQUAL(a, b, test_name)