Update preset.
[bertos.git] / test / enablecfg.py
1 #!/usr/bin/env python
2 # This file is part of BeRTOS.
3 #
4 # Bertos is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 #
18 # As a special exception, you may use this file as part of a free software
19 # library without restriction.  Specifically, if other files instantiate
20 # templates or use macros or inline functions from this file, or you compile
21 # this file and link it with other files to produce an executable, this
22 # file does not by itself cause the resulting executable to be covered by
23 # the GNU General Public License.  This exception does not however
24 # invalidate any other reasons why the executable file might be covered by
25 # the GNU General Public License.
26 #
27 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
28 #
29 # Author David Mugnai <dvd@develer.com>
30
31 # This file scan a module configuration file (cfg_module.h) 
32 # and tries to enable all configuration options.
33 # This is useful in nightly test to test all possible configurations.
34
35 # A whitelist of options that should not be enabled is supplied.
36
37 import sys
38 import re
39
40 # Options that should be left disabled
41 whitelist = [
42         'CONFIG_BATTFS_SHUFFLE_FREE_PAGES',
43         'CONFIG_FAT_FS_READONLY',
44         'CONFIG_INTERNAL_COMMANDS',
45         'CONFIG_KERN_IRQ',
46         'CONFIG_KERN_HEAP',
47         'CONFIG_KERN_PREEMPT',
48         'RAMP_USE_FLOATING_POINT',
49         'CONFIG_SER_HWHANDSHAKE',
50         'CONFIG_KDEBUG_PORT',
51 ]
52
53 tests = [
54         '#define T_0 0\n',
55         '#define T_1 0\n',
56         '    #define            T_2     0               \n',
57         '#define T_3 0    /* */\n',
58         '#define T_4 0/* */\n',
59 ]
60 no_tests = [
61         '#define T_1 0A\n',
62         '#define T_1 0x0A/* */\n',
63         '#define T_1 0UL /* */\n',
64         '#define T_1 0UL/* */\n',
65 ]
66 pattern = r'\s*#define\s+(\w+)\s+(0)(?:\s+|/|$)'
67
68 def f(match):
69         if match.group(1) in whitelist:
70                 return match.group(0)
71         else:
72                 data = match.group(0)
73                 sx = match.start(2) - match.start(0)
74                 ex = match.end(2) - match.end(0)
75                 return data[:sx] + '1' + data[ex:]
76
77 if len(sys.argv) == 1:
78         for t in tests:
79                 print t, re.subn(pattern, f, t)[0]
80         print '-' * 42
81         for t in no_tests:
82                 print t, re.subn(pattern, f, t)[0]
83 else:
84         data = file(sys.argv[1]).read()
85         data, count = re.subn(pattern, f, data)
86         if count:
87                 file(sys.argv[1], 'w').write(data)