|
| 1 | +"""Tests for the 'transitional' keyword (Linux >= 6.18). |
| 2 | +
|
| 3 | +Transitional symbols are read from old .config files to populate new symbol |
| 4 | +defaults, but must never appear in generated .config, autoconf.h, or |
| 5 | +min-config output. |
| 6 | +""" |
| 7 | + |
| 8 | +import os |
| 9 | +import tempfile |
| 10 | + |
| 11 | +import kconfiglib |
| 12 | + |
| 13 | +KCONFIG_PATH = "tests/Ktransitional" |
| 14 | +CONFIG_PATH = "tests/config_transitional" |
| 15 | + |
| 16 | + |
| 17 | +def _load(config_path=None): |
| 18 | + """Load the transitional test Kconfig, optionally with a .config.""" |
| 19 | + kconf = kconfiglib.Kconfig(KCONFIG_PATH, warn=False) |
| 20 | + if config_path: |
| 21 | + kconf.load_config(config_path) |
| 22 | + return kconf |
| 23 | + |
| 24 | + |
| 25 | +def test_transitional_flag(): |
| 26 | + """is_transitional is True for transitional syms, False for normal.""" |
| 27 | + kconf = _load() |
| 28 | + |
| 29 | + assert kconf.syms["LEGACY_BOOL"].is_transitional is True |
| 30 | + assert kconf.syms["LEGACY_INT"].is_transitional is True |
| 31 | + assert kconf.syms["NEW_BOOL"].is_transitional is False |
| 32 | + assert kconf.syms["NEW_INT"].is_transitional is False |
| 33 | + assert kconf.syms["NORMAL_BOOL"].is_transitional is False |
| 34 | + assert kconf.syms["NORMAL_INT"].is_transitional is False |
| 35 | + |
| 36 | + |
| 37 | +def test_transitional_migration(): |
| 38 | + """Loading old .config with LEGACY_BOOL=y causes NEW_BOOL to default to y.""" |
| 39 | + kconf = _load(CONFIG_PATH) |
| 40 | + |
| 41 | + # LEGACY_BOOL=y was loaded, so NEW_BOOL (default LEGACY_BOOL) should be y |
| 42 | + assert kconf.syms["NEW_BOOL"].str_value == "y" |
| 43 | + # LEGACY_INT=99 was loaded, so NEW_INT (default LEGACY_INT) should be 99 |
| 44 | + assert kconf.syms["NEW_INT"].str_value == "99" |
| 45 | + |
| 46 | + |
| 47 | +def test_transitional_write_config(): |
| 48 | + """Transitional symbols absent from write_config output; normal symbols present.""" |
| 49 | + kconf = _load(CONFIG_PATH) |
| 50 | + |
| 51 | + with tempfile.NamedTemporaryFile(mode="r", suffix=".config", delete=False) as f: |
| 52 | + tmppath = f.name |
| 53 | + try: |
| 54 | + kconf.write_config(tmppath) |
| 55 | + with open(tmppath) as f: |
| 56 | + content = f.read() |
| 57 | + finally: |
| 58 | + os.unlink(tmppath) |
| 59 | + |
| 60 | + assert "LEGACY_BOOL" not in content |
| 61 | + assert "LEGACY_INT" not in content |
| 62 | + assert "NEW_BOOL" in content |
| 63 | + assert "NORMAL_BOOL" in content |
| 64 | + assert "NORMAL_INT" in content |
| 65 | + |
| 66 | + |
| 67 | +def test_transitional_write_autoconf(): |
| 68 | + """Transitional symbols absent from write_autoconf output.""" |
| 69 | + kconf = _load(CONFIG_PATH) |
| 70 | + |
| 71 | + with tempfile.NamedTemporaryFile(mode="r", suffix=".h", delete=False) as f: |
| 72 | + tmppath = f.name |
| 73 | + try: |
| 74 | + kconf.write_autoconf(tmppath) |
| 75 | + with open(tmppath) as f: |
| 76 | + content = f.read() |
| 77 | + finally: |
| 78 | + os.unlink(tmppath) |
| 79 | + |
| 80 | + assert "LEGACY_BOOL" not in content |
| 81 | + assert "LEGACY_INT" not in content |
| 82 | + # NEW_BOOL=y should produce a #define |
| 83 | + assert "NEW_BOOL" in content |
| 84 | + |
| 85 | + |
| 86 | +def test_transitional_write_min_config(): |
| 87 | + """Transitional symbols absent from write_min_config output.""" |
| 88 | + kconf = _load(CONFIG_PATH) |
| 89 | + |
| 90 | + with tempfile.NamedTemporaryFile(mode="r", suffix=".config", delete=False) as f: |
| 91 | + tmppath = f.name |
| 92 | + try: |
| 93 | + kconf.write_min_config(tmppath) |
| 94 | + with open(tmppath) as f: |
| 95 | + content = f.read() |
| 96 | + finally: |
| 97 | + os.unlink(tmppath) |
| 98 | + |
| 99 | + assert "LEGACY_BOOL" not in content |
| 100 | + assert "LEGACY_INT" not in content |
| 101 | + |
| 102 | + |
| 103 | +def test_transitional_config_string(): |
| 104 | + """config_string returns '' for transitional symbols.""" |
| 105 | + kconf = _load(CONFIG_PATH) |
| 106 | + |
| 107 | + assert kconf.syms["LEGACY_BOOL"].config_string == "" |
| 108 | + assert kconf.syms["LEGACY_INT"].config_string == "" |
| 109 | + # Normal symbols should have non-empty config_string |
| 110 | + assert kconf.syms["NORMAL_BOOL"].config_string != "" |
| 111 | + assert kconf.syms["NORMAL_INT"].config_string != "" |
| 112 | + |
| 113 | + |
| 114 | +def test_transitional_repr(): |
| 115 | + """repr() includes 'transitional' for flagged symbols.""" |
| 116 | + kconf = _load() |
| 117 | + |
| 118 | + # Use ", transitional," to avoid false-matching the filename Ktransitional |
| 119 | + assert ", transitional," in repr(kconf.syms["LEGACY_BOOL"]) |
| 120 | + assert ", transitional," in repr(kconf.syms["LEGACY_INT"]) |
| 121 | + assert ", transitional," not in repr(kconf.syms["NEW_BOOL"]) |
| 122 | + assert ", transitional," not in repr(kconf.syms["NORMAL_BOOL"]) |
0 commit comments