Skip to content

Commit 97bdea0

Browse files
authored
Fix & improve test worlds (#5996)
* Backport * test * test * test * Faster test * Fix * Test * Fix * Fix * Fix * Restore full test * Fix worlds * Cleanup * Remove checkout * Fixes * use diff rather than git diff * Fix branch name * Show error * Faster failure * Install runtime dependencies * Fix * Fix * Finalize * Cleanup
1 parent 77b3632 commit 97bdea0

File tree

9 files changed

+49
-47
lines changed

9 files changed

+49
-47
lines changed

.github/workflows/test_suite_linux.yml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ jobs:
127127
name: test-results-${{ matrix.os }}
128128
path: |
129129
tests/
130-
131130
test-ros:
132131
needs: build
133132
if: ${{ contains(github.event.pull_request.labels.*.name, 'test ros') || github.event_name == 'schedule' }}
@@ -171,44 +170,33 @@ jobs:
171170
if: ${{ contains(github.event.pull_request.labels.*.name, 'test worlds') || github.event_name == 'schedule' }}
172171
runs-on: ubuntu-20.04
173172
steps:
174-
- uses: actions/checkout@v3
175173
- name: Download Artifacts
176174
uses: actions/download-artifact@v2
177175
with:
178176
name: build-ubuntu-20.04
179177
path: artifact
178+
- name: Get branch name
179+
id: branch-name
180+
uses: tj-actions/[email protected]
180181
- name: Extract Webots and Cache
181182
run: |
182183
tar xjf artifact/webots-*-x86-64*.tar.bz2 -C artifact
184+
cp -R artifact/ untouched-artifact/
183185
mkdir -p ~/.cache/Cyberbotics/Webots/
184186
unzip -q artifact/assets-*.zip -d ~/.cache/Cyberbotics/Webots/assets
185-
- name: Install Webots Dependencies
186-
run: sudo scripts/install/linux_runtime_dependencies.sh
187187
- name: Set up Python 3.9
188188
uses: actions/setup-python@v2
189189
with:
190190
python-version: 3.9
191191
- name: Update World, Check Warnings and Validate Cache
192192
run: |
193-
git config --global user.name ${GITHUB_ACTOR}
194-
git config --global user.email ${GITHUB_ACTOR}@github.com
193+
wget https://raw.githubusercontent.com/cyberbotics/webots/${{ steps.branch-name.outputs.current_branch }}/scripts/install/linux_runtime_dependencies.sh && sudo bash linux_runtime_dependencies.sh
195194
export LIBGL_ALWAYS_SOFTWARE=true
196195
export WEBOTS_DISABLE_SAVE_SCREEN_PERSPECTIVE_ON_CLOSE=true
197-
xvfb-run --auto-servernum python scripts/packaging/update_urls.py $(git log -1 --format='%H')
198-
echo "Updated urls with commit $(git log -1 --format='%H')"
199-
git add -u && git commit -m "Fake-commit the updated urls so that no diff exists prior to running the test"
200196
export WEBOTS_HOME=$PWD/artifact/webots
201-
if [[ -d ~/.cache/Cyberbotics/Webots/assets/ ]]; then cached_files_before=$(ls ~/.cache/Cyberbotics/Webots/assets/ | wc -l); else cached_files_before=0; fi
202-
xvfb-run --auto-servernum python tests/test_worlds.py
203-
if [[ "$(git diff --name-only *.wbt *.wbproj | wc -l)" -ne "0" ]]; then echo Some world and/or wbproj files are not up to date: "$(git diff *.wbt *.wbproj)"; exit -1; fi
204-
if [[ -d ~/.cache/Cyberbotics/Webots/assets/ ]]; then cached_files_after=$(ls ~/.cache/Cyberbotics/Webots/assets/ | wc -l); else cached_files_after=0; fi
205-
# Note: need an offset of 22 because world 'url.wbt' uses non-cached assets on purpose
206-
if [ "$cached_files_after" -ne "$((cached_files_before + 22))" ]; then
207-
echo "Some assets are not included in the cache (before $cached_files_before, after $cached_files_after)";
208-
echo "Asset log content is:"
209-
cat ~/.cache/Cyberbotics/Webots/assets/log.txt
210-
exit 1
211-
fi
197+
wget https://raw.githubusercontent.com/cyberbotics/webots/${{ steps.branch-name.outputs.current_branch }}/tests/test_worlds.py
198+
xvfb-run --auto-servernum python3 test_worlds.py
199+
if [[ "$(diff -qr artifact/ untouched-artifact/ | wc -l)" -ne "0" ]]; then echo Some world and/or wbproj files are not up to date: "$(diff -qr artifact/ untouched-artifact/)"; exit 1; fi
212200
delete-artifacts:
213201
needs: [build, test-suite, test-ros, test-worlds]
214202
if: ${{ always() && !contains(github.event.pull_request.labels.*.name, 'test distribution') && !contains(github.event.pull_request.labels.*.name, 'test webots build') }}

.github/workflows/test_suite_linux_develop.yml

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -163,43 +163,33 @@ jobs:
163163
if: ${{ contains(github.event.pull_request.labels.*.name, 'test worlds') || github.event_name == 'schedule' }}
164164
runs-on: ubuntu-20.04
165165
steps:
166-
- uses: actions/checkout@v3
167-
with:
168-
ref: develop
169166
- name: Download Artifacts
170167
uses: actions/download-artifact@v2
171168
with:
172169
name: build-ubuntu-20.04
173170
path: artifact
171+
- name: Get branch name
172+
id: branch-name
173+
uses: tj-actions/[email protected]
174174
- name: Extract Webots and Cache
175175
run: |
176176
tar xjf artifact/webots-*-x86-64*.tar.bz2 -C artifact
177+
cp -R artifact/ untouched-artifact/
177178
mkdir -p ~/.cache/Cyberbotics/Webots/
178179
unzip -q artifact/assets-*.zip -d ~/.cache/Cyberbotics/Webots/assets
179-
- name: Install Webots Dependencies
180-
run: sudo scripts/install/linux_runtime_dependencies.sh
181180
- name: Set up Python 3.9
182181
uses: actions/setup-python@v2
183182
with:
184183
python-version: 3.9
185184
- name: Update World, Check Warnings and Validate Cache
186185
run: |
187-
git config --global user.name ${GITHUB_ACTOR}
188-
git config --global user.email ${GITHUB_ACTOR}@github.com
186+
wget https://raw.githubusercontent.com/cyberbotics/webots/${{ steps.branch-name.outputs.current_branch }}/scripts/install/linux_runtime_dependencies.sh && sudo bash linux_runtime_dependencies.sh
189187
export LIBGL_ALWAYS_SOFTWARE=true
190188
export WEBOTS_DISABLE_SAVE_SCREEN_PERSPECTIVE_ON_CLOSE=true
191-
xvfb-run --auto-servernum python scripts/packaging/update_urls.py $(git log -1 --format='%H')
192-
git add -u && git commit -m "Fake-commit the updated urls so that no diff exists prior to running the test"
193189
export WEBOTS_HOME=$PWD/artifact/webots
194-
if [[ -d ~/.cache/Cyberbotics/Webots/assets/ ]]; then cached_files_before=$(ls ~/.cache/Cyberbotics/Webots/assets/ | wc -l); else cached_files_before=0; fi
195-
xvfb-run --auto-servernum python tests/test_worlds.py
196-
if [[ "$(git diff --name-only *.wbt *.wbproj | wc -l)" -ne "0" ]]; then echo Some world and/or wbproj files are not up to date: "$(git diff *.wbt *.wbproj)"; exit -1; fi
197-
if [[ -d ~/.cache/Cyberbotics/Webots/assets/ ]]; then cached_files_after=$(ls ~/.cache/Cyberbotics/Webots/assets/ | wc -l); else cached_files_after=0; fi
198-
# Note: need an offset of 22 because world 'url.wbt' uses non-cached assets on purpose
199-
if [ "$cached_files_after" -ne "$((cached_files_before + 22))" ]; then
200-
echo "Some assets are not included in the cache (before $cached_files_before, after $cached_files_after)";
201-
exit 1
202-
fi
190+
sudo apt install -y wget && wget https://raw.githubusercontent.com/cyberbotics/webots/${{ steps.branch-name.outputs.current_branch }}/tests/test_worlds.py
191+
xvfb-run --auto-servernum python3 test_worlds.py
192+
if [[ "$(diff -qr artifact/ untouched-artifact/ | wc -l)" -ne "0" ]]; then echo Some world and/or wbproj files are not up to date: "$(diff -qr artifact/ untouched-artifact/)"; exit 1; fi
203193
delete-artifacts:
204194
needs: [build, test-suite, test-ros, test-worlds]
205195
if: ${{ always() && !contains(github.event.pull_request.labels.*.name, 'test distribution') && !contains(github.event.pull_request.labels.*.name, 'test webots build') }}

projects/robots/mobsya/thymio/worlds/thymio2.wbt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,5 @@ TexturedBackgroundLight {
2828
CircleArena {
2929
}
3030
Thymio2 {
31-
controller "thymio2_demo"
32-
controllerArgs []
3331
window "thymio2"
3432
}

projects/robots/mobsya/thymio/worlds/thymio2_ball.wbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ CircleArena {
3030
}
3131
Thymio2 {
3232
translation 0 0 1
33-
controller "thymio2_demo"
3433
window "thymio2"
3534
}
3635
Thymio2Ball {

projects/robots/mobsya/thymio/worlds/thymio2_pen.wbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ RectangleArena {
3939
}
4040
}
4141
Thymio2 {
42-
controller "thymio2_demo"
4342
window "thymio2"
4443
bodySlot [
4544
Thymio2Pen {

projects/samples/robotbenchmark/maze_runner/worlds/maze_runner.wbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ DEF THYMIO2 Thymio2 {
242242
translation -0.279509 0.02923 0.610695
243243
rotation 0.0014800006661173696 0.9997794499798363 0.020949009428711335 -0.014665
244244
controller "move_in_maze"
245-
controllerArgs []
246245
}
247246
MazeRunnerBenchmark {
248247
}

projects/samples/robotbenchmark/obstacle_avoidance/worlds/obstacle_avoidance.wbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ DEF THYMIO2 Thymio2 {
5858
translation 0 -2.68 0
5959
rotation 0 0 -1 -1.570795
6060
controller "avoid_obstacles"
61-
controllerArgs []
6261
bodySlot [
6362
Compass {
6463
}

projects/samples/robotbenchmark/robot_programming/worlds/robot_programming.wbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ CircleArena {
3838
DEF THYMIO2 Thymio2 {
3939
rotation 0 0 1 3.14159
4040
controller "move"
41-
controllerArgs []
4241
}
4342
RobotProgrammingBenchmark {
4443
}

tests/test_worlds.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@
1919
import os
2020
import fnmatch
2121
import sys
22+
import platform
2223
from subprocess import Popen, PIPE, TimeoutExpired
2324

2425
if sys.version_info[0] != 3 or sys.version_info[1] < 7:
2526
sys.exit('This script requires Python version 3.7')
2627

28+
if platform.system() == 'Darwin':
29+
CACHE_DIR = os.path.join(os.path.expanduser('~'), 'Library', 'Caches', 'Cyberbotics', 'Webots', 'assets')
30+
elif platform.system() == 'Linux':
31+
CACHE_DIR = os.path.join(os.path.expanduser('~'), '.cache', 'Cyberbotics', 'Webots', 'assets')
32+
elif platform.system() == 'Windows':
33+
CACHE_DIR = os.path.join(os.path.expanduser('~'), 'AppData', 'Local', 'Cyberbotics', 'Webots', 'cache', 'assets')
34+
2735

2836
class TestWorldsWarnings(unittest.TestCase):
2937
"""Unit test of the worlds."""
@@ -64,10 +72,12 @@ def setUp(self):
6472
sys.exit(1)
6573
self.webotsFullPath = os.path.normpath(self.webotsFullPath)
6674

67-
def test_worlds_warnings(self):
68-
"""Test all the 'projects' worlds for loading warnings."""
75+
def test_worlds_warnings_and_cache(self):
76+
"""Test all the 'projects' worlds for loading warnings and if they reference un-cached assets."""
6977
problematicWorlds = []
7078
crashedWorlds = []
79+
worldsWithNonCachedAssets = []
80+
cacheSizeBefore = len(os.listdir(CACHE_DIR))
7181
for i in range(len(self.worlds)):
7282
print('Testing: %d/%d: %s' % (i + 1, len(self.worlds), self.worlds[i]))
7383
self.process = Popen([
@@ -93,13 +103,34 @@ def test_worlds_warnings(self):
93103
problematicWorlds.append(self.worlds[i])
94104
if errors and self.crashError in str(errors):
95105
crashedWorlds.append(self.worlds[i])
106+
107+
# url.wbt and camera.wbt are exceptional as they contain non-cached assets on purpose, adapt cache size accordingly
108+
worldName = os.path.basename(self.worlds[i])
109+
if worldName == 'url.wbt':
110+
cacheSizeBefore += 22
111+
if worldName == 'camera.wbt':
112+
cacheSizeBefore += 26
113+
114+
cacheSizeAfter = len(os.listdir(CACHE_DIR))
115+
if cacheSizeAfter - cacheSizeBefore > 0:
116+
worldsWithNonCachedAssets.append(self.worlds[i])
117+
cacheSizeBefore = cacheSizeAfter # update the counter so it doesn't trigger again for the same reason
118+
96119
if crashedWorlds:
97120
print('\n\t'.join(['Impossible to test the following worlds because they crash when loading:'] + crashedWorlds))
98121
self.assertTrue(
99122
not problematicWorlds,
100123
msg='\n\t'.join(['The following worlds have unwanted warnings:'] + problematicWorlds)
101124
)
102125

126+
if worldsWithNonCachedAssets:
127+
print('\nThe following worlds reference non-cached assets:')
128+
for world in worldsWithNonCachedAssets:
129+
print('- ' + world)
130+
131+
if crashedWorlds or problematicWorlds or worldsWithNonCachedAssets:
132+
self.fail('Problematic worlds have been found.')
133+
103134

104135
if __name__ == '__main__':
105136
unittest.main()

0 commit comments

Comments
 (0)