|
1 # |
|
2 # Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # This scripts scans all header files under .\security folder to see if they are classifed properly. |
|
16 # DEF098862: Categorisation tags need to be checked for all of security sub-system |
|
17 # |
|
18 |
|
19 use Cwd; |
|
20 |
|
21 my $masterdir = "$ENV{'SECURITYSOURCEDIR'}"; |
|
22 my $keyTagFile = "@" . "file"; |
|
23 my $keyTagInternal = "@" . "internal"; |
|
24 my $keyTagPublished = "@" . "published"; |
|
25 |
|
26 my $numfiles = 0; |
|
27 my $numuntagged = 0; |
|
28 my $numtagged = 0; |
|
29 |
|
30 $logFile = "\\epoc32\\winscw\\c\\searchtags.txt"; |
|
31 |
|
32 # |
|
33 #Function to write log into file |
|
34 # |
|
35 sub WriteLog |
|
36 { |
|
37 my ($log) = @_; |
|
38 unless( open($fh, ">> $logFile")) |
|
39 { |
|
40 printf STDERR "Can\'t open $logfile:$!\n"; |
|
41 return; |
|
42 } |
|
43 printf $fh $log; |
|
44 printf $log; |
|
45 close $fh; |
|
46 } |
|
47 |
|
48 # |
|
49 #Main |
|
50 # |
|
51 unlink($logFile); |
|
52 WriteLog("Searching Classification Tags test.\n\n"); |
|
53 WriteLog("Scans all header files to make sure that all the files are already classified correctly at file level.\n"); |
|
54 WriteLog("A properly classifed header file must contain an \@file tag and then one of the following API classification tags:\n"); |
|
55 WriteLog("\@publishedAll, \@publishedPartner, \@internalAll, \@internalTechnology or \@internalComponent\n\n"); |
|
56 |
|
57 #check if the folder is really exists |
|
58 if ( ! -d $masterdir ) |
|
59 { |
|
60 WriteLog("Can't find `$masterdir'\n"); |
|
61 } |
|
62 else |
|
63 { |
|
64 chdir $masterdir; |
|
65 &SearchFolder($masterdir); |
|
66 } |
|
67 # |
|
68 # Display the result |
|
69 # |
|
70 WriteLog("\n\nTests completed OK\n"); |
|
71 WriteLog(sprintf "Run: %d\n", $numfiles); |
|
72 WriteLog(sprintf "Passed: %d\n", $numtagged); |
|
73 WriteLog(sprintf "%d tests failed out of %d\n", $numuntagged, $numfiles); |
|
74 |
|
75 # |
|
76 #Function to check a file to see whether it has any file level classification tag |
|
77 # |
|
78 sub SearchEngine |
|
79 { |
|
80 my ($filename) = @_; |
|
81 |
|
82 my $fileexist = 0; |
|
83 my $fileleveltag = 0; |
|
84 my $subleveltag = 0; |
|
85 my $distance = 0; |
|
86 |
|
87 if ( lc(substr($filename,-2)) eq ".h" ) |
|
88 { |
|
89 ++$numfiles; |
|
90 $pid = open FILE, "<$filename"; |
|
91 while (<FILE>) |
|
92 { |
|
93 chop; |
|
94 if($distance) |
|
95 { |
|
96 ++$distance; |
|
97 } |
|
98 if ((/$keyTagFile/)) #check if file level tag exists |
|
99 { |
|
100 ++$fileexist; |
|
101 ++$distance; |
|
102 } |
|
103 |
|
104 if((/$keyTagInternal/) || (/$keyTagPublished/)) #check if the classification tag exists |
|
105 { |
|
106 if(($fileexist == 1) && ($fileleveltag == 0)) |
|
107 { |
|
108 if($distance < 15)#if the classification tag is far away, it means it belongs to something else. |
|
109 { |
|
110 ++$fileleveltag; |
|
111 $distance = 0; |
|
112 } |
|
113 } |
|
114 elsif(($fileexist == 1) && ($fileleveltag == 1)) |
|
115 { |
|
116 ++$subleveltag; |
|
117 } |
|
118 } |
|
119 } |
|
120 |
|
121 if (($fileexist!=1) || ($fileleveltag != 1)) |
|
122 { |
|
123 ++$numuntagged; |
|
124 WriteLog("$filename: $_\nFailed\n"); |
|
125 } |
|
126 else |
|
127 { |
|
128 ++$numtagged; |
|
129 } |
|
130 |
|
131 close FILE; |
|
132 #print "fileexist=$fileexist fileleveltag=$fileleveltag\n"; |
|
133 } |
|
134 } |
|
135 |
|
136 # |
|
137 #Function to search all subfolders of the given base folder |
|
138 # |
|
139 sub SearchFolder |
|
140 { |
|
141 local($dir,$nlink) = @_; |
|
142 local($dev,$ino,$mode,$subcount); |
|
143 |
|
144 ($dev,$ino,$mode,$nlink) = stat('.') unless $nlink; |
|
145 |
|
146 opendir(DIR,'.') || die "Can't open $dir"; |
|
147 local(@filenames) = readdir(DIR); |
|
148 closedir(DIR); |
|
149 |
|
150 if ($nlink == 2) |
|
151 {# There is no subdirectories. |
|
152 for (@filenames) |
|
153 { |
|
154 next if $_ eq '.'; |
|
155 next if $_ eq '..'; |
|
156 |
|
157 SearchEngine("$dir/$_"); |
|
158 } |
|
159 } |
|
160 else |
|
161 {# There are some subdirectories. |
|
162 $subcount = $nlink - 2; |
|
163 |
|
164 for (@filenames) |
|
165 { |
|
166 next if $_ eq '.'; |
|
167 next if $_ eq '..'; |
|
168 |
|
169 next if lc(substr($_,0,4)) eq "test"; #Ignore test files |
|
170 next if lc(substr($_,0,7)) eq "openssl"; #Ignore openssl files |
|
171 next if lc(substr($_,0,9)) eq "wincrypto"; #Ignore wincrypto files |
|
172 next if lc(substr($_,0,4)) eq "utf8"; #Ignore utf8.h sntpclient |
|
173 next if lc(substr($_,0,10))eq "sntpclient"; #Ignore sntpclient |
|
174 next if lc(substr($_,0,6)) eq "xerces"; #Ignore xerces |
|
175 next if lc(substr($_,0,6)) eq "sqlite"; #Ignore sqlite |
|
176 next if lc(substr($_,0,9)) eq "switestfw"; #Ignore switestfw |
|
177 |
|
178 $name = "$dir/$_"; |
|
179 SearchEngine("$name"); |
|
180 # If checked all the subdirs |
|
181 next if $subcount == 0; |
|
182 |
|
183 ($dev,$ino,$mode,$nlink) = lstat($_); |
|
184 next unless -d _; |
|
185 |
|
186 chdir $_ || die "Can't cd to $name"; |
|
187 &SearchFolder($name,$nlink); |
|
188 chdir '..'; |
|
189 --$subcount; |
|
190 } |
|
191 } |
|
192 } |
|
193 |
|
194 # end. |
|
195 |