Commit a84ebca5 authored by Tristan Gingold's avatar Tristan Gingold

unittest: add test_msg_time

parent 6f5fc0a1
......@@ -324,6 +324,96 @@ static void test_msg_mix(CuTest *tc)
wrtd_close(wrtd_1);
}
/**
* For this test you need 2 WRTD boards (LUN 0 LUN 1) and 1 white rabbit switch.
* You have to connect a pulse generator to the channel 0 of the TDC
* mezzanine on board with LUN 1.
* You have to put the following lemo cables:
* - LUN 0, FineDelay channel 0 (Out1) -----> LUN 1 TDC channel 1 (In2)
* Path:
* Lun1/In1 -> tid1 -> Lun0/Out1 -> Lun1/In2
*/
static void test_msg_time(CuTest *tc)
{
struct wrtd_node *wrtd_0, *wrtd_1;
struct wrtd_trig_id tid_1 = {0, 2, 1};
struct wrtd_trig_id tid_2 = {0, 2, 2};
struct wrtd_trigger_handle h_1;
struct wrtd_input_state sti1, sti2;
struct wrtd_output_state sto1, sto2;
const uint64_t tdelay = 200 * 1000 * 1000;
wrtd_0 = wrtd_open(1);
CuAssertPtrNotNull(tc, wrtd_0);
wrtd_1 = wrtd_open(2);
CuAssertPtrNotNull(tc, wrtd_1);
clear_counters(tc, wrtd_0);
clear_counters(tc, wrtd_1);
/* Assign trigger input */
CuAssertIntEquals(tc, 0, wrtd_in_trigger_assign(wrtd_1, 0, &tid_1));
CuAssertIntEquals(tc, 0, wrtd_in_trigger_assign(wrtd_1, 1, &tid_2));
CuAssertIntEquals(tc, 0, wrtd_in_trigger_mode_set(wrtd_1, 0, WRTD_TRIGGER_MODE_SINGLE));
CuAssertIntEquals(tc, 0, wrtd_in_trigger_mode_set(wrtd_1, 1, WRTD_TRIGGER_MODE_AUTO));
/* Assign trigger output */
CuAssertIntEquals(tc, 0, wrtd_out_trig_assign(wrtd_0, 0, &h_1, &tid_1, NULL));
CuAssertIntEquals(tc, 0, wrtd_out_trig_delay_set(wrtd_0, &h_1, tdelay));
CuAssertIntEquals(tc, 0, wrtd_out_trigger_mode_set(wrtd_0, 0, WRTD_TRIGGER_MODE_AUTO));
CuAssertIntEquals(tc, 0, wrtd_in_dead_time_set(wrtd_0, 0, 80000000));
CuAssertIntEquals(tc, 0, wrtd_in_dead_time_set(wrtd_0, 1, 80000000));
/* Enable and Arm */
CuAssertIntEquals(tc, 0, wrtd_out_arm(wrtd_0, 0, 1));
CuAssertIntEquals(tc, 0, wrtd_out_enable(wrtd_0, 0, 1));
CuAssertIntEquals(tc, 0, wrtd_out_trig_enable(wrtd_0, &h_1, 1));
CuAssertIntEquals(tc, 0, wrtd_in_arm(wrtd_1, 1, 1));
/* Last because connected to pulse generator */
CuAssertIntEquals(tc, 0, wrtd_in_arm(wrtd_1, 0, 1));
CuAssertIntEquals(tc, 0, wrtd_in_enable(wrtd_1, 1, 1));
/* Last because connected to pulse generator */
CuAssertIntEquals(tc, 0, wrtd_in_enable(wrtd_1, 0, 1));
sleep(2);
/* Stop getting pulses from pulse-generator */
CuAssertIntEquals(tc, 0, wrtd_in_enable(wrtd_1, 0, 0));
sleep(1);
CuAssertIntEquals(tc, 0, wrtd_in_enable(wrtd_1, 1, 0));
CuAssertIntEquals(tc, 0, wrtd_out_enable(wrtd_0, 0, 0));
CuAssertIntEquals(tc, 0, wrtd_out_enable(wrtd_0, 1, 0));
CuAssertIntEquals(tc, 0, wrtd_in_state_get(wrtd_1, 0, &sti1));
CuAssertIntEquals(tc, 0, wrtd_out_state_get(wrtd_0, 0, &sto1));
CuAssertIntEquals(tc, 0, wrtd_in_state_get(wrtd_1, 1, &sti2));
/* Sent and received messages are the same */
CuAssertIntEquals(tc, sti1.sent_triggers, sto1.executed_pulses);
CuAssertIntEquals(tc, sti1.sent_triggers, sti2.sent_triggers);
/* Last sent trigger is the last executed */
CuAssertIntEquals(tc, sti1.last_sent.seq, sto1.last_executed.seq);
CuAssertIntEquals(tc, sti2.last_sent.seq, sto2.last_executed.seq);
CuAssertIntEquals(tc, 0, memcmp(&sti1.last_sent.id,
&sto1.last_executed.id,
sizeof(struct wrtd_trig_id)));
CuAssertIntEquals(tc, 0, memcmp(&sti2.last_sent.id,
&sto2.last_executed.id,
sizeof(struct wrtd_trig_id)));
CuAssertIntEquals(tc, 0, wrtd_out_trig_unassign(wrtd_0, &h_1));
/* Close */
wrtd_close(wrtd_0);
wrtd_close(wrtd_1);
}
CuSuite *wrtd_ut_op_suite_get(void)
{
CuSuite *suite = CuSuiteNew();
......@@ -332,6 +422,7 @@ CuSuite *wrtd_ut_op_suite_get(void)
SUITE_ADD_TEST(suite, test_msg_loop);
SUITE_ADD_TEST(suite, test_msg_wr);
SUITE_ADD_TEST(suite, test_msg_mix);
SUITE_ADD_TEST(suite, test_msg_time);
return suite;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment