xref: /trunk/test/odf-validate/fixtures/base/run.sh (revision 0e16a31d78a652c56c5c0fc79c752f48b9048df9)
1#!/bin/zsh
2#**************************************************************
3#
4#  Licensed to the Apache Software Foundation (ASF) under one
5#  or more contributor license agreements.  See the NOTICE file
6#  distributed with this work for additional information
7#  regarding copyright ownership.  The ASF licenses this file
8#  to you under the Apache License, Version 2.0 (the
9#  "License"); you may not use this file except in compliance
10#  with the License.  You may obtain a copy of the License at
11#
12#    http://www.apache.org/licenses/LICENSE-2.0
13#
14#  Unless required by applicable law or agreed to in writing,
15#  software distributed under the License is distributed on an
16#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17#  KIND, either express or implied.  See the License for the
18#  specific language governing permissions and limitations
19#  under the License.
20#
21#**************************************************************
22# usage: run.sh gen|verify   -- builds or reloads the base-*.odb corpus in strict and ext mode (ports 2130-2133)
23# A fresh profile is made for every office start: a profile left by a crashed office does not come up again.
24source ${0:A:h:h:h}/env.sh
25G=$D/runs/task12/gen-base
26what=$1
27
28fresh() {  # fresh <profile name> <DefaultVersion> <port>
29  [[ $1 == t12_base_* ]] || { echo "run.sh: bad profile $1" >&2; exit 2; }
30  pkill -f "[p]rofile_$1"; sleep 1
31  /bin/rm -rf "${D:?}/runs/profile_${1:?}"
32  mkdir -p $D/runs/profile_$1/user
33  cat > $D/runs/profile_$1/user/registrymodifications.xcu <<XCU
34<?xml version="1.0" encoding="UTF-8"?>
35<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
36<item oor:path="/org.openoffice.Office.Common/Save/ODF"><prop oor:name="DefaultVersion" oor:op="fuse"><value>$2</value></prop></item>
37</oor:items>
38XCU
39  dismiss &
40  dp=$!
41  $D/start.sh $1 $3; rc=$?
42  kill $dp 2>/dev/null
43  return $rc
44}
45
46dismiss() {  # after a crash macOS asks whether to reopen windows; clicks the first soffice window, which may be another session's
47  for i in {1..90}; do
48    osascript -e 'tell application "System Events" to tell process "soffice" to click button "Don’t Reopen" of window 1' >/dev/null 2>&1 && return
49    sleep 1
50  done
51}
52
53if [[ $what == gen ]]; then
54  for m in strict:4:2130 ext:3:2131; do
55    n=${m%%:*}; rest=${m#*:}; v=${rest%%:*}; port=${rest##*:}
56    /bin/rm -rf "${G:?}/${n:?}/out" "${G:?}/work/${n:?}"
57    mkdir -p $G/$n/out
58    fresh t12_base_$n $v $port || exit 1
59    gtimeout 600 $D/runpy.sh fixtures/base/make.py $port $G/$n/out $G/work/$n
60    pkill -f "[p]rofile_t12_base_$n"
61  done
62elif [[ $what == verify ]]; then
63  for m in strict:4:2132 ext:3:2133; do
64    n=${m%%:*}; rest=${m#*:}; v=${rest%%:*}; port=${rest##*:}
65    for f in $G/$n/out/base-*.odb; do
66      for try in 1 2 3; do
67        fresh t12_base_verify_$n $v $port || continue
68        out=$(gtimeout 120 $D/runpy.sh fixtures/base/verify.py $port $G/$n/out ${f:t} 2>&1 | tail -1)
69        pkill -f "[p]rofile_t12_base_verify_$n"
70        [[ $out == base-* ]] && { echo "[$n] try=$try $out"; break; }
71        echo "[$n] try=$try ${f:t} FAILED: ${out:0:120}"
72      done
73    done
74  done
75else
76  echo "usage: run.sh gen|verify" >&2; exit 2
77fi
78