aboutsummaryrefslogtreecommitdiff
path: root/dacapo/setup_dacapo.sh
blob: 1f200c4cbe1b5a93aba8a8c8bdb42a6db5be3239 (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
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
#!/bin/bash
#
# Copyright (C) 2021 Linaro Limited. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

unset DEST_DIR

readonly local_path="$(dirname "$0")"
source "${local_path}/../utils/utils.sh"

readonly usage="Usage: $(basename "$0") -d dest_dir
Setup DaCapo binaries and resource files and workloads runners into
a provided destination directory.

Options:
    -h                  Show this help message.
    -d                  Path to the AOSP tree root.
    -u                  Uninstall only.
"

# Remove existing DaCapo files
remove_existing() {
  if [[ -d ${RUNNERS_DIR} ]]; then
    info "Removing runners"
    safe rm -r ${RUNNERS_DIR}
  fi
  if [[ -d ${FRAMEWORK_DIR} ]]; then
    info "Removing framework code"
    safe rm -r ${FRAMEWORK_DIR}
  fi
  if [[ -f ${LIB_DIR}/dacapo.jar ]]; then
    info "Removing dacapo.jar"
    safe rm ${LIB_DIR}/dacapo.jar
  fi
  if [[ -d ${DACAPO_RESOURCES_DIR} ]]; then
    info "Removing resources"
    safe rm -rf ${DACAPO_RESOURCES_DIR}
  fi
}

setup_dacapo_variables() {
  readonly RUNNERS_DIR=${DEST_DIR}/benchmarks/benchmarks/dacapo
  readonly FRAMEWORK_DIR=${DEST_DIR}/benchmarks/framework/benchmarks/dacapo
  readonly DACAPO_RESOURCES_DIR=${DEST_DIR}/benchmarks/benchmarks/resources/dacapo
  readonly LIB_DIR=${DEST_DIR}/benchmarks/benchmarks/lib
}

main() {
  local UNINSTALL_ONLY=false

  while getopts ":hd:u" option; do
    if [[ ${OPTARG} == -* ]]; then
      exit_with_error "Option -${option} requires an argument." >&2
    fi
    case "${option}" in
      h) info "${usage}"; exit ;;
      d) DEST_DIR=${OPTARG};
        setup_dacapo_variables
        ;;
      u)  UNINSTALL_ONLY=true ;;
      \?)
        error "Illegal option: -${OPTARG}" >&2
        error "${usage}"
        exit 1
        ;;
      :)
        exit_with_error "Option -${OPTARG} requires an argument." >&2
        ;;
    esac
  done

  if [ -z ${DEST_DIR} ]; then
    exit_with_error "Please, use -d argument to specify the location of Linaro tree."
  fi

  if [ ! -d ${DEST_DIR} ]; then
    exit_with_error "The directory ${DEST_DIR} does not exist. Please specify a valid path" \
                    "to your Linaro tree."
  fi

  validate_java

  cd "${local_path}"


  # uninstall DaCapo if it is already installed
  info "Removing existing DaCapo files if possible"
  remove_existing
  if [[ ${UNINSTALL_ONLY} = true ]]; then
    exit
  fi

  # copy runners code
  info "Copying wrappers"
  if [[ ! -d ${RUNNERS_DIR} ]]; then
    safe mkdir -p ${RUNNERS_DIR}
  fi
  safe cp -r wrappers/dacapo/. ${RUNNERS_DIR}

  #copy framework code
  if [[ ! -d ${FRAMEWORK_DIR} ]]; then
    safe mkdir -p ${FRAMEWORK_DIR}
  fi
  safe cp -r framework/dacapo/. ${FRAMEWORK_DIR}

  # build DaCapo
  if [[ -d dacapo_src ]]; then
    safe rm -rf dacapo_src
  fi
  mkdir dacapo_src
  cd dacapo_src

  local -r DACAPO_REPO="https://github.com/dacapobench/dacapobench.git"
  info "Cloning ${DACAPO_REPO} into dacapo_src..."
  safe git clone --branch master ${DACAPO_REPO}

  safe cd dacapobench
  # commit id that is used as a base for all patches
  local -r DACAPO_COMMIT="6cf03808b686896eb092c038d6add7d9384f03f5"
  info "Reseting to ${DACAPO_COMMIT}"
  safe git reset --hard ${DACAPO_COMMIT}

  info "Applying patches..."
  safe patch -p1 <../../patches/dacapo_patch.patch

  safe cd benchmarks

  # See https://github.com/dacapobench/dacapobench/tree/dev-chopin "Building" section
  # for more info on how to build DaCapo
  info "Building DaCapo benchmarks..."
  safe ant

  # Ant is expected to package everything into JAR file
  # with the name that includes commit id
  local -r GENERATED_JAR_NAME="dacapo-9.12-MR1-git+6cf03808.jar"
  safe mv ${GENERATED_JAR_NAME} dacapo.jar

  # Removing these JAR files to fix an error for duplicate .class files
  safe zip -d dacapo.jar /jar/dacapo-digest.jar
  safe zip -d dacapo.jar /jar/xercesImpl.jar /jar/xml-apis.jar
  safe zip -d dacapo.jar /jar/derby.jar /jar/derbyclient.jar /jar/derbynet.jar /jar/derbytools.jar

  info "Copying dacapo.jar..."
  if [[ ! -d ${LIB_DIR} ]]; then
    safe mkdir -p ${LIB_DIR}
  fi
  safe cp dacapo.jar ${LIB_DIR}/

  safe mkdir -p ${DACAPO_RESOURCES_DIR}/dat
  safe mkdir -p ${DACAPO_RESOURCES_DIR}/cnf

  local -r DACAPO_PATCHES_DIR="../../../patches"
  #avrora
  info "Copying Avrora files..."
  safe patch bms/avrora/avrora.cnf <${DACAPO_PATCHES_DIR}/avrora_conf.patch
  safe cp bms/avrora/dist/dat/* ${DACAPO_RESOURCES_DIR}/dat/
  safe cp bms/avrora/*.cnf ${DACAPO_RESOURCES_DIR}/cnf/

  #h2
  info "Copying H2 files..."
  safe patch bms/h2/h2.cnf <${DACAPO_PATCHES_DIR}/h2_conf.patch
  safe cp bms/h2/*.cnf ${DACAPO_RESOURCES_DIR}/cnf/

  #xalan
  info "Copying Xalan files..."
  safe patch bms/xalan/xalan.cnf <${DACAPO_PATCHES_DIR}/xalan_conf.patch
  safe cp bms/xalan/dist/dat/* ${DACAPO_RESOURCES_DIR}/dat/
  safe cp bms/xalan/*.cnf ${DACAPO_RESOURCES_DIR}/cnf/
}

main "$@"