2015-01-02 20:27:39 +01:00
|
|
|
/* Copyright (c) 2013-2015, The Tor Project, Inc. */
|
2013-05-31 15:51:25 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
#define CONNECTION_PRIVATE
|
|
|
|
#define TOR_CHANNEL_INTERNAL_
|
|
|
|
#define CONTROL_PRIVATE
|
|
|
|
#include "or.h"
|
|
|
|
#include "channel.h"
|
|
|
|
#include "channeltls.h"
|
|
|
|
#include "connection.h"
|
|
|
|
#include "control.h"
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
help_test_bucket_note_empty(uint32_t expected_msec_since_midnight,
|
|
|
|
int tokens_before, size_t tokens_removed,
|
|
|
|
uint32_t msec_since_epoch)
|
|
|
|
{
|
|
|
|
uint32_t timestamp_var = 0;
|
|
|
|
struct timeval tvnow;
|
|
|
|
tvnow.tv_sec = msec_since_epoch / 1000;
|
|
|
|
tvnow.tv_usec = (msec_since_epoch % 1000) * 1000;
|
|
|
|
connection_buckets_note_empty_ts(×tamp_var, tokens_before,
|
2013-09-12 10:10:38 +02:00
|
|
|
tokens_removed, &tvnow);
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_int_op(expected_msec_since_midnight, OP_EQ, timestamp_var);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_cntev_bucket_note_empty(void *arg)
|
|
|
|
{
|
|
|
|
(void)arg;
|
|
|
|
|
|
|
|
/* Two cases with nothing to note, because bucket was empty before;
|
|
|
|
* 86442200 == 1970-01-02 00:00:42.200000 */
|
|
|
|
help_test_bucket_note_empty(0, 0, 0, 86442200);
|
|
|
|
help_test_bucket_note_empty(0, -100, 100, 86442200);
|
|
|
|
|
|
|
|
/* Nothing to note, because bucket has not been emptied. */
|
|
|
|
help_test_bucket_note_empty(0, 101, 100, 86442200);
|
|
|
|
|
|
|
|
/* Bucket was emptied, note 42200 msec since midnight. */
|
|
|
|
help_test_bucket_note_empty(42200, 101, 101, 86442200);
|
|
|
|
help_test_bucket_note_empty(42200, 101, 102, 86442200);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_cntev_bucket_millis_empty(void *arg)
|
|
|
|
{
|
|
|
|
struct timeval tvnow;
|
|
|
|
(void)arg;
|
|
|
|
|
|
|
|
/* 1970-01-02 00:00:42.200000 */
|
|
|
|
tvnow.tv_sec = 86400 + 42;
|
|
|
|
tvnow.tv_usec = 200000;
|
|
|
|
|
|
|
|
/* Bucket has not been refilled. */
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_int_op(0, OP_EQ, bucket_millis_empty(0, 42120, 0, 100, &tvnow));
|
|
|
|
tt_int_op(0, OP_EQ, bucket_millis_empty(-10, 42120, -10, 100, &tvnow));
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* Bucket was not empty. */
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_int_op(0, OP_EQ, bucket_millis_empty(10, 42120, 20, 100, &tvnow));
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* Bucket has been emptied 80 msec ago and has just been refilled. */
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_int_op(80, OP_EQ, bucket_millis_empty(-20, 42120, -10, 100, &tvnow));
|
|
|
|
tt_int_op(80, OP_EQ, bucket_millis_empty(-10, 42120, 0, 100, &tvnow));
|
|
|
|
tt_int_op(80, OP_EQ, bucket_millis_empty(0, 42120, 10, 100, &tvnow));
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* Bucket has been emptied 180 msec ago, last refill was 100 msec ago
|
|
|
|
* which was insufficient to make it positive, so cap msec at 100. */
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_int_op(100, OP_EQ, bucket_millis_empty(0, 42020, 1, 100, &tvnow));
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* 1970-01-02 00:00:00:050000 */
|
|
|
|
tvnow.tv_sec = 86400;
|
|
|
|
tvnow.tv_usec = 50000;
|
|
|
|
|
|
|
|
/* Last emptied 30 msec before midnight, tvnow is 50 msec after
|
|
|
|
* midnight, that's 80 msec in total. */
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_int_op(80, OP_EQ, bucket_millis_empty(0, 86400000 - 30, 1, 100, &tvnow));
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_testing_cell_stats_entry(circuit_t *circ, uint8_t command,
|
|
|
|
unsigned int waiting_time,
|
|
|
|
unsigned int removed, unsigned int exitward)
|
|
|
|
{
|
|
|
|
testing_cell_stats_entry_t *ent = tor_malloc_zero(
|
|
|
|
sizeof(testing_cell_stats_entry_t));
|
|
|
|
ent->command = command;
|
|
|
|
ent->waiting_time = waiting_time;
|
|
|
|
ent->removed = removed;
|
|
|
|
ent->exitward = exitward;
|
|
|
|
if (!circ->testing_cell_stats)
|
|
|
|
circ->testing_cell_stats = smartlist_new();
|
|
|
|
smartlist_add(circ->testing_cell_stats, ent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_cntev_sum_up_cell_stats(void *arg)
|
|
|
|
{
|
|
|
|
or_circuit_t *or_circ;
|
|
|
|
circuit_t *circ;
|
2013-11-22 18:21:14 +01:00
|
|
|
cell_stats_t *cell_stats = NULL;
|
2013-05-31 15:51:25 +02:00
|
|
|
(void)arg;
|
|
|
|
|
2013-11-22 18:21:14 +01:00
|
|
|
/* This circuit is fake. */
|
2013-05-31 15:51:25 +02:00
|
|
|
or_circ = tor_malloc_zero(sizeof(or_circuit_t));
|
|
|
|
or_circ->base_.magic = OR_CIRCUIT_MAGIC;
|
|
|
|
or_circ->base_.purpose = CIRCUIT_PURPOSE_OR;
|
|
|
|
circ = TO_CIRCUIT(or_circ);
|
|
|
|
|
|
|
|
/* A single RELAY cell was added to the appward queue. */
|
|
|
|
cell_stats = tor_malloc_zero(sizeof(cell_stats_t));
|
|
|
|
add_testing_cell_stats_entry(circ, CELL_RELAY, 0, 0, 0);
|
|
|
|
sum_up_cell_stats_by_command(circ, cell_stats);
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_u64_op(1, OP_EQ, cell_stats->added_cells_appward[CELL_RELAY]);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* A single RELAY cell was added to the exitward queue. */
|
|
|
|
add_testing_cell_stats_entry(circ, CELL_RELAY, 0, 0, 1);
|
|
|
|
sum_up_cell_stats_by_command(circ, cell_stats);
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_u64_op(1, OP_EQ, cell_stats->added_cells_exitward[CELL_RELAY]);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* A single RELAY cell was removed from the appward queue where it spent
|
|
|
|
* 20 msec. */
|
|
|
|
add_testing_cell_stats_entry(circ, CELL_RELAY, 2, 1, 0);
|
|
|
|
sum_up_cell_stats_by_command(circ, cell_stats);
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_u64_op(20, OP_EQ, cell_stats->total_time_appward[CELL_RELAY]);
|
|
|
|
tt_u64_op(1, OP_EQ, cell_stats->removed_cells_appward[CELL_RELAY]);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* A single RELAY cell was removed from the exitward queue where it
|
|
|
|
* spent 30 msec. */
|
|
|
|
add_testing_cell_stats_entry(circ, CELL_RELAY, 3, 1, 1);
|
|
|
|
sum_up_cell_stats_by_command(circ, cell_stats);
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_u64_op(30, OP_EQ, cell_stats->total_time_exitward[CELL_RELAY]);
|
|
|
|
tt_u64_op(1, OP_EQ, cell_stats->removed_cells_exitward[CELL_RELAY]);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
done:
|
2013-11-22 18:21:14 +01:00
|
|
|
tor_free(cell_stats);
|
|
|
|
tor_free(or_circ);
|
2013-05-31 15:51:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_cntev_append_cell_stats(void *arg)
|
|
|
|
{
|
|
|
|
smartlist_t *event_parts;
|
2014-04-26 06:12:39 +02:00
|
|
|
char *cp = NULL;
|
2013-05-31 15:51:25 +02:00
|
|
|
const char *key = "Z";
|
|
|
|
uint64_t include_if_non_zero[CELL_COMMAND_MAX_ + 1],
|
|
|
|
number_to_include[CELL_COMMAND_MAX_ + 1];
|
|
|
|
(void)arg;
|
|
|
|
|
|
|
|
event_parts = smartlist_new();
|
|
|
|
memset(include_if_non_zero, 0,
|
|
|
|
(CELL_COMMAND_MAX_ + 1) * sizeof(uint64_t));
|
|
|
|
memset(number_to_include, 0,
|
|
|
|
(CELL_COMMAND_MAX_ + 1) * sizeof(uint64_t));
|
|
|
|
|
|
|
|
/* All array entries empty. */
|
2013-09-12 10:51:55 +02:00
|
|
|
append_cell_stats_by_command(event_parts, key,
|
2013-10-28 10:48:18 +01:00
|
|
|
include_if_non_zero,
|
|
|
|
number_to_include);
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_int_op(0, OP_EQ, smartlist_len(event_parts));
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* There's a RELAY cell to include, but the corresponding field in
|
|
|
|
* include_if_non_zero is still zero. */
|
|
|
|
number_to_include[CELL_RELAY] = 1;
|
2013-09-12 10:51:55 +02:00
|
|
|
append_cell_stats_by_command(event_parts, key,
|
2013-10-28 10:48:18 +01:00
|
|
|
include_if_non_zero,
|
|
|
|
number_to_include);
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_int_op(0, OP_EQ, smartlist_len(event_parts));
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* Now include single RELAY cell. */
|
|
|
|
include_if_non_zero[CELL_RELAY] = 2;
|
2013-09-12 10:51:55 +02:00
|
|
|
append_cell_stats_by_command(event_parts, key,
|
2013-10-28 10:48:18 +01:00
|
|
|
include_if_non_zero,
|
|
|
|
number_to_include);
|
2014-04-26 06:12:39 +02:00
|
|
|
cp = smartlist_pop_last(event_parts);
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_str_op("Z=relay:1", OP_EQ, cp);
|
2014-04-26 06:12:39 +02:00
|
|
|
tor_free(cp);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* Add four CREATE cells. */
|
|
|
|
include_if_non_zero[CELL_CREATE] = 3;
|
|
|
|
number_to_include[CELL_CREATE] = 4;
|
2013-09-12 10:51:55 +02:00
|
|
|
append_cell_stats_by_command(event_parts, key,
|
2013-10-28 10:48:18 +01:00
|
|
|
include_if_non_zero,
|
|
|
|
number_to_include);
|
2014-04-26 06:12:39 +02:00
|
|
|
cp = smartlist_pop_last(event_parts);
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_str_op("Z=create:4,relay:1", OP_EQ, cp);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
done:
|
2014-04-26 06:12:39 +02:00
|
|
|
tor_free(cp);
|
2014-04-26 06:40:22 +02:00
|
|
|
smartlist_free(event_parts);
|
2013-05-31 15:51:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_cntev_format_cell_stats(void *arg)
|
|
|
|
{
|
2013-11-22 18:21:14 +01:00
|
|
|
char *event_string = NULL;
|
2014-04-26 06:40:22 +02:00
|
|
|
origin_circuit_t *ocirc = NULL;
|
|
|
|
or_circuit_t *or_circ = NULL;
|
2013-11-22 18:21:14 +01:00
|
|
|
cell_stats_t *cell_stats = NULL;
|
2014-04-26 06:40:22 +02:00
|
|
|
channel_tls_t *n_chan=NULL, *p_chan=NULL;
|
2013-05-31 15:51:25 +02:00
|
|
|
(void)arg;
|
|
|
|
|
|
|
|
n_chan = tor_malloc_zero(sizeof(channel_tls_t));
|
|
|
|
n_chan->base_.global_identifier = 1;
|
|
|
|
|
|
|
|
ocirc = tor_malloc_zero(sizeof(origin_circuit_t));
|
|
|
|
ocirc->base_.magic = ORIGIN_CIRCUIT_MAGIC;
|
|
|
|
ocirc->base_.purpose = CIRCUIT_PURPOSE_C_GENERAL;
|
|
|
|
ocirc->global_identifier = 2;
|
|
|
|
ocirc->base_.n_circ_id = 3;
|
|
|
|
ocirc->base_.n_chan = &(n_chan->base_);
|
|
|
|
|
|
|
|
/* Origin circuit was completely idle. */
|
|
|
|
cell_stats = tor_malloc_zero(sizeof(cell_stats_t));
|
|
|
|
format_cell_stats(&event_string, TO_CIRCUIT(ocirc), cell_stats);
|
2014-11-12 19:28:07 +01:00
|
|
|
tt_str_op("ID=2 OutboundQueue=3 OutboundConn=1", OP_EQ, event_string);
|
2013-11-22 18:21:14 +01:00
|
|
|
tor_free(event_string);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* Origin circuit had 4 RELAY cells added to its exitward queue. */
|
|
|
|
cell_stats->added_cells_exitward[CELL_RELAY] = 4;
|
|
|
|
format_cell_stats(&event_string, TO_CIRCUIT(ocirc), cell_stats);
|
|
|
|
tt_str_op("ID=2 OutboundQueue=3 OutboundConn=1 OutboundAdded=relay:4",
|
2014-11-12 19:28:07 +01:00
|
|
|
OP_EQ, event_string);
|
2013-11-22 18:21:14 +01:00
|
|
|
tor_free(event_string);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* Origin circuit also had 5 CREATE2 cells added to its exitward
|
|
|
|
* queue. */
|
|
|
|
cell_stats->added_cells_exitward[CELL_CREATE2] = 5;
|
|
|
|
format_cell_stats(&event_string, TO_CIRCUIT(ocirc), cell_stats);
|
|
|
|
tt_str_op("ID=2 OutboundQueue=3 OutboundConn=1 OutboundAdded=relay:4,"
|
2014-11-12 19:28:07 +01:00
|
|
|
"create2:5", OP_EQ, event_string);
|
2013-11-22 18:21:14 +01:00
|
|
|
tor_free(event_string);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* Origin circuit also had 7 RELAY cells removed from its exitward queue
|
|
|
|
* which together spent 6 msec in the queue. */
|
|
|
|
cell_stats->total_time_exitward[CELL_RELAY] = 6;
|
|
|
|
cell_stats->removed_cells_exitward[CELL_RELAY] = 7;
|
|
|
|
format_cell_stats(&event_string, TO_CIRCUIT(ocirc), cell_stats);
|
|
|
|
tt_str_op("ID=2 OutboundQueue=3 OutboundConn=1 OutboundAdded=relay:4,"
|
|
|
|
"create2:5 OutboundRemoved=relay:7 OutboundTime=relay:6",
|
2014-11-12 19:28:07 +01:00
|
|
|
OP_EQ, event_string);
|
2013-11-22 18:21:14 +01:00
|
|
|
tor_free(event_string);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
p_chan = tor_malloc_zero(sizeof(channel_tls_t));
|
|
|
|
p_chan->base_.global_identifier = 2;
|
|
|
|
|
|
|
|
or_circ = tor_malloc_zero(sizeof(or_circuit_t));
|
|
|
|
or_circ->base_.magic = OR_CIRCUIT_MAGIC;
|
|
|
|
or_circ->base_.purpose = CIRCUIT_PURPOSE_OR;
|
|
|
|
or_circ->p_circ_id = 8;
|
|
|
|
or_circ->p_chan = &(p_chan->base_);
|
|
|
|
or_circ->base_.n_circ_id = 9;
|
|
|
|
or_circ->base_.n_chan = &(n_chan->base_);
|
|
|
|
|
2013-11-22 18:21:14 +01:00
|
|
|
tor_free(cell_stats);
|
|
|
|
|
2013-05-31 15:51:25 +02:00
|
|
|
/* OR circuit was idle. */
|
|
|
|
cell_stats = tor_malloc_zero(sizeof(cell_stats_t));
|
|
|
|
format_cell_stats(&event_string, TO_CIRCUIT(or_circ), cell_stats);
|
|
|
|
tt_str_op("InboundQueue=8 InboundConn=2 OutboundQueue=9 OutboundConn=1",
|
2014-11-12 19:28:07 +01:00
|
|
|
OP_EQ, event_string);
|
2013-11-22 18:21:14 +01:00
|
|
|
tor_free(event_string);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* OR circuit had 3 RELAY cells added to its appward queue. */
|
|
|
|
cell_stats->added_cells_appward[CELL_RELAY] = 3;
|
|
|
|
format_cell_stats(&event_string, TO_CIRCUIT(or_circ), cell_stats);
|
|
|
|
tt_str_op("InboundQueue=8 InboundConn=2 InboundAdded=relay:3 "
|
2014-11-12 19:28:07 +01:00
|
|
|
"OutboundQueue=9 OutboundConn=1", OP_EQ, event_string);
|
2013-11-22 18:21:14 +01:00
|
|
|
tor_free(event_string);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/* OR circuit had 7 RELAY cells removed from its appward queue which
|
|
|
|
* together spent 6 msec in the queue. */
|
|
|
|
cell_stats->total_time_appward[CELL_RELAY] = 6;
|
|
|
|
cell_stats->removed_cells_appward[CELL_RELAY] = 7;
|
|
|
|
format_cell_stats(&event_string, TO_CIRCUIT(or_circ), cell_stats);
|
|
|
|
tt_str_op("InboundQueue=8 InboundConn=2 InboundAdded=relay:3 "
|
|
|
|
"InboundRemoved=relay:7 InboundTime=relay:6 "
|
2014-11-12 19:28:07 +01:00
|
|
|
"OutboundQueue=9 OutboundConn=1", OP_EQ, event_string);
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
done:
|
2013-11-22 18:21:14 +01:00
|
|
|
tor_free(cell_stats);
|
|
|
|
tor_free(event_string);
|
2014-04-26 06:40:22 +02:00
|
|
|
tor_free(or_circ);
|
|
|
|
tor_free(ocirc);
|
|
|
|
tor_free(p_chan);
|
|
|
|
tor_free(n_chan);
|
2013-05-31 15:51:25 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 04:22:56 +01:00
|
|
|
static void
|
|
|
|
test_cntev_event_mask(void *arg)
|
|
|
|
{
|
|
|
|
unsigned int test_event, selected_event;
|
|
|
|
(void)arg;
|
|
|
|
|
|
|
|
/* Check that nothing is interesting when no events are set */
|
|
|
|
control_testing_set_global_event_mask(EVENT_MASK_NONE_);
|
|
|
|
|
|
|
|
/* Check that nothing is interesting between EVENT_MIN_ and EVENT_MAX_ */
|
|
|
|
for (test_event = EVENT_MIN_; test_event <= EVENT_MAX_; test_event++)
|
|
|
|
tt_assert(!control_event_is_interesting(test_event));
|
|
|
|
|
|
|
|
/* Check that nothing is interesting outside EVENT_MIN_ to EVENT_MAX_
|
|
|
|
* This will break if control_event_is_interesting() checks its arguments */
|
|
|
|
for (test_event = 0; test_event < EVENT_MIN_; test_event++)
|
|
|
|
tt_assert(!control_event_is_interesting(test_event));
|
|
|
|
for (test_event = EVENT_MAX_ + 1;
|
|
|
|
test_event < EVENT_CAPACITY_;
|
|
|
|
test_event++)
|
|
|
|
tt_assert(!control_event_is_interesting(test_event));
|
|
|
|
|
|
|
|
/* Check that all valid events are interesting when all events are set */
|
|
|
|
control_testing_set_global_event_mask(EVENT_MASK_ALL_);
|
|
|
|
|
|
|
|
/* Check that everything is interesting between EVENT_MIN_ and EVENT_MAX_ */
|
|
|
|
for (test_event = EVENT_MIN_; test_event <= EVENT_MAX_; test_event++)
|
|
|
|
tt_assert(control_event_is_interesting(test_event));
|
|
|
|
|
|
|
|
/* Check that nothing is interesting outside EVENT_MIN_ to EVENT_MAX_
|
|
|
|
* This will break if control_event_is_interesting() checks its arguments */
|
|
|
|
for (test_event = 0; test_event < EVENT_MIN_; test_event++)
|
|
|
|
tt_assert(!control_event_is_interesting(test_event));
|
|
|
|
for (test_event = EVENT_MAX_ + 1;
|
|
|
|
test_event < EVENT_CAPACITY_;
|
|
|
|
test_event++)
|
|
|
|
tt_assert(!control_event_is_interesting(test_event));
|
|
|
|
|
|
|
|
/* Check that only that event is interesting when a single event is set */
|
|
|
|
for (selected_event = EVENT_MIN_;
|
|
|
|
selected_event <= EVENT_MAX_;
|
|
|
|
selected_event++) {
|
|
|
|
control_testing_set_global_event_mask(EVENT_MASK_(selected_event));
|
|
|
|
|
|
|
|
/* Check that only this event is interesting
|
|
|
|
* between EVENT_MIN_ and EVENT_MAX_ */
|
|
|
|
for (test_event = EVENT_MIN_; test_event <= EVENT_MAX_; test_event++) {
|
|
|
|
if (test_event == selected_event) {
|
|
|
|
tt_assert(control_event_is_interesting(test_event));
|
|
|
|
} else {
|
|
|
|
tt_assert(!control_event_is_interesting(test_event));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that nothing is interesting outside EVENT_MIN_ to EVENT_MAX_
|
|
|
|
* This will break if control_event_is_interesting checks its arguments */
|
|
|
|
for (test_event = 0; test_event < EVENT_MIN_; test_event++)
|
|
|
|
tt_assert(!control_event_is_interesting(test_event));
|
|
|
|
for (test_event = EVENT_MAX_ + 1;
|
|
|
|
test_event < EVENT_CAPACITY_;
|
|
|
|
test_event++)
|
|
|
|
tt_assert(!control_event_is_interesting(test_event));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that only that event is not-interesting
|
|
|
|
* when a single event is un-set */
|
|
|
|
for (selected_event = EVENT_MIN_;
|
|
|
|
selected_event <= EVENT_MAX_;
|
|
|
|
selected_event++) {
|
|
|
|
control_testing_set_global_event_mask(
|
|
|
|
EVENT_MASK_ALL_
|
|
|
|
& ~(EVENT_MASK_(selected_event))
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Check that only this event is not-interesting
|
|
|
|
* between EVENT_MIN_ and EVENT_MAX_ */
|
|
|
|
for (test_event = EVENT_MIN_; test_event <= EVENT_MAX_; test_event++) {
|
|
|
|
if (test_event == selected_event) {
|
|
|
|
tt_assert(!control_event_is_interesting(test_event));
|
|
|
|
} else {
|
|
|
|
tt_assert(control_event_is_interesting(test_event));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that nothing is interesting outside EVENT_MIN_ to EVENT_MAX_
|
|
|
|
* This will break if control_event_is_interesting checks its arguments */
|
|
|
|
for (test_event = 0; test_event < EVENT_MIN_; test_event++)
|
|
|
|
tt_assert(!control_event_is_interesting(test_event));
|
|
|
|
for (test_event = EVENT_MAX_ + 1;
|
|
|
|
test_event < EVENT_CAPACITY_;
|
|
|
|
test_event++)
|
|
|
|
tt_assert(!control_event_is_interesting(test_event));
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2013-05-31 15:51:25 +02:00
|
|
|
#define TEST(name, flags) \
|
|
|
|
{ #name, test_cntev_ ## name, flags, 0, NULL }
|
|
|
|
|
|
|
|
struct testcase_t controller_event_tests[] = {
|
|
|
|
TEST(bucket_note_empty, 0),
|
|
|
|
TEST(bucket_millis_empty, 0),
|
|
|
|
TEST(sum_up_cell_stats, 0),
|
|
|
|
TEST(append_cell_stats, 0),
|
|
|
|
TEST(format_cell_stats, 0),
|
2015-03-22 04:22:56 +01:00
|
|
|
TEST(event_mask, 0),
|
2013-05-31 15:51:25 +02:00
|
|
|
END_OF_TESTCASES
|
|
|
|
};
|
|
|
|
|