-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequirementTraceability.pl
548 lines (545 loc) · 20.2 KB
/
RequirementTraceability.pl
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
#!/usr/bin/perl
=cut;
********************************************************************************
#Description: Check for Description and Testcase Match from
#Singularity table
#
#Author: Vikram
#
#Revision history
********************************************************************************
#rev.no Name Date Description
#0.1 Vikram 24 July 14 Generate the IRT/ST from the Objective Sections
#0.5 Vikram 04 Aug 14 Generate Report to map the Objectives with the IRT
********************************************************************************
=cut;
package Checklist;
#use strict;
#use warnings;
use File::Find qw(find);
use Test;
use IO::Handle;
use Benchmark qw/cmpthese timethese/;
use Data::Dumper;
#use List::Util 'first';
my @ListTestcases =();
my @Testcase =();
my %hash =();
my @TestcaseIRT=();
my @TestcaseST=();
#enter the directory path
my $dir_path;
my $filename;
my $line ;
my @file_name_arr="";
my $dirname;
#list of Placeholders for the 7 different Parameters listed in IRT
my $list_min ;
my $list_max ;
my $list_Zero ;
my $mid_Pos ;
my $mid_Neg ;
my $OutBou_lo ;
my $OutBou_hi ;
#list of Placeholders for the 4 different Parameters listed in ST
my $STCond;
my $NMinus;
my $NValue;
my $NPosit;
my @identlines = ();
my @identSingLine = ();
my @ListTestcases =();
my @value=();
my @var_list =();
my @objfiles =();
my @min_list=();
my @midNeg_list=();
my @zero_list=();
my @midpos_List =();
my @max_list=();
my @ob_lolist =();
my @ob_hiList=();
my @Uniqmin_list=();
my @UniqmidNeg_list=();
my @Uniqzero_list=();
my @Uniqmidpos_List =();
my @Uniqmax_list=();
my @Uniqob_lolist =();
my @Uniqob_hiList=();
my @STList=();
my @NNeg=();
my @Nval=();
my @NPlus=();
my @uniqNMinus=();
my @uniqNCond=();
my @uniqNPlus=();
my @objfiles;
my @Rule =('min', 'mid-ve', 'zero', 'mid+ve','max', 'ob low', 'ob high');
my @Singularity = ('N', 'N-1', 'N+1'); # ,'N+1' ,'N-1', 'Singularity');
#enter the directory path
print ("enter the directory path where the files are present\n");
$dir_path = <STDIN>;
chomp($dir_path);
#opens the directory
opendir( TD, $dir_path ) || die("cannot open directory");
#perfom for all the files in the directory.
while($filename = readdir(TD))
{
#List all Files but pick only TCF Files
@file_name_arr = split(/\./, $filename);
if ( $file_name_arr[1] eq "tcf" )
{
undef @ListTestcases;
undef @objfiles;
undef %hash;
undef @Testcase;
undef @ListTestcases;
undef @objfiles;
undef %hash;
undef @Testcase;
undef @TestcaseIRT;
undef @TestcaseST;
local $buffer ;
undef @identlines;
undef @ListTestcases;
undef @value;
undef @identSingLine;
undef @objfiles;
undef @var_list;
undef @min_list;
undef @midNeg_list;
undef @zero_list;
undef @midpos_List;
undef @max_list;
undef @ob_lolist;
undef @ob_hiList;
undef @Uniqmin_list;
undef @UniqmidNeg_list;
undef @Uniqzero_list;
undef @Uniqmidpos_List;
undef @Uniqmax_list;
undef @Uniqob_lolist;
undef @Uniqob_hiList;
undef @STList;
undef @NNeg;
undef @Nval;
undef @NPlus;
undef @uniqNMinus;
undef @uniqNCond;
undef @uniqNPlus;
my $flag_blankIRT =1;
my $flag_blankST =1;
open(OUTFILE,">",$dirname.$filename."csv") or die $!;
# Change the Filehandle to redirect Console Output.
STDOUT->fdopen( \*OUTFILE, 'w' ) or die $!;
&ListIRT;
&ListTestcases; # Parse and Create an Array for the Total Number of testcases
if ($flag_blankIRT) #check if the Section is Present
{
print("VariableName|Minimum|MidNegative|Zero|MidPositive|Maximum|OutBoundLow|OutBoundHigh"."\n");
@identlines = split ("\n", $buffer);
my $inputLine=0;
foreach my $val (@identlines)
{
$list_min = "" ;
$list_max ="";
$list_Zero ="" ;
$mid_Pos ="";
$mid_Neg ="";
$OutBou_lo ="";
$OutBou_hi ="";
$val =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
@value = split (/\|/, $val);
# TODO find a method to ensure that End of File is used to Align the Tables
if (@value[1] !~ m/NA/i) { $list_var= @value[1];} else{$list_var=0;}
if (@value[4] !~ m/NA/i) { $list_min= @value[4];} else{$list_min=0;}
if (@value[5] !~ m/NA/i) { $mid_Neg= @value[5];} else{$mid_Neg=0; }
if (@value[6] !~ m/NA/i) { $list_Zero=@value[6];} else{$list_Zero=0;}
if (@value[7] !~ m/NA/i) { $mid_Pos= @value[7];} else{$mid_Pos=0;}
if (@value[8] !~ m/NA/i) { $list_max= @value[8];} else{$list_max=0;}
if (@value[9] !~ m/NA/i) { $OutBou_lo=@value[9];} else{$OutBou_lo=0;}
if (@value[10] !~ m/NA/i) { $OutBou_hi=@value[10];} else{$OutBou_hi=0;}
# Update the List of Variables into a Buffer here.
#if ($list_var)
#{
my $varname = $list_var;
$varname =~ s/^\s+|\s+$//g;
$list_min =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
$mid_Neg =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
$list_Zero =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
$mid_Pos =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
$list_max =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
$OutBou_lo =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
$OutBou_hi =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
push (@var_list, $list_var);
#Print the Table
print ($inputLine+1); #TODO DEBUG Code here
print "::".$list_var."\t".$list_min."\t".$mid_Neg."\t".$list_Zero."\t".$mid_Pos."\t".$list_max."\t".$OutBou_lo."\t".$OutBou_hi."\n";
#}
# Create a Unique List of testcases based on the Rule
#Task#1 - #TODO: Create a Matrix here
#Clear the Matrix Elements
for my $ruleset (0..6)
{
for ($i=0; $i < 1; $i++)
{
$TestcaseIRT[$inputLine][$ruleset][$i] = 0;
}
} # Cleared all the Matrix Elements
for my $ruleset (0..6)
{
for my $j (0..6)
{
$TestcaseIRT[$inputLine][$ruleset][0] = $varname; #Done
$TestcaseIRT[$inputLine][$ruleset][1] = uc($Rule[$ruleset]);
if ($ruleset==0) {$TestcaseIRT[$inputLine][$ruleset][2] = $list_min;}
if ($ruleset==1) {$TestcaseIRT[$inputLine][$ruleset][2] = $mid_Neg;}
if ($ruleset==2) {$TestcaseIRT[$inputLine][$ruleset][2] = $list_Zero;}
if ($ruleset==3) {$TestcaseIRT[$inputLine][$ruleset][2] = $mid_Pos;}
if ($ruleset==4) {$TestcaseIRT[$inputLine][$ruleset][2] = $list_max;}
if ($ruleset==5) {$TestcaseIRT[$inputLine][$ruleset][2] = $OutBou_lo;}
if ($ruleset==6) {$TestcaseIRT[$inputLine][$ruleset][2] = $OutBou_hi;}
}
}
$inputLine++;
} # Complete parsing all Lines
print Dumper(@TestcaseIRT); #TODO: For Debug
my $inputLineIRT =$inputLine;
} # End of the IRT Block
local $bufferSing = FALSE;
&ListST;
if ($flag_blankST)
{
@identSingLine = split ("\n", $bufferSing);
undef @value;
my $inputLine=0;
print("\nSingularity Condition |N-1 Condition|N Condition|N+1 Condition"."\n");
foreach my $val (@identSingLine)
{
$STCond="";
$NMinus="";
$NValue="";
$NPosit="";
$val =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
@value = split (/\|/, $val);
if (@value[1] !~ m/NA/i) { $STCond= @value[1];} else{$STCond=0;} #print $NMinus."\t";
if (@value[2] !~ m/NA/i) { $NMinus= @value[2];} else{$NMinus=0;} #print $NMinus."\t";
if (@value[3] !~ m/NA/i) { $NValue= @value[3];} else{$NValue=0;} #print $NValue."\t";
if (@value[4] !~ m/NA/i) { $NPosit= @value[4];} else{$NPosit=0;} #print $NPosit."\t";
# Update the List of Variables into a Buffer here.
$STCond =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
$NMinus =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
$NValue =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
$NPosit =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
#Print the Table
print $STCond."\t".$NMinus."\t".$NValue."\t".$NPosit."\n";
#Task#1 - #TODO: Create a Matrix here
#Clear the Matrix Elements
for my $singlty (0..3)
{
for ($i=0; $i < 1; $i++)
{
$TestcaseST[$inputLine][$singlty][$i] = 0;
}
} # Cleared all the Matrix Elements
for my $singlty (0..2)
{
for my $j (0..2)
{
$TestcaseST[$inputLine][$singlty][0] = $STCond; #Done
$TestcaseIRT[$inputLine][$singlty][1] = uc($Singularity[$singlty]);
if ($singlty==0) {$TestcaseST[$inputLine][$singlty][2] = $NMinus;}
if ($singlty==1) {$TestcaseST[$inputLine][$singlty][2] = $NValue;}
if ($singlty==2) {$TestcaseST[$inputLine][$singlty][2] = $NPosit;}
}
}
$inputLine++;
} # Complete parsing all Lines
} # End of the Singularity Table Block
print "\n";
my $inputLineST =$inputLine;
print "++++++++++++++++++++++++\n";
#print Dumper(@TestcaseST); #TODO: For Debug
print "\n+++++++++++++++++++++++++++++++++\n";
print "Condition | Input | Testcase \n";
# Parse the IRT Table
foreach my $t (@ListTestcases)
{
#Parse the Test Sections to generate the KVP
&ParseTestSections($t); #TODO: For Debug
}
foreach my $t (@ListTestcases)
{
#Parse the Individual testcases t
&ParseObjectiveList($t); #TODO: For Debug
}
close(OUTFILE); # close the OUTFILE per file
} # End of the If Loop
}
closedir(TD);
sub ListTestcases
{
#opens the file inside the dir
open(FP,"$dir_path/$filename")or die( "cannot open the file:$filename\n");
#print "\n".$dir_path.$filename."-----------------\n";
#my $TCFFile = $filename;
while (<FP>)
{
if ( s/ Description = TEST//ig)
{
my $str=$_;
$str =~ s/^\s+|\s+$//g ;
push (@ListTestcases, $str);
}
}
close(FP);
}
sub ParseTestSections
{
#opens the file inside the dir
open(FP,"$dir_path/$filename")or die( "cannot open the file:$filename\n");
#print "\n".$dir_path.$filename."-----------------\n";
my $buffer =();
my $testcase =();
my $TestNumber = "";
$TestNumber = $_[0]; # Prepare this Array for the testcase
$TestNumber =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
OUTER:
while (<FP>)
{
if(m/Description = TEST $TestNumber/i)
{
while(<FP>)
{
$_ =~ s/[\x0A\x0D]//g; # to Strip lines of Extra Characters
if (m/Control Flow/i)
{ last OUTER;}
# skip blank lines
next if /^[ \t]*$/;
# skip comment lines
next if /#/;
# skip if not starting with a number ..thats the bullet items or objectives ..rest are not the lines to check for rules.
next if /^\D(.\s)?+/;
$testcase .=$_;
}
}
}
push (@objfiles,$testcase);
#[Vineeth] : Changed testcase to @objfiles ,,these creates $Testcase[undef], $TestCase[M1], $Testcase[M2] ...etc..old one was always the last test case ..in your case $Testcase[M3]
$Testcase[@objfiles][0] =$TestNumber;
$Testcase[@objfiles][1] =$testcase;
$Testcase[@objfiles][2] =@objfiles;
#create the Multi Dimensional Array here
#print Dumper(@Testcase); #TODO Debug to check all Objectives for each Testcase
close(FP); # Close the opened TCF
}
# for each testcase parse and Fill the details in a Multi Dimensional Array
sub ParseObjectiveList
{
local $testNo = $_[0];
$testNo =~ s/^\s+|\s+$//g ; #remove spaces and Trim the values
#Vik : Start with 1 ..0 is empty undef
for (my $i=1; $i <= @objfiles; $i++)
{
if ($Testcase[$i][0] eq $testNo)
{
my @lines = split(/(\d[.])+/,$Testcase[$i][1]);
#print "In loop $i \n\t$Testcase[$i][1]\n";
#print Dumper (@lines);
foreach my $objective (@lines)
{
#parse the Input and Attributes depending on type of Condition.
# Here if this is a Input Range table
if ($objective =~ m/To Verify/i) # TODO: need help Here to split the Objective into
{
foreach my $rule (@Rule)
{
if(grep(/$rule/i, $objective))
{
#print ("Rule Found : $objective\n");
&LineSplitter($objective,1,0,$testNo);
next;
}
}
foreach my $sing (@Singularity)
{
if(grep(/$sing/i, $objective))
{
# Here if this is a Singularity
#print ("Singularity Found : $objective :");
&LineSplitter($objective,0,1,$testNo);
next;
}
}
}
}
}
} # end of intitial for loop for the Array Object
}
# Recursively run on each Line/Objective and get the Inputs and Objectives
sub LineSplitter #TODO: Need help with this here.
{
my $line = $_[0];
my $IRT = $_[1];
my $ST = $_[2];
my $testnumber = $_[3];
#$print $testnumber."\n"; #TODO for Debug
my @LineObject ='';
if ($IRT)
{
#if ($line =~ m/\r\n/i)
{
@LineObject = split /[',"]/,$line;
#print "+++ ".$LineObject[1]."\t".$LineObject[3]."\t".$testnumber."\n";
&matchIRT($LineObject[1],$LineObject[3], $testnumber);
$IRT=0;
}
}
if ($ST)
{
#if ($line =~ m/\r\n/i)
{
@LineObject = split /[',"]+/,$line;
#print "+++ ".$lineObject[1]."\t".$lineObject[3]."\t".$testnumber."\n";
&matchST($LineObject[1],$LineObject[3], $testnumber);
$ST =0;
}
}
#print Dumper(@LineObject); #TODO: For Debug
}
=cut; #Start of Commented Code
#Generate the Input Range Report here - Functionality yet to be implemented
sub GenerateIRT
{
foreach my $InputIRT (sort keys %TestcaseIRT)
{
foreach my $AttributeIRT (sort keys $TestcaseIRT{$InputIRT})
{
print $InputIRT."|".$AttributeIRT."|".$TestcaseIRT{$InputIRT}{$AttributeIRT}."\n";
}
}
}
#Generate the Singularity Report here - Functionality yet to be implemented
sub GenerateST
{
foreach my $InputST (sort keys %TestcaseST)
{
foreach my $AttributeST (sort keys $TestcaseST{$InputST})
{
print $InputST."|".$AttributeST."|".$TestcaseST{$InputST}{$AttributeST}."\n";
}
}
}
=cut; #End of Commented Code
sub ListIRT
{
#opens the file inside the dir
open(FP,"$dir_path/$filename")or die( "cannot open the file:$filename\n");
#print "-----------------".$dir_path.$filename."-----------------\n";
#my $TCFFile = $filename;
while (<FP>)
{
if ( /INPUT RANGE/i) {
#$buffer .=$_; # removed as this is Duplicated
while (<FP>)
{
#TODO: Need to check if Blank Values are assigned to the Value
if ((m/None/i) ||( m/---/) || ( m/Variable/i))
{
next;
}
else
{
$buffer .=$_;
last if /^\n$/;
}
}
}
#check for Blank Entries returned
if (($buffer cmp '' ) || ($buffer =~ m/none/i ))
{
$flag_blankIRT = 0;
}
}
#print $buffer;
close(FP);
}
sub ListST
{
#opens the file inside the dir
open(FP,"$dir_path/$filename")or die( "cannot open the file:$filename\n");
#print "\n".$dir_path.$filename."-----------------\n";
while (<FP>)
{
if ( /SINGULARITY/i)
{
#$buffer .=$_; # skip the Current string
while (<FP>)
{
#TODO: Need to check if Blank Values are assigned to the Value
if ((m/None/i) ||( m/---/) || ( m/Expression/i)) # || (m/ /i))
{
next;
}
else
{
$bufferSing .=$_;
last if /^\n$/;
}
}
}
#check for Blank Entries returned
if (($bufferSing cmp '' ) ||($bufferSing =~ m/none/i ))
{
$flag_blankST = 0;
}
}
close(FP);
}
sub matchIRT
{
my $tc_IRT = $_[1];
my $tc_AttrIrt =$_[0];
my $localTestcase = $_[2];
#print Dumper(@TestcaseIRT); #TODO for DEBUG
#Task#2 - Create a Report Entry here
if (($tc_IRT ne '') &&($tc_AttrIrt ne '')) # Check for Blank Calls :-)
{
print "Range: ".$tc_IRT."\t|:".$tc_AttrIrt.":|\t".$localTestcase."::";
for my $inputTC (0..$inputLineIRT)
{
for my $j (0..6)
{
#Match all the 3 Conditions from the Matrix - Testcase, Input and Rule
if (
($TestcaseIRT[$inputTC][$j][0] eq (uc($tc_IRT)))
||
($TestcaseIRT[$inputTC][$j][1] eq (uc($tc_AttrIrt)))
||
($TestcaseIRT[$inputTC][$j][2] eq uc($localTestcase))
)
{
print "Matched in IRT"; #Reach here
}
else
{
#print "Mismatch Noted";
}
}
}
print "\n";
} # Check Blank Entries
}
sub matchST
{
my $tc_ST =$_[0];
my $tc_AttrSt =$_[1];
my $localTestcase = $_[2];
#print Dumper(@TestcaseST); #TODO for DEBUG
#Task#2 - Create a Report Entry here
if (($tc_ST ne '') &&($tc_AttrSt ne ''))
{
print "Singularity:\t".$tc_ST."\t|:".$tc_AttrSt.":|\t".$localTestcase."\n";
} # Check Blank Entries
}
# End of File