+#define O(x) ((x) + NI_NAMES_BASE)
+#define B(x) ((x) - NI_NAMES_BASE)
+#define V(x) ((x) | 0x80)
+
+/* *** BEGIN fake board data *** */
+static const char *pci_6070e = "pci-6070e";
+static const char *pci_6220 = "pci-6220";
+static const char *pci_fake = "pci-fake";
+
+static const char *ni_eseries = "ni_eseries";
+static const char *ni_mseries = "ni_mseries";
+
+static struct ni_board_struct board = {
+ .name = NULL,
+};
+
+static struct ni_private private = {
+ .is_m_series = 0,
+};
+
+static const int badsrc = O(8), src0 = O(0), srci = O(5);
+static const int ith_src_index = 2;
+static const int no_val_src = O(7), no_val_index = 4;
+
+/* These have to be defs to be used in init code below */
+#define rgout0_src0 (O(100))
+#define rgout0_src1 (O(101))
+#define brd0_src0 (O(110))
+#define brd0_src1 (O(111))
+#define brd1_src0 (O(120))
+#define brd1_src1 (O(121))
+#define brd2_src0 (O(130))
+#define brd2_src1 (O(131))
+#define brd3_src0 (O(140))
+#define brd3_src1 (O(141))
+
+/* I1 and I2 should not call O(...). Mostly here to shut checkpatch.pl up */
+#define I1(x1) \
+ (const int[]){ \
+ x1 \
+ }
+#define I2(x1, x2) \
+ (const int[]){ \
+ (x1), (x2) \
+ }
+
+/* O9 is build to call O(...) for each arg */
+#define O9(x1, x2, x3, x4, x5, x6, x7, x8, x9) \
+ (const int[]){ \
+ O(x1), O(x2), O(x3), O(x4), O(x5), O(x6), O(x7), O(x8), O(x9) \
+ }
+
+static const struct ni_device_routes DR = {
+ .device = "testdev",
+ .n_route_sets = 16,
+ .routes = (const struct ni_route_set[]){
+ {.src = O(0), .n_dest = 9,
+ .dest = O9(/**/1, 2, 3, 4, 5, 6, 7, 8, 9)},
+ {.src = O(1), .n_dest = 9,
+ .dest = O9(0, /**/2, 3, 4, 5, 6, 7, 8, 9)},
+ /* ith route_set */
+ {.src = O(5), .n_dest = 9,
+ .dest = O9(0, 1, 2, 3, 4,/**/ 6, 7, 8, 9)},
+ {.src = O(6), .n_dest = 9,
+ .dest = O9(0, 1, 2, 3, 4, 5,/**/ 7, 8, 9)},
+ /* next one will not have valid reg values */
+ {.src = O(7), .n_dest = 9,
+ .dest = O9(0, 1, 2, 3, 4, 5, 6,/**/ 8, 9)},
+ {.src = O(9), .n_dest = 9,
+ .dest = O9(0, 1, 2, 3, 4, 5, 6, 7, 8/**/)},
+
+ /* indirect routes done through muxes */
+ {.src = rgout0_src0, .n_dest = 2,
+ .dest = I2(TRIGGER_LINE(0), TRIGGER_LINE(1))},
+ {.src = rgout0_src1, .n_dest = 2,
+ .dest = I2(TRIGGER_LINE(2), TRIGGER_LINE(3))},
+ {.src = brd0_src0, .n_dest = 1,
+ .dest = I1(TRIGGER_LINE(4))},
+ {.src = brd0_src1, .n_dest = 1,
+ .dest = I1(TRIGGER_LINE(4))},
+ {.src = brd1_src0, .n_dest = 1,
+ .dest = I1(TRIGGER_LINE(3))},
+ {.src = brd1_src1, .n_dest = 1,
+ .dest = I1(TRIGGER_LINE(3))},
+ {.src = brd2_src0, .n_dest = 1,
+ .dest = I1(TRIGGER_LINE(2))},
+ {.src = brd2_src1, .n_dest = 1,
+ .dest = I1(TRIGGER_LINE(2))},
+ {.src = brd3_src0, .n_dest = 1,
+ .dest = I1(TRIGGER_LINE(1))},
+ {.src = brd3_src1, .n_dest = 1,
+ .dest = I1(TRIGGER_LINE(1))},
+ },
+};
+
+#undef I1
+#undef I2
+#undef O9
+
+#define RV9(x1, x2, x3, x4, x5, x6, x7, x8, x9, val) \
+ [x1] = val, [x2] = val, [x3] = val, [x4] = val, [x5] = val, \
+ [x6] = val, [x7] = val, [x8] = val, [x9] = val,
+
+static const u8 RV[NI_NUM_NAMES][NI_NUM_NAMES] = {
+ [0] = {RV9(/**/1, 2, 3, 4, 5, 6, 7, 8, 9, V(0))},
+ [1] = {RV9(0,/**/ 2, 3, 4, 5, 6, 7, 8, 9, V(1))},
+ [2] = {RV9(0, 1,/**/3, 4, 5, 6, 7, 8, 9, V(2))},
+ [3] = {RV9(0, 1, 2,/**/4, 5, 6, 7, 8, 9, V(3))},
+ [4] = {RV9(0, 1, 2, 3,/**/5, 6, 7, 8, 9, V(4))},
+ [5] = {RV9(0, 1, 2, 3, 4,/**/6, 7, 8, 9, V(5))},
+ [6] = {RV9(0, 1, 2, 3, 4, 5,/**/7, 8, 9, V(6))},
+ /* [7] is intentionaly left absent to test invalid routes */
+ [8] = {RV9(0, 1, 2, 3, 4, 5, 6, 7,/**/9, V(8))},
+ [9] = {RV9(0, 1, 2, 3, 4, 5, 6, 7, 8,/**/V(9))},
+ /* some tests for needing extra muxes */
+ [B(rgout0_src0)] = {[B(NI_RGOUT0)] = V(0)},
+ [B(rgout0_src1)] = {[B(NI_RGOUT0)] = V(1)},
+ [B(brd0_src0)] = {[B(NI_RTSI_BRD(0))] = V(0)},
+ [B(brd0_src1)] = {[B(NI_RTSI_BRD(0))] = V(1)},
+ [B(brd1_src0)] = {[B(NI_RTSI_BRD(1))] = V(0)},
+ [B(brd1_src1)] = {[B(NI_RTSI_BRD(1))] = V(1)},
+ [B(brd2_src0)] = {[B(NI_RTSI_BRD(2))] = V(0)},
+ [B(brd2_src1)] = {[B(NI_RTSI_BRD(2))] = V(1)},
+ [B(brd3_src0)] = {[B(NI_RTSI_BRD(3))] = V(0)},
+ [B(brd3_src1)] = {[B(NI_RTSI_BRD(3))] = V(1)},
+};
+
+#undef RV9
+
+/* *** END fake board data *** */
+
+/* *** BEGIN board data initializers *** */
+static inline void init_private(void)
+{
+ memset(&private, 0, sizeof(struct ni_private));
+}
+
+static inline void init_pci_6070e(void)
+{
+ board.name = pci_6070e;
+ init_private();
+ private.is_m_series = 0;
+}
+
+static inline void init_pci_6220(void)
+{
+ board.name = pci_6220;
+ init_private();
+ private.is_m_series = 1;
+}
+
+static inline void init_pci_fake(void)
+{
+ board.name = pci_fake;
+ init_private();
+ private.routing_tables.route_values = &RV[0][0];
+ private.routing_tables.valid_routes = &DR;
+}
+
+/* *** END board data initializers *** */
+
+/* Tests that route_sets are in order of the source signal. */
+static inline bool
+route_set_sources_in_order(const struct ni_device_routes *devroutes)
+{
+ int i;
+ int last = NI_NAMES_BASE - 1;
+
+ for (i = 0; i < devroutes->n_route_sets; ++i) {
+ if (last >= devroutes->routes[i].src)
+ return false;
+ last = devroutes->routes[i].src;
+ }
+ return true;
+}
+
+/* Tests that all route_set->dests are in order of the dest terminal. */
+bool route_set_dests_in_order(const struct ni_device_routes *devroutes)
+{
+ int i;
+
+ for (i = 0; i < devroutes->n_route_sets; ++i) {
+ int j;
+ int last = NI_NAMES_BASE - 1;
+
+ for (j = 0; j < devroutes->routes[i].n_dest; ++j) {
+ if (last >= devroutes->routes[i].dest[j])
+ return false;
+ last = devroutes->routes[i].dest[j];
+ }
+ }
+ return true;
+}
+
+void test_ni_assign_device_routes(void)
+{
+ const struct ni_device_routes *devroutes, *olddevroutes;
+ const u8 *table, *oldtable;
+
+ init_pci_6070e();
+ ni_assign_device_routes(ni_eseries, pci_6070e, &private.routing_tables);
+ devroutes = private.routing_tables.valid_routes;
+ table = private.routing_tables.route_values;
+
+ unittest(strncmp(devroutes->device, pci_6070e, 10) == 0,
+ "find device pci-6070e\n");
+ unittest(devroutes->n_route_sets == 39,
+ "number of pci-6070e route_sets == 39\n");
+ unittest(devroutes->routes->src == NI_PFI(0),
+ "first pci-6070e route_set is for NI_PFI(0)\n");
+ unittest(devroutes->routes->n_dest == 14,
+ "first pci-6070e route_set length == 14\n");
+ unittest(devroutes->routes->dest[0] == NI_CtrSource(0),
+ "first pci-6070e route_set dest. == NI_CtrSource(0)\n");
+ unittest(route_set_sources_in_order(devroutes),
+ "all pci-6070e route_sets in order of source signal values\n");
+ unittest(route_set_dests_in_order(devroutes),
+ "all pci-6070e route_set->dests in order of dest terminal\n");
+
+ unittest(
+ RVi(table, B(NI_10MHzRefClock), B(NI_MasterTimebase)) == V(0) &&
+ RVi(table, B(NI_10MHzRefClock), B(TRIGGER_LINE(0))) == 0 &&
+ RVi(table, B(NI_AI_ConvertClock), B(NI_PFI(0))) == 0 &&
+ RVi(table, B(NI_AI_ConvertClock), B(NI_PFI(2))) ==
+ V(NI_PFI_OUTPUT_AI_CONVERT),
+ "pci-6070e finds e-series route_values table\n");
+
+ olddevroutes = devroutes;
+ oldtable = table;
+ init_pci_6220();
+ ni_assign_device_routes(ni_mseries, pci_6220, &private.routing_tables);
+ devroutes = private.routing_tables.valid_routes;
+ table = private.routing_tables.route_values;
+
+ unittest(strncmp(devroutes->device, pci_6220, 10) == 0,
+ "find device pci-6220\n");
+ unittest(oldtable != table, "pci-6220 find other route_values table\n");
+ unittest((devroutes - olddevroutes) == 1,
+ "pci-6070e,pci-6220 consecutive elements in device_routes_list\n");
+
+ unittest(
+ RVi(table, B(NI_10MHzRefClock), B(NI_MasterTimebase)) == V(0) &&
+ RVi(table, B(NI_10MHzRefClock), B(TRIGGER_LINE(0))) == V(12) &&
+ RVi(table, B(NI_AI_ConvertClock), B(NI_PFI(0))) == V(3) &&
+ RVi(table, B(NI_AI_ConvertClock), B(NI_PFI(2))) == V(3),
+ "pci-6220 finds m-series route_values table\n");
+}
+
+void test_ni_find_route_set(void)
+{
+ unittest(ni_find_route_set(badsrc, &DR) == NULL,
+ "check for nonexistent route_set\n");
+ unittest(ni_find_route_set(src0, &DR) == &DR.routes[0],
+ "find first route_set\n");
+ unittest(ni_find_route_set(srci, &DR) == &DR.routes[ith_src_index],
+ "find ith route_set\n");
+ unittest(ni_find_route_set(no_val_src, &DR) == &DR.routes[no_val_index],
+ "find no_val route_set in spite of missing values\n");
+ unittest(ni_find_route_set(DR.routes[DR.n_route_sets - 1].src, &DR) ==
+ &DR.routes[DR.n_route_sets - 1],
+ "find last route_set\n");
+}
+
+void test_ni_route_set_has_destination(void)
+{
+ unittest(!ni_route_set_has_destination(&DR.routes[0], O(0)),
+ "check for bad destination\n");
+ unittest(ni_route_set_has_destination(&DR.routes[0], O(1)),
+ "find first destination\n");
+ unittest(ni_route_set_has_destination(&DR.routes[0], O(5)),
+ "find fifth destination\n");
+ unittest(ni_route_set_has_destination(&DR.routes[0], O(9)),
+ "find last destination\n");
+}
+
+void test_ni_route_to_register(void)
+{
+ const struct ni_route_tables *T = &private.routing_tables;
+
+ init_pci_fake();
+ unittest(ni_route_to_register(O(0), O(0), T) < 0,
+ "check for bad route 0-->0\n");
+ unittest(ni_route_to_register(O(0), O(1), T) == 0,
+ "validate first destination\n");
+ unittest(ni_route_to_register(O(5), O(6), T) == 5,
+ "validate middle destination\n");
+ unittest(ni_route_to_register(O(9), O(8), T) == 9,
+ "validate last destination\n");
+
+ /* choice of trigger line in the following is somewhat random */
+ unittest(ni_route_to_register(rgout0_src0, TRIGGER_LINE(0), T) == 0,
+ "validate indirect route through rgout0 to TRIGGER_LINE(0)\n");
+ unittest(ni_route_to_register(rgout0_src0, TRIGGER_LINE(1), T) == 0,
+ "validate indirect route through rgout0 to TRIGGER_LINE(1)\n");
+ unittest(ni_route_to_register(rgout0_src1, TRIGGER_LINE(2), T) == 1,
+ "validate indirect route through rgout0 to TRIGGER_LINE(2)\n");
+ unittest(ni_route_to_register(rgout0_src1, TRIGGER_LINE(3), T) == 1,
+ "validate indirect route through rgout0 to TRIGGER_LINE(3)\n");
+
+ unittest(ni_route_to_register(brd0_src0, TRIGGER_LINE(4), T) ==
+ BIT(6),
+ "validate indirect route through brd0 to TRIGGER_LINE(4)\n");
+ unittest(ni_route_to_register(brd0_src1, TRIGGER_LINE(4), T) ==
+ BIT(6),
+ "validate indirect route through brd0 to TRIGGER_LINE(4)\n");
+ unittest(ni_route_to_register(brd1_src0, TRIGGER_LINE(3), T) ==
+ BIT(6),
+ "validate indirect route through brd1 to TRIGGER_LINE(3)\n");
+ unittest(ni_route_to_register(brd1_src1, TRIGGER_LINE(3), T) ==
+ BIT(6),
+ "validate indirect route through brd1 to TRIGGER_LINE(3)\n");
+ unittest(ni_route_to_register(brd2_src0, TRIGGER_LINE(2), T) ==
+ BIT(6),
+ "validate indirect route through brd2 to TRIGGER_LINE(2)\n");
+ unittest(ni_route_to_register(brd2_src1, TRIGGER_LINE(2), T) ==
+ BIT(6),
+ "validate indirect route through brd2 to TRIGGER_LINE(2)\n");
+ unittest(ni_route_to_register(brd3_src0, TRIGGER_LINE(1), T) ==
+ BIT(6),
+ "validate indirect route through brd3 to TRIGGER_LINE(1)\n");
+ unittest(ni_route_to_register(brd3_src1, TRIGGER_LINE(1), T) ==
+ BIT(6),
+ "validate indirect route through brd3 to TRIGGER_LINE(1)\n");
+}
+
+void test_ni_lookup_route_register(void)
+{
+ const struct ni_route_tables *T = &private.routing_tables;
+
+ init_pci_fake();
+ unittest(ni_lookup_route_register(O(0), O(0), T) == -EINVAL,
+ "check for bad route 0-->0\n");
+ unittest(ni_lookup_route_register(O(0), O(1), T) == 0,
+ "validate first destination\n");
+ unittest(ni_lookup_route_register(O(5), O(6), T) == 5,
+ "validate middle destination\n");
+ unittest(ni_lookup_route_register(O(9), O(8), T) == 9,
+ "validate last destination\n");
+ unittest(ni_lookup_route_register(O(9), O(10), T) == -EINVAL,
+ "lookup invalid desination\n");
+
+ unittest(ni_lookup_route_register(rgout0_src0, TRIGGER_LINE(0), T) ==
+ -EINVAL,
+ "rgout0_src0: directly lookup indirect route register (should fail)\n");
+ unittest(ni_lookup_route_register(rgout0_src0, NI_RGOUT0, T) == 0,
+ "rgout0_src0: lookup indirect route register\n");
+ unittest(ni_lookup_route_register(rgout0_src1, TRIGGER_LINE(2), T) ==
+ -EINVAL,
+ "rgout0_src1: directly lookup indirect route register (should fail)\n");
+ unittest(ni_lookup_route_register(rgout0_src1, NI_RGOUT0, T) == 1,
+ "rgout0_src1: lookup indirect route register\n");
+
+ unittest(ni_lookup_route_register(brd0_src0, TRIGGER_LINE(4), T) ==
+ -EINVAL,
+ "brd0_src0: directly lookup indirect route register (should fail)\n");
+ unittest(ni_lookup_route_register(brd0_src0, NI_RTSI_BRD(0), T) == 0,
+ "brd0_src0: lookup indirect route register\n");
+ unittest(ni_lookup_route_register(brd0_src1, TRIGGER_LINE(4), T) ==
+ -EINVAL,
+ "brd0_src1: directly lookup indirect route register (should fail)\n");
+ unittest(ni_lookup_route_register(brd0_src1, NI_RTSI_BRD(0), T) == 1,
+ "brd0_src1: lookup indirect route register\n");
+}
+
+void test_route_is_valid(void)
+{
+ const struct ni_route_tables *T = &private.routing_tables;
+
+ init_pci_fake();
+ unittest(!route_is_valid(O(0), O(0), T),
+ "check for bad route 0-->0\n");
+ unittest(route_is_valid(O(0), O(1), T),
+ "validate first destination\n");
+ unittest(route_is_valid(O(5), O(6), T),
+ "validate middle destination\n");
+ unittest(route_is_valid(O(9), O(8), T),
+ "validate last destination\n");
+}
+
+void test_ni_is_cmd_dest(void)
+{
+ init_pci_fake();
+ unittest(ni_is_cmd_dest(NI_AI_SampleClock),
+ "check that AI/SampleClock is cmd destination\n");
+ unittest(ni_is_cmd_dest(NI_AI_StartTrigger),
+ "check that AI/StartTrigger is cmd destination\n");
+ unittest(ni_is_cmd_dest(NI_AI_ConvertClock),
+ "check that AI/ConvertClock is cmd destination\n");
+ unittest(ni_is_cmd_dest(NI_AO_SampleClock),
+ "check that AO/SampleClock is cmd destination\n");
+ unittest(ni_is_cmd_dest(NI_DO_SampleClock),
+ "check that DO/SampleClock is cmd destination\n");
+ unittest(!ni_is_cmd_dest(NI_AO_SampleClockTimebase),
+ "check that AO/SampleClockTimebase _not_ cmd destination\n");
+}
+
+void test_channel_is_pfi(void)
+{
+ init_pci_fake();
+ unittest(channel_is_pfi(NI_PFI(0)), "check First pfi channel\n");
+ unittest(channel_is_pfi(NI_PFI(10)), "check 10th pfi channel\n");
+ unittest(channel_is_pfi(NI_PFI(-1)), "check last pfi channel\n");
+ unittest(!channel_is_pfi(NI_PFI(-1) + 1),
+ "check first non pfi channel\n");
+}
+
+void test_channel_is_rtsi(void)
+{
+ init_pci_fake();
+ unittest(channel_is_rtsi(TRIGGER_LINE(0)),
+ "check First rtsi channel\n");
+ unittest(channel_is_rtsi(TRIGGER_LINE(3)),
+ "check 3rd rtsi channel\n");
+ unittest(channel_is_rtsi(TRIGGER_LINE(-1)),
+ "check last rtsi channel\n");
+ unittest(!channel_is_rtsi(TRIGGER_LINE(-1) + 1),
+ "check first non rtsi channel\n");
+}
+
+void test_ni_count_valid_routes(void)
+{
+ const struct ni_route_tables *T = &private.routing_tables;
+
+ init_pci_fake();
+ unittest(ni_count_valid_routes(T) == 57, "count all valid routes\n");
+}
+
+void test_ni_get_valid_routes(void)
+{
+ const struct ni_route_tables *T = &private.routing_tables;
+
+ init_pci_fake();
+ unittest(ni_get_valid_routes(T, NULL) == 57,
+ "count all valid routes through ni_get_valid_routes\n");
+}
+
+void test_ni_find_route_source(void)
+{
+ const struct ni_route_tables *T = &private.routing_tables;
+
+ init_pci_fake();
+ unittest(ni_find_route_source(4, O(4), T) == -EINVAL,
+ "check for bad source 4-->4\n");
+ unittest(ni_find_route_source(0, O(1), T) == O(0),
+ "find first source\n");
+ unittest(ni_find_route_source(4, O(6), T) == O(4),
+ "find middle source\n");
+ unittest(ni_find_route_source(9, O(8), T) == O(9),
+ "find last source");
+
+ unittest(ni_find_route_source(8, O(9), T) == O(8),
+ "find invalid source (without checking device routes)\n");
+}
+
+void test_route_register_is_valid(void)
+{
+ const struct ni_route_tables *T = &private.routing_tables;
+
+ init_pci_fake();
+ unittest(route_register_is_valid(4, O(4), T) == false,
+ "check for bad source 4-->4\n");
+ unittest(route_register_is_valid(0, O(1), T) == true,
+ "find first source\n");
+ unittest(route_register_is_valid(4, O(6), T) == true,
+ "find middle source\n");
+ unittest(route_register_is_valid(9, O(8), T) == true,
+ "find last source");
+}
+
+void test_ni_check_trigger_arg(void)
+{
+ const struct ni_route_tables *T = &private.routing_tables;
+
+ init_pci_fake();
+ unittest(ni_check_trigger_arg(0, O(0), T) == -EINVAL,
+ "check bad direct trigger arg for first reg->dest\n");
+ unittest(ni_check_trigger_arg(0, O(1), T) == 0,
+ "check direct trigger arg for first reg->dest\n");
+ unittest(ni_check_trigger_arg(4, O(6), T) == 0,
+ "check direct trigger arg for middle reg->dest\n");
+ unittest(ni_check_trigger_arg(9, O(8), T) == 0,
+ "check direct trigger arg for last reg->dest\n");
+
+ unittest(ni_check_trigger_arg_roffs(-1, O(0), T, 1) == -EINVAL,
+ "check bad direct trigger arg for first reg->dest w/offs\n");
+ unittest(ni_check_trigger_arg_roffs(0, O(1), T, 0) == 0,
+ "check direct trigger arg for first reg->dest w/offs\n");
+ unittest(ni_check_trigger_arg_roffs(3, O(6), T, 1) == 0,
+ "check direct trigger arg for middle reg->dest w/offs\n");
+ unittest(ni_check_trigger_arg_roffs(7, O(8), T, 2) == 0,
+ "check direct trigger arg for last reg->dest w/offs\n");
+
+ unittest(ni_check_trigger_arg(O(0), O(0), T) == -EINVAL,
+ "check bad trigger arg for first src->dest\n");
+ unittest(ni_check_trigger_arg(O(0), O(1), T) == 0,
+ "check trigger arg for first src->dest\n");
+ unittest(ni_check_trigger_arg(O(5), O(6), T) == 0,
+ "check trigger arg for middle src->dest\n");
+ unittest(ni_check_trigger_arg(O(9), O(8), T) == 0,
+ "check trigger arg for last src->dest\n");
+}
+
+void test_ni_get_reg_value(void)
+{
+ const struct ni_route_tables *T = &private.routing_tables;
+
+ init_pci_fake();
+ unittest(ni_get_reg_value(0, O(0), T) == -1,
+ "check bad direct trigger arg for first reg->dest\n");
+ unittest(ni_get_reg_value(0, O(1), T) == 0,
+ "check direct trigger arg for first reg->dest\n");
+ unittest(ni_get_reg_value(4, O(6), T) == 4,
+ "check direct trigger arg for middle reg->dest\n");
+ unittest(ni_get_reg_value(9, O(8), T) == 9,
+ "check direct trigger arg for last reg->dest\n");
+
+ unittest(ni_get_reg_value_roffs(-1, O(0), T, 1) == -1,
+ "check bad direct trigger arg for first reg->dest w/offs\n");
+ unittest(ni_get_reg_value_roffs(0, O(1), T, 0) == 0,
+ "check direct trigger arg for first reg->dest w/offs\n");
+ unittest(ni_get_reg_value_roffs(3, O(6), T, 1) == 4,
+ "check direct trigger arg for middle reg->dest w/offs\n");
+ unittest(ni_get_reg_value_roffs(7, O(8), T, 2) == 9,
+ "check direct trigger arg for last reg->dest w/offs\n");
+
+ unittest(ni_get_reg_value(O(0), O(0), T) == -1,
+ "check bad trigger arg for first src->dest\n");
+ unittest(ni_get_reg_value(O(0), O(1), T) == 0,
+ "check trigger arg for first src->dest\n");
+ unittest(ni_get_reg_value(O(5), O(6), T) == 5,
+ "check trigger arg for middle src->dest\n");
+ unittest(ni_get_reg_value(O(9), O(8), T) == 9,
+ "check trigger arg for last src->dest\n");
+}
+
+/* **** BEGIN simple module entry/exit functions **** */
+static int ni_routes_unittest(void)
+{
+ const unittest_fptr unit_tests[] = {
+ (unittest_fptr)test_ni_assign_device_routes,
+ (unittest_fptr)test_ni_find_route_set,
+ (unittest_fptr)test_ni_route_set_has_destination,
+ (unittest_fptr)test_ni_route_to_register,
+ (unittest_fptr)test_ni_lookup_route_register,
+ (unittest_fptr)test_route_is_valid,
+ (unittest_fptr)test_ni_is_cmd_dest,
+ (unittest_fptr)test_channel_is_pfi,
+ (unittest_fptr)test_channel_is_rtsi,
+ (unittest_fptr)test_ni_count_valid_routes,
+ (unittest_fptr)test_ni_get_valid_routes,
+ (unittest_fptr)test_ni_find_route_source,
+ (unittest_fptr)test_route_register_is_valid,
+ (unittest_fptr)test_ni_check_trigger_arg,
+ (unittest_fptr)test_ni_get_reg_value,
+ NULL,
+ };
+
+ exec_unittests("ni_routes", unit_tests);
+ return 0;
+}
+
+static void __exit ni_routes_unittest_exit(void) { }
+
+module_init(ni_routes_unittest);
+module_exit(ni_routes_unittest_exit);
+
+MODULE_AUTHOR("Comedi http://www.comedi.org");
+MODULE_DESCRIPTION("Comedi unit-tests for ni_routes module");
+MODULE_LICENSE("GPL");
+/* **** END simple module entry/exit functions **** */