This source file includes following definitions.
- init_private
- init_pci_6070e
- init_pci_6220
- init_pci_fake
- route_set_dests_in_order
- route_set_sources_in_order
- test_ni_assign_device_routes
- test_ni_sort_device_routes
- test_ni_find_route_set
- test_ni_route_set_has_source
- test_ni_route_to_register
- test_ni_lookup_route_register
- test_route_is_valid
- test_ni_is_cmd_dest
- test_channel_is_pfi
- test_channel_is_rtsi
- test_ni_count_valid_routes
- test_ni_get_valid_routes
- test_ni_find_route_source
- test_route_register_is_valid
- test_ni_check_trigger_arg
- test_ni_get_reg_value
- ni_routes_unittest
- ni_routes_unittest_exit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <linux/module.h>
22
23 #include "../ni_stc.h"
24 #include "../ni_routes.h"
25 #include "unittest.h"
26
27 #define RVi(table, src, dest) ((table)[(dest) * NI_NUM_NAMES + (src)])
28 #define O(x) ((x) + NI_NAMES_BASE)
29 #define B(x) ((x) - NI_NAMES_BASE)
30 #define V(x) ((x) | 0x80)
31
32
33 static const char *pci_6070e = "pci-6070e";
34 static const char *pci_6220 = "pci-6220";
35 static const char *pci_fake = "pci-fake";
36
37 static const char *ni_eseries = "ni_eseries";
38 static const char *ni_mseries = "ni_mseries";
39
40 static struct ni_board_struct board = {
41 .name = NULL,
42 };
43
44 static struct ni_private private = {
45 .is_m_series = 0,
46 };
47
48 static const int bad_dest = O(8), dest0 = O(0), desti = O(5);
49 static const int ith_dest_index = 2;
50 static const int no_val_dest = O(7), no_val_index = 4;
51
52
53 #define rgout0_src0 (O(100))
54 #define rgout0_src1 (O(101))
55 #define brd0_src0 (O(110))
56 #define brd0_src1 (O(111))
57 #define brd1_src0 (O(120))
58 #define brd1_src1 (O(121))
59 #define brd2_src0 (O(130))
60 #define brd2_src1 (O(131))
61 #define brd3_src0 (O(140))
62 #define brd3_src1 (O(141))
63
64
65 #define I1(x1) \
66 (int[]){ \
67 x1, 0 \
68 }
69 #define I2(x1, x2) \
70 (int[]){ \
71 (x1), (x2), 0 \
72 }
73 #define I3(x1, x2, x3) \
74 (int[]){ \
75 (x1), (x2), (x3), 0 \
76 }
77
78
79 #define O9(x1, x2, x3, x4, x5, x6, x7, x8, x9) \
80 (int[]){ \
81 O(x1), O(x2), O(x3), O(x4), O(x5), O(x6), O(x7), O(x8), O(x9), \
82 0 \
83 }
84
85 static struct ni_device_routes DR = {
86 .device = "testdev",
87 .routes = (struct ni_route_set[]){
88 {.dest = O(0), .src = O9(1, 2, 3, 4, 5, 6, 7, 8, 9)},
89 {.dest = O(1), .src = O9(0, 2, 3, 4, 5, 6, 7, 8, 9)},
90
91 {.dest = O(5), .src = O9(0, 1, 2, 3, 4, 6, 7, 8, 9)},
92 {.dest = O(6), .src = O9(0, 1, 2, 3, 4, 5, 7, 8, 9)},
93
94 {.dest = O(7), .src = O9(0, 1, 2, 3, 4, 5, 6, 8, 9)},
95 {.dest = O(9), .src = O9(0, 1, 2, 3, 4, 5, 6, 7, 8)},
96
97
98 {.dest = TRIGGER_LINE(0), .src = I1(rgout0_src0)},
99 {.dest = TRIGGER_LINE(1), .src = I3(rgout0_src0,
100 brd3_src0,
101 brd3_src1)},
102 {.dest = TRIGGER_LINE(2), .src = I3(rgout0_src1,
103 brd2_src0,
104 brd2_src1)},
105 {.dest = TRIGGER_LINE(3), .src = I3(rgout0_src1,
106 brd1_src0,
107 brd1_src1)},
108 {.dest = TRIGGER_LINE(4), .src = I2(brd0_src0,
109 brd0_src1)},
110 {.dest = 0},
111 },
112 };
113
114 #undef I1
115 #undef I2
116 #undef O9
117
118 #define RV9(x1, x2, x3, x4, x5, x6, x7, x8, x9) \
119 [x1] = V(x1), [x2] = V(x2), [x3] = V(x3), [x4] = V(x4), \
120 [x5] = V(x5), [x6] = V(x6), [x7] = V(x7), [x8] = V(x8), \
121 [x9] = V(x9),
122
123
124 static const u8 RV[NI_NUM_NAMES][NI_NUM_NAMES] = {
125 [0] = {RV9(1, 2, 3, 4, 5, 6, 7, 8, 9)},
126 [1] = {RV9(0, 2, 3, 4, 5, 6, 7, 8, 9)},
127 [2] = {RV9(0, 1,3, 4, 5, 6, 7, 8, 9)},
128 [3] = {RV9(0, 1, 2,4, 5, 6, 7, 8, 9)},
129 [4] = {RV9(0, 1, 2, 3,5, 6, 7, 8, 9)},
130 [5] = {RV9(0, 1, 2, 3, 4,6, 7, 8, 9)},
131 [6] = {RV9(0, 1, 2, 3, 4, 5,7, 8, 9)},
132
133 [8] = {RV9(0, 1, 2, 3, 4, 5, 6, 7,9)},
134 [9] = {RV9(0, 1, 2, 3, 4, 5, 6, 7, 8)},
135
136 [B(NI_RGOUT0)] = {[B(rgout0_src0)] = V(0),
137 [B(rgout0_src1)] = V(1)},
138 [B(NI_RTSI_BRD(0))] = {[B(brd0_src0)] = V(0),
139 [B(brd0_src1)] = V(1)},
140 [B(NI_RTSI_BRD(1))] = {[B(brd1_src0)] = V(0),
141 [B(brd1_src1)] = V(1)},
142 [B(NI_RTSI_BRD(2))] = {[B(brd2_src0)] = V(0),
143 [B(brd2_src1)] = V(1)},
144 [B(NI_RTSI_BRD(3))] = {[B(brd3_src0)] = V(0),
145 [B(brd3_src1)] = V(1)},
146 };
147
148 #undef RV9
149
150
151
152
153 static void init_private(void)
154 {
155 memset(&private, 0, sizeof(struct ni_private));
156 }
157
158 static void init_pci_6070e(void)
159 {
160 board.name = pci_6070e;
161 init_private();
162 private.is_m_series = 0;
163 }
164
165 static void init_pci_6220(void)
166 {
167 board.name = pci_6220;
168 init_private();
169 private.is_m_series = 1;
170 }
171
172 static void init_pci_fake(void)
173 {
174 board.name = pci_fake;
175 init_private();
176 private.routing_tables.route_values = &RV[0][0];
177 private.routing_tables.valid_routes = &DR;
178 }
179
180
181
182
183 static bool route_set_dests_in_order(const struct ni_device_routes *devroutes)
184 {
185 int i;
186 int last = NI_NAMES_BASE - 1;
187
188 for (i = 0; i < devroutes->n_route_sets; ++i) {
189 if (last >= devroutes->routes[i].dest)
190 return false;
191 last = devroutes->routes[i].dest;
192 }
193 return true;
194 }
195
196
197 bool route_set_sources_in_order(const struct ni_device_routes *devroutes)
198 {
199 int i;
200
201 for (i = 0; i < devroutes->n_route_sets; ++i) {
202 int j;
203 int last = NI_NAMES_BASE - 1;
204
205 for (j = 0; j < devroutes->routes[i].n_src; ++j) {
206 if (last >= devroutes->routes[i].src[j])
207 return false;
208 last = devroutes->routes[i].src[j];
209 }
210 }
211 return true;
212 }
213
214 void test_ni_assign_device_routes(void)
215 {
216 const struct ni_device_routes *devroutes, *olddevroutes;
217 const u8 *table, *oldtable;
218
219 init_pci_6070e();
220 ni_assign_device_routes(ni_eseries, pci_6070e, &private.routing_tables);
221 devroutes = private.routing_tables.valid_routes;
222 table = private.routing_tables.route_values;
223
224 unittest(strncmp(devroutes->device, pci_6070e, 10) == 0,
225 "find device pci-6070e\n");
226 unittest(devroutes->n_route_sets == 37,
227 "number of pci-6070e route_sets == 37\n");
228 unittest(devroutes->routes->dest == NI_PFI(0),
229 "first pci-6070e route_set is for NI_PFI(0)\n");
230 unittest(devroutes->routes->n_src == 1,
231 "first pci-6070e route_set length == 1\n");
232 unittest(devroutes->routes->src[0] == NI_AI_StartTrigger,
233 "first pci-6070e route_set src. == NI_AI_StartTrigger\n");
234 unittest(devroutes->routes[10].dest == TRIGGER_LINE(0),
235 "10th pci-6070e route_set is for TRIGGER_LINE(0)\n");
236 unittest(devroutes->routes[10].n_src == 10,
237 "10th pci-6070e route_set length == 10\n");
238 unittest(devroutes->routes[10].src[0] == NI_CtrSource(0),
239 "10th pci-6070e route_set src. == NI_CtrSource(0)\n");
240 unittest(route_set_dests_in_order(devroutes),
241 "all pci-6070e route_sets in order of signal destination\n");
242 unittest(route_set_sources_in_order(devroutes),
243 "all pci-6070e route_set->src's in order of signal source\n");
244
245 unittest(
246 RVi(table, B(PXI_Star), B(NI_AI_SampleClock)) == V(17) &&
247 RVi(table, B(NI_10MHzRefClock), B(TRIGGER_LINE(0))) == 0 &&
248 RVi(table, B(NI_AI_ConvertClock), B(NI_PFI(0))) == 0 &&
249 RVi(table, B(NI_AI_ConvertClock), B(NI_PFI(2))) ==
250 V(NI_PFI_OUTPUT_AI_CONVERT),
251 "pci-6070e finds e-series route_values table\n");
252
253 olddevroutes = devroutes;
254 oldtable = table;
255 init_pci_6220();
256 ni_assign_device_routes(ni_mseries, pci_6220, &private.routing_tables);
257 devroutes = private.routing_tables.valid_routes;
258 table = private.routing_tables.route_values;
259
260 unittest(strncmp(devroutes->device, pci_6220, 10) == 0,
261 "find device pci-6220\n");
262 unittest(oldtable != table, "pci-6220 find other route_values table\n");
263
264 unittest(
265 RVi(table, B(PXI_Star), B(NI_AI_SampleClock)) == V(20) &&
266 RVi(table, B(NI_10MHzRefClock), B(TRIGGER_LINE(0))) == V(12) &&
267 RVi(table, B(NI_AI_ConvertClock), B(NI_PFI(0))) == V(3) &&
268 RVi(table, B(NI_AI_ConvertClock), B(NI_PFI(2))) == V(3),
269 "pci-6220 finds m-series route_values table\n");
270 }
271
272 void test_ni_sort_device_routes(void)
273 {
274
275 ni_sort_device_routes(&DR);
276
277 unittest(route_set_dests_in_order(&DR),
278 "all route_sets of fake data in order of sig. destination\n");
279 unittest(route_set_sources_in_order(&DR),
280 "all route_set->src's of fake data in order of sig. source\n");
281 }
282
283 void test_ni_find_route_set(void)
284 {
285 unittest(!ni_find_route_set(bad_dest, &DR),
286 "check for nonexistent route_set\n");
287 unittest(ni_find_route_set(dest0, &DR) == &DR.routes[0],
288 "find first route_set\n");
289 unittest(ni_find_route_set(desti, &DR) == &DR.routes[ith_dest_index],
290 "find ith route_set\n");
291 unittest(ni_find_route_set(no_val_dest, &DR) ==
292 &DR.routes[no_val_index],
293 "find no_val route_set in spite of missing values\n");
294 unittest(ni_find_route_set(DR.routes[DR.n_route_sets - 1].dest, &DR) ==
295 &DR.routes[DR.n_route_sets - 1],
296 "find last route_set\n");
297 }
298
299 void test_ni_route_set_has_source(void)
300 {
301 unittest(!ni_route_set_has_source(&DR.routes[0], O(0)),
302 "check for bad source\n");
303 unittest(ni_route_set_has_source(&DR.routes[0], O(1)),
304 "find first source\n");
305 unittest(ni_route_set_has_source(&DR.routes[0], O(5)),
306 "find fifth source\n");
307 unittest(ni_route_set_has_source(&DR.routes[0], O(9)),
308 "find last source\n");
309 }
310
311 void test_ni_route_to_register(void)
312 {
313 const struct ni_route_tables *T = &private.routing_tables;
314
315 init_pci_fake();
316 unittest(ni_route_to_register(O(0), O(0), T) < 0,
317 "check for bad route 0-->0\n");
318 unittest(ni_route_to_register(O(1), O(0), T) == 1,
319 "validate first destination\n");
320 unittest(ni_route_to_register(O(6), O(5), T) == 6,
321 "validate middle destination\n");
322 unittest(ni_route_to_register(O(8), O(9), T) == 8,
323 "validate last destination\n");
324
325
326 unittest(ni_route_to_register(rgout0_src0, TRIGGER_LINE(0), T) == 0,
327 "validate indirect route through rgout0 to TRIGGER_LINE(0)\n");
328 unittest(ni_route_to_register(rgout0_src0, TRIGGER_LINE(1), T) == 0,
329 "validate indirect route through rgout0 to TRIGGER_LINE(1)\n");
330 unittest(ni_route_to_register(rgout0_src1, TRIGGER_LINE(2), T) == 1,
331 "validate indirect route through rgout0 to TRIGGER_LINE(2)\n");
332 unittest(ni_route_to_register(rgout0_src1, TRIGGER_LINE(3), T) == 1,
333 "validate indirect route through rgout0 to TRIGGER_LINE(3)\n");
334
335 unittest(ni_route_to_register(brd0_src0, TRIGGER_LINE(4), T) ==
336 BIT(6),
337 "validate indirect route through brd0 to TRIGGER_LINE(4)\n");
338 unittest(ni_route_to_register(brd0_src1, TRIGGER_LINE(4), T) ==
339 BIT(6),
340 "validate indirect route through brd0 to TRIGGER_LINE(4)\n");
341 unittest(ni_route_to_register(brd1_src0, TRIGGER_LINE(3), T) ==
342 BIT(6),
343 "validate indirect route through brd1 to TRIGGER_LINE(3)\n");
344 unittest(ni_route_to_register(brd1_src1, TRIGGER_LINE(3), T) ==
345 BIT(6),
346 "validate indirect route through brd1 to TRIGGER_LINE(3)\n");
347 unittest(ni_route_to_register(brd2_src0, TRIGGER_LINE(2), T) ==
348 BIT(6),
349 "validate indirect route through brd2 to TRIGGER_LINE(2)\n");
350 unittest(ni_route_to_register(brd2_src1, TRIGGER_LINE(2), T) ==
351 BIT(6),
352 "validate indirect route through brd2 to TRIGGER_LINE(2)\n");
353 unittest(ni_route_to_register(brd3_src0, TRIGGER_LINE(1), T) ==
354 BIT(6),
355 "validate indirect route through brd3 to TRIGGER_LINE(1)\n");
356 unittest(ni_route_to_register(brd3_src1, TRIGGER_LINE(1), T) ==
357 BIT(6),
358 "validate indirect route through brd3 to TRIGGER_LINE(1)\n");
359 }
360
361 void test_ni_lookup_route_register(void)
362 {
363 const struct ni_route_tables *T = &private.routing_tables;
364
365 init_pci_fake();
366 unittest(ni_lookup_route_register(O(0), O(0), T) == -EINVAL,
367 "check for bad route 0-->0\n");
368 unittest(ni_lookup_route_register(O(1), O(0), T) == 1,
369 "validate first destination\n");
370 unittest(ni_lookup_route_register(O(6), O(5), T) == 6,
371 "validate middle destination\n");
372 unittest(ni_lookup_route_register(O(8), O(9), T) == 8,
373 "validate last destination\n");
374 unittest(ni_lookup_route_register(O(10), O(9), T) == -EINVAL,
375 "lookup invalid destination\n");
376
377 unittest(ni_lookup_route_register(rgout0_src0, TRIGGER_LINE(0), T) ==
378 -EINVAL,
379 "rgout0_src0: no direct lookup of indirect route\n");
380 unittest(ni_lookup_route_register(rgout0_src0, NI_RGOUT0, T) == 0,
381 "rgout0_src0: lookup indirect route register\n");
382 unittest(ni_lookup_route_register(rgout0_src1, TRIGGER_LINE(2), T) ==
383 -EINVAL,
384 "rgout0_src1: no direct lookup of indirect route\n");
385 unittest(ni_lookup_route_register(rgout0_src1, NI_RGOUT0, T) == 1,
386 "rgout0_src1: lookup indirect route register\n");
387
388 unittest(ni_lookup_route_register(brd0_src0, TRIGGER_LINE(4), T) ==
389 -EINVAL,
390 "brd0_src0: no direct lookup of indirect route\n");
391 unittest(ni_lookup_route_register(brd0_src0, NI_RTSI_BRD(0), T) == 0,
392 "brd0_src0: lookup indirect route register\n");
393 unittest(ni_lookup_route_register(brd0_src1, TRIGGER_LINE(4), T) ==
394 -EINVAL,
395 "brd0_src1: no direct lookup of indirect route\n");
396 unittest(ni_lookup_route_register(brd0_src1, NI_RTSI_BRD(0), T) == 1,
397 "brd0_src1: lookup indirect route register\n");
398 }
399
400 void test_route_is_valid(void)
401 {
402 const struct ni_route_tables *T = &private.routing_tables;
403
404 init_pci_fake();
405 unittest(!route_is_valid(O(0), O(0), T),
406 "check for bad route 0-->0\n");
407 unittest(route_is_valid(O(0), O(1), T),
408 "validate first destination\n");
409 unittest(route_is_valid(O(5), O(6), T),
410 "validate middle destination\n");
411 unittest(route_is_valid(O(8), O(9), T),
412 "validate last destination\n");
413 }
414
415 void test_ni_is_cmd_dest(void)
416 {
417 init_pci_fake();
418 unittest(ni_is_cmd_dest(NI_AI_SampleClock),
419 "check that AI/SampleClock is cmd destination\n");
420 unittest(ni_is_cmd_dest(NI_AI_StartTrigger),
421 "check that AI/StartTrigger is cmd destination\n");
422 unittest(ni_is_cmd_dest(NI_AI_ConvertClock),
423 "check that AI/ConvertClock is cmd destination\n");
424 unittest(ni_is_cmd_dest(NI_AO_SampleClock),
425 "check that AO/SampleClock is cmd destination\n");
426 unittest(ni_is_cmd_dest(NI_DO_SampleClock),
427 "check that DO/SampleClock is cmd destination\n");
428 unittest(!ni_is_cmd_dest(NI_AO_SampleClockTimebase),
429 "check that AO/SampleClockTimebase _not_ cmd destination\n");
430 }
431
432 void test_channel_is_pfi(void)
433 {
434 init_pci_fake();
435 unittest(channel_is_pfi(NI_PFI(0)), "check First pfi channel\n");
436 unittest(channel_is_pfi(NI_PFI(10)), "check 10th pfi channel\n");
437 unittest(channel_is_pfi(NI_PFI(-1)), "check last pfi channel\n");
438 unittest(!channel_is_pfi(NI_PFI(-1) + 1),
439 "check first non pfi channel\n");
440 }
441
442 void test_channel_is_rtsi(void)
443 {
444 init_pci_fake();
445 unittest(channel_is_rtsi(TRIGGER_LINE(0)),
446 "check First rtsi channel\n");
447 unittest(channel_is_rtsi(TRIGGER_LINE(3)),
448 "check 3rd rtsi channel\n");
449 unittest(channel_is_rtsi(TRIGGER_LINE(-1)),
450 "check last rtsi channel\n");
451 unittest(!channel_is_rtsi(TRIGGER_LINE(-1) + 1),
452 "check first non rtsi channel\n");
453 }
454
455 void test_ni_count_valid_routes(void)
456 {
457 const struct ni_route_tables *T = &private.routing_tables;
458
459 init_pci_fake();
460 unittest(ni_count_valid_routes(T) == 57, "count all valid routes\n");
461 }
462
463 void test_ni_get_valid_routes(void)
464 {
465 const struct ni_route_tables *T = &private.routing_tables;
466 unsigned int pair_data[2];
467
468 init_pci_fake();
469 unittest(ni_get_valid_routes(T, 0, NULL) == 57,
470 "count all valid routes through ni_get_valid_routes\n");
471
472 unittest(ni_get_valid_routes(T, 1, pair_data) == 1,
473 "copied first valid route from ni_get_valid_routes\n");
474 unittest(pair_data[0] == O(1),
475 "source of first valid pair from ni_get_valid_routes\n");
476 unittest(pair_data[1] == O(0),
477 "destination of first valid pair from ni_get_valid_routes\n");
478 }
479
480 void test_ni_find_route_source(void)
481 {
482 const struct ni_route_tables *T = &private.routing_tables;
483
484 init_pci_fake();
485 unittest(ni_find_route_source(4, O(4), T) == -EINVAL,
486 "check for bad source 4-->4\n");
487 unittest(ni_find_route_source(0, O(1), T) == O(0),
488 "find first source\n");
489 unittest(ni_find_route_source(4, O(6), T) == O(4),
490 "find middle source\n");
491 unittest(ni_find_route_source(9, O(8), T) == O(9),
492 "find last source");
493 unittest(ni_find_route_source(8, O(9), T) == O(8),
494 "find invalid source (without checking device routes)\n");
495 }
496
497 void test_route_register_is_valid(void)
498 {
499 const struct ni_route_tables *T = &private.routing_tables;
500
501 init_pci_fake();
502 unittest(route_register_is_valid(4, O(4), T) == false,
503 "check for bad source 4-->4\n");
504 unittest(route_register_is_valid(0, O(1), T) == true,
505 "find first source\n");
506 unittest(route_register_is_valid(4, O(6), T) == true,
507 "find middle source\n");
508 unittest(route_register_is_valid(9, O(8), T) == true,
509 "find last source");
510 }
511
512 void test_ni_check_trigger_arg(void)
513 {
514 const struct ni_route_tables *T = &private.routing_tables;
515
516 init_pci_fake();
517 unittest(ni_check_trigger_arg(0, O(0), T) == -EINVAL,
518 "check bad direct trigger arg for first reg->dest\n");
519 unittest(ni_check_trigger_arg(0, O(1), T) == 0,
520 "check direct trigger arg for first reg->dest\n");
521 unittest(ni_check_trigger_arg(4, O(6), T) == 0,
522 "check direct trigger arg for middle reg->dest\n");
523 unittest(ni_check_trigger_arg(9, O(8), T) == 0,
524 "check direct trigger arg for last reg->dest\n");
525
526 unittest(ni_check_trigger_arg_roffs(-1, O(0), T, 1) == -EINVAL,
527 "check bad direct trigger arg for first reg->dest w/offs\n");
528 unittest(ni_check_trigger_arg_roffs(0, O(1), T, 0) == 0,
529 "check direct trigger arg for first reg->dest w/offs\n");
530 unittest(ni_check_trigger_arg_roffs(3, O(6), T, 1) == 0,
531 "check direct trigger arg for middle reg->dest w/offs\n");
532 unittest(ni_check_trigger_arg_roffs(7, O(8), T, 2) == 0,
533 "check direct trigger arg for last reg->dest w/offs\n");
534
535 unittest(ni_check_trigger_arg(O(0), O(0), T) == -EINVAL,
536 "check bad trigger arg for first src->dest\n");
537 unittest(ni_check_trigger_arg(O(0), O(1), T) == 0,
538 "check trigger arg for first src->dest\n");
539 unittest(ni_check_trigger_arg(O(5), O(6), T) == 0,
540 "check trigger arg for middle src->dest\n");
541 unittest(ni_check_trigger_arg(O(8), O(9), T) == 0,
542 "check trigger arg for last src->dest\n");
543 }
544
545 void test_ni_get_reg_value(void)
546 {
547 const struct ni_route_tables *T = &private.routing_tables;
548
549 init_pci_fake();
550 unittest(ni_get_reg_value(0, O(0), T) == -1,
551 "check bad direct trigger arg for first reg->dest\n");
552 unittest(ni_get_reg_value(0, O(1), T) == 0,
553 "check direct trigger arg for first reg->dest\n");
554 unittest(ni_get_reg_value(4, O(6), T) == 4,
555 "check direct trigger arg for middle reg->dest\n");
556 unittest(ni_get_reg_value(9, O(8), T) == 9,
557 "check direct trigger arg for last reg->dest\n");
558
559 unittest(ni_get_reg_value_roffs(-1, O(0), T, 1) == -1,
560 "check bad direct trigger arg for first reg->dest w/offs\n");
561 unittest(ni_get_reg_value_roffs(0, O(1), T, 0) == 0,
562 "check direct trigger arg for first reg->dest w/offs\n");
563 unittest(ni_get_reg_value_roffs(3, O(6), T, 1) == 4,
564 "check direct trigger arg for middle reg->dest w/offs\n");
565 unittest(ni_get_reg_value_roffs(7, O(8), T, 2) == 9,
566 "check direct trigger arg for last reg->dest w/offs\n");
567
568 unittest(ni_get_reg_value(O(0), O(0), T) == -1,
569 "check bad trigger arg for first src->dest\n");
570 unittest(ni_get_reg_value(O(0), O(1), T) == 0,
571 "check trigger arg for first src->dest\n");
572 unittest(ni_get_reg_value(O(5), O(6), T) == 5,
573 "check trigger arg for middle src->dest\n");
574 unittest(ni_get_reg_value(O(8), O(9), T) == 8,
575 "check trigger arg for last src->dest\n");
576 }
577
578
579 static int __init ni_routes_unittest(void)
580 {
581 const unittest_fptr unit_tests[] = {
582 (unittest_fptr)test_ni_assign_device_routes,
583 (unittest_fptr)test_ni_sort_device_routes,
584 (unittest_fptr)test_ni_find_route_set,
585 (unittest_fptr)test_ni_route_set_has_source,
586 (unittest_fptr)test_ni_route_to_register,
587 (unittest_fptr)test_ni_lookup_route_register,
588 (unittest_fptr)test_route_is_valid,
589 (unittest_fptr)test_ni_is_cmd_dest,
590 (unittest_fptr)test_channel_is_pfi,
591 (unittest_fptr)test_channel_is_rtsi,
592 (unittest_fptr)test_ni_count_valid_routes,
593 (unittest_fptr)test_ni_get_valid_routes,
594 (unittest_fptr)test_ni_find_route_source,
595 (unittest_fptr)test_route_register_is_valid,
596 (unittest_fptr)test_ni_check_trigger_arg,
597 (unittest_fptr)test_ni_get_reg_value,
598 NULL,
599 };
600
601 exec_unittests("ni_routes", unit_tests);
602 return 0;
603 }
604
605 static void __exit ni_routes_unittest_exit(void) { }
606
607 module_init(ni_routes_unittest);
608 module_exit(ni_routes_unittest_exit);
609
610 MODULE_AUTHOR("Comedi http://www.comedi.org");
611 MODULE_DESCRIPTION("Comedi unit-tests for ni_routes module");
612 MODULE_LICENSE("GPL");
613