File: generate-vh-tests.sh

package info (click to toggle)
openjdk-11 11.0.4%2B11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 757,028 kB
  • sloc: java: 5,016,041; xml: 1,191,974; cpp: 934,731; ansic: 555,697; sh: 24,299; objc: 12,703; python: 3,602; asm: 3,415; makefile: 2,772; awk: 351; sed: 172; perl: 114; jsp: 24; csh: 3
file content (167 lines) | stat: -rw-r--r-- 3,801 bytes parent folder | download | duplicates (3)
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
#!/bin/bash

javac -d . ../../../../../../make/jdk/src/classes/build/tools/spp/Spp.java

SPP=build.tools.spp.Spp

# Generates variable handle tests for objects and all primitive types
# This is likely to be a temporary testing approach as it may be more
# desirable to generate code using ASM which will allow more flexibility
# in the kinds of tests that are generated.

for type in boolean byte short char int long float double String
do
  Type="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}"
  args="-K$type -Dtype=$type -DType=$Type"

  args="$args -KCAS"

  case $type in
    byte|short|char|int|long|float|double)
      args="$args -KAtomicAdd"
      ;;
  esac

  case $type in
    boolean|byte|short|char|int|long)
      args="$args -KBitwise"
      ;;
  esac

  wrong_primitive_type=boolean

  case $type in
    boolean)
      value1=true
      value2=false
      value3=false
      wrong_primitive_type=int
      ;;
    byte)
      value1=(byte)0x01
      value2=(byte)0x23
      value3=(byte)0x45
      ;;
    short)
      value1=(short)0x0123
      value2=(short)0x4567
      value3=(short)0x89AB
      ;;
    char)
      value1=\'\\\\u0123\'
      value2=\'\\\\u4567\'
      value3=\'\\\\u89AB\'
      ;;
    int)
      value1=0x01234567
      value2=0x89ABCDEF
      value3=0xCAFEBABE
      ;;
    long)
      value1=0x0123456789ABCDEFL
      value2=0xCAFEBABECAFEBABEL
      value3=0xDEADBEEFDEADBEEFL
      ;;
    float)
      value1=1.0f
      value2=2.0f
      value3=3.0f
      ;;
    double)
      value1=1.0d
      value2=2.0d
      value3=3.0d
      ;;
    String)
      value1=\"foo\"
      value2=\"bar\"
      value3=\"baz\"
      ;;
  esac

  args="$args -Dvalue1=$value1 -Dvalue2=$value2 -Dvalue3=$value3 -Dwrong_primitive_type=$wrong_primitive_type"

  echo $args
  java $SPP -nel $args < X-VarHandleTestAccess.java.template > VarHandleTestAccess${Type}.java
  java $SPP -nel $args < X-VarHandleTestMethodHandleAccess.java.template > VarHandleTestMethodHandleAccess${Type}.java
  java $SPP -nel $args < X-VarHandleTestMethodType.java.template > VarHandleTestMethodType${Type}.java
done

for type in short char int long float double
do
  Type="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}"
  args="-K$type -Dtype=$type -DType=$Type"

  BoxType=$Type
  case $type in
    char)
      BoxType=Character
      ;;
    int)
      BoxType=Integer
      ;;
  esac
  args="$args -DBoxType=$BoxType"

  case $type in
    int|long|float|double)
      args="$args -KCAS"
      ;;
  esac

  case $type in
    int|long)
      args="$args -KAtomicAdd"
      ;;
  esac

  case $type in
    int|long)
      args="$args -KBitwise"
      ;;
  esac

  # The value of `value3` is chosen such that when added to `value1` or `value2`
  # it will result in carrying of bits over to the next byte, thereby detecting
  # possible errors in endianness conversion e.g. if say for atomic addition the
  # augend is incorrectly processed
  case $type in
    short)
      value1=(short)0x0102
      value2=(short)0x1112
      value3=(short)0xFFFE
      ;;
    char)
      value1=(char)0x0102
      value2=(char)0x1112
      value3=(char)0xFFFE
      ;;
    int)
      value1=0x01020304
      value2=0x11121314
      value3=0xFFFEFDFC
      ;;
    long)
      value1=0x0102030405060708L
      value2=0x1112131415161718L
      value3=0xFFFEFDFCFBFAF9F8L
      ;;
    float)
      value1=0x01020304
      value2=0x11121314
      value3=0xFFFEFDFC
      ;;
    double)
      value1=0x0102030405060708L
      value2=0x1112131415161718L
      value3=0xFFFEFDFCFBFAF9F8L
      ;;
  esac

  args="$args -Dvalue1=$value1 -Dvalue2=$value2 -Dvalue3=$value3"

  echo $args
  java $SPP -nel $args < X-VarHandleTestByteArrayView.java.template > VarHandleTestByteArrayAs${Type}.java
done

rm -fr build