-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
87 lines (71 loc) · 2.48 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import csv
from datetime import datetime
import sys
records = {} # a dict of (pnpid, name)
reader = csv.reader(sys.stdin)
next(reader) # skip header
for line in reader:
name = line[0]
pnpid = line[1]
if len(pnpid) != 3:
print("Warning: skipping invalid PNP ID %s" % (repr(pnpid)), file=sys.stderr)
continue
if len(name) > 127:
print("Warning: skipping long name %s" % (repr(name)), file=sys.stderr)
records[pnpid] = name
ids = sorted(records.keys())
dt = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def checker(x):
return ''' name = pnp_name("%s"); assert(name != NULL); assert(0 == strcmp(name, "%s"));''' % (x, records[x])
checks = map(checker, ids)
csrc = '''
/*
* PNP IDs automatically generated from http://www.uefi.org/pnp_id_list
*
* There is no charge for use of the specification itself. The promoters of
* UEFI specifications have agreed that any IP needed to implement the
* specification will be made available on reasonable and non-discriminatory
* terms.
*
* This file was automatically generated on {dt}
* by https://github.com/golightlyb/PNP-ID
*
* This file is a trivial and obvious implementation of a part of the spec
* dealing exclusively with facts, where the expression in code is dictated
* entirely by practical or technical considerations so this should not be a
* considered an "original" or "creative" work for the purposes of EU or US
* Copyright law. As such, you are free to use it how you wish.
*
*/
#include <string.h> // strcmp
#include <assert.h>
const char *pnp_name(const char *key);
int main(void)
{{
const char *name;
/* super paranoid check to make sure the binary search never infinite loops */
for (int a = 'A'; a <= 'Z'; a++)
{{
for (int b = 'A'; b <= 'Z'; b++)
{{
for (int c = 'A'; c <= 'Z'; c++)
{{
char buf[3];
buf[0] = a;
buf[1] = b;
buf[2] = c;
name = pnp_name(buf);
}}
}}
}}
/* Check a few unused names don't give a result when they shouldn't! */
name = pnp_name("???"); assert(name == NULL);
name = pnp_name("A??"); assert(name == NULL);
name = pnp_name("AA?"); assert(name == NULL);
name = pnp_name("Z??"); assert(name == NULL);
name = pnp_name("AZ?"); assert(name == NULL);
/* Check every used name gives the correct result! */
{checks}
}}
'''
print(csrc.format(dt=dt, checks='\n'.join(checks)))