-
Notifications
You must be signed in to change notification settings - Fork 160
/
testsuite.py
3203 lines (2464 loc) · 101 KB
/
testsuite.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2011-2019, Ulf Magnusson
# SPDX-License-Identifier: ISC
# This is the Kconfiglib test suite. It runs selftests on Kconfigs provided by
# us and tests compatibility with the C Kconfig implementation by comparing the
# output of Kconfiglib with the output of the scripts/kconfig/*conf utilities
# for different targets and defconfigs. It should be run from the top-level
# kernel directory with
#
# $ python Kconfiglib/testsuite.py
#
# Some additional options can be turned on by passing them as arguments. They
# default to off.
#
# - obsessive:
# By default, only valid arch/defconfig pairs are tested. In obsessive mode,
# every arch will be tested with every defconfig. Increases the testing time
# by an order of magnitude. Occasionally finds (usually obscure) bugs, and I
# make sure everything passes with it.
#
# - obsessive-min-config:
# Like obsessive, for the minimal configuation (defconfig) tests.
#
# - log:
# Log timestamped defconfig test failures to the file test_defconfig_fails.
# Handy in obsessive mode.
#
# For example, this commands runs the test suite in obsessive mode with logging
# enabled:
#
# $ python(3) Kconfiglib/testsuite.py obsessive log
#
# pypy works too, and runs most tests much faster than CPython.
#
# All tests should pass. Report regressions to ulfalizer a.t Google's email
# service.
import difflib
import errno
import os
import re
import shutil
import subprocess
import sys
import tempfile
import textwrap
from kconfiglib import Kconfig, Symbol, Choice, COMMENT, MENU, MenuNode, \
BOOL, TRISTATE, HEX, \
TRI_TO_STR, \
escape, unescape, \
expr_str, expr_items, split_expr, \
_ordered_unique, \
OR, AND, \
KconfigError
def shell(cmd):
with open(os.devnull, "w") as devnull:
subprocess.call(cmd, shell=True, stdout=devnull, stderr=devnull)
all_passed = True
def fail(msg=None):
global all_passed
all_passed = False
if msg is not None:
print("fail: " + msg)
def verify(cond, msg):
if not cond:
fail(msg)
def verify_equal(x, y):
if x != y:
fail("'{}' does not equal '{}'".format(x, y))
# Prevent accidental loading of configuration files by removing
# KCONFIG_ALLCONFIG from the environment
os.environ.pop("KCONFIG_ALLCONFIG", None)
obsessive = False
obsessive_min_config = False
log = False
def run_tests():
global obsessive, log
for s in sys.argv[1:]:
if s == "obsessive":
obsessive = True
print("Obsessive mode enabled")
elif s == "obsessive-min-config":
obsessive_min_config = True
print("Obsessive minimal config mode enabled")
elif s == "log":
log = True
print("Log mode enabled")
else:
print("Unrecognized option '{}'".format(s))
return
run_selftests()
run_compatibility_tests()
def run_selftests():
#
# Common helper functions. These all expect 'c' to hold the current
# configuration.
#
def verify_value(sym_name, val):
# Verifies that a symbol has a particular value.
if isinstance(val, int):
val = TRI_TO_STR[val]
sym = c.syms[sym_name]
verify(sym.str_value == val,
'expected {} to have the value "{}", had the value "{}"'
.format(sym_name, val, sym.str_value))
def assign_and_verify_value(sym_name, val, new_val):
# Assigns 'val' to a symbol and verifies that its value becomes
# 'new_val'. Assumes (and tests) that 'val' is valid for the
# symbol type.
if isinstance(new_val, int):
new_val = TRI_TO_STR[new_val]
sym = c.syms[sym_name]
old_val = sym.str_value
verify(sym.set_value(val),
"assigning '{}' to {} unexpectedly failed"
.format(val, sym_name))
verify(sym.str_value == new_val,
"expected {} to have the value '{}' after being assigned the "
"value '{}'. Instead, the value is '{}'. The old value was "
"'{}'."
.format(sym_name, new_val, val, sym.str_value, old_val))
def assign_and_verify(sym_name, user_val):
# Like assign_and_verify_value(), with the expected value being the
# value just set.
assign_and_verify_value(sym_name, user_val, user_val)
def assign_and_verify_user_value(sym_name, val, user_val, valid):
# Assigns a user value to the symbol and verifies the new user value.
# If valid is True, the user value is valid for the type, otherwise
# not. This is used to test the set_value() return value.
sym = c.syms[sym_name]
sym_old_user_val = sym.user_value
verify(sym.set_value(val) == valid,
"expected the user value '{}' to be {} for {}, was not"
.format(val, "valid" if valid else "invalid", sym_name))
verify(sym.user_value == user_val,
"the assigned user value '{}' wasn't reflected in user_value "
"on the symbol {}. Instead, the new user_value was '{}'. The "
"old user value was '{}'."
.format(user_val, sym_name, sym.user_value, sym_old_user_val))
#
# Selftests
#
print("Testing string literal lexing")
# Dummy empty configuration just to get a Kconfig object
c = Kconfig("Kconfiglib/tests/empty")
def verify_string_lex(s, expected):
# Verifies that a constant symbol with the name 'res' is produced from
# lexing 's'
res = c._tokenize("if " + s)[1].name
verify(res == expected,
"expected <{}> to produced the constant symbol <{}>, "
'produced <{}>'.format(s[1:-1], expected, res))
verify_string_lex(r""" "" """, "")
verify_string_lex(r""" '' """, "")
verify_string_lex(r""" "a" """, "a")
verify_string_lex(r""" 'a' """, "a")
verify_string_lex(r""" "ab" """, "ab")
verify_string_lex(r""" 'ab' """, "ab")
verify_string_lex(r""" "abc" """, "abc")
verify_string_lex(r""" 'abc' """, "abc")
verify_string_lex(r""" "'" """, "'")
verify_string_lex(r""" '"' """, '"')
verify_string_lex(r""" "\"" """, '"')
verify_string_lex(r""" '\'' """, "'")
verify_string_lex(r""" "\"\"" """, '""')
verify_string_lex(r""" '\'\'' """, "''")
verify_string_lex(r""" "\'" """, "'")
verify_string_lex(r""" '\"' """, '"')
verify_string_lex(r""" "\\" """, "\\")
verify_string_lex(r""" '\\' """, "\\")
verify_string_lex(r""" "\a\\'\b\c\"'d" """, 'a\\\'bc"\'d')
verify_string_lex(r""" '\a\\"\b\c\'"d' """, "a\\\"bc'\"d")
def verify_string_bad(s):
# Verifies that tokenizing 's' throws a KconfigError. Strips the first
# and last characters from 's' so we can use readable raw strings as
# input.
try:
c.eval_string(s)
except KconfigError:
pass
else:
fail("expected tokenization of {} to fail, didn't".format(s[1:-1]))
verify_string_bad(r""" " """)
verify_string_bad(r""" ' """)
verify_string_bad(r""" "' """)
verify_string_bad(r""" '" """)
verify_string_bad(r""" "\" """)
verify_string_bad(r""" '\' """)
verify_string_bad(r""" "foo """)
verify_string_bad(r""" 'foo """)
print("Testing escape() and unescape()")
def verify_escape_unescape(s, sesc):
# Verify that 's' escapes to 'sesc' and that 'sesc' unescapes to 's'
verify_equal(escape(s), sesc)
verify_equal(unescape(sesc), s)
verify_escape_unescape(r'' , r'' )
verify_escape_unescape(r'foo' , r'foo' )
verify_escape_unescape(r'"' , r'\"' )
verify_escape_unescape(r'""' , r'\"\"' )
verify_escape_unescape('\\' , r'\\' )
verify_escape_unescape(r'\\' , r'\\\\' )
verify_escape_unescape(r'\"' , r'\\\"' )
verify_escape_unescape(r'"ab\cd"ef"', r'\"ab\\cd\"ef\"')
# Backslashes before any character should be unescaped, not just before "
# and \
verify_equal(unescape(r"\afoo\b\c\\d\\\e\\\\f"), r"afoobc\d\e\\f")
print("Testing _ordered_unique()")
verify_equal(_ordered_unique([]), [])
verify_equal(_ordered_unique([1]), [1])
verify_equal(_ordered_unique([1, 2]), [1, 2])
verify_equal(_ordered_unique([1, 1]), [1])
verify_equal(_ordered_unique([1, 1, 2]), [1, 2])
verify_equal(_ordered_unique([1, 2, 1]), [1, 2])
verify_equal(_ordered_unique([1, 2, 2]), [1, 2])
verify_equal(_ordered_unique([1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 0]),
[1, 2, 3, 4, 0])
print("Testing expression evaluation")
c = Kconfig("Kconfiglib/tests/Keval", warn=False)
def verify_eval(expr, val):
res = c.eval_string(expr)
verify(res == val,
"'{}' evaluated to {}, expected {}".format(expr, res, val))
# No modules
verify_eval("n", 0)
verify_eval("m", 0)
verify_eval("y", 2)
verify_eval("'n'", 0)
verify_eval("'m'", 0)
verify_eval("'y'", 2)
verify_eval("M", 2)
# Modules
c.modules.set_value(2)
verify_eval("n", 0)
verify_eval("m", 1)
verify_eval("y", 2)
verify_eval("'n'", 0)
verify_eval("'m'", 1)
verify_eval("'y'", 2)
verify_eval("M", 1)
verify_eval("(Y || N) && (m && y)", 1)
# Non-bool/non-tristate symbols are always n in a tristate sense
verify_eval("Y_STRING", 0)
verify_eval("Y_STRING || m", 1)
# As are all constants besides y and m
verify_eval('"foo"', 0)
verify_eval('"foo" || "bar"', 0)
verify_eval('"foo" || m', 1)
# Test equality for symbols
verify_eval("N = N", 2)
verify_eval("N = n", 2)
verify_eval("N = 'n'", 2)
verify_eval("N != N", 0)
verify_eval("N != n", 0)
verify_eval("N != 'n'", 0)
verify_eval("M = M", 2)
verify_eval("M = m", 2)
verify_eval("M = 'm'", 2)
verify_eval("M != M", 0)
verify_eval("M != m", 0)
verify_eval("M != 'm'", 0)
verify_eval("Y = Y", 2)
verify_eval("Y = y", 2)
verify_eval("Y = 'y'", 2)
verify_eval("Y != Y", 0)
verify_eval("Y != y", 0)
verify_eval("Y != 'y'", 0)
verify_eval("N != M", 2)
verify_eval("N != Y", 2)
verify_eval("M != Y", 2)
verify_eval("Y_STRING = y", 2)
verify_eval("Y_STRING = 'y'", 2)
verify_eval('FOO_BAR_STRING = "foo bar"', 2)
verify_eval('FOO_BAR_STRING != "foo bar baz"', 2)
verify_eval('INT_37 = 37', 2)
verify_eval("INT_37 = '37'", 2)
verify_eval('HEX_0X37 = 0x37', 2)
verify_eval("HEX_0X37 = '0x37'", 2)
# These should also hold after 31847b67 (kconfig: allow use of relations
# other than (in)equality)
verify_eval("HEX_0X37 = '0x037'", 2)
verify_eval("HEX_0X37 = '0x0037'", 2)
# Constant symbol comparisons
verify_eval('"foo" != "bar"', 2)
verify_eval('"foo" = "bar"', 0)
verify_eval('"foo" = "foo"', 2)
# Undefined symbols get their name as their value
c.warn = False
verify_eval("'not_defined' = not_defined", 2)
verify_eval("not_defined_2 = not_defined_2", 2)
verify_eval("not_defined_1 != not_defined_2", 2)
# Test less than/greater than
# Basic evaluation
verify_eval("INT_37 < 38", 2)
verify_eval("38 < INT_37", 0)
verify_eval("INT_37 < '38'", 2)
verify_eval("'38' < INT_37", 0)
verify_eval("INT_37 < 138", 2)
verify_eval("138 < INT_37", 0)
verify_eval("INT_37 < '138'", 2)
verify_eval("'138' < INT_37", 0)
verify_eval("INT_37 < -138", 0)
verify_eval("-138 < INT_37", 2)
verify_eval("INT_37 < '-138'", 0)
verify_eval("'-138' < INT_37", 2)
verify_eval("INT_37 < 37", 0)
verify_eval("37 < INT_37", 0)
verify_eval("INT_37 < 36", 0)
verify_eval("36 < INT_37", 2)
# Different formats in comparison
verify_eval("INT_37 < 0x26", 2) # 38
verify_eval("INT_37 < 0x25", 0) # 37
verify_eval("INT_37 < 0x24", 0) # 36
verify_eval("HEX_0X37 < 56", 2) # 0x38
verify_eval("HEX_0X37 < 55", 0) # 0x37
verify_eval("HEX_0X37 < 54", 0) # 0x36
# Other int comparisons
verify_eval("INT_37 <= 38", 2)
verify_eval("INT_37 <= 37", 2)
verify_eval("INT_37 <= 36", 0)
verify_eval("INT_37 > 38", 0)
verify_eval("INT_37 > 37", 0)
verify_eval("INT_37 > 36", 2)
verify_eval("INT_37 >= 38", 0)
verify_eval("INT_37 >= 37", 2)
verify_eval("INT_37 >= 36", 2)
# Other hex comparisons
verify_eval("HEX_0X37 <= 0x38", 2)
verify_eval("HEX_0X37 <= 0x37", 2)
verify_eval("HEX_0X37 <= 0x36", 0)
verify_eval("HEX_0X37 > 0x38", 0)
verify_eval("HEX_0X37 > 0x37", 0)
verify_eval("HEX_0X37 > 0x36", 2)
verify_eval("HEX_0X37 >= 0x38", 0)
verify_eval("HEX_0X37 >= 0x37", 2)
verify_eval("HEX_0X37 >= 0x36", 2)
# A hex holding a value without a "0x" prefix should still be treated as
# hexadecimal
verify_eval("HEX_37 < 0x38", 2)
verify_eval("HEX_37 < 0x37", 0)
verify_eval("HEX_37 < 0x36", 0)
# Symbol comparisons
verify_eval("INT_37 < HEX_0X37", 2)
verify_eval("INT_37 > HEX_0X37", 0)
verify_eval("HEX_0X37 < INT_37 ", 0)
verify_eval("HEX_0X37 > INT_37 ", 2)
verify_eval("INT_37 < INT_37 ", 0)
verify_eval("INT_37 <= INT_37 ", 2)
verify_eval("INT_37 > INT_37 ", 0)
verify_eval("INT_37 <= INT_37 ", 2)
# Tristate value comparisons
verify_eval("n < n", 0)
verify_eval("n < m", 2)
verify_eval("n < y", 2)
verify_eval("n < N", 0)
verify_eval("n < M", 2)
verify_eval("n < Y", 2)
verify_eval("0 > n", 0)
verify_eval("1 > n", 2)
verify_eval("2 > n", 2)
verify_eval("m < n", 0)
verify_eval("m < m", 0)
verify_eval("m < y", 2)
# Strings compare lexicographically
verify_eval("'aa' < 'ab'", 2)
verify_eval("'aa' > 'ab'", 0)
verify_eval("'ab' < 'aa'", 0)
verify_eval("'ab' > 'aa'", 2)
# Comparisons where one of the operands doesn't parse as a number also give
# a lexicographic comparison
verify_eval("INT_37 < '37a' ", 2)
verify_eval("'37a' > INT_37", 2)
verify_eval("INT_37 <= '37a' ", 2)
verify_eval("'37a' >= INT_37", 2)
verify_eval("INT_37 >= '37a' ", 0)
verify_eval("INT_37 > '37a' ", 0)
verify_eval("'37a' < INT_37", 0)
verify_eval("'37a' <= INT_37", 0)
def verify_eval_bad(expr):
try:
c.eval_string(expr)
except KconfigError:
pass
else:
fail('expected eval_string("{}") to throw KconfigError, '
"didn't".format(expr))
# Verify that some bad stuff throws KconfigError's
verify_eval_bad("")
verify_eval_bad("&")
verify_eval_bad("|")
verify_eval_bad("!")
verify_eval_bad("(")
verify_eval_bad(")")
verify_eval_bad("=")
verify_eval_bad("(X")
verify_eval_bad("X)")
verify_eval_bad("X X")
verify_eval_bad("!X X")
verify_eval_bad("X !X")
verify_eval_bad("(X) X")
verify_eval_bad("X &&")
verify_eval_bad("&& X")
verify_eval_bad("X && && X")
verify_eval_bad("X && !&&")
verify_eval_bad("X ||")
verify_eval_bad("|| X")
print("Testing Symbol.__str__()/custom_str() and def_{int,hex,string}")
def verify_str(item, s):
verify_equal(str(item), s[1:-1])
def verify_custom_str(item, s):
verify_equal(item.custom_str(lambda sc: "[{}]".format(sc.name)),
s[1:-1])
c = Kconfig("Kconfiglib/tests/Kstr", warn=False)
c.modules.set_value(2)
verify_str(c.syms["UNDEFINED"], """
""")
verify_str(c.syms["BASIC_NO_PROMPT"], """
config BASIC_NO_PROMPT
bool
help
blah blah
blah blah blah
blah
""")
verify_str(c.syms["BASIC_PROMPT"], """
config BASIC_PROMPT
bool "basic"
""")
verify_str(c.syms["ADVANCED"], """
config ADVANCED
tristate "prompt" if DEP
default DEFAULT_1
default DEFAULT_2 if DEP
select SELECTED_1
select SELECTED_2 if DEP
imply IMPLIED_1
imply IMPLIED_2 if DEP
help
first help text
config ADVANCED
tristate "prompt 2"
menuconfig ADVANCED
tristate "prompt 3"
config ADVANCED
tristate
depends on (A || !B || (C && D) || !(E && F) || G = H || (I && !J && (K || L) && !(M || N) && O = P)) && DEP4 && DEP3
help
second help text
config ADVANCED
tristate "prompt 4" if VIS
depends on DEP4 && DEP3
""")
verify_custom_str(c.syms["ADVANCED"], """
config ADVANCED
tristate "prompt" if [DEP]
default [DEFAULT_1]
default [DEFAULT_2] if [DEP]
select [SELECTED_1]
select [SELECTED_2] if [DEP]
imply [IMPLIED_1]
imply [IMPLIED_2] if [DEP]
help
first help text
config ADVANCED
tristate "prompt 2"
menuconfig ADVANCED
tristate "prompt 3"
config ADVANCED
tristate
depends on ([A] || ![B] || ([C] && [D]) || !([E] && [F]) || [G] = [H] || ([I] && ![J] && ([K] || [L]) && !([M] || [N]) && [O] = [P])) && [DEP4] && [DEP3]
help
second help text
config ADVANCED
tristate "prompt 4" if [VIS]
depends on [DEP4] && [DEP3]
""")
verify_str(c.syms["ONLY_DIRECT_DEPS"], """
config ONLY_DIRECT_DEPS
int
depends on DEP1 && DEP2
""")
verify_str(c.syms["STRING"], """
config STRING
string
default "foo"
default "bar" if DEP
default STRING2
default STRING3 if DEP
""")
verify_str(c.syms["INT"], """
config INT
int
range 1 2
range FOO BAR
range BAZ QAZ if DEP
default 7 if DEP
""")
verify_str(c.syms["HEX"], """
config HEX
hex
range 0x100 0x200
range FOO BAR
range BAZ QAZ if DEP
default 0x123
""")
verify_str(c.modules, """
config MODULES
bool "MODULES"
option modules
""")
verify_str(c.syms["OPTIONS"], """
config OPTIONS
option allnoconfig_y
option defconfig_list
option env="ENV"
""")
verify_str(c.syms["CORRECT_PROP_LOCS_BOOL"], """
config CORRECT_PROP_LOCS_BOOL
bool "prompt 1"
default DEFAULT_1
default DEFAULT_2
select SELECT_1
select SELECT_2
imply IMPLY_1
imply IMPLY_2
depends on LOC_1
help
help 1
menuconfig CORRECT_PROP_LOCS_BOOL
bool "prompt 2"
default DEFAULT_3
default DEFAULT_4
select SELECT_3
select SELECT_4
imply IMPLY_3
imply IMPLY_4
depends on LOC_2
help
help 2
config CORRECT_PROP_LOCS_BOOL
bool "prompt 3"
default DEFAULT_5
default DEFAULT_6
select SELECT_5
select SELECT_6
imply IMPLY_5
imply IMPLY_6
depends on LOC_3
help
help 2
""")
verify_str(c.syms["CORRECT_PROP_LOCS_INT"], """
config CORRECT_PROP_LOCS_INT
int
range 1 2
range 3 4
depends on LOC_1
config CORRECT_PROP_LOCS_INT
int
range 5 6
range 7 8
depends on LOC_2
""")
verify_str(c.syms["PROMPT_ONLY"], """
config PROMPT_ONLY
prompt "prompt only"
""")
verify_custom_str(c.syms["CORRECT_PROP_LOCS_INT"], """
config CORRECT_PROP_LOCS_INT
int
range [1] [2]
range [3] [4]
depends on [LOC_1]
config CORRECT_PROP_LOCS_INT
int
range [5] [6]
range [7] [8]
depends on [LOC_2]
""")
print("Testing Choice.__str__()/custom_str()")
verify_str(c.named_choices["CHOICE"], """
choice CHOICE
tristate "foo"
default CHOICE_1
default CHOICE_2 if dep
""")
verify_str(c.named_choices["CHOICE"].nodes[0].next.item, """
choice
tristate "no name"
optional
""")
verify_str(c.named_choices["CORRECT_PROP_LOCS_CHOICE"], """
choice CORRECT_PROP_LOCS_CHOICE
bool
default CHOICE_3
depends on LOC_1
choice CORRECT_PROP_LOCS_CHOICE
bool
default CHOICE_4
depends on LOC_2
choice CORRECT_PROP_LOCS_CHOICE
bool
default CHOICE_5
depends on LOC_3
""")
verify_custom_str(c.named_choices["CORRECT_PROP_LOCS_CHOICE"], """
choice CORRECT_PROP_LOCS_CHOICE
bool
default [CHOICE_3]
depends on [LOC_1]
choice CORRECT_PROP_LOCS_CHOICE
bool
default [CHOICE_4]
depends on [LOC_2]
choice CORRECT_PROP_LOCS_CHOICE
bool
default [CHOICE_5]
depends on [LOC_3]
""")
print("Testing MenuNode.__str__()/custom_str() for menus and comments")
verify_str(c.syms["SIMPLE_MENU_HOOK"].nodes[0].next, """
menu "simple menu"
""")
verify_str(c.syms["ADVANCED_MENU_HOOK"].nodes[0].next, """
menu "advanced menu"
depends on A
visible if B && (C || D)
""")
verify_custom_str(c.syms["ADVANCED_MENU_HOOK"].nodes[0].next, """
menu "advanced menu"
depends on [A]
visible if [B] && ([C] || [D])
""")
verify_str(c.syms["SIMPLE_COMMENT_HOOK"].nodes[0].next, """
comment "simple comment"
""")
verify_str(c.syms["ADVANCED_COMMENT_HOOK"].nodes[0].next, """
comment "advanced comment"
depends on A && B
""")
verify_custom_str(c.syms["ADVANCED_COMMENT_HOOK"].nodes[0].next, """
comment "advanced comment"
depends on [A] && [B]
""")
print("Testing {MenuNode,Symbol,Choice}.orig_*")
# Just test some corner cases here re. MenuNode.orig_*. They are already
# indirectly tested above. Use MenuNode.__str__() as a proxy.
verify_str(c.syms["DEP_REM_CORNER_CASES"], """
config DEP_REM_CORNER_CASES
bool
default A
depends on n
config DEP_REM_CORNER_CASES
bool
default B if n
config DEP_REM_CORNER_CASES
bool
default C
depends on m && MODULES
config DEP_REM_CORNER_CASES
bool
default D if A
config DEP_REM_CORNER_CASES
bool
default E if !E1
default F if F1 = F2
default G if G1 || H1
depends on !H
config DEP_REM_CORNER_CASES
bool
default H
depends on "foo" = "bar"
config DEP_REM_CORNER_CASES
bool "prompt" if FOO || BAR
depends on BAZ && QAZ
""")
# Test {Symbol,Choice}.orig_*
def verify_deps(elms, dep_index, expected):
verify_equal(" ".join(expr_str(elm[dep_index]) for elm in elms),
expected)
verify_deps(c.syms["BOOL_SYM_ORIG"].orig_defaults, 1, "DEP y y")
verify_deps(c.syms["BOOL_SYM_ORIG"].orig_selects, 1, "y DEP y")
verify_deps(c.syms["BOOL_SYM_ORIG"].orig_implies, 1, "y y DEP")
verify_deps(c.syms["INT_SYM_ORIG"].orig_ranges, 2, "DEP y DEP")
verify_deps(c.named_choices["CHOICE_ORIG"].orig_defaults, 1, "y DEP DEP")
print("Testing Symbol.__repr__()")
def verify_repr(item, s):
verify_equal(repr(item) + "\n", s[1:])
c = Kconfig("Kconfiglib/tests/Krepr", warn=False)
verify_repr(c.n, """
<symbol n, tristate, value n, constant>
""")
verify_repr(c.m, """
<symbol m, tristate, value m, constant>
""")
verify_repr(c.y, """
<symbol y, tristate, value y, constant>
""")
verify_repr(c.syms["UNDEFINED"], """
<symbol UNDEFINED, unknown, value "UNDEFINED", visibility n, direct deps n, undefined>
""")
verify_repr(c.syms["BASIC"], """
<symbol BASIC, bool, value y, visibility n, direct deps y, Kconfiglib/tests/Krepr:9>
""")
verify_repr(c.syms["VISIBLE"], """
<symbol VISIBLE, bool, "visible", value n, visibility y, direct deps y, Kconfiglib/tests/Krepr:14>
""")
c.syms["VISIBLE"].set_value(2)
c.syms["STRING"].set_value("foo")
verify_repr(c.syms["VISIBLE"], """
<symbol VISIBLE, bool, "visible", value y, user value y, visibility y, direct deps y, Kconfiglib/tests/Krepr:14>
""")
verify_repr(c.syms["STRING"], """
<symbol STRING, string, "visible", value "foo", user value "foo", visibility y, direct deps y, Kconfiglib/tests/Krepr:17>
""")
verify_repr(c.syms["DIR_DEP_N"], """
<symbol DIR_DEP_N, unknown, value "DIR_DEP_N", visibility n, direct deps n, Kconfiglib/tests/Krepr:20>
""")
verify_repr(c.syms["OPTIONS"], """
<symbol OPTIONS, unknown, value "OPTIONS", visibility n, allnoconfig_y, is the defconfig_list symbol, from environment variable ENV, direct deps y, Kconfiglib/tests/Krepr:23>
""")
verify_repr(c.syms["MULTI_DEF"], """
<symbol MULTI_DEF, unknown, value "MULTI_DEF", visibility n, direct deps y, Kconfiglib/tests/Krepr:28, Kconfiglib/tests/Krepr:29>
""")
verify_repr(c.syms["CHOICE_1"], """
<symbol CHOICE_1, tristate, "choice sym", value n, visibility m, choice symbol, direct deps m, Kconfiglib/tests/Krepr:36>
""")
verify_repr(c.modules, """
<symbol MODULES, bool, value y, visibility n, is the modules symbol, direct deps y, Kconfiglib/tests/Krepr:1>
""")
print("Testing Choice.__repr__()")
verify_repr(c.named_choices["CHOICE"], """
<choice CHOICE, tristate, "choice", mode m, visibility y, Kconfiglib/tests/Krepr:33>
""")
c.named_choices["CHOICE"].set_value(2)
verify_repr(c.named_choices["CHOICE"], """
<choice CHOICE, tristate, "choice", mode y, user mode y, CHOICE_1 selected, visibility y, Kconfiglib/tests/Krepr:33>
""")
c.syms["CHOICE_2"].set_value(2)
verify_repr(c.named_choices["CHOICE"], """
<choice CHOICE, tristate, "choice", mode y, user mode y, CHOICE_2 selected, CHOICE_2 selected by user, visibility y, Kconfiglib/tests/Krepr:33>
""")
c.named_choices["CHOICE"].set_value(1)
verify_repr(c.named_choices["CHOICE"], """
<choice CHOICE, tristate, "choice", mode m, user mode m, CHOICE_2 selected by user (overridden), visibility y, Kconfiglib/tests/Krepr:33>
""")
verify_repr(c.syms["CHOICE_HOOK"].nodes[0].next.item, """
<choice, tristate, "optional choice", mode n, visibility n, optional, Kconfiglib/tests/Krepr:46>
""")
print("Testing MenuNode.__repr__()")
verify_repr(c.syms["BASIC"].nodes[0], """
<menu node for symbol BASIC, deps y, has help, has next, Kconfiglib/tests/Krepr:9>
""")
verify_repr(c.syms["DIR_DEP_N"].nodes[0], """
<menu node for symbol DIR_DEP_N, deps n, has next, Kconfiglib/tests/Krepr:20>
""")
verify_repr(c.syms["MULTI_DEF"].nodes[0], """
<menu node for symbol MULTI_DEF, deps y, has next, Kconfiglib/tests/Krepr:28>
""")
verify_repr(c.syms["MULTI_DEF"].nodes[1], """
<menu node for symbol MULTI_DEF, deps y, has next, Kconfiglib/tests/Krepr:29>
""")
verify_repr(c.syms["MENUCONFIG"].nodes[0], """
<menu node for symbol MENUCONFIG, is menuconfig, deps y, has next, Kconfiglib/tests/Krepr:31>
""")
verify_repr(c.named_choices["CHOICE"].nodes[0], """
<menu node for choice CHOICE, prompt "choice" (visibility y), deps y, has child, has next, Kconfiglib/tests/Krepr:33>
""")
verify_repr(c.syms["CHOICE_HOOK"].nodes[0].next, """
<menu node for choice, prompt "optional choice" (visibility n), deps y, has next, Kconfiglib/tests/Krepr:46>
""")
verify_repr(c.syms["NO_VISIBLE_IF_HOOK"].nodes[0].next, """
<menu node for menu, prompt "no visible if" (visibility y), deps y, 'visible if' deps y, has next, Kconfiglib/tests/Krepr:53>
""")
verify_repr(c.syms["VISIBLE_IF_HOOK"].nodes[0].next, """
<menu node for menu, prompt "visible if" (visibility y), deps y, 'visible if' deps m, has next, Kconfiglib/tests/Krepr:58>
""")
verify_repr(c.syms["COMMENT_HOOK"].nodes[0].next, """
<menu node for comment, prompt "comment" (visibility y), deps y, Kconfiglib/tests/Krepr:64>
""")
print("Testing Kconfig.__repr__()")
verify_repr(c, """
<configuration with 15 symbols, main menu prompt "Main menu", srctree is current directory, config symbol prefix "CONFIG_", warnings disabled, printing of warnings to stderr enabled, undef. symbol assignment warnings disabled, overriding symbol assignment warnings enabled, redundant symbol assignment warnings enabled>
""")
os.environ["srctree"] = "Kconfiglib"
os.environ["CONFIG_"] = "CONFIG_ value"
c = Kconfig("tests/Krepr", warn=False)
c.warn = True
c.warn_to_stderr = False
c.warn_assign_override = False
c.warn_assign_redun = False
c.warn_assign_undef = True
verify_repr(c, """
<configuration with 15 symbols, main menu prompt "Main menu", srctree "Kconfiglib", config symbol prefix "CONFIG_ value", warnings enabled, printing of warnings to stderr disabled, undef. symbol assignment warnings enabled, overriding symbol assignment warnings disabled, redundant symbol assignment warnings disabled>
""")
os.environ.pop("srctree", None)
os.environ.pop("CONFIG_", None)
print("Testing tricky help strings")
c = Kconfig("Kconfiglib/tests/Khelp")