summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-2630.c
blob: d87c88429d9efcdd8e873a004c9f1ed8cd7bc784 (plain)
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
/*
   bug-2630.c
*/

#include <testfwk.h>

#define NUM_CORE_STATES 4

int core_state_transition(unsigned char **instr , unsigned long *transition_count)
{
	static unsigned long i;

	transition_count;

	if (i >= NUM_CORE_STATES * 2)
		**instr=0;

	return i++ % NUM_CORE_STATES;
}

unsigned int crcu32(unsigned long newval, unsigned int crc)
{
	return (newval>>16)+crc;
}

#ifndef __SDCC_pdk14 // Lack of memory
unsigned int core_bench_state(unsigned long blksize, unsigned char *memblock, int seed2, int step, unsigned int crc) 
{
	unsigned long final_counts[NUM_CORE_STATES];
	unsigned long track_counts[NUM_CORE_STATES];
	unsigned char *p=memblock;
	unsigned long i;

	for (i=0; i<NUM_CORE_STATES; i++) {
		final_counts[i]=track_counts[i]=(1ul << 16) - 2 + i;
	}

	p=memblock;

	while (*p!=0) {
		int fstate=core_state_transition(&p,track_counts);
		final_counts[fstate]++; // Wrong code generated for increment here.
	}

	p=memblock;
	while (p < (memblock+blksize)) {
		if (*p!=',')
			*p^=(unsigned char)seed2;
		p+=step;
	}

	for (i=0; i<NUM_CORE_STATES; i++) {
		crc=crcu32(final_counts[i],crc);
		crc=crcu32(track_counts[i],crc);
	}

	return crc;
}
#endif

void testBug(void)
{
#ifndef __SDCC_pdk14 // Lack of memory
	unsigned char c = 1;
	ASSERT(core_bench_state(0, &c, 0x5a0a, 0x5a0a, 0) == 6);
#endif
}