Skip to content

Commit

Permalink
ci: fix crash bug and recording gif in test
Browse files Browse the repository at this point in the history
  • Loading branch information
Chance.H committed Sep 11, 2024
1 parent b474b19 commit 729002f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 40 deletions.
68 changes: 60 additions & 8 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
sudo apt update
sudo apt install --fix-missing -y doxygen graphviz clang-format clang-tidy cppcheck lcov
sudo apt install --fix-missing -y gcc g++ libspdlog-dev libcgal-dev freeglut3-dev libboost-all-dev libvtk9-dev qtbase5-dev xorg-dev libglu1-mesa-dev libglm-dev libglfw3-dev libglew-dev
sudo apt-get install --no-install-recommends -y xvfb
sudo apt-get install --no-install-recommends -y xvfb ffmpeg
- name: Build
run: |
Expand All @@ -59,21 +59,47 @@ jobs:
- name: Start Xvfb
run: |
nohup Xvfb :99 -screen 0 1024x768x24 &
nohup Xvfb :99 -screen 0 800x600x24 &
echo "DISPLAY=:99" >> $GITHUB_ENV
- name: Run demo2d
run: |
for i in {1..7}; do
./build/bin/demo2d --test --instruction $i
# Start recording with ffmpeg
ffmpeg -y -f x11grab -video_size 800x600 -i :99 -t 5 -r 10 ./build/bin/demo2d_$i.gif &
FFmpeg_PID=$!
# Run the demo2d program in the background
./build/bin/demo2d --instruction $i &
Demo2d_PID=$!
# Wait for 5 seconds
sleep 5
# Stop the ffmpeg recording
kill $FFmpeg_PID
# Terminate the demo2d program
kill $Demo2d_PID
done
env:
DISPLAY: :99

- name: Run MassSpring3D
run: ./build/bin/MassSpring3D --test --instruction 1
run: |
for i in {1..1}; do
ffmpeg -y -f x11grab -video_size 800x600 -i :99 -t 5 -r 10 ./build/bin/MassSpring3D_$i.gif &
FFmpeg_PID=$!
./build/bin/MassSpring3D --instruction $i &
MassSpring3D_PID=$!
sleep 5
kill $FFmpeg_PID
kill $MassSpring3D_PID
done
env:
DISPLAY: :99

- name: Upload GIFs
uses: actions/upload-artifact@v3
with:
name: gifs
path: build/bin/*.gif

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
Expand All @@ -98,7 +124,7 @@ jobs:
- name: Start Xvfb
run: |
sudo Xvfb :99 -screen 0 1024x768x24 &
sudo Xvfb :99 -screen 0 800x600x24 &
echo "DISPLAY=:99" >> $GITHUB_ENV
- name: Build
Expand All @@ -109,20 +135,46 @@ jobs:
- name: Run demo2d
run: |
for i in {1..7}; do
./build/bin/demo2d --test --instruction $i
# Start recording with ffmpeg
ffmpeg -y -f x11grab -video_size 800x600 -i :99 -t 5 -r 10 ./build/bin/demo2d_$i.gif &
FFmpeg_PID=$!
# Run the demo2d program in the background
./build/bin/demo2d --instruction $i &
Demo2d_PID=$!
# Wait for 5 seconds
sleep 5
# Stop the ffmpeg recording
kill $FFmpeg_PID
# Terminate the demo2d program
kill $Demo2d_PID
done
env:
DISPLAY: :99

- name: Run MassSpring3D
run: ./build/bin/MassSpring3D --test --instruction 1
run: |
for i in {1..1}; do
ffmpeg -y -f x11grab -video_size 800x600 -i :99 -t 5 -r 10 ./build/bin/MassSpring3D_$i.gif &
FFmpeg_PID=$!
./build/bin/MassSpring3D --instruction $i &
MassSpring3D_PID=$!
sleep 5
kill $FFmpeg_PID
kill $MassSpring3D_PID
done
env:
DISPLAY: :99

- name: Upload GIFs
uses: actions/upload-artifact@v3
with:
name: gifs
path: build/bin/*.gif

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: build/coverage/coverage.info
verbose: true
# @bug 在 osx 下无法正常执行 lcov
# cmake --build build --target coverage
# cmake --build build --target coverage
23 changes: 5 additions & 18 deletions test/system_test/MassSpring3D/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const unsigned int WINDOW_HEIGHT = 600;
static ClothSimulation scene(WINDOW_WIDTH, WINDOW_HEIGHT, { 0, -9.8 });
// static ProgramInput* g_render_target; // vertex, index

bool TEST = false;
char INSTRUCTION = '0';

static void checkGlErrors();
Expand Down Expand Up @@ -81,15 +80,6 @@ void display() {
auto dt = std::chrono::duration_cast<std::chrono::duration<double>>(
now - last_clock)
.count();
if (TEST) {
auto total_time = std::chrono::duration_cast<std::chrono::duration<double>>(
now - init_clock)
.count();
if (total_time > 5.0) {
std::cout << "TEST " << INSTRUCTION << "." << std::endl;
exit(1);
}
}
last_clock = now;

int h = glutGet(GLUT_WINDOW_HEIGHT);
Expand Down Expand Up @@ -181,10 +171,10 @@ static void initGlutState(int argc, char** argv, const char* window_title = "",

static void initGlewState() {
GLenum err = glewInit();
// if (!glewIsSupported("GL_VERSION_2_0")) {
// printf("OpenGL 2.0 not supported\n");
// exit(1);
// }
if (!glewIsSupported("GL_VERSION_2_0")) {
printf("OpenGL 2.0 not supported\n");
exit(1);
}
if (err != GLEW_OK) {
std::cerr << "Error initializing GLEW: " << glewGetErrorString(err) << std::endl;
exit(0);
Expand Down Expand Up @@ -218,10 +208,7 @@ static void initGLState() {
int main(int argc, char* argv[]) {
// Parse command line arguments
for (int i = 1; i < argc; ++i) {
if (std::strcmp(argv[i], "--test") == 0) {
TEST = true;
}
else if (std::strcmp(argv[i], "--instruction") == 0 && i + 1 < argc) {
if (std::strcmp(argv[i], "--instruction") == 0 && i + 1 < argc) {
INSTRUCTION = argv[++i][0];
}
}
Expand Down
15 changes: 1 addition & 14 deletions test/system_test/demo2d/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const unsigned int SCREEN_WIDTH = 800;
const unsigned int SCREEN_HEIGHT = 600;
static FemSimulation world({ 0, -9.8 });

bool TEST = false;
char INSTRUCTION = '0';

static void draw_text(int x, int y, const char* format, ...) {
Expand Down Expand Up @@ -296,15 +295,6 @@ void display() {
auto dt = std::chrono::duration_cast<std::chrono::duration<double>>(
now - last_clock)
.count();
if (TEST) {
auto total_time = std::chrono::duration_cast<std::chrono::duration<double>>(
now - init_clock)
.count();
if (total_time > 5.0) {
std::cout << "TEST " << INSTRUCTION << "." << std::endl;
exit(0);
}
}

last_clock = now;

Expand Down Expand Up @@ -420,10 +410,7 @@ void idle() { display(); }
int main(int argc, char* argv[]) {
// Parse command line arguments
for (int i = 1; i < argc; ++i) {
if (std::strcmp(argv[i], "--test") == 0) {
TEST = true;
}
else if (std::strcmp(argv[i], "--instruction") == 0 && i + 1 < argc) {
if (std::strcmp(argv[i], "--instruction") == 0 && i + 1 < argc) {
INSTRUCTION = argv[++i][0];
}
}
Expand Down

0 comments on commit 729002f

Please sign in to comment.