summaryrefslogtreecommitdiffstats
path: root/tools/PowerPCtoPPE/p2p-test-gen.py
blob: 983cec033b355d19947dce15a06a7012f6919d09 (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
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
#!/usr/bin/python2.6

# \file  p2p-test-gen.py
# \brief this program generates random constructed test cases
#        in the form of input file consumed by ppc-ppe-pcp.py
# \usage create a file named 'test.s' and make sure it has at
#        least one blank line before executing this program.

import fileinput
import random

DotLabel = ['', 'Label:', '.Label']

Comments = ['', '// Comments', '/* Comments */']

TabSpace = ['', '\t', ' ', '\t ', ' \t', ' \t ']

RegLabel = ['', '%r']

Register = [0,1,2,3,4,5,6,7,8,9,10,13,28,29,30,31]

TestEnable = [0,1,2,3]

TestBook = {'eieio'   : 0,
            'isync'   : 0,
            'icbi'    : 0,
            'icbt'    : 0,
            'stbux'   : 3,
            'sthux'   : 3,
            'stwux'   : 3,
            'lbzux'   : 3,
            'lhzux'   : 3,
            'lwzux'   : 3,
            'lha'     : 2,
            'lhau'    : 2,
            'lhax'    : 3,
            'lhaux'   : 3,
            'mulhhw'  : 3,
            'mulhhwu' : 3,
            'mulhw'   : 3,
            'mulhwu'  : 3,
            'mullw'   : 3,
            'mulli'   : 1,
            'divw'    : 3,
            'divwu'   : 3,
            'lmw'     : 2,
            'stmw'    : 2,
            'lwz'     : 4,
            'stw'     : 4,
            'cmplw'   : 5,
            'cmpw'    : 5,
            'cmpwi'   : 5}

BranchList = ['bc', 'bcl', 'blt', 'bltl', 'ble', 'blel', 'bgt', 'bgtl', 'bge',
              'bgel', 'beq', 'beql', 'bne', 'bnel']

def p2p_test():
  for line in fileinput.input('test.s', inplace=1):
    print '// start generating test cases:',
    for opcode,format in TestBook.iteritems():
      opcode += ' '
      if random.randint(1, 10) > 5:
        print random.sample(TabSpace,1)[0] + random.sample(Comments,1)[0] +\
              random.sample(TabSpace,1)[0]
      else:
        print random.sample(TabSpace,1)[0] + random.sample(DotLabel,1)[0] +\
              random.sample(TabSpace,1)[0]
      if format == 0 in TestEnable:
        print random.sample(TabSpace,1)[0] + opcode +\
              random.sample(TabSpace,1)[0] + random.sample(Comments,1)[0]
      if format == 3 in TestEnable:
        regs = random.sample(Register, 3)
        reg_field = random.sample(RegLabel,1)[0] + str(regs[0]) + ',' +\
                    random.sample(TabSpace,1)[0] +\
                    random.sample(RegLabel,1)[0] + str(regs[1]) + ',' +\
                    random.sample(TabSpace,1)[0] +\
                    random.sample(RegLabel,1)[0] + str(regs[2])
        print random.sample(TabSpace,1)[0] + opcode +\
              random.sample(TabSpace,1)[0] + reg_field +\
              random.sample(TabSpace,1)[0] + random.sample(Comments,1)[0]
      if format == 1 in TestEnable:
        regs = random.sample(Register, 2)
        reg_field = random.sample(RegLabel,1)[0] + str(regs[0]) + ',' +\
                    random.sample(TabSpace,1)[0] +\
                    random.sample(RegLabel,1)[0] + str(regs[1]) + ',' +\
                    random.sample(TabSpace,1)[0] +\
                    str(random.randint(-128, 128))
        print random.sample(TabSpace,1)[0] + opcode +\
              random.sample(TabSpace,1)[0] + reg_field +\
              random.sample(TabSpace,1)[0] + random.sample(Comments,1)[0]
      if format == 2 in TestEnable:
        regs = random.sample(Register, 2)
        reg_field = random.sample(RegLabel,1)[0] + str(regs[0]) + ',' +\
                    random.sample(TabSpace,1)[0] +\
                    str(random.randint(-128, 128)) +\
                    '(' + random.sample(RegLabel,1)[0] + str(regs[1]) + ')'
        print random.sample(TabSpace,1)[0] + opcode +\
              random.sample(TabSpace,1)[0] + reg_field +\
              random.sample(TabSpace,1)[0] + random.sample(Comments,1)[0]
      if format == 4 in TestEnable:
        for i in [1,2]:
          regs = random.sample(Register, 2)
          reg_field = random.sample(RegLabel,1)[0] + str(regs[0]) + ',' +\
                      random.sample(TabSpace,1)[0] +\
                      str(random.randint(-128, 128)) +\
                      '(' + random.sample(RegLabel,1)[0] + str(regs[1]) + ')'
          print random.sample(TabSpace,1)[0] + opcode +\
                random.sample(TabSpace,1)[0] + reg_field +\
                random.sample(TabSpace,1)[0] + random.sample(Comments,1)[0]
      if format == 5 in TestEnable:
        if 'i' in opcode:
          regs = random.sample(Register, 1)
          reg_field = random.sample(RegLabel,1)[0] + str(regs[0]) + ',' +\
                      random.sample(TabSpace,1)[0] +\
                      random.sample(RegLabel,1)[0] +\
                      str(random.randint(-128, 128))
        else:
          regs = random.sample(Register, 2)
          reg_field = random.sample(RegLabel,1)[0] + str(regs[0]) + ',' +\
                      random.sample(TabSpace,1)[0] +\
                      random.sample(RegLabel,1)[0] + str(regs[1])
        print random.sample(TabSpace,1)[0] + opcode +\
              random.sample(TabSpace,1)[0] + reg_field +\
              random.sample(TabSpace,1)[0] + random.sample(Comments,1)[0]
        branch = random.sample(BranchList, 1)[0] + ' '
        if 'bc' in branch:
          reg_field = random.sample(TabSpace,1)[0] +\
                      str(random.randint(0, 15)) + ',' +\
                      random.sample(TabSpace,1)[0] +\
                      str(random.randint(0, 7)) + ',' +\
                      random.sample(TabSpace,1)[0] +\
                      str(random.randint(-128, 128)) +\
                      random.sample(TabSpace,1)[0]
        else:
          reg_field = random.sample(TabSpace,1)[0] +\
                      str(random.randint(-128, 128)) +\
                      random.sample(TabSpace,1)[0]
        print random.sample(TabSpace,1)[0] + branch +\
              random.sample(TabSpace,1)[0] + reg_field +\
              random.sample(TabSpace,1)[0] + random.sample(Comments,1)[0]
  fileinput.close()

if __name__ == '__main__':
  p2p_test()



OpenPOWER on IntegriCloud