Skip to content

build.yml

build.yml #3

Workflow file for this run

name: Build CAN Analyzer
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libc6-dev gcc make gnuplot
- name: Build project
run: make
- name: Run mock test
run: |
# Create a mock CAN data file
echo "0 123 8 DE AD BE EF 00 00 00 00" > mock_can_data.log
echo "1 456 8 01 23 45 67 89 AB CD EF" >> mock_can_data.log
# Modify CAN Analyzer to read from file instead of CAN interface
sed -i 's/can_receive(socket_fd, &frame)/read_mock_can_data("mock_can_data.log", &frame)/' src/main.c
# Add mock function to main.c
echo "
#include <stdio.h>
int read_mock_can_data(const char* filename, struct can_frame *frame);
int read_mock_can_data(const char* filename, struct can_frame *frame) {
static FILE *file = NULL;
if (!file) file = fopen(filename, \"r\");
if (!file) return -1;
unsigned int id;
int dlc;
if (fscanf(file, \"%*d %x %d\", &id, &dlc) != 2) {
fclose(file);
file = NULL;
return -1;
}
frame->can_id = id;
frame->can_dlc = dlc;
for (int i = 0; i < dlc; i++) {
unsigned int byte;
fscanf(file, \"%x\", &byte);
frame->data[i] = byte;
}
return 0;
}" >> src/main.c
# Rebuild the project
make
# Run CAN Analyzer with mock data
./can_analyzer mock &
CAN_PID=$!
# Wait for a moment to allow processing
sleep 5
# Kill CAN Analyzer
kill $CAN_PID
# Check if graph was generated
if [ -f can_data.png ]; then
echo "Graph generated successfully"
else
echo "Graph generation failed"
exit 1
fi
- name: Upload graph artifact
uses: actions/upload-artifact@v2
with:
name: can-data-graph
path: can_data.png