-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_test_env.sh
More file actions
executable file
·53 lines (43 loc) · 1.43 KB
/
setup_test_env.sh
File metadata and controls
executable file
·53 lines (43 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Setup script for CANSocket test environment
# This script creates virtual CAN interfaces needed for testing
set -e
echo "Setting up virtual CAN interfaces for testing..."
# Check if running as root or with sudo
if [ "$EUID" -ne 0 ]; then
echo "This script requires root privileges. Please run with sudo."
exit 1
fi
# Load vcan kernel module
echo "Loading vcan kernel module..."
if ! lsmod | grep -q vcan; then
modprobe vcan
echo "vcan module loaded successfully"
else
echo "vcan module already loaded"
fi
# Function to create virtual CAN interface
create_vcan_interface() {
local interface=$1
# Check if interface already exists
if ip link show "$interface" &>/dev/null; then
echo "Interface $interface already exists"
# Make sure it's up
ip link set up "$interface"
else
echo "Creating virtual CAN interface: $interface"
ip link add dev "$interface" type vcan
ip link set up "$interface"
echo "Interface $interface created and brought up"
fi
}
# Create test interfaces
create_vcan_interface "vcan0"
create_vcan_interface "vcan1"
echo ""
echo "Virtual CAN interfaces setup complete!"
echo "Available CAN interfaces:"
ip link show | grep -E "(vcan|can)" || echo "No CAN interfaces found"
echo ""
echo "You can now run the tests with: ./build.sh"
echo "To remove the interfaces later, run: sudo ip link delete vcan0 && sudo ip link delete vcan1"