aboutsummaryrefslogtreecommitdiffstats
path: root/test/testFuncs1.c
blob: 115cad025c509d4e12240200120cb090dc7cba9a (plain) (blame)
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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
/* the first line's been intentionally left blank.*/

/*include*/
/**********************************************************************************************************************/
#include "testFuncs1.h"

/**************************************************MACROS & DEFS*******************************************************/
/**********************************************************************************************************************/
#define LUPO 1U
#define LOCO 2U

typedef unsigned int ut_int;
typedef unsigned char BYTE;

/******************************************************Globals*********************************************************/


/**********************************************************************************************************************/
void test (void);
void test2 (void);
void test11 (void);


/**********************************************************************************************************************/

/*testing for simple statement coverage*/
void testFuncStatementsinmple (void)
{
	int int1 = 1U;
	int int2 = 2U;
	int int3 = 3U;

	int1 = int2 + int3;
	int2 = int1 + int2;
	int3 = int2 + int3;
	im_a_minion_01();
	im_a_minion_02();
	im_a_minion_03();
}

/*testing for complex statement coverage*/
void testFuncStatementComplexIf (void)
{
	int int1 = 1U;
	int int2 = 2U;
	int int3 = 3U;
	int int4 = 4U;

	if ( int4 > int3 )
		if ( int3 > int2 )
			if ( int2 > int1 )
				if ( int2 > int1 )
					im_a_minion_02();
}

/*testing to see whether the tool recognizes not covering statements*/
void testFuncStatementNotCoverage (void)
{
	int int1 = 1U;
	int int2 = 2U;
	int int3 = 3U;
	int int4 = 4U;

	if (int4 < int3)
	{
		int4 = int3;
	}

	/*do note that your compiler might optimize this by completely erasing this*/
	if (int2 > int1)
	{
		if (int1 > int2)
		{
			im_a_minion_01();
		}
	}

	if (int2 > int1)
	{
		if (int3 < int2)
		{
			im_a_minion_02();
		}
	}

}

/*verifying for loops*/
void testFuncLoopFor (void)
{
	int i = 1U;

	for (i = 1; i < 10; i++)
	{
		im_a_minion_01();
	}

	i = 1U;

	for (i = 1; i < 10; i++)
	{
		if (1U == (i % 2U) )
		{
			im_a_minion_01();
		}
	}
}

/*verifying while loops*/
void testFuncLoopWhile (void)
{
	int i = 20U;

	while (i > 10U)
	{
		i = i - 1U;
	}

	i = 20;

#if (TRUE == INF_LOOP)
	while (20U == i)
	{
		im_a_minion_03();
	}
#endif
}

/*verifying the correct handling of continue*/
void testFuncContinue (void)
{
	int i = 1U;

	for (i = 1U; i < 20U; i++)
	{
		if (i < 19U)
		{
			continue;
		}
		im_a_minion_01();
	}
}

/*verifying the correct handling of break*/
void testFuncBreak (void)
{
	int i = 1U;

	for (i = 1U; i < 10U ; i++)
	{
		if (i > 0U)
		{
			break;
		}
		im_a_minion_03();
	}
}

/*checking whether goto is handled correctly*/
void testFuncGoto (void)
{
	im_a_minion_01();
	goto jumpy;
	im_a_minion_02();
jumpy:
	im_a_minion_03();
}

/*checking whether the basic blocks do not complete execution due to return statements*/
int testFuncNotReturn (int a, int b)
{
	int sum = 0U;

	sum = a + b;

	if (10U == sum)
	{
		return (sum);
	}
	else
	{
		im_a_dummy();
	}

	im_a_minion_01();

	return (sum);
}

/*checking whether the tool handles multi-line statements correctly*/
void testFuncMultiLineStatement (void)
{
	im_a_minion_01();
}

/*checking how the tool handles multiple statements on the same line*/
void testFuncMultipleStatement (void)
{
	int a = 1U;
	int b = 2U;
	int c = 3U;
	int d = 4U;

	a = a + b; b = b + c; c = c + d; d = d + a;
}

/*checking whether multiple statements are handled correctly on the same line*/
void testFuncMultipleStatementNot (void)
{
	int a = 10U;

	if (a < 10U) {im_a_minion_01();} else {im_a_minion_02();}

	testFuncMultipleStatementNot();
}

/*checking how compiler optimizations may affect the coverage reported-killed assignment elimination*/
void testFuncCompOpti1 (void)
{
	int a = 1U;
	int b = 2U;
}

/*checking how compiler optimizations may affect the coverage reported-common subexpression optimization*/
void testFuncCompOpti2 (void)
{
	int a = 1U;
	int b = 1U;

	if ( 0U == (((a * b) + (a / b) - a) - b) )
	{
		im_a_benign_func();
	}

	if ( 0U == (((a * b) + (a / b) - a) - b) )
	{
		im_a_mlaign_func();
	}
}

/*checking how compiler optimizations may affect the coverage reported-loop invariant optimization*/
void testFuncCompOpti3 (void)
{
	int i = 1U;
	int counter = 0U;
	int a = 0U;
	int b = 10U;
	int sum = 0U;

	for (i = 1U; i < 100U ; i++)
	{
		counter = counter + 1U;
		sum = a + b;
	}

	sum = sum * 2U;
}

/*checking how compiler optimizations may affect the coverage reported-dead code optimization*/
void testFuncCompOpti4 (void)
{
	im_a_minion_01();
	im_a_minion_02();
	im_a_minion_03();
}

/*testing if declarative statements that have a run-time footprint are covered by statement coverage.*/
void testFuncStatementDecl1 (void)
{
	int declaration1 = 1001U;
	int declaration2 = 666U;
}


/*testing to see whether statement coverage covers the return.*/
int testFuncStatementInt1 (int int1, int int2)
{
	int sum = 0U;
	sum = int1 + int2;
	return (sum);
}


/* to test this one we need two test cases:*/
/* bool1 = FALSE and bool2 = whatever*/
/* bool1 = TRUE and bool2 = whatever*/
/* obviously if you get a full coverage with just the first test case, your tool didnt understand*/
/* the short-circuit. if you need both test cases for a full coverage, then your tool is doing decision coverage,*/
/* not branch coverage so good for you!*/
blreplacement testFuncStatementbool1 (blreplacement bool1 , blreplacement bool2)
{
	return (bool1 && bool2);
}


/*same as above but with these test cases*/
/*bool1 = TRUE and bool2 = whatever*/
/*bool1 = FALSE and bool2 = whatever*/
/* obviously if you get a full coverage with just the first test case, your tool didnt understand*/
/* the short-circuit. if you need both test cases for a full coverage, then your tool is doing decision coverage,*/
/* not branch coverage so good for you!*/
blreplacement testFuncStatementbool2 (blreplacement bool1, blreplacement bool2)
{
	return (bool1 || bool2);
}


/*the fault will only be generated only if decision1 is FALSE. if we get a full coverage by running*/
/* d1 = d2 = FALSE and d1 = FALSE and d2 = TRUE, then we dont have decision coverage. for a decision*/
/* coverage we need to have an extra test case, wehre d1 = TRUE and d2 = whatever.*/
void testFuncStatementDecision1 (blreplacement decision1 , blreplacement decision2)
{
	if ( decision1 || decision2 )
	{
		/*this function will supposedly casue a bug if decision1 is true*/
		im_a_mlaign_func();
	}
	else
	{
		im_a_benign_func();
	}
}


/* short-circuit!*/
/* the compiler could go for short-cuircuit for both conditions.if it does, then we can see if we still get*/
/* a full coverage. if the compiler doesnt go for a short-circuit, then all this dont apply.*/
void testFuncShortCircuit (blreplacement bool1, blreplacement bool2)
{
	if (FALSE == bool1 && TRUE == bool2)
	{
		im_a_dummy ();
	}
	if (TRUE == bool2 || FALSE == bool1)
	{
		im_a_dummy();
	}
}


/*checking MCDC coverage behavior of the tool for multiply occuring conditions*/
void testFuncMCDC1 (blreplacement decision1, blreplacement decision2)
{
	if (decision1 &&  (( decision2 || decision1) || (!decision1 || decision2)) )
	{
		im_a_dummy();
	}
}


/* this one is to test how the tool handles inline functions.do  all instances get covered separately or they get*/
/* covered accumulatively*/
#if 0
void testFuncMultiInstantiation (int level)
{
	switch (level)
	{
	case 10U:
		babeFunk(20);
		break;
	case 20U:
		babeFunk(10);
		break;
	case 30U:
		babeFunk(5);
		break;
	case 40U:
		im_a_dummy();
		break;
	case 50U:
		im_a_dummy();
		break;
	case 60U:
		im_a_dummy();
		break;
	case 70U:
		im_a_dummy();
		break;
	case 80U:
		im_a_dummy();
		break;
	case 90U:
		im_a_dummy();
		break;
	default:
		im_a_dummy();
		break;
	}
}
#endif

/* this function will check how the tool handles the "?" operator*/
void testFuncQMark (int int1, int int2)
{
	(int1 > int2) ? im_a_minion_01() : im_a_minion_02();
}


/* checking how the tool handles calling a function that returns boolean*/
void testFuncCallBool (void)
{
	int local1 = 0U;
	int local2 = 0U;
	local1 = testFuncStatementbool1(1U , 0U);
	local2 = testFuncStatementbool2(1U , 0U);
}


/**********************************************************************************************************************/
/* where all the fakes go.*/


/*the function that is *supposedly* carrying a bug*/
void im_a_mlaign_func (void)
{
	/* KATSU!*/
}


/*the function that is *supposedly* the good guy here*/
void im_a_benign_func (void)
{
	/* see the light ring?!*/
}


/*the dummy function.*/
void im_a_dummy (void)
{
	/* dumb dumb*/
}


/* minion function number #01*/
void im_a_minion_01 (void)
{
	/* minion1*/
}


/* minion function number #02*/
void im_a_minion_02 (void)
{
	/* minion1*/
}


/* minion function number #03*/
void im_a_minion_03 (void)
{
	/* minion1*/
}


/* the only thing special about this one is that it has been inlined.*/
/*since different compilers have different methods of inlining a function, this function has multiple versions.*/
#if (TRUE == INLINE)
#if (MPC == COMPILER)
inline void babeFunk (int entry)
{
	if (10U > entry)
	{
		im_a_minion_01();
	}
	else if (10U == entry)
	{
		im_a_minion_02();
	}
	else
	{
		im_a_minion_03();
	}
}
#endif

#if (HCS12 == COMPILER)
#pragma INLINE
void babeFunk (int entry)
{
	if (10U > entry)
	{
		im_a_minion_01();
	}
	else if (10U == entry)
	{
		im_a_minion_02();
	}
	else
	{
		im_a_minion_03();
	}
}
#endif
#endif
/*RL78s dont have inline for all functions, so no use trying to test the functionality*/

void test (void)
{
	int i = 0U;
	int j = 0U;
	int a, b;
	int c, d;

	for (;;)
	{
		a = b;
	}

	for (i = 1; i < 100U; i++)
		b++              ;

	while (a > 10U)
		im_a_minion_01()   ;

	while (a == 90U)
	{
		b++;
	}

	if (a == d)
		b = c;

	if (a == d)
	{
		a = d;
	}

	if (d > a)
		if (c > b)
			a++;

	if (a > c)
		b++;
	else if (a > b)
		c++;
	else if (a > d)
		d++;


}

void test2 (void)
{
	int a = 0U;
	int b = 10U;
	int c, d;

	if (a == b)
	{
		/*do something*/
	}
	else
		b = a;

	if (20U == a)
	{
		/*kill all mutants.*/
	}

	if (20U == a)
	{
		/*do somethin good*/
		a = b;
	}
	else if (30U == a)
	{
		/*do something else*/
		b = a;
	}

	if (10U == a)
	{/*die*/}
	else if (15U == a)
		a = b;
	else if (17U == a)
		a = 10000000U;
	else if (19U == a)
		a = 50U;

	if (b == a) {
		if (10U == b)
		{}
		else
		{}
	}



	if (a > b) {
		if (a > d)
		{}
		else
			a++;
	}

	if (a > b)
	{a++;}
	else if (b > a)
	{b++;}
	else if (a == b)
	{a++;}

	int level = 10U;

	switch (level)
	{
	case 10U:
	{	level++;
		test();
		break;
	}
	case 20U:
	{	level = 10000U;
		break;
	}
	case 30U:
	{	level++;
		break;
	}
	case 40U:
	{	level++;
		break;
	}
	case 50U:
	{	level++;
		break;
	}
	case 60U:
	{	level = 1000U;
		break;
	}
	case 70U:
	{	level++;
		break;
	}
	case 80U:
	{	level++;
		break;
	}
	case 90U:
	{	level++;
		break;
	}
	default:
	{	level++;
		break;
	}
	}

	switch (level)
	{
	case 1:
	{	level++;
		break;
	}
	case 2:
		level = 10;
		level--;
		{
		case 3:
			level = 10U;
			level++;
			break;
		}
	}

	switch (level)
	{
	case 1:
		level++;
	case 2:
		level = 1;
	case 3:
		level = 2;
	default:
		level++;
	}

	switch (level)
	{}


}

#if 0
void test3 (int a, int, ...)
{

}
#endif

test3()
{
	int a;
	int b;
}

double test4 (int a, int b, double c)
{
	return a + b + c;
}

void test5(void)
{
	int i = 0;
	if (test4)
	{
		i++;
	}
}

void test6 (void)
{
	int a[100];
	int *p = a;

	int i = 0;

	for (i = 0; i < 100; ++i)
	{
		a[i] = i;
	}
}

void test7(void)
{
	double a[100];

	double *pointer;

	pointer = a;

	int i = 0;

	for (i = 0; i < 50; i++)
	{
		*(a + i) = i;
	}

}

void test8 (void)
{
	union uni uni2;
}

void test9 (void)
{
	/*im a comment*/
	//im also a comment
}

void test10 (void)
{
	struct {
		unsigned int r1 : 1;
		unsigned int r2 : 2;
	} reg1;

	struct {
		signed int r3 : 1;
		signed int r4 : 15;
	} reg2;

	struct {
		char a : 8;
		signed int r5 : 14;
		unsigned int r6 : 5;
		ut_int r7 : 32;
		BYTE r8 : 8;
	} reg3;
}

void test11 (void)
{
	/*empty*/
}

double test12(double a)
{
	return a * 2;
}

/**********************************************************************************************************************/
/*the last line's been intentionally left blank.*/