Debian Codegraph @

unit/test-rvf.c

raw
1 /*
2 * Copyright (c) 2021, Fastree3D
3 * Adrian Fiergolski <[email protected]>
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Intel Corporation nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <alloca.h>
30 #include <stdarg.h>
31 #include <stddef.h>
32 #include <string.h>
33 #include <setjmp.h>
34 #include <cmocka.h>
35 #include <arpa/inet.h>
36
37 #include "avtp.h"
38 #include "avtp_rvf.h"
39
40 static void rvf_get_field_null_pdu(void **state)
41 {
42 int res;
43 uint64_t val = 1;
44
45 res = avtp_rvf_pdu_get(NULL, AVTP_RVF_FIELD_SV, &val);
46
47 assert_int_equal(res, -EINVAL);
48 }
49
50 static void rvf_get_field_null_val(void **state)
51 {
52 int res;
53 struct avtp_stream_pdu pdu = { 0 };
54
55 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_SV, NULL);
56
57 assert_int_equal(res, -EINVAL);
58 }
59
60 static void rvf_get_field_invalid_field(void **state)
61 {
62 int res;
63 uint64_t val = 1;
64 struct avtp_stream_pdu pdu = { 0 };
65
66 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_MAX, &val);
67
68 assert_int_equal(res, -EINVAL);
69 }
70
71 static void rvf_get_field_sv(void **state)
72 {
73 int res;
74 uint64_t val;
75 struct avtp_stream_pdu pdu = { 0 };
76
77 /* Set 'sv' field to 1. */
78 pdu.subtype_data = htonl(0x00800000);
79
80 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_SV, &val);
81
82 assert_int_equal(res, 0);
83 assert_true(val == 1);
84 }
85
86 static void rvf_get_field_mr(void **state)
87 {
88 int res;
89 uint64_t val;
90 struct avtp_stream_pdu pdu = { 0 };
91
92 /* Set 'mr' field to 1. */
93 pdu.subtype_data = htonl(0x00080000);
94
95 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_MR, &val);
96
97 assert_int_equal(res, 0);
98 assert_true(val == 1);
99 }
100
101 static void rvf_get_field_tv(void **state)
102 {
103 int res;
104 uint64_t val;
105 struct avtp_stream_pdu pdu = { 0 };
106
107 /* Set 'tv' field to 1. */
108 pdu.subtype_data = htonl(0x00010000);
109
110 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_TV, &val);
111
112 assert_int_equal(res, 0);
113 assert_true(val == 1);
114 }
115
116 static void rvf_get_field_seq_num(void **state)
117 {
118 int res;
119 uint64_t val;
120 struct avtp_stream_pdu pdu = { 0 };
121
122 /* Set 'sequence_num' field to 0x55. */
123 pdu.subtype_data = htonl(0x00005500);
124
125 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_SEQ_NUM, &val);
126
127 assert_int_equal(res, 0);
128 assert_true(val == 0x55);
129 }
130
131 static void rvf_get_field_tu(void **state)
132 {
133 int res;
134 uint64_t val;
135 struct avtp_stream_pdu pdu = { 0 };
136
137 /* Set 'tu' field to 1. */
138 pdu.subtype_data = htonl(0x00000001);
139
140 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_TU, &val);
141
142 assert_int_equal(res, 0);
143 assert_true(val == 1);
144 }
145
146 static void rvf_get_field_stream_id(void **state)
147 {
148 int res;
149 uint64_t val;
150 struct avtp_stream_pdu pdu = { 0 };
151
152 /* Set 'stream_id' field to 0xAABBCCDDEEFF0001. */
153 pdu.stream_id = htobe64(0xAABBCCDDEEFF0001);
154
155 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_STREAM_ID, &val);
156
157 assert_int_equal(res, 0);
158 assert_true(val == 0xAABBCCDDEEFF0001);
159 }
160
161 static void rvf_get_field_timestamp(void **state)
162 {
163 int res;
164 uint64_t val;
165 struct avtp_stream_pdu pdu = { 0 };
166
167 /* Set 'avtp_timestamp' field to 0x80C0FFEE. */
168 pdu.avtp_time = htonl(0x80C0FFEE);
169
170 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_TIMESTAMP, &val);
171
172 assert_int_equal(res, 0);
173 assert_true(val == 0x80C0FFEE);
174 }
175
176 static void rvf_get_field_active_pixels(void **state)
177 {
178 int res;
179 uint64_t val;
180 struct avtp_stream_pdu pdu = { 0 };
181
182 /* Set 'active_pixels' field to 0x20. */
183 pdu.format_specific = htonl(0x00200000);
184
185 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_ACTIVE_PIXELS, &val);
186
187 assert_int_equal(res, 0);
188 assert_true(val == 0x20);
189 }
190
191 static void rvf_get_field_format_total_lines(void **state)
192 {
193 int res;
194 uint64_t val;
195 struct avtp_stream_pdu pdu = { 0 };
196
197 /* Set 'total_lines' field to 0x3C. */
198 pdu.format_specific = htonl(0x0000003C);
199
200 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_TOTAL_LINES, &val);
201
202 assert_int_equal(res, 0);
203 assert_true(val == 0x3C);
204 }
205
206 static void rvf_get_field_data_len(void **state)
207 {
208 int res;
209 uint64_t val;
210 struct avtp_stream_pdu pdu = { 0 };
211
212 /* Set 'stream_data_length' field to 0xAAAA. */
213 pdu.packet_info = htonl(0xAAAA0000);
214
215 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_STREAM_DATA_LEN, &val);
216
217 assert_int_equal(res, 0);
218 assert_true(val == 0xAAAA);
219 }
220
221 static void rvf_get_field_ap(void **state)
222 {
223 int res;
224 uint64_t val;
225 struct avtp_stream_pdu pdu = { 0 };
226
227 /* Set 'AP' field to 0x1. */
228 pdu.packet_info = htonl(0x00008000);
229
230 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_AP, &val);
231
232 assert_int_equal(res, 0);
233 assert_true(val == 0x1);
234 }
235
236 static void rvf_get_field_f(void **state)
237 {
238 int res;
239 uint64_t val;
240 struct avtp_stream_pdu pdu = { 0 };
241
242 /* Set 'F' field to 0x1. */
243 pdu.packet_info = htonl(0x00002000);
244
245 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_F, &val);
246
247 assert_int_equal(res, 0);
248 assert_true(val == 0x1);
249 }
250
251 static void rvf_get_field_ef(void **state)
252 {
253 int res;
254 uint64_t val;
255 struct avtp_stream_pdu pdu = { 0 };
256
257 /* Set 'EF' field to 0x1. */
258 pdu.packet_info = htonl(0x00001000);
259
260 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_EF, &val);
261
262 assert_int_equal(res, 0);
263 assert_true(val == 0x1);
264 }
265
266 static void rvf_get_field_evt(void **state)
267 {
268 int res;
269 uint64_t val;
270 struct avtp_stream_pdu pdu = { 0 };
271
272 /* Set 'evt' field to 0xA. */
273 pdu.packet_info = htonl(0x00000A00);
274
275 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_EVT, &val);
276
277 assert_int_equal(res, 0);
278 assert_true(val == 0xA);
279 }
280
281 static void rvf_get_field_pd(void **state)
282 {
283 int res;
284 uint64_t val;
285 struct avtp_stream_pdu pdu = { 0 };
286
287 /* Set 'PD' field to 0x1. */
288 pdu.packet_info = htonl(0x00000080);
289
290 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_PD, &val);
291
292 assert_int_equal(res, 0);
293 assert_true(val == 0x1);
294 }
295
296 static void rvf_get_field_i(void **state)
297 {
298 int res;
299 uint64_t val;
300 struct avtp_stream_pdu pdu = { 0 };
301
302 /* Set 'I' field to 0x1. */
303 pdu.packet_info = htonl(0x00000040);
304
305 res = avtp_rvf_pdu_get(&pdu, AVTP_RVF_FIELD_I, &val);
306
307 assert_int_equal(res, 0);
308 assert_true(val == 0x1);
309 }
310
311 static void rvf_set_field_null_pdu(void **state)
312 {
313 int res;
314
315 res = avtp_rvf_pdu_set(NULL, AVTP_RVF_FIELD_SV, 1);
316
317 assert_int_equal(res, -EINVAL);
318 }
319
320 static void rvf_set_field_invalid_field(void **state)
321 {
322 int res;
323 struct avtp_stream_pdu pdu = { 0 };
324
325 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_MAX, 1);
326
327 assert_int_equal(res, -EINVAL);
328 }
329
330 static void rvf_set_field_sv(void **state)
331 {
332 int res;
333 struct avtp_stream_pdu pdu = { 0 };
334
335 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_SV, 1);
336
337 assert_int_equal(res, 0);
338 assert_true(ntohl(pdu.subtype_data) == 0x00800000);
339 assert_true(pdu.stream_id == 0);
340 assert_true(pdu.avtp_time == 0);
341 assert_true(pdu.format_specific == 0);
342 assert_true(pdu.packet_info == 0);
343 }
344
345 static void rvf_set_field_mr(void **state)
346 {
347 int res;
348 struct avtp_stream_pdu pdu = { 0 };
349
350 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_MR, 1);
351
352 assert_int_equal(res, 0);
353 assert_true(ntohl(pdu.subtype_data) == 0x00080000);
354 assert_true(pdu.stream_id == 0);
355 assert_true(pdu.avtp_time == 0);
356 assert_true(pdu.format_specific == 0);
357 assert_true(pdu.packet_info == 0);
358 }
359
360 static void rvf_set_field_tv(void **state)
361 {
362 int res;
363 struct avtp_stream_pdu pdu = { 0 };
364
365 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_TV, 1);
366
367 assert_int_equal(res, 0);
368 assert_true(ntohl(pdu.subtype_data) == 0x00010000);
369 assert_true(pdu.stream_id == 0);
370 assert_true(pdu.avtp_time == 0);
371 assert_true(pdu.format_specific == 0);
372 assert_true(pdu.packet_info == 0);
373 }
374
375 static void rvf_set_field_seq_num(void **state)
376 {
377 int res;
378 struct avtp_stream_pdu pdu = { 0 };
379
380 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_SEQ_NUM, 0x55);
381
382 assert_int_equal(res, 0);
383 assert_true(ntohl(pdu.subtype_data) == 0x00005500);
384 assert_true(pdu.stream_id == 0);
385 assert_true(pdu.avtp_time == 0);
386 assert_true(pdu.format_specific == 0);
387 assert_true(pdu.packet_info == 0);
388 }
389
390 static void rvf_set_field_tu(void **state)
391 {
392 int res;
393 struct avtp_stream_pdu pdu = { 0 };
394
395 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_TU, 1);
396
397 assert_int_equal(res, 0);
398 assert_true(ntohl(pdu.subtype_data) == 0x00000001);
399 assert_true(pdu.stream_id == 0);
400 assert_true(pdu.avtp_time == 0);
401 assert_true(pdu.format_specific == 0);
402 assert_true(pdu.packet_info == 0);
403 }
404
405 static void rvf_set_field_stream_id(void **state)
406 {
407 int res;
408 struct avtp_stream_pdu pdu = { 0 };
409
410 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_STREAM_ID,
411 0xAABBCCDDEEFF0001);
412
413 assert_int_equal(res, 0);
414 assert_true(be64toh(pdu.stream_id) == 0xAABBCCDDEEFF0001);
415 assert_true(pdu.subtype_data == 0);
416 assert_true(pdu.avtp_time == 0);
417 assert_true(pdu.format_specific == 0);
418 assert_true(pdu.packet_info == 0);
419 }
420
421 static void rvf_set_field_timestamp(void **state)
422 {
423 int res;
424 struct avtp_stream_pdu pdu = { 0 };
425
426 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_TIMESTAMP, 0x80C0FFEE);
427
428 assert_int_equal(res, 0);
429 assert_true(ntohl(pdu.avtp_time) == 0x80C0FFEE);
430 assert_true(pdu.subtype_data == 0);
431 assert_true(pdu.stream_id == 0);
432 assert_true(pdu.format_specific == 0);
433 assert_true(pdu.packet_info == 0);
434 }
435
436 static void rvf_set_field_active_pixels(void **state)
437 {
438 int res;
439 struct avtp_stream_pdu pdu = { 0 };
440
441 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_ACTIVE_PIXELS,
442 AVTP_RVF_PIXEL_DEPTH_16);
443
444 assert_int_equal(res, 0);
445 assert_true(ntohl(pdu.format_specific) == 0x00040000);
446 assert_true(pdu.subtype_data == 0);
447 assert_true(pdu.stream_id == 0);
448 assert_true(pdu.avtp_time == 0);
449 assert_true(pdu.packet_info == 0);
450 }
451
452 static void rvf_set_field_total_lines(void **state)
453 {
454 int res;
455 struct avtp_stream_pdu pdu = { 0 };
456
457 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_TOTAL_LINES, 0x3C);
458
459 assert_int_equal(res, 0);
460 assert_true(ntohl(pdu.format_specific) == 0x3C);
461 assert_true(pdu.subtype_data == 0);
462 assert_true(pdu.stream_id == 0);
463 assert_true(pdu.avtp_time == 0);
464 assert_true(pdu.packet_info == 0);
465 }
466
467 static void rvf_set_field_data_len(void **state)
468 {
469 int res;
470 struct avtp_stream_pdu pdu = { 0 };
471
472 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_STREAM_DATA_LEN, 0xAAAA);
473
474 assert_int_equal(res, 0);
475 assert_true(ntohl(pdu.packet_info) == 0xAAAA0000);
476 assert_true(pdu.subtype_data == 0);
477 assert_true(pdu.stream_id == 0);
478 assert_true(pdu.avtp_time == 0);
479 assert_true(pdu.format_specific == 0);
480 }
481
482 static void rvf_set_field_ap(void **state)
483 {
484 int res;
485 struct avtp_stream_pdu pdu = { 0 };
486
487 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_AP, 1);
488
489 assert_int_equal(res, 0);
490 assert_true(ntohl(pdu.packet_info) == 0x00008000);
491 assert_true(pdu.subtype_data == 0);
492 assert_true(pdu.stream_id == 0);
493 assert_true(pdu.avtp_time == 0);
494 assert_true(pdu.format_specific == 0);
495 }
496
497 static void rvf_set_field_f(void **state)
498 {
499 int res;
500 struct avtp_stream_pdu pdu = { 0 };
501
502 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_F, 1);
503
504 assert_int_equal(res, 0);
505 assert_true(ntohl(pdu.packet_info) == 0x00002000);
506 assert_true(pdu.subtype_data == 0);
507 assert_true(pdu.stream_id == 0);
508 assert_true(pdu.avtp_time == 0);
509 assert_true(pdu.format_specific == 0);
510 }
511
512 static void rvf_set_field_ef(void **state)
513 {
514 int res;
515 struct avtp_stream_pdu pdu = { 0 };
516
517 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_EF, 1);
518
519 assert_int_equal(res, 0);
520 assert_true(ntohl(pdu.packet_info) == 0x00001000);
521 assert_true(pdu.subtype_data == 0);
522 assert_true(pdu.stream_id == 0);
523 assert_true(pdu.avtp_time == 0);
524 assert_true(pdu.format_specific == 0);
525 }
526
527 static void rvf_set_field_evt(void **state)
528 {
529 int res;
530 struct avtp_stream_pdu pdu = { 0 };
531
532 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_EVT, 0xA);
533
534 assert_int_equal(res, 0);
535 assert_true(ntohl(pdu.packet_info) == 0x00000A00);
536 assert_true(pdu.subtype_data == 0);
537 assert_true(pdu.stream_id == 0);
538 assert_true(pdu.avtp_time == 0);
539 assert_true(pdu.format_specific == 0);
540 }
541
542 static void rvf_set_field_pd(void **state)
543 {
544 int res;
545 struct avtp_stream_pdu pdu = { 0 };
546
547 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_PD, 1);
548
549 assert_int_equal(res, 0);
550 assert_true(ntohl(pdu.packet_info) == 0x00000080);
551 assert_true(pdu.subtype_data == 0);
552 assert_true(pdu.stream_id == 0);
553 assert_true(pdu.avtp_time == 0);
554 assert_true(pdu.format_specific == 0);
555 }
556
557 static void rvf_set_field_i(void **state)
558 {
559 int res;
560 struct avtp_stream_pdu pdu = { 0 };
561
562 res = avtp_rvf_pdu_set(&pdu, AVTP_RVF_FIELD_I, 1);
563
564 assert_int_equal(res, 0);
565 assert_true(ntohl(pdu.packet_info) == 0x00000040);
566 assert_true(pdu.subtype_data == 0);
567 assert_true(pdu.stream_id == 0);
568 assert_true(pdu.avtp_time == 0);
569 assert_true(pdu.format_specific == 0);
570 }
571
572 static void rvf_pdu_init_null_pdu(void **state)
573 {
574 int res;
575
576 res = avtp_rvf_pdu_init(NULL);
577 assert_int_equal(res, -EINVAL);
578 }
579
580 static void rvf_pdu_init(void **state)
581 {
582 int res;
583 struct avtp_stream_pdu pdu;
584
585 res = avtp_rvf_pdu_init(&pdu);
586
587 assert_int_equal(res, 0);
588 assert_true(ntohl(pdu.subtype_data) == 0x07800000);
589 assert_true(pdu.stream_id == 0);
590 assert_true(pdu.avtp_time == 0);
591 assert_true(ntohl(pdu.format_specific) == 0x0000000);
592 assert_true(pdu.packet_info == 0);
593 }
594
595 /**** Tests for RAW fields ****/
596
597 static void rvf_get_field_raw_pixel_depth(void **state)
598 {
599 int res;
600 uint64_t val;
601 struct avtp_stream_pdu *pdu =
602 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
603 struct avtp_rvf_payload *pay =
604 (struct avtp_rvf_payload *)pdu->avtp_payload;
605
606 /* Set 'pixel_depth' field to AVTP_RVF_PIXEL_DEPTH_16 */
607 pay->raw_header = htobe64(0x0040000000000000);
608
609 res = avtp_rvf_pdu_get(pdu, AVTP_RVF_FIELD_RAW_PIXEL_DEPTH, &val);
610
611 assert_int_equal(res, 0);
612 assert_true(val == AVTP_RVF_PIXEL_DEPTH_16);
613 }
614
615 static void rvf_get_field_raw_pixel_format(void **state)
616 {
617 int res;
618 uint64_t val;
619 struct avtp_stream_pdu *pdu =
620 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
621 struct avtp_rvf_payload *pay =
622 (struct avtp_rvf_payload *)pdu->avtp_payload;
623
624 /* Set 'pixel_format' field to AVTP_RVF_PIXEL_DEPTH_16 */
625 pay->raw_header = htobe64(0x0003000000000000);
626
627 res = avtp_rvf_pdu_get(pdu, AVTP_RVF_FIELD_RAW_PIXEL_FORMAT, &val);
628
629 assert_int_equal(res, 0);
630 assert_true(val == AVTP_RVF_PIXEL_FORMAT_422);
631 }
632
633 static void rvf_get_field_raw_frame_rate(void **state)
634 {
635 int res;
636 uint64_t val;
637 struct avtp_stream_pdu *pdu =
638 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
639 struct avtp_rvf_payload *pay =
640 (struct avtp_rvf_payload *)pdu->avtp_payload;
641
642 /* Set 'frame rate' field to AVTP_RVF_FRAME_RATE_30 */
643 pay->raw_header = htobe64(0x0000150000000000);
644
645 res = avtp_rvf_pdu_get(pdu, AVTP_RVF_FIELD_RAW_FRAME_RATE, &val);
646
647 assert_int_equal(res, 0);
648 assert_true(val == AVTP_RVF_FRAME_RATE_30);
649 }
650
651 static void rvf_get_field_raw_colorspace(void **state)
652 {
653 int res;
654 uint64_t val;
655 struct avtp_stream_pdu *pdu =
656 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
657 struct avtp_rvf_payload *pay =
658 (struct avtp_rvf_payload *)pdu->avtp_payload;
659
660 /* Set 'colorspace' field to AVTP_RVF_COLORSPACE_GRAY */
661 pay->raw_header = htobe64(0x0000004000000000);
662
663 res = avtp_rvf_pdu_get(pdu, AVTP_RVF_FIELD_RAW_COLORSPACE, &val);
664
665 assert_int_equal(res, 0);
666 assert_true(val == AVTP_RVF_COLORSPACE_GRAY);
667 }
668
669 static void rvf_get_field_raw_num_lines(void **state)
670 {
671 int res;
672 uint64_t val;
673 struct avtp_stream_pdu *pdu =
674 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
675 struct avtp_rvf_payload *pay =
676 (struct avtp_rvf_payload *)pdu->avtp_payload;
677
678 /* Set 'num_lines' field to 0x05 */
679 pay->raw_header = htobe64(0x0000000500000000);
680
681 res = avtp_rvf_pdu_get(pdu, AVTP_RVF_FIELD_RAW_NUM_LINES, &val);
682
683 assert_int_equal(res, 0);
684 assert_true(val == 0x5);
685 }
686
687 static void rvf_get_field_raw_i_seq_num(void **state)
688 {
689 int res;
690 uint64_t val;
691 struct avtp_stream_pdu *pdu =
692 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
693 struct avtp_rvf_payload *pay =
694 (struct avtp_rvf_payload *)pdu->avtp_payload;
695
696 /* Set 'i_seq_num' field to 0x03 */
697 pay->raw_header = htobe64(0x0000000000030000);
698
699 res = avtp_rvf_pdu_get(pdu, AVTP_RVF_FIELD_RAW_I_SEQ_NUM, &val);
700
701 assert_int_equal(res, 0);
702 assert_true(val == 0x3);
703 }
704
705 static void rvf_get_field_raw_line_number(void **state)
706 {
707 int res;
708 uint64_t val;
709 struct avtp_stream_pdu *pdu =
710 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
711 struct avtp_rvf_payload *pay =
712 (struct avtp_rvf_payload *)pdu->avtp_payload;
713
714 /* Set 'i_seq_num' field to 0x123 */
715 pay->raw_header = htobe64(0x0000000000000123);
716
717 res = avtp_rvf_pdu_get(pdu, AVTP_RVF_FIELD_RAW_LINE_NUMBER, &val);
718
719 assert_int_equal(res, 0);
720 assert_true(val == 0x123);
721 }
722
723 static void rvf_set_field_raw_pixel_depth(void **state)
724 {
725 int res;
726 struct avtp_stream_pdu *pdu =
727 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
728 struct avtp_rvf_payload *pay =
729 (struct avtp_rvf_payload *)pdu->avtp_payload;
730 memset(pdu, 0, sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
731
732 res = avtp_rvf_pdu_set(pdu, AVTP_RVF_FIELD_RAW_PIXEL_DEPTH,
733 AVTP_RVF_PIXEL_DEPTH_16);
734
735 assert_int_equal(res, 0);
736 assert_true(pdu->avtp_time == 0);
737 assert_true(pdu->subtype_data == 0);
738 assert_true(pdu->stream_id == 0);
739 assert_true(pdu->format_specific == 0);
740 assert_true(pdu->packet_info == 0);
741 assert_true(be64toh(pay->raw_header) == 0x0040000000000000);
742 }
743
744 static void rvf_set_field_raw_pixel_format(void **state)
745 {
746 int res;
747 struct avtp_stream_pdu *pdu =
748 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
749 struct avtp_rvf_payload *pay =
750 (struct avtp_rvf_payload *)pdu->avtp_payload;
751 memset(pdu, 0, sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
752
753 res = avtp_rvf_pdu_set(pdu, AVTP_RVF_FIELD_RAW_PIXEL_FORMAT,
754 AVTP_RVF_PIXEL_FORMAT_422);
755
756 assert_int_equal(res, 0);
757 assert_true(pdu->avtp_time == 0);
758 assert_true(pdu->subtype_data == 0);
759 assert_true(pdu->stream_id == 0);
760 assert_true(pdu->format_specific == 0);
761 assert_true(pdu->packet_info == 0);
762 assert_true(be64toh(pay->raw_header) == 0x0003000000000000);
763 }
764
765 static void rvf_set_field_raw_frame_rate(void **state)
766 {
767 int res;
768 struct avtp_stream_pdu *pdu =
769 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
770 struct avtp_rvf_payload *pay =
771 (struct avtp_rvf_payload *)pdu->avtp_payload;
772 memset(pdu, 0, sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
773
774 res = avtp_rvf_pdu_set(pdu, AVTP_RVF_FIELD_RAW_FRAME_RATE,
775 AVTP_RVF_FRAME_RATE_30);
776
777 assert_int_equal(res, 0);
778 assert_true(pdu->avtp_time == 0);
779 assert_true(pdu->subtype_data == 0);
780 assert_true(pdu->stream_id == 0);
781 assert_true(pdu->format_specific == 0);
782 assert_true(pdu->packet_info == 0);
783 assert_true(be64toh(pay->raw_header) == 0x0000150000000000);
784 }
785
786 static void rvf_set_field_raw_colorspace(void **state)
787 {
788 int res;
789 struct avtp_stream_pdu *pdu =
790 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
791 struct avtp_rvf_payload *pay =
792 (struct avtp_rvf_payload *)pdu->avtp_payload;
793 memset(pdu, 0, sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
794
795 res = avtp_rvf_pdu_set(pdu, AVTP_RVF_FIELD_RAW_COLORSPACE,
796 AVTP_RVF_COLORSPACE_GRAY);
797
798 assert_int_equal(res, 0);
799 assert_true(pdu->avtp_time == 0);
800 assert_true(pdu->subtype_data == 0);
801 assert_true(pdu->stream_id == 0);
802 assert_true(pdu->format_specific == 0);
803 assert_true(pdu->packet_info == 0);
804 assert_true(be64toh(pay->raw_header) == 0x0000004000000000);
805 }
806
807 static void rvf_set_field_raw_num_lines(void **state)
808 {
809 int res;
810 struct avtp_stream_pdu *pdu =
811 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
812 struct avtp_rvf_payload *pay =
813 (struct avtp_rvf_payload *)pdu->avtp_payload;
814 memset(pdu, 0, sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
815
816 res = avtp_rvf_pdu_set(pdu, AVTP_RVF_FIELD_RAW_NUM_LINES, 0x05);
817
818 assert_int_equal(res, 0);
819 assert_true(pdu->avtp_time == 0);
820 assert_true(pdu->subtype_data == 0);
821 assert_true(pdu->stream_id == 0);
822 assert_true(pdu->format_specific == 0);
823 assert_true(pdu->packet_info == 0);
824 assert_true(be64toh(pay->raw_header) == 0x0000000500000000);
825 }
826
827 static void rvf_set_field_raw_i_seq_num(void **state)
828 {
829 int res;
830 struct avtp_stream_pdu *pdu =
831 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
832 struct avtp_rvf_payload *pay =
833 (struct avtp_rvf_payload *)pdu->avtp_payload;
834 memset(pdu, 0, sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
835
836 res = avtp_rvf_pdu_set(pdu, AVTP_RVF_FIELD_RAW_I_SEQ_NUM, 0x03);
837
838 assert_int_equal(res, 0);
839 assert_true(pdu->avtp_time == 0);
840 assert_true(pdu->subtype_data == 0);
841 assert_true(pdu->stream_id == 0);
842 assert_true(pdu->format_specific == 0);
843 assert_true(pdu->packet_info == 0);
844 assert_true(be64toh(pay->raw_header) == 0x0000000000030000);
845 }
846
847 static void rvf_set_field_raw_line_number(void **state)
848 {
849 int res;
850 struct avtp_stream_pdu *pdu =
851 alloca(sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
852 struct avtp_rvf_payload *pay =
853 (struct avtp_rvf_payload *)pdu->avtp_payload;
854 memset(pdu, 0, sizeof(struct avtp_stream_pdu) + sizeof(uint64_t));
855
856 res = avtp_rvf_pdu_set(pdu, AVTP_RVF_FIELD_RAW_LINE_NUMBER, 0x123);
857
858 assert_int_equal(res, 0);
859 assert_true(pdu->avtp_time == 0);
860 assert_true(pdu->subtype_data == 0);
861 assert_true(pdu->stream_id == 0);
862 assert_true(pdu->format_specific == 0);
863 assert_true(pdu->packet_info == 0);
864 assert_true(be64toh(pay->raw_header) == 0x0000000000000123);
865 }
866
867 int main(void)
868 {
869 const struct CMUnitTest tests[] = {
870 cmocka_unit_test(rvf_get_field_null_pdu),
871 cmocka_unit_test(rvf_get_field_null_val),
872 cmocka_unit_test(rvf_get_field_invalid_field),
873 cmocka_unit_test(rvf_get_field_sv),
874 cmocka_unit_test(rvf_get_field_mr),
875 cmocka_unit_test(rvf_get_field_tv),
876 cmocka_unit_test(rvf_get_field_seq_num),
877 cmocka_unit_test(rvf_get_field_tu),
878 cmocka_unit_test(rvf_get_field_stream_id),
879 cmocka_unit_test(rvf_get_field_timestamp),
880 cmocka_unit_test(rvf_get_field_active_pixels),
881 cmocka_unit_test(rvf_get_field_format_total_lines),
882 cmocka_unit_test(rvf_get_field_data_len),
883 cmocka_unit_test(rvf_get_field_ap),
884 cmocka_unit_test(rvf_get_field_f),
885 cmocka_unit_test(rvf_get_field_ef),
886 cmocka_unit_test(rvf_get_field_evt),
887 cmocka_unit_test(rvf_get_field_pd),
888 cmocka_unit_test(rvf_get_field_i),
889 cmocka_unit_test(rvf_get_field_raw_pixel_depth),
890 cmocka_unit_test(rvf_get_field_raw_pixel_format),
891 cmocka_unit_test(rvf_get_field_raw_frame_rate),
892 cmocka_unit_test(rvf_get_field_raw_colorspace),
893 cmocka_unit_test(rvf_get_field_raw_num_lines),
894 cmocka_unit_test(rvf_get_field_raw_i_seq_num),
895 cmocka_unit_test(rvf_get_field_raw_line_number),
896 cmocka_unit_test(rvf_set_field_null_pdu),
897 cmocka_unit_test(rvf_set_field_invalid_field),
898 cmocka_unit_test(rvf_set_field_sv),
899 cmocka_unit_test(rvf_set_field_mr),
900 cmocka_unit_test(rvf_set_field_tv),
901 cmocka_unit_test(rvf_set_field_seq_num),
902 cmocka_unit_test(rvf_set_field_tu),
903 cmocka_unit_test(rvf_set_field_stream_id),
904 cmocka_unit_test(rvf_set_field_timestamp),
905 cmocka_unit_test(rvf_set_field_active_pixels),
906 cmocka_unit_test(rvf_set_field_total_lines),
907 cmocka_unit_test(rvf_set_field_data_len),
908 cmocka_unit_test(rvf_set_field_ap),
909 cmocka_unit_test(rvf_set_field_f),
910 cmocka_unit_test(rvf_set_field_ef),
911 cmocka_unit_test(rvf_set_field_evt),
912 cmocka_unit_test(rvf_set_field_pd),
913 cmocka_unit_test(rvf_set_field_i),
914 cmocka_unit_test(rvf_set_field_raw_pixel_depth),
915 cmocka_unit_test(rvf_set_field_raw_pixel_format),
916 cmocka_unit_test(rvf_set_field_raw_frame_rate),
917 cmocka_unit_test(rvf_set_field_raw_colorspace),
918 cmocka_unit_test(rvf_set_field_raw_num_lines),
919 cmocka_unit_test(rvf_set_field_raw_i_seq_num),
920 cmocka_unit_test(rvf_set_field_raw_line_number),
921 cmocka_unit_test(rvf_pdu_init_null_pdu),
922 cmocka_unit_test(rvf_pdu_init),
923 };
924
925 return cmocka_run_group_tests(tests, NULL, NULL);
926 }