iPXE
asn1_test.h
Go to the documentation of this file.
1#ifndef _ASN1_TEST_H
2#define _ASN1_TEST_H
3
4FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5
6#include <stdint.h>
7#include <ipxe/image.h>
8#include <ipxe/sha1.h>
9#include <ipxe/test.h>
10
11/** Digest algorithm used for ASN.1 tests */
12#define asn1_test_digest_algorithm sha1_algorithm
13
14/** Digest size used for ASN.1 tests */
15#define ASN1_TEST_DIGEST_SIZE SHA1_DIGEST_SIZE
16
17/** An ASN.1 test digest */
19 /** Digest value */
21};
22
23/** An ASN.1 test */
24struct asn1_test {
25 /** Image type */
27 /** Source image */
28 struct image *image;
29 /** Expected digests of ASN.1 objects */
31 /** Number of ASN.1 objects */
32 unsigned int count;
33};
34
35/**
36 * Define an ASN.1 test
37 *
38 * @v _name Test name
39 * @v _type Test image file type
40 * @v _file Test image file data
41 * @v ... Expected ASN.1 object digests
42 * @ret test ASN.1 test
43 */
44#define ASN1( _name, _type, _file, ... ) \
45 static const char _name ## __raw[] = _file; \
46 static const char _name ## __file \
47 [ sizeof ( _name ## __raw ) + 1 /* NUL */ ] = _file; \
48 static struct image _name ## __image = { \
49 .refcnt = REF_INIT ( ref_no_free ), \
50 .name = #_name, \
51 .flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
52 .data = _name ## __file, \
53 .len = ( sizeof ( _name ## __file ) - 1 /* NUL */ ), \
54 }; \
55 static struct asn1_test_digest _name ## _expected[] = { \
56 __VA_ARGS__ \
57 }; \
58 static struct asn1_test _name = { \
59 .type = _type, \
60 .image = & _name ## __image, \
61 .expected = _name ## _expected, \
62 .count = ( sizeof ( _name ## _expected ) / \
63 sizeof ( _name ## _expected[0] ) ), \
64 };
65
66extern void asn1_okx ( struct asn1_test *test, const char *file,
67 unsigned int line );
68
69/**
70 * Report ASN.1 test result
71 *
72 * @v test ASN.1 test
73 */
74#define asn1_ok( test ) asn1_okx ( test, __FILE__, __LINE__ )
75
76#endif /* _ASN1_TEST_H */
unsigned char uint8_t
Definition stdint.h:10
#define ASN1_TEST_DIGEST_SIZE
Digest size used for ASN.1 tests.
Definition asn1_test.h:15
void asn1_okx(struct asn1_test *test, const char *file, unsigned int line)
Report ASN.1 test result.
Definition asn1_test.c:50
static int test
Definition epic100.c:73
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
Executable images.
SHA-1 algorithm.
An ASN.1 test digest.
Definition asn1_test.h:18
uint8_t digest[ASN1_TEST_DIGEST_SIZE]
Digest value.
Definition asn1_test.h:20
An ASN.1 test.
Definition asn1_test.h:24
struct image * image
Source image.
Definition asn1_test.h:28
struct asn1_test_digest * expected
Expected digests of ASN.1 objects.
Definition asn1_test.h:30
struct image_type * type
Image type.
Definition asn1_test.h:26
unsigned int count
Number of ASN.1 objects.
Definition asn1_test.h:32
An executable image type.
Definition image.h:102
Self-test infrastructure.