09-implement-kconfig-probability.patch 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ---
  2. confdata.c | 22 +++++++++++++++++++---
  3. 1 file changed, 19 insertions(+), 3 deletions(-)
  4. Index: b/confdata.c
  5. ===================================================================
  6. --- a/confdata.c
  7. +++ b/confdata.c
  8. @@ -1106,7 +1106,16 @@
  9. void conf_set_all_new_symbols(enum conf_def_mode mode)
  10. {
  11. struct symbol *sym, *csym;
  12. - int i, cnt;
  13. + int i, cnt, prob = 50;
  14. +
  15. + if (mode == def_random) {
  16. + char *endp, *env = getenv("KCONFIG_PROBABILITY");
  17. + if (env && *env) {
  18. + int tmp = (int)strtol(env, &endp, 10);
  19. + if (*endp == '\0' && tmp >= 0 && tmp <= 100)
  20. + prob = tmp;
  21. + }
  22. + }
  23. for_all_symbols(i, sym) {
  24. if (sym_has_value(sym))
  25. @@ -1125,8 +1134,15 @@
  26. sym->def[S_DEF_USER].tri = no;
  27. break;
  28. case def_random:
  29. - cnt = sym_get_type(sym) == S_TRISTATE ? 3 : 2;
  30. - sym->def[S_DEF_USER].tri = (tristate)(rand() % cnt);
  31. + cnt = (rand() % 100) - (100 - prob);
  32. + if (cnt < 0)
  33. + sym->def[S_DEF_USER].tri = no;
  34. + else
  35. + if ((sym_get_type(sym) == S_TRISTATE)
  36. + && (cnt > prob/2))
  37. + sym->def[S_DEF_USER].tri = mod;
  38. + else
  39. + sym->def[S_DEF_USER].tri = yes;
  40. break;
  41. default:
  42. continue;