Skip to content

Ticker: add fire interrupt now function #4644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 17, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
ticker test: add test for set interrupt with timestamp in the past
2 test cases added, one for event in the past, one for event in future but very close
to the current time, thus once is set, it is already in the past, and we fire
interrupt immediately.
  • Loading branch information
0xc0170 committed Jul 13, 2017
commit 56cb1582bef242d8a5c47fa67ef04c86de858fb3
60 changes: 60 additions & 0 deletions TESTS/mbed_hal/ticker/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,58 @@ static void test_irq_handler_insert_non_immediate_in_irq()
TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call);
}

static uint32_t ticker_interface_stub_read_interrupt_time()
{
++interface_stub.read_call;
// only if set interrupt call, to test the condition afterwards
if (interface_stub.set_interrupt_call) {
return interface_stub.interrupt_timestamp;
} else {
return interface_stub.timestamp;
}
}

/**
* Test to insert an event that is already in the past, the fire_interrupt should
* be invoked, instead of set_interrupt
*/
static void test_set_interrupt_past_time()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you comment what the test do like it is done for other test. The documentation (and test) is supposed to act as a specification of the code behavior .

{
interface_stub.set_interrupt_call = 0;
interface_stub.fire_interrupt_call = 0;
interface_stub.timestamp = 0xFF;


// This tests fire now functinality when next_event_timestamp <= present
ticker_event_t event = { 0 };
const timestamp_t event_timestamp = interface_stub.timestamp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add another test similar to this one where event_timestamp is more than interface_stub.timestamp.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, added

const uint32_t id_last_event = 0xDEADDEAF;

ticker_insert_event(&ticker_stub, &event, event_timestamp, id_last_event);
TEST_ASSERT_EQUAL(0, interface_stub.set_interrupt_call);
TEST_ASSERT_EQUAL(1, interface_stub.fire_interrupt_call);
}
/**
* Test to insert an event that is being delayed, set_interrupt is set
* but then event is already in the past, thus fire_interrupt should be invoked right-away
*/
static void test_set_interrupt_past_time_with_delay()
{
interface_stub.set_interrupt_call = 0;
interface_stub.fire_interrupt_call = 0;
interface_stub.timestamp = 0xFF;

// This tests fire now functionality when present time >= new_match_time
interface_stub.interface.read = ticker_interface_stub_read_interrupt_time;
ticker_event_t event = { 0 };
const timestamp_t event_timestamp = interface_stub.timestamp + 5;
const uint32_t id_last_event = 0xDEADDEAF;

ticker_insert_event(&ticker_stub, &event, event_timestamp, id_last_event);
TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call);
TEST_ASSERT_EQUAL(1, interface_stub.fire_interrupt_call);
}

static const case_t cases[] = {
MAKE_TEST_CASE("ticker initialization", test_ticker_initialization),
MAKE_TEST_CASE(
Expand Down Expand Up @@ -2070,6 +2122,14 @@ static const case_t cases[] = {
MAKE_TEST_CASE(
"test_irq_handler_insert_non_immediate_in_irq",
test_irq_handler_insert_non_immediate_in_irq
),
MAKE_TEST_CASE(
"test_set_interrupt_past_time",
test_set_interrupt_past_time
),
MAKE_TEST_CASE(
"test_set_interrupt_past_time_with_delay",
test_set_interrupt_past_time_with_delay
)
};

Expand Down