31 using namespace basis;
41 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
50 test_ucast_spocket() {}
52 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_ucast_spocket::execute()
117 const char *DEFAULT_HOST =
"127.0.0.1";
118 const int DEFAULT_PORT = 12342;
119 const int DEFAULT_SEND_SIZE = 1008;
120 const int DEFAULT_SEND_COUNT = 10;
125 This program takes six command line arguments to begin operation.\n\
126 These arguments (in order) are:\n\
127 \tIP address for src\tIn the form w.x.y.z\n\
128 \tIP address for dest\tIn the form w.x.y.z\n\
129 \tReceive Port number\tAs a short integer\n\
130 \tSending Port number\tAs a short integer\n\
131 \tSend size\t\tThe size of the data to exchange.\n\
132 \tSend count\t\tThe number of \"packets\" to exchange.\n\
133 Note: it is expected that the testers have equal send sizes; this\n\
134 allows the receiver to know when it's gotten all the data that's\n\
135 expected during a cycle.");
138 parse_address(DEFAULT_HOST, ip_address);
139 parse_address(DEFAULT_HOST, dest_addr);
140 rcv_port = DEFAULT_PORT;
141 send_port = DEFAULT_PORT + 1;
142 send_size = DEFAULT_SEND_SIZE;
143 send_count = DEFAULT_SEND_COUNT;
152 LOG(
"failed to parse source address.");
157 (
int)ip_address[0], (
int)ip_address[1], (
int)ip_address[2],
158 (
int)ip_address[3]));
161 LOG(
"failed to parse dest address.");
165 LOG(
a_sprintf(
"\tParsed a destination of: \"%d.%d.%d.%d\".",
166 (
int)dest_addr[0], (
int)dest_addr[1], (
int)dest_addr[2],
171 LOG(
"The port entry is malformed. Exiting.");
174 LOG(
a_sprintf(
"\tGot a receive port of %d.", rcv_port));
178 LOG(
"The port entry is malformed. Exiting.");
185 LOG(
"The send size entry is malformed. Exiting.");
192 LOG(
"The send count entry is malformed. Exiting.");
195 LOG(
a_sprintf(
"\tGot a send count of %d.", send_count));
203 astring(DEFAULT_HOST) +
" " + DEFAULT_HOST +
" "
206 +
" " +
a_sprintf(
"%d", DEFAULT_SEND_SIZE) +
" " +
a_sprintf(
"%d", DEFAULT_SEND_COUNT),
207 launch_process::RETURN_IMMEDIATELY, kidnum);
208 ASSERT_EQUAL(result, 0,
"launching paired process should start successfully");
219 bool outcome = tester.connect();
221 LOG(
astring(
"Failed to connect on the tester."));
225 LOG(
a_sprintf(
"you now have %d seconds; get other side ready.",
228 LOG(
"starting test");
232 outcome = tester.perform_test(dest, send_size, send_count * 2, stats);
235 LOG(
"Failed out of send_data; maybe other side terminated.");
246 LOG(
"\t\tsend stats\t\treceive stats");
247 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 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.
abyte ip_address_holder[4]
HOOPLE_MAIN(test_ucast_spocket,)
#define ASSERT_EQUAL(a, b, test_name)