~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/ipxe/src/tests/asn1_test.h

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _ASN1_TEST_H
 
2
#define _ASN1_TEST_H
 
3
 
 
4
FILE_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 */
 
18
struct asn1_test_digest {
 
19
        /** Digest value */
 
20
        uint8_t digest[ASN1_TEST_DIGEST_SIZE];
 
21
};
 
22
 
 
23
/** An ASN.1 test */
 
24
struct asn1_test {
 
25
        /** Image type */
 
26
        struct image_type *type;
 
27
        /** Source image */
 
28
        struct image *image;
 
29
        /** Expected digests of ASN.1 objects */
 
30
        struct asn1_test_digest *expected;
 
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 ## __file[] = _file;                    \
 
46
        static struct image _name ## __image = {                        \
 
47
                .refcnt = REF_INIT ( ref_no_free ),                     \
 
48
                .name = #_name,                                         \
 
49
                .data = ( userptr_t ) ( _name ## __file ),              \
 
50
                .len = sizeof ( _name ## __file ),                      \
 
51
        };                                                              \
 
52
        static struct asn1_test_digest _name ## _expected[] = {         \
 
53
                __VA_ARGS__                                             \
 
54
        };                                                              \
 
55
        static struct asn1_test _name = {                               \
 
56
                .type = _type,                                          \
 
57
                .image = & _name ## __image,                            \
 
58
                .expected = _name ## _expected,                         \
 
59
                .count = ( sizeof ( _name ## _expected ) /              \
 
60
                           sizeof ( _name ## _expected[0] ) ),          \
 
61
        };
 
62
 
 
63
extern void asn1_okx ( struct asn1_test *test, const char *file,
 
64
                       unsigned int line );
 
65
 
 
66
/**
 
67
 * Report ASN.1 test result
 
68
 *
 
69
 * @v test              ASN.1 test
 
70
 */
 
71
#define asn1_ok( test ) asn1_okx ( test, __FILE__, __LINE__ )
 
72
 
 
73
#endif /* _ASN1_TEST_H */