Skip to content

Commit 2955a7a

Browse files
committed
Add test.sh to run certain tests in Docker
Add ability to run build-simulator and test-format tests in Docker.
1 parent 9afc23c commit 2955a7a

2 files changed

Lines changed: 133 additions & 0 deletions

File tree

‎docker/Dockerfile‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ RUN apt-get update -qq \
1212
# x86_64 / generic packages
1313
bash \
1414
build-essential \
15+
clang-format \
16+
clang-format-14 \
1517
cmake \
1618
git \
19+
libsdl2-dev \
20+
libpng-dev \
1721
make \
22+
ninja-build \
1823
nodejs \
1924
python3 \
2025
python3-pip \
@@ -54,6 +59,9 @@ RUN npm i lv_font_conv@1.5.2 -g
5459
# build.sh knows how to compile
5560
COPY build.sh /opt/
5661

62+
# test.sh to easily run some tests
63+
COPY test.sh /opt/
64+
5765
# Lets get each in a separate docker layer for better downloads
5866
# GCC
5967
RUN bash -c "source /opt/build.sh; GetGcc;"

‎docker/test.sh‎

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/bash
2+
(return 0 2>/dev/null) && SOURCED="true" || SOURCED="false"
3+
export LC_ALL=C.UTF-8
4+
export LANG=C.UTF-8
5+
set -e
6+
7+
# Default locations if the var isn't already set
8+
export SOURCES_DIR="${SOURCES_DIR:=/sources}"
9+
10+
main() {
11+
local target="$1"
12+
13+
case "$1" in
14+
"build-simulator")
15+
cd $SOURCES_DIR
16+
BuildSimulator $2 $3
17+
BUILD_RESULT=$?
18+
;;
19+
"test-format")
20+
cd $SOURCES_DIR
21+
TestFormat $2
22+
BUILD_RESULT=$?
23+
;;
24+
*)
25+
echo "Usage: $0 build-simulator [repo branch]"
26+
echo "Usage: $0 test-format [commit]"
27+
;;
28+
esac
29+
30+
return $BUILD_RESULT
31+
}
32+
33+
BuildSimulator() {
34+
if [ "$1" != "" ] && [ -e "$SOURCES_DIR/InfiniSim" ]
35+
then
36+
echo -e "\033[31mRepo specified and InfiniSim subfolder exists.\033[0m"
37+
return 1
38+
elif [ "$1" != "" ] && [ "$2" == "" ]
39+
then
40+
echo -e "\033[31mRepo specified, branch not specified.\033[0m"
41+
return 1
42+
elif [ "$2" != "" ]
43+
then
44+
GetSimulator $1 $2
45+
elif [ ! -d "$SOURCES_DIR/InfiniSim" ]
46+
then
47+
GetSimulator https://github.com/InfiniTimeOrg/InfiniSim.git main
48+
else
49+
echo -e "\033[33mUsing InfiniSim from InfiniSim subfolder.\033[0m"
50+
fi
51+
cmake -G Ninja -S InfiniSim -B build_lv_sim -DInfiniTime_DIR="${PWD}"
52+
BUILD_RESULT=$?
53+
[ "$BUILD_RESULT" == "0" ] || return $BUILD_RESULT
54+
cmake --build build_lv_sim --clean-first
55+
BUILD_RESULT=$?
56+
[ "$BUILD_RESULT" == "0" ] && echo -e "\033[32mSIMULATOR BUILD SUCCEEDED! \033[0m"
57+
cd $SOURCES_DIR
58+
return $BUILD_RESULT
59+
}
60+
61+
GetSimulator() {
62+
[ ! -e "$SOURCES_DIR/InfiniSim" ] || return 1
63+
trap "rm $SOURCES_DIR/InfiniSim" EXIT
64+
ln -s /tmp/InfiniSim $SOURCES_DIR/InfiniSim
65+
echo -e "\033[33mDownloading InfiniSim Git repo from: $1 $2 \033[0m"
66+
git -C /tmp clone $1 /tmp/InfiniSim --depth 1 --branch $2
67+
git -C /tmp/InfiniSim submodule update --init lv_drivers
68+
}
69+
70+
TestFormat() {
71+
CMPBASE=$1
72+
if [ "$CMPBASE" == "" ]
73+
then
74+
if [ "$(git diff --name-only upstream/main...HEAD)" != "" ]
75+
then
76+
CMPBASE=upstream/main
77+
elif [ "$(git diff --name-only origin/main...HEAD)" != "" ]
78+
then
79+
CMPBASE=origin/main
80+
else
81+
CMPBASE=main
82+
fi
83+
fi
84+
85+
echo -e "\033[33mComparing against: $CMPBASE \033[0m"
86+
CHANGED_FILES=$(git diff --name-only $CMPBASE...HEAD)
87+
CHANGED=0
88+
89+
for file in $CHANGED_FILES
90+
do
91+
[ -e "$file" ] || continue
92+
case "$file" in
93+
src/libs/*|src/FreeRTOS/*) continue ;;
94+
*.cpp|*.h)
95+
echo Checking "$file"
96+
PATCH="$(basename "$file").patch"
97+
if [ "`git clang-format-14 -q --style file --diff "$CMPBASE" "$file" | wc -c`" != "0" ]
98+
then
99+
printf "\033[94m--------------------------------------------------\033[0m\n"
100+
printf "\033[31mError:\033[0m Formatting error in %s\n" "$file"
101+
CHANGED=1
102+
git clang-format-14 --style file --diff "$CMPBASE" "$file"
103+
printf "\033[94m--------------------------------------------------\033[0m\n"
104+
fi
105+
esac
106+
done
107+
108+
if [ $CHANGED = 1 ]
109+
then
110+
return 1
111+
else
112+
printf "\033[32mNO FORMAT ERRORS DETECTED! \033[0m\n"
113+
return 0
114+
fi
115+
}
116+
117+
if [ $SOURCED = "false" ]; then
118+
# It is important to return exit code of main
119+
# To be future-proof, this is handled explicitely
120+
main "$@"
121+
BUILD_RESULT=$?
122+
exit $BUILD_RESULT
123+
else
124+
echo "Sourced!"
125+
fi

0 commit comments

Comments
 (0)